jobin-sun / raspberry-gpio-python

Automatically exported from code.google.com/p/raspberry-gpio-python
MIT License
0 stars 0 forks source link

GPIO: channel is already in use #16

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Simple test program for HD44780 LC-display

What is the expected output? What do you see instead?
lcd4x20.py:63: RuntimeWarning: This channel is already in use, continuing 
anyway. Use GPIO.setwarnings(False) to disable warnings.
 GPIO.setup(LCD_D4, GPIO.OUT) # DB4

->no LCD output

What version of the product are you using? On what operating system?
0.4.1a

Please provide any additional information below.
In previous version (Linux, RPi.GPIO) LCD was working properly.

Original issue reported on code.google.com by micha2...@googlemail.com on 15 Oct 2012 at 2:01

GoogleCodeExporter commented 9 years ago
Could you send some more of your code please.

Does it work with just a LED instead of the LCD?  Are you using a revision 1 or 
a revision 2 RPi board?

To remove the warning message, add GPIO.setwarnings(False) before any setup() 
calls or add GPIO.cleanup() at the end of your program.

Original comment by btcros...@googlemail.com on 17 Oct 2012 at 3:38

GoogleCodeExporter commented 9 years ago
Im having the same warning message for a simple python program that lights up 
and turns off a LED connected to GPIO.18

Python code:

#!/usr/bin/env python

import RPi.GPIO as GPIO, time,os.path

FREQ = 1      # check every X seconds

GPIO.setmode(GPIO.BCM)
LED = 18
GPIO.setup(LED, GPIO.OUT)
filepath='/var/www/test/gpio.txt'

while True:

        if(os.path.exists(filepath)):
        #       print('JA')
                GPIO.output(LED,True)
        else:
        #       print('Nej')
                GPIO.output(LED,False)

        time.sleep(MAIL_CHECK_FREQ)

Original comment by stefan.f...@gmail.com on 8 Jan 2013 at 10:50

GoogleCodeExporter commented 9 years ago
I get this bug and looking at py_gpio.c I can't see why it does not happen to 
everybody. Just setup() any input and you will get this warning.

Original comment by mark.bla...@bullet-systems.net on 11 Jan 2013 at 6:39

GoogleCodeExporter commented 9 years ago
No fault found.  This is not a bug - it is a valid warning message. Try 
following the suggestions it makes, or use GPIO.cleanup () at the end of your 
code!

Original comment by btcros...@googlemail.com on 21 Jan 2013 at 5:49

GoogleCodeExporter commented 9 years ago
I to have the same problem: pi@raspberrypi ~ $ sudo python blink-led.py
blink-led.py:25: RuntimeWarning: This channel is already in use, continuing 
anyway.  Use GPIO.setwarnings(False) to disable warnings.
  GPIO.setup(LED,GPIO.OUT)    
Here is my Code:
Install Package
$ sudo apt-get update
$ sudo apt-get install python-dev
$ sudo sudo apt-get install python-rpi.gpi

 #!/usr/bin/python
2 # Jean Yav
3 # projekrex@gmail.com
6 # Simple Diagram
7 #
8 # GPIO#7 >>>> RESISTOR(470ohm) >>>(+)LED >>> GND
9 #
10 from time import sleep
11 import RPi.GPIO as GPIO
12
13 # Pin configuration
14 LED= 7
15
16 # Pin setup
17 GPIO.setmode(GPIO.BCM)
18
19 # Led pin configured as ouput
20 GPIO.setup(LED, GPIO.OUT)
21
22 # control the delay (in sec)
23 delay = 2
24
25 run = True
26 state = True
27 while(run):
28
29 try:
30
31 GPIO.output(LED, state)
32 state = not state
33 sleep(delay)
34
35 except KeyboardInterrupt:
36 run = False
38 GPIO.cleanup()

Could someone help Please!!! 

Original comment by missyand...@gmail.com on 17 Mar 2013 at 10:49

GoogleCodeExporter commented 9 years ago
I have a similar problem. I connected 3 LEDs to my RPi to use them as a traffic 
light. Short leg of 3 LEDs (cathodes) are connected to pin 17, 20 and 25. Long 
legs are connected to pin 3, 5 and 7. I have the latest Python and GPIO library 
installed. Here is my code:

1 import time
2 import RPi.GPIO as GPIO
3 GPIO.cleanup()
4 GPIO.setmode(GPIO.BOARD)
5 GPIO.setup(3,GPIO.OUT)
6 GPIO.setup(5,GPIO.OUT)
7 GPIO.setup(7,GPIO.OUT)
8 while True:
9   GPIO.output(3,GPIO.HIGH)
10 time.sleep(2)
11 GPIO.output(5,GPIO.HIGH)
12 time.sleep(2)
13 GPIO.output(5,GPIO.LOW)
14 GPIO.output(3,GPIO.LOW)
15 GPIO.output(7,GPIO.HIGH)
16 time.sleep(2)
17 GPIO.output(7,GPIO.LOW)
18 GPIO.output(5,GPIO.HIGH)
19 time.sleep(2)
20 GPIO.cleanup()

Could someone please tell me how can I fix the issue?

I get the below warning. When I use GPIO.setwarnings(False) I do not get any 
error but the LEDs still do not work as I wanted in the code.

Warning (from warnings module):
  File "/home/pi/TrafficLED.py", line 7
    GPIO.setup(3,GPIO.OUT) # Set Pin 3 on the GPIO header to act as an output
RuntimeWarning: This channel is already in use, continuing anyway.  Use 
GPIO.setwarnings(False) to disable warnings.

Warning (from warnings module):
  File "/home/pi/TrafficLED.py", line 8
    GPIO.setup(5,GPIO.OUT) # Set Pin 5 on the GPIO header to act as an output
RuntimeWarning: This channel is already in use, continuing anyway.  Use 
GPIO.setwarnings(False) to disable warnings.

Warning (from warnings module):
  File "/home/pi/TrafficLED.py", line 9
    GPIO.setup(7,GPIO.OUT) # Set Pin 7 on the GPIO header to act as an output
RuntimeWarning: This channel is already in use, continuing anyway.  Use 
GPIO.setwarnings(False) to disable warnings.

Original comment by ersind...@gmail.com on 27 Jun 2013 at 5:14

GoogleCodeExporter commented 9 years ago
I got the same poblem, here is my code

>>> import RPi.GPIO as GPIO
>>> import time
>>> pinNum = 8
>>> GPIO.setmode(GPIO.BCM) #numbering scheme that corresponds to breakout board 
and pin layout
>>> GPIO.setup(pinNum,GPIO.OUT) #replace pinNum with whatever pin you used, 
this sets up that pin as an output
__main__:1: RuntimeWarning: This channel is already in use, continuing anyway.  
Use GPIO.setwarnings(False) to disable warnings.
>>> #set LED to flash forever
... while True:
...   GPIO.output(pinNum,GPIO.HIGH)
...   time.sleep(0.5)
...   GPIO.output(pinNum,GPIO.LOW)
...   time.sleep(0.5)
... 

I am a still a noob in python and have no clue to solve this problem.  thx
sushi 

Original comment by christop...@gmail.com on 13 Dec 2013 at 9:22

GoogleCodeExporter commented 9 years ago
This is marked invalid, but the only justification I can see for that is that 
it is possible to turn off the warning message!

I have been programming since FORTRAN was big, and just hiding the warnings has 
never been considered good practice before.

Either there should be a way of knowing what is using GPIO 18, and preventing 
or cleaning up that state, or this is a bug.

Original comment by ryast...@gmail.com on 13 Jan 2014 at 12:15

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Try to use "while 1:" , if you want to run the program endless.
You can stop it with 'STRG + C'.

Original comment by o1bla...@gmail.com on 31 Mar 2014 at 10:48

GoogleCodeExporter commented 9 years ago
Agreed with christop...@gmail.com.

Steps to reproduce:

1: Obtain a brand new Raspberry Pi with a brand new install of Wheezy.
2: su to Root.
3: Launch an interactive Python interpreter.
4: Import RPi.GPIO and setmode(GPIO.BCM).
5: GPIO.setup(18, GPIO.OUT)

You will see this message:
__main__:3: RuntimeWarning: This channel is already in use, continuing anyway. 
Use GPIO.setwarnings(False) to disable warnings.

I imagine this is related to pin 18 being designated as PCM.

This bug is top result in a google search for that error message, so info about 
what process could already be initializing pin 18 would be very handy.  Also I 
have a few gripes with the warning:

1: The exception does not tell you what pin generated the warning.  This is 
pertinent info that a developer needs to see.  Exception message should 
contain, "Channel %s is already in use" %channel

2: Continuing by default even though there is a conflict on the pin is bad.  
User should have to force.  Does it setup the pin even if you give it a 
reserved number, like the I/O pins for the SD card?

Original comment by miste...@gmail.com on 27 May 2014 at 5:00

GoogleCodeExporter commented 9 years ago
It will work once on strt up then not again for me

Original comment by mbrindl...@gmail.com on 4 Jun 2014 at 5:28

GoogleCodeExporter commented 9 years ago
For other people landing here via Google search on this error message:

I have resolved this issue on my own Raspberry Pi by:

1: Perform an apt-get upgrade.  (This retrieves latest GPIO package amongst 
many other things.)
2: Wait.  This will take a long time.
3: Reboot the Raspberry Pi.

After the apt-get upgrade, a newly booted Raspberry Pi does not display the 
warning.

I've also confirmed that the port's use state persists after quitting and 
restarting the Python interpreter.  Python does not cleanup the pins on 
interpreter exit, you have to run GPIO.cleanup().

The best way to run GPIO.cleanup() is probably using the 'atexit' module.  
Register GPIO.cleanup() using atexit, and it will automatically run when your 
interpreter quits even if it quit due to an unhandled exception.

import atexit
atexit.register(GPIO.cleanup)

According to the GPIO module documentation, this will cause any pins you have 
GPIO.setup() during your program to reset themselves as input pins and mark 
themselves not in use.

Note that if your code has an exception and quits, this will cause the RPi to 
stop driving any lines attached to your GPIO pins.  If your circuit does bad 
things in that situation, it's best to just remember that you were the one 
using those pins and suppress the warnings.

Original comment by miste...@gmail.com on 5 Jun 2014 at 2:49