Notes » 2008 » 10 » 11

The process of getting Flash to communicate with an Arduino on Linux (specifically Ubuntu 8.04) seems to be poorly documented. The basic steps are as follows:

  1. Download, compile and install serproxy using the whole make, make install rigmarole. Serproxy will be installed by default in /usr/local/bin.

  2. Configure serproxy appropriately by copying the sample serdata.cfg file to the /etc directory and editing the requisite information.

    • Ensure serproxy uses the same baud setting as the Firmata firmware, which by default is 57600.

    • Also, serproxy does not seem to give an option for the USB port (/dev/ttyUSB0) that an Arduino Diecimila connects through on Ubuntu. A symlink from /dev/ttyUSB0 to /dev/ttyS2 (which is COM3 as far as serproxy is concerned) should do the trick. Any other unused serial port will probably also work.

  3. Install Firmata for protocol version 1.0 on the Arduino board using the Arduino software.

  4. Use the Glue Actionscript 3.0 library to communicate with the Firmata firmware on the Arduino via a running instance of serproxy. Unfortunately, Glue does not seem terribly well-documented, but the source code is readable enough. This is a quick-and-dirty sample app that turns on and off an LED connected to pin 13 when the mouse button is clicked:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package
{
  import net.eriksjodin.arduino.Arduino;
  import flash.display.Sprite;
  import flash.events.MouseEvent;
  import flash.events.Event;
 
  public class ArduinoTest extends Sprite
  {
    public static const LED_PIN:int = 13;
    private var arduino:Arduino;
    private var ledOn:Boolean = false;
 
    public function ArduinoTest()
    {
      arduino = new Arduino( "127.0.0.1", 5331 );
      arduino.addEventListener( Event.CONNECT, handleSocketConnect );
    }
 
    public function handleSocketConnect( event:Event ):void
    {
      trace( "Arduino socket connected!" );
      arduino.setPinMode( LED_PIN, Arduino.OUTPUT );
      stage.addEventListener( MouseEvent.MOUSE_UP, handleMouseUp );
    }
 
    private function handleMouseUp( event:MouseEvent ):void
    {
      if( ledOn ) {
        trace( "Light off!" );
        arduino.writeDigitalPin( LED_PIN, Arduino.LOW );
        ledOn = false;
      }
      else {
        trace( "Light off!" );
        arduino.writeDigitalPin( LED_PIN, Arduino.HIGH );
        ledOn = true;
      }
    }
  }
}

Et, voila!