4

gpio.py:5: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings. GPIO.setup(8, GPIO.OUT) That is what I get after I run:

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setup(7, GPIO.OUT)
GPIO.setup(8, GPIO.OUT)
GPIO.output(7, 0)
GPIO.output(8, 0)

Is there anyway I can fix the warning?

  • Also, what does GPIO.cleanup() do? Should I use it? – LilVinny Sep 18 '16 at 16:40
6

This code helped me get rid of the warning (the "finally" part at the end):

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM) # Broadcom pin-numbering scheme

GPIO.setup(6, GPIO.OUT) # output rf

# Initial state for LEDs:
print("Testing RF out, Press CTRL+C to exit")

try:
     print("set GIOP high")
     GPIO.output(6, GPIO.HIGH)
     time.sleep(5)               
except KeyboardInterrupt: # If CTRL+C is pressed, exit cleanly:
   print("Keyboard interrupt")

except:
   print("some error") 

finally:
   print("clean up") 
   GPIO.cleanup() # cleanup all GPIO 
2

You can safely ignore the warning.

As the message says add GPIO.setwarnings(False) to the start of your script to disable warnings.

GPIO.cleanup() sets any GPIO you have used within RPi.GPIO to INPUT mode. If that behaviour is desirable call the method before exiting your script.

  • Is there a way that I can repeat the script after every 5 minutes and after every loop turn the lights off. – LilVinny Sep 18 '16 at 17:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.