19

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?

Chetan Bhargava
  • 1,262
  • 3
  • 15
  • 29
LilVinny
  • 440
  • 1
  • 4
  • 16

3 Answers3

24

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 
user1231247
  • 426
  • 3
  • 6
5

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.

joan
  • 71,024
  • 5
  • 73
  • 106
  • 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
0

List item

import RPi.GPIO as GPIO 
from time import sleep

GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) GPIO.setup(7, GPIO.OUT) GPIO.setup(8, GPIO.IN)

state = "ON"

if GPIO.input(8) == 0: GPIO.output(7, GPIO.HIGH) state = “OFF” print(state) else: GPIO.output(7, GPIO.LOW) print(state)

Greenonline
  • 2,740
  • 4
  • 23
  • 36