giuliom_95
Posts: 6
Joined: Thu Oct 02, 2014 7:09 pm

GPIO input problems

Thu Nov 20, 2014 10:31 am

Hi all,
Using this guide as reference (http://falsinsoft.blogspot.it/2012/11/a ... space.html), I've started to discover the world of GPIO ports. But now there is a problem...
After that I've initialized the GPIO port #2 to make it ready for input with these commands:
echo 2 > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio2/direction

and even if there is nothing connected to the pin number 3 on my Raspberry the output of the command:
cat /sys/class/gpio/gpio2/value
is ever "1".
For being sure that I'm working with the right pin I've connected a LED in this way:
Image
and with these:
echo "out" > /sys/class/gpio/gpio2/direction
echo 1 > /sys/class/gpio/gpio2/value

the LED lights up.
What is wrong with my setup?

EDIT: Even if on the image there is a Raspberry Pi model B rev2, I'm working on a B+ board...

User avatar
Burngate
Posts: 6313
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: GPIO input problems

Thu Nov 20, 2014 11:02 am

Point 1: connecting a LED directly between a GPIO and ground is a bad idea - you should put a resistor in series with the LED to limit the current to a safe level.

Point 2: You've chosen to use one of the I2C pins - pin 5 (GPIO-3) would do the same. They both have 1k8 resistors pulling them to 3v3, so will both register as high, as inputs.

Massi
Posts: 1691
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: GPIO input problems

Thu Nov 20, 2014 11:46 am

giuliom_95 wrote:and even if there is nothing connected to the pin number 3 on my Raspberry the output of the command:
cat /sys/class/gpio/gpio2/value
is ever "1".
as always Burngate said all right things, but i wanted to underline that even on "non specific" gpios (take a look to rpi pinout to see other special pins that can have particular behaviour) if you do not connect something to the port, you can not expect a specific reading unless you put/enable a pullup/pulldown resistor.

The function of pullups (and down) is exatcly to avoid not specified reading when the port is floating (=there is nothing that is fixing its level)

(led with no resistor is a bad idea :))

Return to “Interfacing (DSI, CSI, I2C, etc.)”