wpi - an Erlang NIF for the WiringPi library for the Raspberry Pi
This application is an Erlang wrapper around the WiringPi library.
Start by downloading and installing the WiringPi library.
Then it should be possible to build wpi using rebar.
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:pin_mode(Pin, ?WPI_OUTPUT), wpi:digital_write(Pin, ?WPI_HIGH),
It helps setting the ERL_LIBS environment variable to tell Erlang
where to find the code. Assuming you have a copy of the
/home/pi/src/wpi you can add
wpi and other apps in
src directory to the code path by setting the environment
variable like this:
If you get an error like this, it means that the library doesn't have root access. This is solved by running Erlang as root, but please consider the security implications of doing so. A future version of the library may have another way of handling this.
wiringPiSetup: Unable to open /dev/mem: Permission denied
- 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
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.
This library currently only supports wiringPiSetup(), not wiringPiSetupGpio() nor wiringPiSetupSys(). This means that it's currently only possible to use the WiringPi pin numbering scheme outlined in the pins section.
Contributions are more than welcome.
Credits go to Gordon Henderson for the WiringPi library.