The GPIO: General Purpose Input/Output lets you interface your Raspberry Pi with the outside world, making it a powerful interactive device for just $40-$50.

This Instructable will show you how to install the GPIO package on your Raspberry Pi and how to wire up a simple push button circuit with an LED.

I use the command-line and Python for this, no web browser or GUI.

Before you do this Instructable, make sure you have your Raspberry Pi ready for action. My Ultimate Raspberry Pi Configuration Guide covers how to do this in detail.

You will want to have an internet connection to download the packages and probably use ssh. 

Step 1: Gather your components

* Raspberry Pi
* Cobbler breakout board with cable — you can order this from Adafruit for $8.
* Breadboard
* Wires — breadboard or otherwise
* standard LED
* 270 Ohm resistor
* 1K resistor
* 10K resistor
* Push button
* USB power for RPI (not pictured)
* Monitor + keyboard (not pictured)

* wire-stripper
* small diagonal snips
* multimeter for checking continuity

<p>I need this pdf to use this feature for my project. But I cant afford this. Can anyone mail me this PDF.</p>
<p>You can convert this page to a pdf from a website.</p><p>Example- www.web2pdfconvert.com</p>
<p>good catch! my circuit diagram has the LED flipped. I'll have to correct this at some point soon.</p>
<p>Hey! thanks a lot for the tutorial! it's an indescriptible feeling when you make it work!. I just have a quick comment:</p><p> I am no expert on electronics, however, from other tutorials I have taken, I have noticed that in the breadboard diagrams, the anode (+) leg is usually depicted as the longer &quot;curved&quot; leg. however, in your diagram this leg is connected to ground (also the LED triangle in schematic points towards the output). Thus, the first time I tried it it didn't work but once I changed the direction of the legs it worked like magic!.</p>
<p>Good point. I'm usually stopping my Python scripts with a ctrl-C rather than an event like a keydown, and so the GPIO.cleanup() doesn't get called. My workaround is setting the warnings to false. But, as you point out, the GPIOs will stay at the state they were last in, leaving the LEDs on &mdash; better coding practice would be to properly close the ports.</p>
<p>The simplest way to ensure some cleanup code gets run is to wrap your while loop in a try/finally block.</p><p>If you specifically want to catch Ctrl+C but nothing else, you can use try/except to catch KeyboardInterrupt.</p><p>Finally, if you want a more robust way to ensure some cleanup gets done, take a look at lines 312 through 322 in this revision of my Procrastinator's Timeclock utility.</p><p><a href="https://github.com/ssokolow/timeclock/blob/3bb9889b6bdbe364087780aae22e349d6544f98c/timeclock.py#L312" rel="nofollow">https://github.com/ssokolow/timeclock/blob/3bb9889...</a></p><p>First, it assigns the cleanup function to sys.exitfunc so it'll get called on clean exit, then it hooks all the common POSIX signals the kernel might send s ensure that they trigger a clean exit.</p><p>* SIGINT is sent by Ctrl+C, which INTerrupts the program.<br>* SIGTERM is sent by things like task managers politely asking your program to TERMinate itself.<br>* SIGHUP is sent by the kernel when your program loses the terminal it's attached to.<br>* SIGQUIT is sent by Ctrl+\, which asks the program to quit and dump core if core dumping is enabled.</p><p>(My code technically doesn't handle SIGQUIT properly, since it doesn't dump core, but I've never seen people using it properly.)</p><p>Finally, it also uses try/except to catch Ctrl+C, just to play it safe. (And it's still not perfect because PyGTK doesn't let the program attach a handler for &quot;lost connection to X server&quot;)</p><p>If you want a version that's a bit more complicated, but also works on Windows, look at this revision:</p><p><a href="https://github.com/ssokolow/timeclock/blob/7a505000662678fed29deeb418951c5e741e42b4/timeclock.py#L234" rel="nofollow">https://github.com/ssokolow/timeclock/blob/7a50500...</a></p><p>(It checks that each signal exists before hooking it)</p>
Thanks for sharing!<br><br>This is beyond what I've tried to do so far. But, I'll check out the SIG___ interrupts that you've pointed out here.<br><br>And hopefully others can make use of your code on GitHub as well.
<p>Oh, I meant to mention where the name &quot;SIGHUP&quot; comes from.</p><p>Back in the days when computers cost a fortune and users had to share them, it meant that the modem connecting the terminal to the computer had Hung UP.</p>
sometimes if your don't properly close the gpios they stay at the state they were last set. when I was making a robot with my pi, and I quickly cancelled the script so it wouldn't run into something, it continued on its merry way. simply put GPIO.cleanup() at the end of your program, and you should stop getting that warning. great little indestructible though:)
great little instructable*

About This Instructable


318 favorites


Bio: Scott Kildall is an artist who indulges in network performances and creative coding. He currently is an artist-in-residence at Autodesk.
More by scottkildall: Bad Data: Waterjet Etching Datasets Guide to the T-962A Reflow Oven Water Works: 3D prints of the San Francisco Water System with Map
Add instructable to: