rasolar/log_geiger.py

30 lines
988 B
Python

import time
from datetime import datetime
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM) # use RaspPi board layout pin numbering
GPIO.setup(0, GPIO.IN, pull_up_down=GPIO.PUD_UP)
counter = 0
def tube_impulse_callback(channel): # threaded callback -- falling edge detected
global counter # make counter global to be able to increment it
counter+=1
# when a falling edge is detected on port 12, regardless of whatever
# else is happening in the program, the tube_impulse_callback will be run
GPIO.add_event_detect(0, GPIO.FALLING, callback=tube_impulse_callback)
try:
while True:
currentMinute = datetime.now().minute
while datetime.now().minute == currentMinute: # this minute..
time.sleep(1) # .. wait while add_event_detect detects pulses
print str(counter)+" cpm"
counter=0 # reset counter
except KeyboardInterrupt:
GPIO.cleanup() # clean up GPIO on CTRL+C exit
except:
GPIO.cleanup() # clean up GPIO on normal exit