WorldFamousElectronics / PulseSensorPlayground

A PulseSensor library (for Arduino) that collects our most popular projects in one place.
https://PulseSensor.com
MIT License
204 stars 98 forks source link

PulseSensor + Feather nRF52840 Bluefruit LE #133

Closed marcjan closed 4 years ago

marcjan commented 4 years ago

Hi,

I bought original PulseSensor and Feather nRF52840 Bluefruit LE, but values which I get are very bad - doesnt looks like heartbeat. image Heartbeats are not detected, condition if sawStartOfBeat is always false. I use the code from alternative sketch. I read other issues which describe problem with timer, is there any easy workaround for that?

Edit I tried also with laptop on battery and there is still the same problem.

Thanks Marcin

biomurph commented 4 years ago

@marcjan That does not look like a good signal at all. Please send a picture of your physical setup. That can help sometimes. What pin are you connecting the Pulse Sensor to? Also, what exact Adafruit module are you using? They have a few nRF52840 boards.

marcjan commented 4 years ago

@biomurph Thanks for quick response :)

https://www.adafruit.com/product/4516 image

I soldered directly GND and VCC to board and results are far better, but they are too high (comparing to SGS8+ pulsemeter). A2 Has signal from Pulsesensor.

image

Edit Ok, results looks good ) I will try to compare with another device :)

Thanks!

biomurph commented 4 years ago

OK, that looks much better on the plotter.

OK, what will you compare it to?

marcjan commented 4 years ago

With some professional medical device. So there is no timer problems on nRF52840 (Ive seen some issues)?

biomurph commented 4 years ago

Some folks have worked out hardware timer issues, but they are not tested by us so not in the library. Check the issues tab for the thread that goes into it. Reach out to them there, as they may share code

marcjan commented 4 years ago

Hi again ;)

It looks like results from pulsesensor are wrong. While correct result on medical device is 59bpms pulsesensor shows ~83. I left only pulsesensor code. Results usually are 30bpms higher. Board works with 3.3V. I get the results in following way:

const int THRESHOLD = 500;   // Adjust this number to avoid noise when idle
const byte SAMPLES_PER_SERIAL_SAMPLE = 10;

if (pulseSensor.sawNewSample()) {

  if (--samplesUntilReport == (byte) 0) {

    samplesUntilReport = SAMPLES_PER_SERIAL_SAMPLE;

    if (pulseSensor.sawStartOfBeat()) {

      // I use this function when I send it over Bluetooth

      uint16_t heartBeatValue = pulseSensor.getBeatsPerMinute();

      // I use this function to debug it in serial monitor

      pulseSensor.outputBeat();

    }
  }
}

Thank you for help Marcin

biomurph commented 4 years ago

@marcjan Ah yes, I'm remembering now. There is a known issue with the nRF52 timing. The micros() function (which we use in the library) is stunningly low resolution Here's a post about the issue https://github.com/adafruit/Adafruit_nRF52_Arduino/issues/451 Also, There is an other issue thread that discusses the problem here https://github.com/WorldFamousElectronics/PulseSensorPlayground/issues/129

This is a feature that we want to include in future library functionality. It's not there yet. If you go to that other issue (129) and @ the author, you may get their attention and ask them to share their solution?

Our timeline for addressing and testing this for the library may be longer than you need for your purpose.

marcjan commented 4 years ago

@biomurph Ok, thx for clarification and help.

Best regards Marcin

marcjan commented 4 years ago

@biomurph I have ported the code to xmega and setup 2ms interrupts with 12 bits ADC (0-4096). Could you tell me how I should calibrate these variables, cause my readings are now about 108 BPM which are much to high: P, T, threshold and IBI. Currently I have: P- 3100, T- 3100, threshold - 3201, amplitude - 100, IBI - 750, obraz above screen with values I get. Heartbeat around ~108 and IBI around ~560 Seond trial with better grapped sensor obraz

Thanks Marcin

biomurph commented 4 years ago

@marcjan
I don't think I understand what you mean by 'ported to xmega' The serial feed you're showing has the numbers going from very high to very low. There's not enough information to really help you debug. Can you share your code? Do you have a link to a repo with the code? Also, details on the hardware you're using. Can you verify that you are getting a 500Hz interrupt?

marcjan commented 4 years ago

@biomurph Xmega128a3-AU Screens above show in one line BPM and in next one IBI and again and again... I found that internal oscillator is very inaccurate, so I put external one (16 Mhz) here is the code: https://gist.github.com/marcjan/3203eb519b16e9735288f3e3799cca4a Still results are bad I get around 115bpm.. Could look at the code? Oh and Im using interrupts

EDIT Ok I found bug in my code, seems like everything working fine now :)

Thanks Marcin

biomurph commented 4 years ago

@marcjan it looks like the link to your repo is broken. Can you tell me what your bug was? I'm very curious.

marcjan commented 4 years ago

@biomurph Thanks for your time again. I was turning off/on timer instead of disabling and enabling interrupts :) BTW when you plan to make your code compataible with Adafruit Feather nRF52840 Bluefruit Sense LE?

biomurph commented 4 years ago

Thanks for letting me know your bug

We will be testing this fall

marcjan commented 1 year ago

Hello @biomurph :)

It's been some time since last post :) Did you manage to make a code compatible with the Adafruit Feather nRF52840?

Thanks, Marcin

biomurph commented 1 year ago

@marcjan i think this is the best lead for a reliable timer interrupt source for the nRF52 boards. I think it also includes the Feather variant that your are talking about in the issue title. This would be my first route for testing with Pulse Sensor Playground. Would you like to try? https://github.com/khoih-prog/NRF52_TimerInterrupt