Page 1 of 1

Script to read A1120EUA-T Hall sensor error

Posted: Sat Dec 03, 2016 5:06 pm
by Mettauk
Just trying to set up a hall sensor with this python script from http://www.raspberrypi-spy.co.uk/2015/0 ... ode]import RPi.GPIO as GPIO
import time
import datetime

def sensorCallback1(channel):
# Called if sensor output goes LOW
timestamp = time.time()
stamp = datetime.datetime.fromtimestamp(timestamp).strftime('%H:%M:%S')
print "Sensor LOW " + stamp

def sensorCallback2(channel):
# Called if sensor output goes HIGH
timestamp = time.time()
stamp = datetime.datetime.fromtimestamp(timestamp).strftime('%H:%M:%S')
print "Sensor HIGH " + stamp

def main():
# Wrap main content in a try block so we can
# catch the user pressing CTRL-C and run the
# GPIO cleanup function. This will also prevent
# the user seeing lots of unnecessary error
# messages.

try:
# Loop until users quits with CTRL-C
while True :
time.sleep(0.1)

except KeyboardInterrupt:
# Reset GPIO settings
GPIO.cleanup()

# Tell GPIO library to use GPIO references
GPIO.setmode(GPIO.BCM)

print "Setup GPIO pin as input"

# Set Switch GPIO as input
GPIO.setup(19 , GPIO.IN)
GPIO.add_event_detect(19, GPIO.FALLING, callback=sensorCallback1)
GPIO.add_event_detect(19, GPIO.RISING, callback=sensorCallback2)

if __name__=="__main__":
main()
[/code]but keep getting this error

Code: Select all

:~ $ sudo python hall2.py
Setup GPIO pin as input
Traceback (most recent call last):
  File "hall2.py", line 61, in <module>
    GPIO.add_event_detect(19, GPIO.RISING, callback=sensorCallback2)
RuntimeError: Conflicting edge detection already enabled for this GPIO channel
Any help would be much appreciated. Pi is updated with latest Jessie as at date of posting.

Re: Script to read A1120EUA-T Hall sensor error

Posted: Sat Dec 03, 2016 5:17 pm
by joan
The RPi.GPIO module only allows one current add_event_detect() per GPIO. You could use one call to EITHER_EDGE instead which should work fine as long as edges aren't too frequent.

Re: Script to read A1120EUA-T Hall sensor error

Posted: Sat Dec 03, 2016 7:30 pm
by Mettauk
Thank you for your speedy reply. Unfortunately I don't understand how to edit the python script, can you give an example or explain a bit more?