(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.
- withArduino :: Bool -> FilePath -> Arduino () -> IO ()
- data Arduino a
- queryFirmware :: Arduino (Word8, Word8, String)
- setPinMode :: Pin -> PinMode -> Arduino ()
- digitalRead :: Pin -> Arduino Bool
- digitalWrite :: Pin -> Bool -> Arduino ()
- waitFor :: Pin -> Arduino Bool
- delay :: Int -> Arduino ()
- pin :: Word8 -> Pin
- data PinMode
Running the controller
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. (
COM1on Windows, '/dev/cu.usbmodemfd131' on Mac, etc.)
- The boolean argument controls verbosity. It should remain
Falseunless 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.
The Arduino monad.
Programming the Arduino
Basic handshake with the board
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
Reading and Writing digital values
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.
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.