Monday, June 18, 2012

Raspberry PI - Playing a bit with GPIO



Playing a bit with the GPIO on the Raspberry pi was looking great.

Being able to do so was like geting out of the virtual;
Sending commands to a computer would interact with the real life for the first time.

There is a lot of informations around to start with :


And of course, keep in mind that :

Extreme caution should be exercised when interfacing hardware at a low level, you may damage your RPi, your equipment and potentially yourself and others. Doing so is at your own risk!

For a first basic step, I wanted to be able to blink a led, turning it on and off from the command line.

Here is just a brief summary on how I get it to work.

- Step 1 : Go buy :

  • 1 x Press conector with cable (http://www.raspberrypi.org/archives/1404)
  • 1 x 270 ohms resistor
  • 1 x Red LED
  • Some wires
  • If you don't know how to solder (neither do I) : 1 x Bread board


A friend of mine gave me his bread board, so i can't tell how much it costs, but I paid from a local electronics store 2 euros for the resistor, the LED and the wires (why did i take 3 meters by the way ?), and an extra 10 euros for the press connector, its cable and the assembly.


- Step 2 : Identify the "Ground" and "GPIO-25" pins on the raspberry pi
GPIO-PINs
  • They are outlined in red on the "GPIO-PINs" image 
  • "Ground" is pin number 6
  • "GPIO-25" is pin number 22
I choose to use GPIO-25, but it could have been any other GPIO.


- Step 3 : Connect all of this together


  • Connect the "GPIO-25" pin on the raspberry pi to the resistor
  • Connect the resistor to the "+" side of the LED (the one that has the long leg)
  • Connect  the "-" side of the LED to the "ground" pin on the raspberry pi 


- Step 4 : Send the appropriate commands to turn the LED On and Off from the command line : 


# set up GPIO-25 and set it to output : 
echo "25" > /sys/class/gpio/export echo "out" > /sys/class/gpio/gpio25/direction
# Turn On the LED connected to GPIO-25 : 
echo "1" > /sys/class/gpio/gpio25/value
# Turn Off the LED connected to GPIO-25 : 
echo "0" > /sys/class/gpio/gpio25/value
# Clean up : 
echo "25" > /sys/class/gpio/unexport
And here it what it looks like at the end : 


That's it



No comments: