ValueError: The submitted channel is invalid on the Raspberry Pi server - Controlling GPIO Pin 2 (BOARD) using Python error

So, I have a small fan connected to pin 6 (Earth) and pin 2. I try to manually start and stop the fan when necessary, but I get this error when I try:

ValueError: The sent channel is invalid on Raspberry Pi

Here is my code that I execute as root. It seems to work with other contacts, but not with pin 2

import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) GPIO.setup(2, GPIO.OUT, pull_up_down=GPIO.PUD_UP) 

I am not sure how to access this conclusion. Is there something I'm doing wrong?

+7
source share
4 answers

It could be something stupid, I looked exactly the same. GPIO seems to have two modes. Change GPIO.setmode (GPIO.BOARD) to

 GPIO.setmode(GPIO.BCM) 

It worked for me on a clean Raspbian installation

+18
source

You can not. Pin 2 of the Raspberry Pi expansion connector connects directly to a USB power source - it is not controlled by the processor.

Do not try to connect the fan directly to the GPIO output; they not only fail to produce the correct voltage, but they cannot drain enough current to start the fan. Trying to do this is very likely to destroy the pin driver, and may also damage other parts of the BCM2835.

If you need to turn the 5V fan on and off, you will need some auxiliary equipment to control it (for example, field transit).

+1
source

I think your mistake is that you gave pull_up_down the OUT output to a specific

 #this is only for input pins GPIO.setup(n, RPIO.OUT, initial=RPIO.LOW, pull_up_down=GPIO.PUD_UP) #CORRECT ("initial" is optional) GPIO.setup(n, RPIO.OUT, initial=RPIO.LOW) 
+1
source

In GPIO.BOARD mode, pin 2 has a voltage of 5 V, which cannot be adjusted.

When converting it to GPIO.BCM mode, it is actually GPIO2.

0
source

Source: https://habr.com/ru/post/970852/


All Articles