LCD not working: GPIO error "This channel is already in use"


13 posts
by jedi23 » Mon Oct 15, 2012 7:46 am
A few weeks ago, i installed successfully my LCD module as shown in this article:
http://www.raspberrypi-spy.co.uk/2012/0 ... ng-python/

But today, i started the python file again and got these errors:

sudo python lcd4.py
lcd4.py:61: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(LCD_E, GPIO.OUT) # E
lcd4.py:62: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(LCD_RS, GPIO.OUT) # RS
lcd4.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
lcd4.py:64: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(LCD_D5, GPIO.OUT) # DB5
lcd4.py:65: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(LCD_D6, GPIO.OUT) # DB6
lcd4.py:66: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(LCD_D7, GPIO.OUT) # DB7
lcd4.py:67: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(LED_ON, GPIO.OUT) # Backlight enable
^CTraceback (most recent call last):
File "lcd4.py", line 192, in <module>
main()
File "lcd4.py", line 99, in main
time.sleep(20) # 20 second delay
KeyboardInterrupt

It doesn't matter if the GPIOs are connected or not, the errors are the same.
Is this a result of a new update? How can I solve this Issue?
Posts: 1
Joined: Mon Oct 08, 2012 5:31 pm
by Smcintosh » Tue Oct 16, 2012 9:12 pm
I would love to know where this error has come from.

I have run scripts today that never previously gave this error and today it does.

This happened on 5 different Pi's on 5 different sd cards that did not do it this time last week. So weird.
Posts: 13
Joined: Tue Jul 31, 2012 11:37 am
by mahjongg » Tue Oct 16, 2012 9:31 pm
My first thought would be that you are somehow running two instances of the program.
User avatar
Forum Moderator
Forum Moderator
Posts: 6041
Joined: Sun Mar 11, 2012 12:19 am
by thogue » Wed Oct 17, 2012 1:16 am
all my scripts have produced this error..... on my two raspberry pis

I troubleshooted for a few days trying to figure out what the issue is. It happens every time after the second run. Basic python script, turning on off LEDS w/ buttons.

I have combed the process list in order to try to solve the issue, but im coming up short...

going to check again now, as when I searched for this issue I did not find much good information.
Posts: 131
Joined: Wed Sep 19, 2012 2:16 am
by mahjongg » Wed Oct 17, 2012 1:27 am
Are you sure your python script closes all channels completely when exiting, it seems they are still open when they are opened a second time, not that I'm a python expert far from it... But it seems a logical explanation.
User avatar
Forum Moderator
Forum Moderator
Posts: 6041
Joined: Sun Mar 11, 2012 12:19 am
by thogue » Wed Oct 17, 2012 1:32 am
Well after another good search, and a little more motivation to care about the error, I figured it out.

I guess I just needed to RTFM

GPIO.cleanup() solves the error for me, I had attempted to do cleanup before but didn't look at the documentation. I was just making sure lights got turned off by... well... turning them off :P. I modified code to do the cleanup if there is a keyboard interrupt. (previously this is where I was making sure lights got turned off)

Code: Select all
try:
      main
except: KeyboardInterrupt:
      GPIO.cleanup()


Posts: 131
Joined: Wed Sep 19, 2012 2:16 am
by thogue » Wed Oct 17, 2012 1:35 am
Figured I might as well post this, this was my light/button testing application. First time playing with the GPIO, thanks to Adafruit's tutorials getting ramped up into python/gpio was pretty straight forward (just like python :D ).
Code: Select all
#!/usr/bin/env python
try:
   from time import sleep
   import os
   import RPi.GPIO as GPIO

   GPIO.setmode(GPIO.BCM)
   GPIO.setup(7, GPIO.IN)
   GPIO.setup(8, GPIO.IN)
   GPIO.setup(11, GPIO.OUT)
   GPIO.setup(25, GPIO.OUT)
   GPIO.output(11,True)      
   GPIO.output(25,True)      
   while True:
      if ( GPIO.input(7) == False ):
         print "On!"
         GPIO.output(11,True)      
         GPIO.output(25,True)      
      if ( GPIO.input(8) == False ):
         print "Off"   
         GPIO.output(11,False)      
         GPIO.output(25,False)   
      sleep(1);
except KeyboardInterrupt:
   GPIO.cleanup()
Posts: 131
Joined: Wed Sep 19, 2012 2:16 am
by thogue » Wed Oct 17, 2012 1:36 am
thinking about it now, I think im gonna ping adafruit about adding some notes about this to their tutorial (after double checking if they exist :lol: )
Posts: 131
Joined: Wed Sep 19, 2012 2:16 am
by mahjongg » Wed Oct 17, 2012 1:44 am
Ah Nice!
User avatar
Forum Moderator
Forum Moderator
Posts: 6041
Joined: Sun Mar 11, 2012 12:19 am
by alexeames » Wed Oct 17, 2012 8:50 am
thogue wrote:
Code: Select all
try:
      main
except: KeyboardInterrupt:
      GPIO.cleanup()




This works, but you've got one colon too many. The one after the except should be deleted. I just found that out when I tried your idea. Nice find :)

It should be...
Code: Select all
try:
      main
except KeyboardInterrupt:
      GPIO.cleanup()
Alex Eames RasPi.TV HDMIPi.com RasP.iO
User avatar
Posts: 2096
Joined: Sat Mar 03, 2012 11:57 am
Location: UK
by SheZz0 » Tue Oct 30, 2012 7:25 pm
I put only that and work:

#Alerts OFF
GPIO.setwarnings(False)
Posts: 1
Joined: Tue Oct 30, 2012 7:24 pm
by Grumpy Mike » Wed Oct 31, 2012 2:13 pm
SheZz0 wrote:I put only that and work:

#Alerts OFF
GPIO.setwarnings(False)


Yes burying your head in the sand is often seen as a cure to a lot of things.
User avatar
Posts: 791
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
by LukeNukem.de » Wed Jun 12, 2013 2:06 pm
Instead of
Code: Select all
except KeyboardInterrupt: GPIO.cleanup()
I would rather use
Code: Select all
finally: GPIO.cleanup()
Thus, the cleanup() will always be executed, no matter whether the program raises an exception or exits normally.
Posts: 1
Joined: Wed Jun 12, 2013 2:00 pm