User avatar
Mettauk
Posts: 237
Joined: Mon Dec 10, 2012 12:40 pm
Location: Zarg

Script to read A1120EUA-T Hall sensor error

Sat Dec 03, 2016 5:06 pm

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.
As humans we have been the same for a very very long time, technology changes how we do... not who we are as people.

User avatar
joan
Posts: 14264
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Script to read A1120EUA-T Hall sensor error

Sat Dec 03, 2016 5:17 pm

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.

User avatar
Mettauk
Posts: 237
Joined: Mon Dec 10, 2012 12:40 pm
Location: Zarg

Re: Script to read A1120EUA-T Hall sensor error

Sat Dec 03, 2016 7:30 pm

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?
As humans we have been the same for a very very long time, technology changes how we do... not who we are as people.

Return to “Python”