hArduino-0.2: Control your Arduino board from Haskell.

Stabilityexperimental
Maintainererkokl@gmail.com
Safe HaskellNone

System.Hardware.Arduino

Contents

Description

(The hArduino library is hosted at http://leventerkok.github.com/hArduino/. Comments, bug reports, and patches are always welcome.)

hArduino: Control Arduino from Haskell, using the Firmata protocol.

The hArduino library allows construction of Haskell programs that control Arduino boards that are running the (freely available) Firmata program. Note that hArduino does not allow you to run arbitrary Haskell code on the Arduino! It simply allows you to control a board from Haskell, where you can exchange information with the board, send/receive commands from other peripherals connected, etc.

Synopsis

Running the controller

withArduinoSource

Arguments

:: Bool

If True, debugging info will be printed

-> FilePath

Path to the USB port

-> Arduino ()

The Haskell controller program to run

-> IO () 

Run the Haskell program to control the board:

  • The file path argument should point to the device file that is associated with the board. (COM1 on Windows, '/dev/cu.usbmodemfd131' on Mac, etc.)
  • The boolean argument controls verbosity. It should remain False unless you have communication issues. The print-out is typically less-than-useful, but it might point to the root cause of the problem.

See System.Hardware.Arduino.Examples.Blink for a simple example.

data Arduino a Source

The Arduino monad.

Programming the Arduino

Basic handshake with the board

queryFirmware :: Arduino (Word8, Word8, String)Source

Retrieve the Firmata firmware version running on the Arduino. The first component is the major, second is the minor. The final value is a human readable identifier for the particular board.

Controlling the pins

setPinMode :: Pin -> PinMode -> Arduino ()Source

Set the mode on a particular pin on the board

Reading and Writing digital values

digitalRead :: Pin -> Arduino BoolSource

Read the value of a pin in digital mode; this is a non-blocking call, returning the current value immediately. See waitFor for a version that waits for a change in the pin first.

digitalWrite :: Pin -> Bool -> Arduino ()Source

Set or clear a digital pin on the board

Misc utilities

waitFor :: Pin -> Arduino BoolSource

Wait for a change in the value of the digital input pin. Returns the new value. Note that this is a blocking call. For a non-blocking version, see digitalRead, which returns the current value of a pin immediately.

delay :: Int -> Arduino ()Source

Delay the computaton for a given number of milli-seconds

Hardware components on the board

Pins

pin :: Word8 -> PinSource

Declare a pin on the board by its number.

data PinMode Source

The mode for a pin.

Constructors

INPUT

Digital input

OUTPUT

Digital output

ANALOG

Analog input

PWM

PWM (Pulse-Width-Modulation) output

SERVO

Servo Motor controller

SHIFT

Shift controller

I2C

I2C (Inter-Integrated-Circuit) connection