Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ValueError: The channel sent is invalid on a Raspberry Pi - Controlling GPIO Pin 2 (BOARD) using Python causes Error

So I have a tiny little fan connected to pin 6(Ground) and pin 2. I am trying to manually start and stop the fan when needed but I am getting this error when trying:

ValueError: The channel sent is invalid on a Raspberry Pi

Here is my code that I am executing as root. It seems to be working on other pins but not 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 pin. Is there something I am doing wrong?

like image 410
Georgi Angelov Avatar asked Jun 15 '14 03:06

Georgi Angelov


1 Answers

It could be something stupid, i was looking exacty the same. It seems there are two modes in the GPIO. Change GPIO.setmode(GPIO.BOARD) to

GPIO.setmode(GPIO.BCM) 

It worked for me on a clean installation of Raspbian

like image 197
Jesus Cepeda Avatar answered Sep 27 '22 18:09

Jesus Cepeda