Search code examples
raspberry-piraspberry-pi3circuit

Why is 'GPIO.setup(6, GPIO.IN)' throwing an error?


I'm trying to read the state of the input pin (BOARD pin 6, which is a ground pin) and I receive the error "ValueError: The channel sent is invalid on a Raspberry Pi".

Am I misunderstanding the definition of an input pin? My understanding was that it is simply the ground/negative pin, connecting back 'in' to the pi?

I'm trying to read the state purely for tinkering purposes, to see the value change when it's floating (not using a pull-down).


Solution

  • The Ground pin is connected, literally, to ground. It is impossible to read or write values to ground or power, as these are the circuit components. You have to connect to a GPIO pin (the green(ish? I'm colorblind) dots at http://pinout.xyz).

    enter image description here

    It is possible for the input of a GPIO pin to be set to HIGH or LOW, depending on the circuit you wish to use. If you expect the GPIO to be normally LOW and HIGH when your input is triggered (such as with a pushbutton switch), then you have to set the state to pulldown.

    I would recommend you read some of the background on microcontrollers: https://embeddedartistry.com/blog/2018/06/04/demystifying-microcontroller-gpio-settings/