hArduino-0.1: 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 (PinMode, Bool)Source

Read the value of a pin in digital mode.

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

Set or clear a particular digital pin on the board.

Misc utilities

delay :: Int -> Arduino ()Source

Delay the computaton for a given number of milli-seconds.

Hardware components on the board

Pins

pin :: Int -> PinSource

Smart constructor for a pin. The input should be between 1 and 13:

  • Pins 0-1 are reserved for TX/RX; so can't be directly used.
  • 13 pins is UNO specific, we will need to expand this definition if we start supporting other boards.

data PinMode Source

The mode for a pin.

Constructors

INPUT 
OUTPUT 
ANALOG 
PWM 
SERVO 

Instances