Tuesday, February 26, 2013

WiringPi: IO control for Raspberry Pi

WiringPi
Is a C library to control the IO pins, like the GPIO, I2C, SPI and so on...
WiringPi also has a commandline tool to control the GPIO from a shell script, which is cool and makes
writing small simple scripts very easy to automate certain stuff.
I'll handle here only the WiringPi utility, as that's all I need for now.
For more information about WiringPi, take a look at this link:
https://projects.drogon.net/raspberry-pi/wiringpi/

Installation:
First we need git tool to download the sources:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install git-core


(clone the project)
git clone git://git.drogon.net/wiringPi

(got the wiringPi folder and build the project)
cd wiringPi
./build


To install the executable in i.e. /usr/bin/ you need sudo for that.
Try the following command to see if all went well:
gpio -v
gpio readall


GPIO Utility:
Now, if we want to use GPIO pin 1 to be the output, we do as follows:
gpio mode 1 out
Here we say, make GPIO pin 1 as output.

To make pin 1 HIGH:
gpio write 1 1
This is translated as write pin 1 as 1.

The GPIO has also an internal pull-up/down resistor, this can be controlled too:
gpio mode 1 up
gpio mode 1 down
gpio mode 1 tri

No comments:

Post a Comment

NSNotification example