Skip to content

Instantly share code, notes, and snippets.

@davidsulpy
Last active March 13, 2017 06:57
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save davidsulpy/b0b490c5fb14ab35ceb2b43108458518 to your computer and use it in GitHub Desktop.
import RPi.GPIO as io # import the GPIO library we just installed but call it "io"
from ISStreamer.Streamer import Streamer # import the IS Streamer we just installed but call it "Streamer"
SAMPLE_COUNT = 10
## name the bucket and individual access_key
## the bucket_key will send all of our messages to the same place
## the access_key tells Initial State to send the messages to you
streamer=Streamer(bucket_name="Heart Rate Monitor",bucket_key="heartrate",access_key="Your_Access_Key_Here")
## set GPIO mode to BCM
## this takes GPIO number instead of pin number
io.setmode(io.BCM)
io.setwarnings(False)
receiver_in = 23 # this is the GPIO number our receiver is connected to
LED_in = 24 # GPIO number the LED is connected to
io.setup(receiver_in, io.IN) # initialize receiver GPIO to take input
io.setup(LED_in, io.OUT) # initialized LED GPIO to give output
io.output(LED_in, io.HIGH) # start with LED off
## log that everything is ready to receive the heartbeat signal
streamer.log("msg","Waiting for heartbeat")
## this try block looks for 1 values (indicate a beat) from the transmitter
try:
firstBeatTime = time.time()
sampleCounter = 0
while True:
if sampleCounter == 0:
firstBeatTime = time.time()
## sample will either be 1 or 0
sample = io.input(receiver_in)
if sample == 1:
io.output(LED_in, io.LOW) # turn LED on
sampleCounter = sampleCounter + 1
if sampleCounter == SAMPLE_COUNT:
sampleCounter = 0 # reset the sample counter
# calculate beats per minute given the SAMPLE_COUNT
sampleMinutes = (time.time() - firstBeatTime)/60
bpm = sampleMinutes * SAMPLE_COUNT
# stream
streamer.log("bpm", bpm)
else:
io.output(LED_in, io.HIGH) # turn LED off
# Set the previous sample to the current sample so that it can be used to
# evaluate if at the front edge of the heartbeat and not count it more than
# once if already in the high position
previousSample = sample
## this allows you to end the script with ctrl+c
except KeyboardInterrupt:
streamer.log("msg", "Received Interrupt")
streamer.close() # safely close the streamer
@vigneshwr
Copy link

can i read the data directly from pulse sensor without any adc or any converter to get the values like this. I'm trying that way and am facing problems in it with calculations. If you have any idea on it help me naa....
thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment