"GPIO.setup(INT, GPIO.IN, pull_up_down=GPIO.PUD_UP)
RuntimeError: Not running on a RPi!"
This is the code:
I can't found the mistake of the code, Is there any problem between Ubuntu and this library?
Code: Select all
#!/usr/bin/env python2.7 import RPi.GPIO as GPIO import subprocess from time import sleep GPIO.setmode(GPIO.BCM) # use GPIO numbering GPIO.setwarnings(False) print('RPi.GPIO:',GPIO.VERSION) INT = 12 # GPIO-12 button interrupt to shutdown procedure # use a weak pull_up to create a high GPIO.setup(INT, GPIO.IN, pull_up_down=GPIO.PUD_UP) def main(): while True: # set an interrupt on a falling edge and wait for it to happen GPIO.wait_for_edge(INT, GPIO.FALLING) # we got here because the button was pressed. # wait for 3 seconds to see if this was deliberate sleep(3) # check the button level again if GPIO.input(INT) == 0: # still pressed, it must be a serious request; shutdown Pi subprocess.call(['poweroff'], shell=True, \ stdout=subprocess.PIPE, stderr=subprocess.PIPE) if __name__ == '__main__': main()
Thank you so much!