Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/python
import RPi.GPIO as GPIO
import time
LOG_PERIOD = 20000
MINUTE_PERIOD = 60000
counts = 0
cpm = 0
inputPin = 14 # set input GPIO pin number here
global previousMillis
previousMillis = 0
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
def geiger_click(channel):
global counts
counts = counts + 1
print "click"
GPIO.setup(inputPin, GPIO.IN)
GPIO.add_event_detect(inputPin, GPIO.RISING, callback=geiger_click)
try:
while(True):
currentMillis = int(round(time.time() * 1000))
if (currentMillis - previousMillis > LOG_PERIOD):
previousMillis = currentMillis
cpm = counts * MINUTE_PERIOD / LOG_PERIOD
print str(cpm) + " cpm"
counts = 0
except KeyboardInterrupt: # If CTRL+C is pressed, exit cleanly:
pass
except:
pass
finally:
GPIO.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.