wiringPi-1.0: Access GPIO pins on Raspberry Pi via wiringPi library

Copyright© Patrick Pelletier 2017
LicenseBSD3
Maintainercode@funwithsoftware.org
Stabilityexperimental
PortabilityRaspberry Pi
Safe HaskellNone
LanguageHaskell2010

System.Hardware.WiringPi

Contents

Description

This is a Haskell binding to the wiringPi library. The functions here (mostly) correspond directly to the functions in the C library, except for how initialization and pin numbering are handled. To use this library, you must either run as root, or set the WIRINGPI_GPIOMEM environment variable. However, if you set WIRINGPI_GPIOMEM, then PWM does not work, so to use PWM you must be root.

Synopsis

Types

data Pin Source #

Represents a pin number. The constructor determines which one of the three pin numbering schemes is used.

Constructors

Wpi Int

use wiringPi pin number

Gpio Int

use BCM_GPIO numbering (these are the numbers on the Adafruit cobbler).

Phys Int

use physical pin numbers on P1 connector

Instances

Eq Pin Source # 

Methods

(==) :: Pin -> Pin -> Bool #

(/=) :: Pin -> Pin -> Bool #

Ord Pin Source # 

Methods

compare :: Pin -> Pin -> Ordering #

(<) :: Pin -> Pin -> Bool #

(<=) :: Pin -> Pin -> Bool #

(>) :: Pin -> Pin -> Bool #

(>=) :: Pin -> Pin -> Bool #

max :: Pin -> Pin -> Pin #

min :: Pin -> Pin -> Pin #

Read Pin Source # 
Show Pin Source # 

Methods

showsPrec :: Int -> Pin -> ShowS #

show :: Pin -> String #

showList :: [Pin] -> ShowS #

data Mode Source #

Pin mode, used with pinMode.

Constructors

INPUT

digital input

OUTPUT

digital output

PWM_OUTPUT

pulse-width modulation; only supported on wiringPi pin 1

GPIO_CLOCK

clock output; only supported on wiringPi pin 7

data Pud Source #

Use with pullUpDnControl to enable internal pull-up or pull-down resistor.

Constructors

PUD_OFF

disable pull-up/pull-down

PUD_DOWN

enable pull-down resistor

PUD_UP

enable pull-up resistor

Instances

Bounded Pud Source # 

Methods

minBound :: Pud #

maxBound :: Pud #

Enum Pud Source # 

Methods

succ :: Pud -> Pud #

pred :: Pud -> Pud #

toEnum :: Int -> Pud #

fromEnum :: Pud -> Int #

enumFrom :: Pud -> [Pud] #

enumFromThen :: Pud -> Pud -> [Pud] #

enumFromTo :: Pud -> Pud -> [Pud] #

enumFromThenTo :: Pud -> Pud -> Pud -> [Pud] #

Eq Pud Source # 

Methods

(==) :: Pud -> Pud -> Bool #

(/=) :: Pud -> Pud -> Bool #

Ord Pud Source # 

Methods

compare :: Pud -> Pud -> Ordering #

(<) :: Pud -> Pud -> Bool #

(<=) :: Pud -> Pud -> Bool #

(>) :: Pud -> Pud -> Bool #

(>=) :: Pud -> Pud -> Bool #

max :: Pud -> Pud -> Pud #

min :: Pud -> Pud -> Pud #

Read Pud Source # 
Show Pud Source # 

Methods

showsPrec :: Int -> Pud -> ShowS #

show :: Pud -> String #

showList :: [Pud] -> ShowS #

type PwmValue = Word16 Source #

Value used with pwmWrite. Typically ranges from 0-1024, but the range can be increased up to 4096 by calling pwmSetRange.

Setup function

See WiringPi Setup functions. Unlike the C version of wiringPi, the Haskell binding will automatically call the setup function the first time a wiringPi function is called. The only reason to call it manually is if you want to check for errors earlier than your first call. It is also harmless to call it multiple times. In the Haskell binding the "GPIO" numbering scheme is always used internally, but the Pin constructors allow you to choose whichever numbering scheme you want, on a pin-by-pin basis. This avoids having to choose a single pin numbering scheme at initialization time, as you do with the C library.

wiringPiSetupGpio :: IO () Source #

Initialize the wiringPi library. This is optional, because it will automatically be called on the first use of a wiringPi function. Raises an exception if the underlying C function returns an error code. However, in practice, the C function wiringPiSetupGpio terminates the program on error. Setting the environment variable WIRINGPI_CODES is supposed to change this behavior, but in my experience it doesn't, and the program is still terminated on error.

Core functions

pinMode :: Pin -> Mode -> IO () Source #

pwmWrite :: Pin -> PwmValue -> IO () Source #

Default range is 0-1024, but it can be changed with pwmSetRange.

Additional functions

digitalWriteByte :: Word8 -> IO () Source #

Write 8 bits to the 8 pins that have wiringPi pin numbers 0-7.

pwmSetRange :: PwmValue -> IO () Source #

Change the range used by pwmWrite. Default is 1024. Maxium is 4096.

pwmSetClock :: PwmValue -> IO () Source #

Change the PWM divisor. Range is 2-4095.

pinToBcmGpio :: Pin -> Maybe Int Source #

Converts a pin to its "Broadcom GPIO" number. This relies on unsafePerformIO internally, because the pin mapping depends on the board revision. Returns Nothing if the pin number is invalid; e. g. it is out of range or is a power or ground pin on the physical connector.