jedi23
Posts: 1
Joined: Mon Oct 08, 2012 5:31 pm

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

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?

Smcintosh
Posts: 13
Joined: Tue Jul 31, 2012 11:37 am

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

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.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 9599
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

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

Tue Oct 16, 2012 9:31 pm

My first thought would be that you are somehow running two instances of the program.

thogue
Posts: 131
Joined: Wed Sep 19, 2012 2:16 am

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

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.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 9599
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

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

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.

thogue
Posts: 131
Joined: Wed Sep 19, 2012 2:16 am

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

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()



thogue
Posts: 131
Joined: Wed Sep 19, 2012 2:16 am

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

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()

thogue
Posts: 131
Joined: Wed Sep 19, 2012 2:16 am

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

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: )

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 9599
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

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

Wed Oct 17, 2012 1:44 am

Ah Nice!

User avatar
alexeames
Forum Moderator
Forum Moderator
Posts: 2808
Joined: Sat Mar 03, 2012 11:57 am
Location: UK
Contact: Website

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

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, RasP.iO

SheZz0
Posts: 1
Joined: Tue Oct 30, 2012 7:24 pm

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

Tue Oct 30, 2012 7:25 pm

I put only that and work:

#Alerts OFF
GPIO.setwarnings(False)

User avatar
Grumpy Mike
Posts: 874
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

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

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.

LukeNukem.de
Posts: 1
Joined: Wed Jun 12, 2013 2:00 pm

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

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.

stenci
Posts: 1
Joined: Mon May 25, 2015 11:32 pm

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

Mon May 25, 2015 11:37 pm

This is a cleaner way, which will cleanup even if the loop exits for other reasons.

Code: Select all

try:
    [...]
except:
    pass

print('Cleaning up')
GPIO.cleanup()

Nobody621
Posts: 2
Joined: Sat Jan 02, 2016 4:21 am

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

Sat Jan 02, 2016 4:26 am

I put GPIO.cleanup( ) at the end of all of my programs to clear up for the next ones and tried restarting my pi. I even put a GPIO.cleanup( ) at the beginning of my code but the pi said that there was nothing to clean up. I just made a simple blinking LED program. This is my code:

Code: Select all

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

GPIO.setup(21, GPIO.OUT)

while True:
        GPIO.output(21, GPIO.LOW)
        time.sleep(250)
        GPIO.output(21, GPIO.HIGH)
        time.sleep(250)

GPIO.cleanup()
The program I ran before it also had a loop but as I said I put GPIO.cleanup( ) at the beginning and it still didn't work.

User avatar
elParaguayo
Posts: 1896
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

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

Sat Jan 02, 2016 10:15 am

Are you sure it's not working? The led will start off and stay off for 250 seconds before it turns on...

Also, has this question got any relevance to thread in which you've posted? Don't be afraid to start a new thread (even if it's your first post) if you can't find anyone else with the same problem.

If you're getting an error message, please post it.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

Nobody621
Posts: 2
Joined: Sat Jan 02, 2016 4:21 am

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

Sat Jan 02, 2016 5:43 pm

elParaguayo wrote:Are you sure it's not working? The led will start off and stay off for 250 seconds before it turns on...

Also, has this question got any relevance to thread in which you've posted? Don't be afraid to start a new thread (even if it's your first post) if you can't find anyone else with the same problem.

If you're getting an error message, please post it.
I thought that was 250 milliseconds, thanks

Return to “Python”

Who is online

Users browsing this forum: No registered users and 22 guests