sparkfun / SparkFun_Bio_Sensor_Hub_Library

25 stars 33 forks source link

ESP32 - Gap in raw data #26

Open christian-nils opened 1 year ago

christian-nils commented 1 year ago

Hi,

Thanks for this library. I bought the oximeter sensor from Sparkfun (https://www.sparkfun.com/products/15219). I am trying to read the IR led count data but there are some periodic gaps in the data. Here is a short excerpt of the Serial monitor: https://pastebin.com/85jETjyG

Here is a graph showing periodic plateaus in the data (which are typically just gaps in data as the ESP32 is just polling the same value until a new value is available).

Screenshot from 2023-06-02 21-07-59

I have the same behaviour when reading the data only on interrupt and when the data ready flag is set to 1 (I am using ESP-IDF for that test):

image

The code I used when using the Arduino library is the following:

#include <SparkFun_Bio_Sensor_Hub_Library.h>
#include <Wire.h>

// No other Address options.
#define DEF_ADDR 0x55

// Reset pin, MFIO pin
const int resPin = 26;
const int mfioPin = 25;

//#define SDA 21
//#define SCL 22

//#define SDA 27
//#define SCL 14

// Possible widths: 69, 118, 215, 411us
int width = 69; 
// Possible samples: 50, 100, 200, 400, 800, 1000, 1600, 3200 samples/second
// Not every sample amount is possible with every width; check out our hookup
// guide for more information.
int samples = 1600; 
int pulseWidthVal;
int sampleVal;

// Takes address, reset pin, and MFIO pin.
SparkFun_Bio_Sensor_Hub bioHub(resPin, mfioPin); 

bioData body; 

// following data: 
// body.irLed      - Infrared LED counts. 
// body.redLed     - Red LED counts. 
// body.heartrate  - Heartrate
// body.confidence - Confidence in the heartrate value
// body.oxygen     - Blood oxygen level
// body.status     - Has a finger been sensed?

void setup(){

  Serial.begin(115200);

  Wire.begin();
  int result = bioHub.begin();

  int error = bioHub.configSensor(); // Configure Sensor

  error = bioHub.setPulseWidth(width);
  error = bioHub.setSampleRate(samples);

  delay(1000);

}

void loop(){

    // Information from the readSensor function will be saved to our "body"
    // variable.  
    body = bioHub.readSensor();
    Serial.println(body.irLed); 
//    Serial.print("  ");
//    Serial.println(body.redLed); 
    // Slow it down or your heart rate will go up trying to keep up
    // with the flow of numbers
}

Any idea why I get those periodic gap in the raw data?

Thanks in advance!

edspark commented 1 year ago

Thanks for the issue, it's on my list and I'll get to this issue if not today, then tomorrow!

christian-nils commented 1 year ago

Thank you for looking into that. From my long investigation during the last days, I can see the following points (in the case you use MFIO as interrupt line):

MicrosoftTeams-image (16)

Anyway, maybe some stuff is wrong (or everything), but I thought that it was worth mentioning those results if it helps. I will use the "counter" from the payload to sync the data.

edspark commented 1 year ago

Thanks for the follow up, this may help quite a bit. This library has a few open issues that I'd like to tackle simultaneously as they have a common thread with the ESP32 platform. Unfortunately I got bludgeoned with illness last week and I'll need to do some catch up on my current projects before I get to this. I expect I'll have some time midweek. Talk to you soon.

christian-nils commented 1 year ago

Thanks for following up :-) I hope you are feeling fine again, take care and good luck with all the catching-up! Let me know if I can help in any ways!

edspark commented 1 year ago

I suspect it has something to do with the "CMD_DELAY" being significantly reduced in later firmware releases but I still need to test with a board that has the latest firmware which I do not have. This is still ongoing, thank you for your patience.