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.

Gru-gru
  • 151
  • 6

1 Answers1

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.

Gru-gru
  • 151
  • 6