Update: 14th May, 2013
wiringPi version 2 has been released and now has its own website (http://wiringpi.com/) to look after it. Most of the documentation on the projects site has been copied over to it the new site, but there may still be 1 or 2 pages that are still missing. I’d encourage you to use the new site if possible where there will be a forum and wiki (when I get time to implement them!)
WiringPi is an Arduino wiring-like library written in C and released under the GNU LGPLv3 license which is usable from C and C++ and many other languages with suitable wrappers (See below)
You may be familiar with the Arduino… Briefly; Arduino is really two things; one is a hardware platform, the other software, and part of the software is a package called Wiring. Wiring is the core of the input and output for the Arduino, so I thought it would be good to replicate that functionality (or a good usable subset) on the Raspberry Pi.
The Raspberry Pi has a 26-pin General Purpose Input/Output (GPIO) connector and this carries a set of signals and buses. There are 8 general purpose digital I/O pins – these can be programmed as either digital outputs or inputs. One of these pins can be designated for PWM output too. Additionally there is a 2-wire I2C interface and a 4-wire SPI interface (with a 2nd select line, making it 5 pins in total) and the serial UART with a further 2 pins.
The Revision 2 Raspberry Pi has an additional 4 GPIO lines on a separate connector which you have to solder onto the board.
The I2C and SPI interfaces can also be used a general purpose I/O pins when not being used in their bus modes, and the UART pins can also be used if you reboot with the serial console disabled, giving a grand total of 8 + 2 + 5 + 2 = 17 I/O pins.
WiringPi includes a command-line utility gpio which can be used to program and setup the GPIO pins. You can use this to read and write the pins and even use it to control them from shell scripts.
WiringPi Resources
Additional Libraries
- Serial port handling (both on-board and USB)
- LCD library
- Software PWM library
- Shift library
- Simplified SPI handling library
- Simplified I2C handling library
- GPIO Interrupt Handling
The PiFace board:
WiringPi fully supports the PiFace board too. See this page for more details.
Other wiringPi resources:
- Thanks to Gadgetoid there are now wrappers for Ruby, Python and Perl and these can all be found here.
- Thanks to Jeroen Kransen there are wrappers for Java which can be found here.
- Thanks to Dave Boulton for creating a TCL wrapper which can be found here.
- Pi4J is another Java project that uses WiringPi. It has a Github repository here.
- An implementation in Node by Igor Soarez
Pin numbering
WiringPi supports both an Arduino style pin numbering scheme which numbers the pins sequentially from 0 upwards, as well as the Raspberry Pi’s native BCM_GPIO pin numbering scheme.
- Note that when using the BCM_GPIO numbering scheme, you must take into account the board revision! Some pins changed their meaning and numbers from revision 1 to revision 2. Using the wiringPi pin numbering scheme caters for these changes and progams will run un-changed on their board revision.
WiringPi normally uses a very low-level mechanism to access the underlying hardware – this results in very fast access, however the down-side is that your programs need to be run as root, so in addition to this, wiringPi has the ability to use the traditional /sys/class/gpio/ style interface, and if the GPIO pins have been exported and had their ownership changed appropriately, then applications using the wiringPi library, can be run without root privileges.
A supporting program, gpio, allows you to export and unexport the devices through the /sys/class/gpio/ interface. This program is a set-uid program and can be run as a normal user. The gpio program can be used to control the GPIO pins in its own right, allowing easy testing of the GPIO interface from the command-line or simple shell scripts.
- See the pins page for a description of the WiringPi pin to GPIO connector mappings, and take note of the…
- … special pin functions too.
- The Functions page lists and documents what’s available, and
- There are some examples here too.
- Download and Install
Additional information can be found on the Raspberry Pi Wiki pages.