Pulse Sensor Amped Incompatible with OS 5.3.0

I use the Pulse Sensor Amped with my students and the PulseSensorAmped library has worked fine, including on OS 5.0.0 and 5.0.1.

However, when the Argon has 5.3.0 firmware, flashing project with the PulseSensorAmped library immediately sends the device in SOS mode (flashing red). I’m pretty sure that it was Assertion failure.

Does anyone know if there is a workaround for this library and OS 5.3.0?

Which library are you using? There are two different libraries listed at that link.

The library I’m using is listed as PulseSensorAmped in Workbench. I think this is the link in the community library: Particle PulseSensorAmped

That library does a whole lot of things that are not particularly safe. However I think the quick workaround to fix the problem you are seeing is during setup() before initializing the library, do an analogRead() of the sensor pin.

The reason is that the library calls hal_adc_read which is an undocumented Device OS function from an ISR, and that’s not guaranteed to be safe, but usually works. However, the first time the pin is read, it has to initialize the ADC. In Device OS 5.3.0 it has to read the configured ADC reference setting, which is not interrupt safe. It previously always used 3V3, so it didn’t cause an issue in older versions of Device OS.


@rickkas7 thank you!

This is awesome! The analogRead solved the problem with the SOS mode.

@rob7, if you are interested, I created a version of PulseSensorAmped 1.4 that uses a Software Timer instead of interrupts. I never published it as a library but here is the code.


Thank you! I’ll look into that for next semester :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.