Stability | experimental |
---|---|
Maintainer | erkokl@gmail.com |
Safe Haskell | None |
(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
:: Bool | If |
-> 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.
The Arduino monad.
Monad Arduino | |
Functor Arduino | |
Applicative Arduino | |
MonadIO Arduino | |
MonadState ArduinoState Arduino |
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.