Arduino and Flash, using SerProxy and AS3Glue
I just thought I'd post my serproxy config file here, with some additional comments for those struggling to get started. As you may have read I've been playing around with it a little and found serproxy + as3glue is a seriously good, quick and easy way to get started. After uploading the correct firmata.pde file, the rest is easy to get anyone started setting and controlling the in- and outputs of the Arduino board. To save you the troubleshooting, I thought I'd share my current working set up.
Here's a little outline of the stuff you'll need to get set up;
- Arduino board
- Arduino IDE and Serial Proxy
- Firmata communication protocol Standard_Firmata_334
- AS3Glue
- and off course Flash/Flex
And just so you are aware, I'm on PC+WindowsXP
To get started, you'll need to download and install the Arduino IDE. I'm using version 0011. The install procedure is quite simple and well explained on the website, so I won't go into that any further. This'll get your arduino up and running. Make a note of the port used for the Arduino. Eventhough there's a workaround, I suggest assigning a port < 10. You can change this by altering the device settings for this USB serial Port in your Device Manager.
Next up, is uploading the right bit of code to the board, the Firmata code. AS3 Glue also includes a version of this software, but this failed to work for me as I couldn't locate the required includes. The Firmata protocol, which can be downloaded here worked fine. With the IDE opened, locate and open the Standard_Firmata.pde file. Before you upload, make sure the baud rate is set to 57600 in the setup method. This will match the configuration settings for the serial proxy later:
-
...
-
/*==============================================================================
-
* SETUP()
-
*============================================================================*/
-
void setup() {
-
byte i;
-
-
Serial.begin(57600); // 9600, 14400, 38400, 57600, 115200
-
...
With this part done, you won't need to touch the IDE any more.
Before running the proxy server, serproxy.exe, alter the configuration settings so it'll work through the right ports and with AS3Glue. I've included my serproxy.cfg file as an example - I'm using port 8:
-
# Config file for serproxy
-
# Original documentation not included you can download the original package at
-
# http://www.arduino.cc/en/Main/Software
-
-
# These settings are for an Arduino board with Standard_Firmata.pde, connected to COM port 8
-
# Ports> 9 are likely to cause errors
-
-
# Transform newlines coming from the serial port into nils
-
# for AS3 Glue by eriksjodin
-
# http://code.google.com/p/as3glue/
-
newlines_to_nils=false
-
-
# Choose the COM port where Arduino is connected
-
# You can find this in the Arduino IDE Tools - Serialport
-
comm_ports=8
-
-
# Default settings
-
# Make sure Standard_Firmata.pde is the same as baud rate set here (57600)
-
# http://www.arduino.cc/playground/Interfacing/Firmata
-
comm_baud=57600
-
comm_databits=8
-
comm_stopbits=1
-
comm_parity=none
-
-
# Idle time out in seconds
-
timeout=300
-
-
# Port settings
-
# Change the net_port number in the same number as the serialport number at the "comm_ports" line
-
net_port8=5331
The final step to get set up is simply to download AS3Glue if you haven't done so already. Set the actionscript path so Flash knows where to find the code (or just copy the 'net' folder and contents to where you're going to be testing), import the classes into your document, add your code, run the serproxy.exe before you connect, and that's pretty much all there is to it. The AS3Glue download has a few examples to get started as well.
Here's my flash version of the pushbutton example to get you started:
-
// Glue example based on the Pushbutton tutorial
-
// http://www.arduino.cc/en/Tutorial/Pushbutton
-
-
package{
-
-
import flash.display.Sprite;
-
import flash.events.Event;
-
import net.eriksjodin.arduino.Arduino;
-
import net.eriksjodin.arduino.events.ArduinoEvent;
-
-
//document class
-
public class PushbuttonExample extends Sprite
-
{
-
public var arduino:Arduino;
-
public var ledPin:int = 13;
-
public var inPin:int = 7;
-
-
public function PushbuttonExample()
-
{
-
// set up new Arduino connection
-
arduino = new Arduino("127.0.0.1", 5331);
-
-
arduino.addEventListener(Event.CONNECT,onSocketConnect);
-
arduino.addEventListener(ArduinoEvent.DIGITAL_DATA, onReceiveDigitalData);
-
}
-
-
// triggered when a serial socket connection has been established
-
public function onSocketConnect(e:Object):void
-
{
-
trace("Arduino connected!");
-
arduino.setPinMode(ledPin, Arduino.OUTPUT);
-
arduino.setPinMode(inPin, Arduino.INPUT);
-
}
-
-
// triggered when any digital input is received
-
public function onReceiveDigitalData(evt:ArduinoEvent):void
-
{
-
// filter out only responses from pin 7
-
if(evt.pin == inPin)
-
{
-
if(evt.value == Arduino.HIGH)
-
{
-
arduino.writeDigitalPin(ledPin, Arduino.LOW);
-
}else{
-
arduino.writeDigitalPin(ledPin, Arduino.HIGH);
-
}
-
}
-
}
-
}
-
}
Problems I've encountered so far:
Flash is not connecting because serproxy may not be running, or may have timed out.
Serproxy is not responding/Flash is not getting a response to the firmwareversion request because the port settings may not be set up right (ports 1-9 should be fine, 10 or higher will need alteration of serproxy)
I hope this was helpful ![]()

June 26th, 2008 at 19:04
How do you import the as3glue into a Flex project?
July 31st, 2008 at 07:54
It’s just a few packages/classes which handle the arduino interaction.
I never realised that would be very different in Flex (I’ll have a look at it..)
August 5th, 2008 at 17:17
I keep getting a “packages cannot be nested” error in Flash. Any thoughts?