jfedor
Posts: 7
Joined: Tue Apr 17, 2012 5:30 pm
Contact: Website

Re: Please explain GPIO like I'm five

Tue Apr 17, 2012 6:40 pm

Hi,

I got my Pi today and I'm incredibly excited.

I'd like to connect a pushbutton (or a switch) to the board and read its state. From what I understand that's what the GPIO pins can be used for. I've seen that there's a sysfs interface to GPIO and I think I can manage that part, but what about the actual physical connections. Two wires come out of the switch, should I connect one of them to one of the GPIO pins and the other to GND? Is that it? Do I need resistors and whatnot? I know absolutely nothing about electronics and I'd rather not fry my shiny new Pi.

Thanks.

naicheben
Posts: 344
Joined: Sat Jan 28, 2012 12:28 pm
Contact: Website

Re: Please explain GPIO like I'm five

Tue Apr 17, 2012 7:15 pm

I think it is realy good explained here:

http://elinux.org/RPi_Tutorial.....6_Software

and for your purpose:

http://elinux.org/RPi_Tutorial.....itch_Input

jfedor
Posts: 7
Joined: Tue Apr 17, 2012 5:30 pm
Contact: Website

Re: Please explain GPIO like I'm five

Tue Apr 17, 2012 7:42 pm

I spent half of today on that wiki, I don't know how I missed that.

Thank you.

naicheben
Posts: 344
Joined: Sat Jan 28, 2012 12:28 pm
Contact: Website

Re: Please explain GPIO like I'm five

Tue Apr 17, 2012 7:53 pm

I know how you feel! If I hadn't read about this article here I would not have found it on the Wiki. It's a big problem I think. Hopefully we can sort it out in time.

User avatar
Gert van Loo
Posts: 2485
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: Please explain GPIO like I'm five

Tue Apr 17, 2012 8:34 pm

Easiest if you connect one pin of your switch to GPIO0 or GPIO1, the other side to ground. That is because those two pins already have an 1800 Ohm pull-up resistor. That is a resistor to the 3.3V supply which pulls the pin high unless you press the button which makes it go low. So button press is LOW, button release is HIGH.

Assume you are using GPIO0 from your unix prompt type:

'sudo sh'

'echo 0 >/sys/class/gpio/export'

'echo in >/sys/class/gpio/gpio0/direction'

'cat /sys/class/gpio/gpio0/value'

Repeat the last command with the button pressed and not pressed.

To come back to your normal prompt type 'exit'

Good luck!

jfedor
Posts: 7
Joined: Tue Apr 17, 2012 5:30 pm
Contact: Website

Re: Please explain GPIO like I'm five

Tue Apr 17, 2012 11:40 pm

Thank you for your reply!

The GPIO0 pin you're talking about would be the second pin from the left in the bottom row of the header, correct? The nomenclature is a bit confusing to me, it seems there's a separate numbering scheme for the SoC's pins and for the board's pins.

texy
Forum Moderator
Forum Moderator
Posts: 5157
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: Please explain GPIO like I'm five

Wed Apr 18, 2012 11:22 am

This other wiki link may help :

http://elinux.org/RPi_Low-leve.....eripherals

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

jfedor
Posts: 7
Joined: Tue Apr 17, 2012 5:30 pm
Contact: Website

Re: Please explain GPIO like I'm five

Wed Apr 18, 2012 1:13 pm

Yeah, this one I managed to find on my own. That's where the confusion comes from. You'll notice how in the diagram on the right, sixth pin in the bottom row is marked as GPIO0? And yet I'm pretty sure the one Gert meant was the one marked "I2C0_SDA"/"BCM2835 GPIO0-ALT0" in one of the tables (a different pin).

User avatar
meltwater
Posts: 1014
Joined: Tue Oct 18, 2011 11:38 am

Re: Please explain GPIO like I'm five

Wed Apr 18, 2012 1:29 pm

Can"t wait to update the Easy GPIO stuff with some RPi code.

And get the rest of the articles done (the alpha-numeric display in particular).

Got nothing to test with yet though

Glad it is useful…will see about trying to link it better perhaps (DONE: linked from Getting Started section).
______________
http://www.themagpi.com/
A Magazine for Raspberry Pi Users
Read Online or Download for Free.

My new book: goo.gl/dmVtsc

Meltwater's Pi Hardware - pihardware.com

Like the MagPi? @TheMagP1 @TheMagPiTeam

Return to “Beginners”