PDA

View Full Version : Sparkfun Pulse Sensor (amplified) on Teensy 3.0



ZTiK.nl
02-20-2013, 02:30 AM
I connected a Sparkfun Pulse Sensor (amplified) (https://www.sparkfun.com/products/11574) 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.
261

To make it work I included loglow's IntervalTimer library (https://github.com/loglow/IntervalTimer), 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 :)

258
259
(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:

timer0.begin(timerCallback0, 1000); // 2 ms
to restore/modify this interval period.

ZTiK.nl
02-20-2013, 02:44 AM
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.

linuxgeek
02-20-2013, 03:33 PM
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

ZTiK.nl
02-20-2013, 04:04 PM
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 (http://forum.pjrc.com/threads/18697-USB-device-not-recognized-after-changing-Analog-port-define) I want to fix first).

Btw, the 2ms was the library's default setting:

// 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!

tmk854
04-01-2013, 08:39 PM
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?

ZTiK.nl
04-01-2013, 09:14 PM
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!

356 (unmodified)
357 (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 (https://github.com/loglow/IntervalTimer) library is written for Teensy 3.0 only.

ZTiK.nl
04-01-2013, 09:17 PM
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:

//int fadePin = 5; // pin to do fancy classy fading blink at each beat

as well as function void ledFadeToBeat().

ZTiK.nl
04-08-2013, 11:41 PM
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...

Michael Madaris
07-11-2014, 06:51 PM
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?