Fine-tuning our control - using the GPIO command-line tools

Controlling the Raspberry Pi's GPIO pins is surprisingly simple using the GPIO command-line interface.

First, install the GPIO command-line tools by running this:

git clone git://git.drogon.net/wiringPi
cd wiringPi/
./build

Verify that the gpio command-line tool has been installed by running this:

gpio -v

Let's say we have an LED connected to pin 4 (to be more specific, the positive end is connected to pin 4 and the negative end is connected to one end of a resistor, whose other end is connected to the ground pin).


This circuit is similar to the pin-low Write mode we discussed earlier.

You can test this circuit through the following steps:

  1. Set the pin 4 to output mode:
gpio mode 4 output
  1. Set the pin to high:
gpio write 4 1

You should now see the LED glowing.

  1. Set the pin to low:
gpio write 4 0

The LED should stop glowing now.

The GPIO command-line tools have many more features, such as pin reading, mode setting, and exporting. You can see a detailed view of all the features this tool has to offer on its main page:

man gpio
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.71.142