An Erlang NIF for the WiringPi library for the Raspberry Pi
Erlang C
Switch branches/tags
Nothing to show
Failed to load latest commit information.
c_src Initial support for Wiring Pi version 2 Jun 19, 2013
include Wrap the shift library Aug 25, 2012
.gitignore Ignore .rebar and doc directories Apr 9, 2015
COPYING Switch from GPL to LGPL to match the switch for WiringPi itself. Jul 29, 2012
COPYING.LESSER Write info on contributions on side branches Jul 23, 2013
THANKS Add THANKS file Sep 23, 2012
rebar.config Initial support for Wiring Pi version 2 Jun 19, 2013

wpi - an Erlang NIF for the WiringPi library for the Raspberry Pi

This application is an Erlang wrapper around the WiringPi library which is a Raspberry Pi dialect of the Wiring library for Arduino. wpi makes it possible to read from and write to GPIO pins, write to LCDs, shift bits in and out or control other devices over serial interfaces or SPI and all this from a Raspberry Pi running Erlang.

Getting started

Start by downloading and installing the WiringPi library.

Then it should be possible to build wpi using rebar.

rebar compile

Before starting, you need to include a hrl file which defines some useful constants (matches those of WiringPi):


Then you can start setting up the pins and use them:

Pin = 7,
wpi:setup(), % or setup_gpio/0 or setup_sys/0
wpi:pin_mode(Pin, output),
wpi:digital_write(Pin, 1),

It helps setting the ERL_LIBS environment variable to tell Erlang where to find the code. Assuming you have a copy of the wpi application in /home/pi/src/wpi you can add wpi and other apps in the src directory to the code path by setting the environment variable like this:

export ERL_LIBS=/home/src/

If you get an error like this, it means that the library doesn't have root access and you have called wpi:setup/0 or wpi:setup_gpio/0. This is solved by running Erlang as root, but please consider the security implications of doing so, or by using the gpio binary followed by wpi:setup_sys/0 which can be run as a normal user.

wiringPi: Must be root to call wiringPiSetup(). (Did you forget sudo?)


  • read from, write to and control pins
  • control and write to LCDs
  • shift in/out bits (untested)
  • soft PWM
  • read from and write to a serial console
  • write and read binary data from the SPI bus


This NIF is entirely experimental - use at your own risk. It has been used to both write to (LED), read from (button) pins and control an LCD successfully, while some functionality may be untested.


Contributions are more than welcome. Please commit them on a side branch (not master) with a descriptive name to make code reviews easier.


Credits go to Gordon Henderson for the WiringPi library.