00001 #!/usr/bin/env python 00002 00003 import time 00004 00005 import pigpio 00006 00007 # 00008 # OH3144E or equivalent Hall effect sensor 00009 # 00010 # Pin 1 - 5V 00011 # Pin 2 - Ground 00012 # Pin 3 - gpio (here P1-8, gpio 14, TXD is used) 00013 # 00014 # The internal gpio pull-up is enabled so that the sensor 00015 # normally reads high. It reads low when a magnet is close. 00016 # 00017 00018 HALL=14 00019 00020 pi = pigpio.pi() # connect to local Pi 00021 00022 pi.set_mode(HALL, pigpio.INPUT) 00023 pi.set_pull_up_down(HALL, pigpio.PUD_UP) 00024 00025 start = time.time() 00026 00027 while (time.time() - start) < 60: 00028 print("Hall = {}".format(pi.read(HALL))) 00029 time.sleep(0.2) 00030 00031 pi.stop() 00032