0

*Hi, I am getting this code error:

*blink.py:25: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.*
GPIO.setup(ENA1,GPIO.OUT)
Traceback (most recent call last):
File "/home/pi/my_python_programs/blink.py", line 27, in <module>
GPIO.output(IN1,GPIO.LOW)
RuntimeError: The GPIO channel has not been set up as an OUTPUT*

It is in reference to this code I made to control a motor controller from the raspberry pi. Here is my code. I am wondering what the error is:

#ImportedLibraries
import RPi.GPIO as GPIO
from time import sleep
#Motor1
PWR= 17
ENA1 = 33
IN1 = 31
IN2 = 29
GND = 39
#Motor2
PWR = 1
ENA2 = 32
IN3 = 18
IN4 = 16
GND = 34
#SetMode
GPIO.setmode(GPIO.BOARD)
#Motor1
GPIO.setup(ENA1,GPIO.OUT)
PWM1=GPIO.PWM(ENA1,100)
GPIO.output(IN1,GPIO.LOW)
GPIO.output(IN2,GPIO.LOW)
#Motor2
GPIO.setup(ENA2,GPIO.OUT)
PWM2=GPIO.PWM(ENA2,100)
GPIO.output(IN3,GPIO.LOW)
GPIO.output(IN4,GPIO.LOW)
PWM1.start(10)
2
  • 4
    stop wondering and start reading ... the error message tells you what the error is – jsotola Dec 21 '20 at 4:08
  • A hint is GPIO.setup(ENA1,GPIO.OUT) defines ENA1 as a output, whereis the rest ? – Mats Karlsson Dec 21 '20 at 21:42
1

The error message reads

RuntimeError: The GPIO channel has not been set up as an OUTPUT*

Notice how for the ENA1 pin you make a call to GPIO.setup() but don't do so for the other pins you are using. You need to set the mode of a pin (to output, in this case) before you attempt to use it.

So you might try something like this:

#ImportedLibraries
import RPi.GPIO as GPIO
from time import sleep
#Motor1
PWR= 17
ENA1 = 33
IN1 = 31
IN2 = 29
GND = 39
#Motor2
PWR = 1
ENA2 = 32
IN3 = 18
IN4 = 16
GND = 34
#SetMode
GPIO.setmode(GPIO.BOARD)
#Motor1
GPIO.setup(ENA1,GPIO.OUT)
PWM1=GPIO.PWM(ENA1,100)

# setup pins before using them
GPIO.setup(IN1, GPIO.OUT) # <-------------
GPIO.output(IN1,GPIO.LOW)
GPIO.setup(IN2, GPIO.OUT) # <-------------
GPIO.output(IN2,GPIO.LOW)
#Motor2
GPIO.setup(ENA2,GPIO.OUT)
PWM2=GPIO.PWM(ENA2,100)
GPIO.setup(IN3, GPIO.OUT) # <-------------
GPIO.output(IN3,GPIO.LOW)
GPIO.setup(IN4, GPIO.OUT) # <-------------
GPIO.output(IN4,GPIO.LOW)
PWM1.start(10)

The other warning that's given:

*blink.py:25: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.*

is from not releasing the pins after the script ends, so you should end the script with GPIO.cleanup() (see here: https://sourceforge.net/p/raspberry-gpio-python/wiki/BasicUsage/ )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.