I bought the Polar heart rate receiver kit (PRODUCT ID: 1077) and hooked it up to a Raspberry Pi B+. My intent is to capture my minute-to-minute heart rate, store it in a mysql DB and view it on demand via lighttpd, all running on the raspi. Most of this is up and running, initial versions anyway. I have one python script running as a service which captures ONLY the now() timestamp of the rising edge of the sensor signal. My code is simply the following:
Code: Select all
#!/usr/bin/env python
import RPi.GPIO as GPIO
from time import sleep
import datetime
#set up GPIO using BCM numbering
GPIO.setmode(GPIO.BCM)
GPIO.setup(21, GPIO.IN, initial=GPIO.LOW, pull_up_down=GPIO.PUD_DOWN)
def beatRise(channel):
print "Beat"
with open('/home/pi/statfile.dat','a') as myfile:
myfile.write(str(datetime.datetime.now()) + "\n")
GPIO.add_event_detect(21, GPIO.RISING, callback=beatRise)
while True:
sleep(0.01)
GPIO.cleanup()
I'm not sure if the interference is actually coming through the sensor, or possibly just random noise caught on the GPIO pin itself. One thought is that I could add a toggle switch on the sensor line that I flip when I want to capture the heart rate, but if the pin is getting the interference rather than the sensor, then I don't see this as being a workable option.
I added the pull down resistor setting as a test, it did nothing and I left the code in there (it wasn't in my code originally).
I also thought about trying to capture both the rise and the fall of the transitions, as the recievers signal is supposed to be 15 ms in duration. I thought if the signal I got wasn't that duration, I could drop it as chatter. But it appears that you can only define one add_event_detection, and I cannot see if it is possible to call different callback functions for the rise and fall events.
So, I am asking for suggestions. Thanks in advance!