MyNixOS website logo
Description

Access GPIO pins on Raspberry Pi via wiringPi library.

This is a Haskell binding to the wiringPi library, which allows you to interface with the GPIO pins on the Raspberry Pi. Unlike some other solutions for using the Raspberry Pi's GPIO pins, wiringPi provides access to more advanced features, such as enabling the internal pull-up or pull-down resistors.

Hackage

This is a Haskell binding to the wiringPi library, which allows you to interface with the GPIO pins on the Raspberry Pi. Unlike some other solutions for using the Raspberry Pi's GPIO pins, wiringPi provides access to more advanced features, such as enabling the internal pull-up or pull-down resistors.

Usage

To use this library, you must either run as root, or set the WIRINGPI_GPIOMEM environment variable. (Set it to anything; the value does not matter.) However, PWM will not work if WIRINGPI_GPIOMEM is set.

This library will only build on the Raspberry Pi. Before building this library, you must install the "wiringPi" C library on your Raspberry Pi, like this:

sudo apt-get install wiringpi

Tested on a Raspberry Pi Model B, with Raspbian Jessie Lite, using the system-provided Haskell compiler. (GHC 7.6.3.)

Pin Numbering

WiringPi allows each pin to be identified by one of three names. A pin can be identified by its physical pin number, by its Broadcom GPIO number (this is the one most commonly used in the Raspberry Pi community), or by its wiringPi pin number. The Pin type has three constructors (Wpi, Gpio, and Phys), allowing you to call a pin by any of its three names. These names are synonymous and interchangeable.

The following diagram illustrates the three names of each pin, and also identifies which pins can be placed in PWM_OUTPUT mode or GPIO_CLOCK mode.

Pinout

Similar diagrams are available on the wiringPi site or on pinout.xyz.

One additional wrinkle is that some very early Raspberry Pis use different Broadcom GPIO numbers for a few of the pins. WiringPi automatically takes this into account, but it means that equality for Pin actually depends on which board revision you have.

Licensing

This Haskell binding is licensed under the 3-clause BSD license, and the examples in the examples directory are in the public domain. However, be aware that the wiringPi C library itself is licensed under the LGPLv3+.

Examples

There are several examples in the examples directory. You can run each example by wiring up a circuit on a breadboard as specified by the comments in the example. Or, for something more permanent and professional-looking, you can use the hs-wiringPi test board. The hs-wiringPi test board can be used with all of the examples, except for wpi-fishdish, which requires the Fish Dish board instead.

Metadata

Version

1.0.1.1

Executables (7)

Show all
  • bin/pwm-example
  • bin/wpi-fishdish
  • bin/output-example
  • bin/write-byte-example
  • bin/turn-off
  • bin/wiringPi-test
  • bin/isr-example

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows