WorldFamousElectronics / PulseSensorPlayground

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

How many signals does the sensor take within a second? #134

Closed DoanThu closed 3 years ago

DoanThu commented 3 years ago

Actually I tried to get the execution time and printed out all the signal points into a text file through Processing. I did it many times and realize that each signal point is collected every 10ms. Just to clarify with you whether it is correct. Also, is there any way I can determine this interval based on baud only? image The image above shows that within 37k mS I have around 3k6 data points. (I am using 4 sensors in total with baud 250000)

biomurph commented 3 years ago

@DoanThu The answer is, well it kind of depends... What hardware platform are you using? If you are using a micro controller that the PulseSensor Playground supports hardware interrupts, then you are getting a tight 500Hz sample rate. If you are using a micro controller that does not have hardware interrupts integrated, then we are using a software timer to get as close as we can to 500Hz sample rate.

Then there's the serial connection. Right now, we are not sending every sample to the serial port. In the basic example sketch PulseSensor_BPM.ino, for example, which uses hardware interrupts, we have a 20mS delay in the loop. That's so that we don't overwhelm the serial port, since the visualizers (arduino plotter and our own processing sketch) don't need all the data to create a trace. The PulseSensor_BPM_Alternative.ino sketch uses software interrupts, and it also doesn't send every sample to the serial port.

While we don't ship every sample to the serial port, we do use every sample to calculate the heart rate on the hardware. That data is all sent (samples, BPM, IBI) to the serial port for visualization.

There are some code stubs somewhere that seek to get every sample into Processing and store it all in a file, but it's not ready for prime time.