Channel Already In Use

Can someone please help!? I’m using VS Code on a Raspberry Pi 4b. Everything is updated and upgraded. After typing my code, there’s no errors, no squiggly lines. I run the code and nothing happens. My RGB LED does not light up and my ‘print()’ statement does not print. After running the debugger the error msg i get is ‘Channel already in use’ for all 3 GPIO pins that I’m using. I get the same error after using 3 different GPIO pins. I then try to type the code directly in the python terminal and on the 3rd line when setting up a GPIO pin as an Output i get the same error message…‘Channel Is Already In Use’… I close everything out and reboot. I ‘sudo apt update’ and ‘sudo apt upgrade’. I reboot one more time and try it all again. I keep getting the exact same results. I even tried different GPIO pins and making various changes to the code…same results. I attached a pic of the code and error message. As a new user I’m only allowed to upload one. Thank you in advance to whoever can help.

Here’s a pic of when attempting in python terminal…

I found a lot of good answers searching for “GPIO channel already in use” - did none of these answer your question?

FYI: hosting images of text is a bad idea in the best of circumstances, because we can’t cut and paste text to try things out. Formatting those images as long, very thin columns where one logical line of code takes half a dozen visual lines makes it even hard for some prospective helper.

1 Like

Please avoid posting pictures of text. See here how to post as preformatted text: About the Python Help category

Got it. My apologies. Code coming soon.Thank you.

import RPi.GPIO as GPIO
GPIO.setup (15, GPIO.OUT)
GPIO.setup (13, GPIO.OUT)
GPIO.setup (11, GPIO.OUT)
RedLed = 15
GreenLed = 13
BlueLed = 11

from time import sleep
delay = .5

ON = True
OFF = False

    while True:
        GPIO.output(RedLed, ON)
        GPIO.output(RedLed, OFF)
        GPIO.output(GreenLed, ON)
        GPIO.output(GreenLed, OFF)
        GPIO.output(BlueLed, ON)
        GPIO.output(BlueLed, OFF)
    print("I AM THAT I AM!!!")

except KeyboardInterrupt:

    print("GOOD SHIT, G!!!")

Other than how to disable the warning, I was not able to find anything on the subject that helped.

It strikes me that perhaps some other program is taking control of the GPIO?

Perhaps try rebooting the machine and running it?

I note you aren’t running cleanup at the end of your program: RPi.GPIO basics 3 – How to Exit GPIO programs cleanly, avoid warnings and protect your Pi – RasPi.TV

I’m not an RPi expert, but it strikes me that you could only run this program once and then the channel would be taken until you cleaned up?

In one article I saw, someone said this was caused by miswiring the project, but they didn’t give details exactly how.

RPi forums might have people who understood this system better…

‘GPIO.cleanup()’ is under the
‘except KeyboardInterrupt:’

I’ll check my circuit after work this evening. Thank you.

Oops, you are quite correct, I didn’t scroll down to see the rest of the code (I didn’t even see the scroll bar.)

Another possibility that comes to mind is that I vaguely remember is that you need to enable the GPIO, like here.

It’s… unfortunate that the system doesn’t give you more error messages!

There seems to be a Python library called gpiozero which might give better diagnostics and certainly gives easier functionality.

Don’t give up, there will be a solution. :smile:

Line 1 is, ‘import RPi.GPIO as GPIO’…

I’ll check my circuit in a few hours. I’ll be sure to take a pic and post it before i make any changes to it.

Is RPi.GPIO is the same as gpiozero? From the documentation, it doesn’t seem to be, but I only spent a few moments on it.

FYI…Initially i was using pins 36, 38 and 40. I switched to 11, 13 and 15 while troubleshooting.

I got it figured out! There were a few things wrong. For starters, I’m using a multi-colored LED. I was unaware that there are two types of multi-colored LEDs(at least). One being a ‘common anode’, of which, the ‘common’ is the positive(+) and the other being a ‘common cathode’ of which, the common is the negative(-). The YouTube tutorial I’m following must be using the common cathode while I, unknowingly, am using the common anode. That is why the LED didn’t illuminate. The reason nothing showed up on the Terminal is because my print() statement was outside of the ‘while loop’. Because I was getting no response from the LED nor the Terminal, I assumed the code was not running so I clicked the RUN button again. That’s the reason for the, ‘Channel Already In Use’ error message. I am so glad I was able to resolve this issue. The feedback I received from this post on this discourse is what kept me thinking, researching and troubleshooting. For that I thank you all for your time, attention, knowledge and willingness to help. An “Extra Thanks” goes out to Tom for bringing to my attention, the existence of the ‘gpiozero’ library. I am seriously considering switching from ‘RPi.GPIO’. ‘gpiozero’ is so much more simplified and understandable, it makes it easier to create and follow a path to the expected result(s). I’m kind of looking forward to the next hurdle I can bring here for help getting over. THANKS AGAIN!

1 Like