Implementing timer interrupts for pulse sensor [SOLVED]

I’m using a red bear Duo, could this be the issue for compilation?

Yes, for sure, as I reply to @peekay123, I’m using a red bear duo device, I don’t know if this could be the issue since I understand is compatible with the Photon code.

@misaelgs90, that is the issue. The conditional compile statements were never setup to include the Duo so there will be problems. I’ll have to look to see what mods you need to do to get it to compile.

Strangely enough, I get the same errors, but when I look at the sample that comes with the PulseSensor_Spark library I can’t see any #include "PulseSensor_Spark.h" and this way the sample builds.

So how about removing those two includes for your code too?
As it seems since the function prototypes and extern variables are in the sample already, so don’t include the header.

It doesn’t build for RedBear Duo nor for Photon tho’

SparkIntervalTimer/SparkIntervalTimer.cpp: In member function 'void IntervalTimer::interrupt_SIT(action)':
SparkIntervalTimer/SparkIntervalTimer.cpp:360:15: warning: variable 'TIMx' set but not used [-Wunused-but-set-variable]
  TIM_TypeDef* TIMx;
               ^
SparkIntervalTimer/SparkIntervalTimer.cpp: In member function 'void IntervalTimer::start_SIT(intPeriod, bool)':
SparkIntervalTimer/SparkIntervalTimer.cpp:276:23: warning: 'TIMx' may be used uninitialized in this function [-Wmaybe-uninitialized]
  TIM_Cmd(TIMx, ENABLE);
                       ^
SparkIntervalTimer/SparkIntervalTimer.cpp: In member function 'void IntervalTimer::stop_SIT()':
SparkIntervalTimer/SparkIntervalTimer.cpp:346:18: warning: 'TIMx' may be used uninitialized in this function [-Wmaybe-uninitialized]
  TIM_DeInit(TIMx);
                  ^
SparkIntervalTimer/SparkIntervalTimer.cpp: In member function 'void IntervalTimer::resetPeriod_SIT(intPeriod, bool)':
SparkIntervalTimer/SparkIntervalTimer.cpp:476:23: warning: 'TIMx' may be used uninitialized in this function [-Wmaybe-uninitialized]
  TIMx->PSC = prescaler;
                       ^
../../../build/target/user/platform-6/libuser.a(PulseSensor_Spark.o):(.bss.pulseTimer+0x0): multiple definition of `pulseTimer'
../../../build/target/user/platform-6/libuser.a(pulsesensoramped_arduino_1dot4.o):/usr/local/gcc-arm-embedded-gcc-arm-none-eabi-4_8-2014q2-20140609-linux-tar-bz2/arm-none-eabi/include/c++/4.8.4/functional:2069: first defined here
../../../build/target/user/platform-6/libuser.a(PulseSensor_Spark.o):(.bss.fadeRate+0x0): multiple definition of `fadeRate'
../../../build/target/user/platform-6/libuser.a(pulsesensoramped_arduino_1dot4.o):/usr/local/gcc-arm-embedded-gcc-arm-none-eabi-4_8-2014q2-20140609-linux-tar-bz2/arm-none-eabi/include/c++/4.8.4/functional:2069: first defined here
../../../build/target/user/platform-6/libuser.a(PulseSensor_Spark.o):(.data.fadePin+0x0): multiple definition of `fadePin'
../../../build/target/user/platform-6/libuser.a(pulsesensoramped_arduino_1dot4.o):(.data.fadePin+0x0): first defined here
../../../build/target/user/platform-6/libuser.a(PulseSensor_Spark.o):(.data.blinkPin+0x0): multiple definition of `blinkPin'
../../../build/target/user/platform-6/libuser.a(pulsesensoramped_arduino_1dot4.o):(.data.blinkPin+0x0): first defined here
../../../build/target/user/platform-6/libuser.a(PulseSensor_Spark.o):(.data.pulsePin+0x0): multiple definition of `pulsePin'
../../../build/target/user/platform-6/libuser.a(pulsesensoramped_arduino_1dot4.o):(.data.pulsePin+0x0): first defined here
../../../build/target/user/platform-6/libuser.a(PulseSensor_Spark.o):(.bss.QS+0x0): multiple definition of `QS'
../../../build/target/user/platform-6/libuser.a(pulsesensoramped_arduino_1dot4.o):/usr/local/gcc-arm-embedded-gcc-arm-none-eabi-4_8-2014q2-20140609-linux-tar-bz2/arm-none-eabi/include/c++/4.8.4/functional:2069: first defined here
../../../build/target/user/platform-6/libuser.a(PulseSensor_Spark.o):(.bss.Pulse+0x0): multiple definition of `Pulse'
../../../build/target/user/platform-6/libuser.a(pulsesensoramped_arduino_1dot4.o):/usr/local/gcc-arm-embedded-gcc-arm-none-eabi-4_8-2014q2-20140609-linux-tar-bz2/arm-none-eabi/include/c++/4.8.4/functional:2069: first defined here
../../../build/target/user/platform-6/libuser.a(PulseSensor_Spark.o):(.data.IBI+0x0): multiple definition of `IBI'
../../../build/target/user/platform-6/libuser.a(pulsesensoramped_arduino_1dot4.o):(.data.IBI+0x0): first defined here
../../../build/target/user/platform-6/libuser.a(PulseSensor_Spark.o):(.bss.Signal+0x0): multiple definition of `Signal'
../../../build/target/user/platform-6/libuser.a(pulsesensoramped_arduino_1dot4.o):/usr/local/gcc-arm-embedded-gcc-arm-none-eabi-4_8-2014q2-20140609-linux-tar-bz2/arm-none-eabi/include/c++/4.8.4/functional:2069: first defined here
../../../build/target/user/platform-6/libuser.a(PulseSensor_Spark.o):(.bss.BPM+0x0): multiple definition of `BPM'
../../../build/target/user/platform-6/libuser.a(pulsesensoramped_arduino_1dot4.o):/usr/local/gcc-arm-embedded-gcc-arm-none-eabi-4_8-2014q2-20140609-linux-tar-bz2/arm-none-eabi/include/c++/4.8.4/functional:2069: first defined here
../../../build/target/user/platform-6/libuser.a(PulseSensor_Spark.o):(.bss.secondBeat+0x0): multiple definition of `secondBeat'
../../../build/target/user/platform-6/libuser.a(pulsesensoramped_arduino_1dot4.o):/usr/local/gcc-arm-embedded-gcc-arm-none-eabi-4_8-2014q2-20140609-linux-tar-bz2/arm-none-eabi/include/c++/4.8.4/functional:2069: first defined here
../../../build/target/user/platform-6/libuser.a(PulseSensor_Spark.o):(.data.firstBeat+0x0): multiple definition of `firstBeat'
../../../build/target/user/platform-6/libuser.a(pulsesensoramped_arduino_1dot4.o):(.data.firstBeat+0x0): first defined here
../../../build/target/user/platform-6/libuser.a(PulseSensor_Spark.o):(.data.amp+0x0): multiple definition of `amp'
../../../build/target/user/platform-6/libuser.a(pulsesensoramped_arduino_1dot4.o):(.data.amp+0x0): first defined here
../../../build/target/user/platform-6/libuser.a(PulseSensor_Spark.o):(.data.thresh+0x0): multiple definition of `thresh'
../../../build/target/user/platform-6/libuser.a(pulsesensoramped_arduino_1dot4.o):(.data.thresh+0x0): first defined here
../../../build/target/user/platform-6/libuser.a(PulseSensor_Spark.o):(.data.T+0x0): multiple definition of `T'
../../../build/target/user/platform-6/libuser.a(pulsesensoramped_arduino_1dot4.o):(.data.T+0x0): first defined here
../../../build/target/user/platform-6/libuser.a(PulseSensor_Spark.o):(.data.P+0x0): multiple definition of `P'
../../../build/target/user/platform-6/libuser.a(pulsesensoramped_arduino_1dot4.o):(.data.P+0x0): first defined here
../../../build/target/user/platform-6/libuser.a(PulseSensor_Spark.o):(.bss.lastBeatTime+0x0): multiple definition of `lastBeatTime'
../../../build/target/user/platform-6/libuser.a(pulsesensoramped_arduino_1dot4.o):/usr/local/gcc-arm-embedded-gcc-arm-none-eabi-4_8-2014q2-20140609-linux-tar-bz2/arm-none-eabi/include/c++/4.8.4/functional:2069: first defined here
../../../build/target/user/platform-6/libuser.a(PulseSensor_Spark.o):(.bss.sampleCounter+0x0): multiple definition of `sampleCounter'
../../../build/target/user/platform-6/libuser.a(pulsesensoramped_arduino_1dot4.o):/usr/local/gcc-arm-embedded-gcc-arm-none-eabi-4_8-2014q2-20140609-linux-tar-bz2/arm-none-eabi/include/c++/4.8.4/functional:2069: first defined here
../../../build/target/user/platform-6/libuser.a(PulseSensor_Spark.o):(.bss.rate+0x0): multiple definition of `rate'
../../../build/target/user/platform-6/libuser.a(pulsesensoramped_arduino_1dot4.o):/usr/local/gcc-arm-embedded-gcc-arm-none-eabi-4_8-2014q2-20140609-linux-tar-bz2/arm-none-eabi/include/c++/4.8.4/functional:2069: first defined here
collect2: error: ld returned 1 exit status
make: *** [182a5dd7bd9df9eb570755d5f7b5810f7003d69482186dd52531410a5c28.elf] Error 1
Error: Could not compile. Please review your code.

These are the errors for Photon (with "#include "PulseSensor_Spark/PulseSensor_Spark.h")

@ScruffR, @misaelgs90, I just loaded the pulsesensor library into the IDE, attached the SparkIntervalTimer library to the example and removed the #include added at the top of the file. I then selected a Photon v0.6.0 target and it compiled without errors.

I then selected a Duo target and it compiled without errors as well.

@peekay123, as updated in my previous post

So I thought I'd just remove these "local" redefinitions and put the include back, but that left my with a unresolvable redef pulseTimer and fadeRate

1 Like

Thank you very much for your guidance guys @peekay123 and @ScruffR, I’ve made it work just as @peekay123 indicated in the previous post, nevertheless what seems curious to me is that it only worked when I loaded the example from the PulseSensor Library, otherwise if I copy and paste the code into a new app, I just get the same errors, why does this happen?, how can I start an application from 0 and use both libraries?. Thanks again! :smiley:

@misaelgs90, when you “paste” the code into a new app, did you include the code for all tabs included in the PulseSensor library? These include PulseSensor_Spark.cpp, PulseSensor_Spark.h and the demo app itself, PulseSensorAmped_Arduino_1dot4.ino?

Not all, I just copied the code in the example and included the library from the IDE (I assume this will link the .cpp and .h files of the library), is that the way I should do it?

Thanks.

@misaelgs90, not sure why it didn’t work. :neutral_face:

Again, try removing the include statement(s) for PulseSensor_Spark.h

hello,
we have the same problem of the interrupts, but We are using the wemos d1 mini board.
this board dont have the ports A1 and A2 ,
its have one analog port A0
is the code can be used in this case ?!
@peekay123

@moatasem, wemos D1 is an entirely different platform from the Particle Photon (ESP8266 vs Broadcom P0). You will need to look at the original Arduino library to see if you can port it.

so your solution of the hardware interrupt cant help us ?!
if not … can you help please ?!
@peekay123

@moatasem, these are not just hardware interrupts. The pulse sensor uses hardware timer interrupts. The hardware setup in the ESP8266 is totally different than the Photon. If I recall, the original Arduino code uses a hardware timer interrupt as well. You may be able to adapt the code to use ESP8266 os_timer callbacks at 2ms intervals. However, I don’t use ESP8266 devices so I can’t adapt the code for you.