Sparkfun Pulse Sensor (amplified) on Teensy 3.0

Status
Not open for further replies.

ZTiK.nl

Well-known member
I connected a Sparkfun Pulse Sensor (amplified) to my Teensy 3.0.

For those who want to use it, but want to know if it works first:
It does now, with some minor modifications to the ISR calls.
Pulse Sensor.jpg

To make it work I included loglow's IntervalTimer library, many thanks once again!

The only files changed are the 2 files in the PulseSensorAmped_Arduino_1dot1.zip files.
I did not remove anything, just commented out things and added replacements, so you can see what has been changed easily

The example code now makes use of "IntervalTimer timer0;" and "uint32_t timerCounter0"
Change these in case you are already using these values :)

View attachment PulseSensorAmped_Arduino_1dot1.zip
View attachment PulseSensorAmpd_Processing_1dot1.zip
(The processing sketch is an unmodified duplicate of the Sparkfun sketch)

One last thing to mention, I noticed that the 2ms interval wasn't getting accurate readings so I lowered this to get a reading every 1ms.
Change the line:
Code:
  timer0.begin(timerCallback0, 1000); // 2 ms
to restore/modify this interval period.
 
I just realized that I also commented out something you might actually want to use, the secondary led.
(this led fades in/out between heartbeats)

If you want to reactivate this, find the 7 lines in the example with the word 'fade' in them (lines: 37, 51, 76, 82-86) and remove the comments.
 
Thanks for the info. At some point I'm going to resurrect my project where I created my own pulse sensor, and I'll share that as well.

What's the duration displayed in the window on the left?
Is it about 10 seconds? I think there could be something not working quite right. 2ms (500hz) should be way more than you need for detecting the pulse rate accurately. I imagine this is using a frequency counter on the interrupt, which I had problems with spurious activity (and your picture reminds of that spurious activity).

In case it's helpful, here's a thread on the light sensor I was working on:
http://arduino.cc/forum/index.php/topic,21536.0.html
 
It is indeed 10 to 12 seconds duration.

At first I wanted to do a quick testrun to see if I could get the Processing sketch to run (never worked with Proc. before).
Then I found out that the interrupt timer functions in the library don't work on Teensy, so I replaced these with loglow's IntervalTimer.

When I got it to function I made a quick screencap posted it, and went to work, haven't tested any further yet (ran into another issue I want to fix first).

Btw, the 2ms was the library's default setting:
Code:
// THIS IS THE TIMER 2 INTERRUPT SERVICE ROUTINE. 
// Timer 2 makes sure that we take a reading every 2 miliseconds
(I replaced ISR Timer 2 with timer0 though)
After running with the default 2ms I was having a critically high heartbeat, so I lowered it to 1 which was when I took the pic and left for work :)

Thank you very much for the link, I will definately read up on that soon!
 
Would you mind posting your code again? Your attachment of PulseSensorAmped_Arduino_1dot1.zip file is missing the modifications. I recommend posting it on github.com, since it's a great way emphasize changed code.

Will that library and your changes work on a Teensy 2?
 
I feel really silly now...
You are completely right, I uploaded the original files from my library folder, instead of the modified files from my sketchbook folder :(

For a quick response I will include them in this post, and I will follow up on your advice and create a github account tonight or tomorrowmorning!

View attachment Interrupt.ino (unmodified)
View attachment PulseSensorAmped_Arduino_1dot1.ino (modified)

I'm sorry to say that I do not own a Teensy 2.0, so I have not really checked into it, but as far as Im aware the intervalTimer library is written for Teensy 3.0 only.
 
doublechecked, and it is the right one this time :)

In case you want to use the 2 LEDs, you might want to uncomment the line:
Code:
//int fadePin = 5;                  // pin to do fancy classy fading blink at each beat

as well as function void ledFadeToBeat().
 
Due to a job change and some personal issues at home, I haven't gotten the time to upload my libraries to GitHub yet.
I haven't forgotten, and will do so as soon as possible.

My apologies for the delay...
 
Would this project work for a 4VDC pulse that rises from 0vdc through 4VDC and back to 0vdc with a total duration of around 5 microseconds?
 
Status
Not open for further replies.
Back
Top