Skip to content

Instantly share code, notes, and snippets.

@sergiomtzlosa
Created January 2, 2019 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sergiomtzlosa/da86cbd298d91240b382023690ae7e03 to your computer and use it in GitHub Desktop.
Save sergiomtzlosa/da86cbd298d91240b382023690ae7e03 to your computer and use it in GitHub Desktop.
#!/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