2

I am trying to connect a button to my raspberry pi 3 (model B). I want to do it via the sysfs approach. Here is a picture or my small circuit: Picture of the circuit

It cannot be simpler: the black wire is connected to a GROUND pin and to the breadboard. The white wire is connected to pin GPIO 2 and a 1K ohm resistance is attached to it. According to https://fr.pinout.xyz/pinout/pin3_gpio2#, this pin features a 1.8k Ohm pull-up resistance.

Now, because I am not using Raspbian but a Debian buster compiled for raspberry, the GPIO pin numbers are offset by 458 (see https://wiki.debian.org/RaspberryPi3).

I export the pin and set it as input:

echo '460' > /sys/class/gpio/export
echo 'in' > /sys/class/gpio/gpio460/direction

Now I read the value:

cat /sys/class/gpio/gpio460/value

This outputs '1', and this is normal since this pin is pulled-up by default.

My problem is the following: when I close the circuit, this still reads '1'. Can you explain this behaviour?

When using another pin as output, I can controll a LED so this does not come from the strange gpio pin numbering of this OS.

  • 1
    It's often said that a picture is worth a thousand words, but you may have found the exception! :) Ground is pin 6, not GPIO3 (pin 5). See raspberrypi-spy.co.uk/2012/06/… – Edward Dec 29 '18 at 15:34
  • Oops yes thanks, I corrected my post (but I indeed used physical pin 6 as ground). – Gru-gru Dec 29 '18 at 16:28
3

I think I know what went wrong. I did the same circuit as the one pictured in Mosmas' post here, except that I used a 1k resistor. It divided the voltage too much and so the pin was not reading a clear 0. I changed to a 300 Ohm resistor and it works now. Also, as Gordon points out in the same thread, I could also remove this resistor entirely, if I'm not afraid of accidentally creating a shot-circuit.

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.