Haskell Arduino Serial I/O
Overview
The Arduino is a popular electronics prototyping platform. It is easy to interface to a computer via a real or emulated (Through USB) serial connection. This write-up details how to communicate with the Arduino in Haskell.
Pre-requisites
- Arduino software installed and working.
- Haskell Platform installed with Serial package from Hackage(cabal install serial)
- A program with serial I/O loaded on the Arduino (The PhysicalPixel example that comes with arduino will work)
Send a simple command
import System.Serial import IO serialCommand :: String -> IO () serialCommand comm = do h <- openSerial "/dev/ttyUSB0" B9600 8 One NoParity Software hPutStr h comm
Serial Monitor
- serialMonitor.hs -- Code that acts like the Arduino serial monitor. Handles input and output of data.
Servo and LED Demo
Quick demo of running a servo motor and LED from Haskell using serialMonitor.hs. H turns on the light, L turns it off, the numbers 0-9 are the step to take (0-180) by 20 degree increments. The Arduino sends back a status after each command, saying either the state of the light, or the degree of the servo.
- serialServo.pde -- Arduino code used in this demo. Moves a servo between 0-180 degrees in 20 degree steps, and turns on a light
Video of serialMonitor.hs program running:
Comments(0)
2010-05-23 22:24:04