Note: these instructions were written for as3glue version 1 and Firmata version 1. These versions are now obsolete. This page is only here for historical documentation.
These instructions were written using a licensed version of Adobe Flash CS3 Professional. If you have a different version of Flash, your mileage may vary.
- Your Arduino board should already run the Firmata Firmware.
- Download the as3glue project from http://code.google.com/p/as3glue/ The file is called Glue.zip
- Unzip Glue.zip. The rest of the instructions will assume that that directory is as3glue.
- To get data from your Arduino board into Flash, in addition to as3glue, you still need a program that takes data from the serial port and relays it via a TCP socket. A program called Serialproxy is included in the as3glue download in subdirectory as3glue/applications/Serproxy-0.1.3-3. There are both MAC and PC versions.
- For PC, open as3glue/applications/Serproxy-0.1.3-3/serialproxy.zip and extract _02_serialproxy/windows/serproxy.exe and serproxy.cfg from that zip file into the as3glue/applications/Serproxy-0.1.3-3/ directory (replacing the existing serproxy.cfg in the process).
- Edit as3glue/applications/Serproxy-0.1.3-3/serproxy.cfg. On my machine, Arduino uses COM3 - this is reflected in the line comm_ports=3 and net_port3=5331. If your board is on COM4, you'd have to change those lines to comm_ports=4 and net_port4=5331. Here is the complete config file:
# Config file for serproxy
# Do not Transform newlines coming from the serial port into nils
newlines_to_nils=false
# Comm ports used
comm_ports=3
# Default settings
comm_baud=57600
comm_databits=8
comm_stopbits=1
comm_parity=none
# Idle time out in seconds
timeout=300
# Settings for COM3
net_port3=5331
- TODO: We need a working MAC example.
- Launch serproxy.exe. On Vista, you have to unblock the program to give it permission to open a socket.
- Start Flash. You'll first have to add as3glue to the classpath so Flash can find the files. Go to Edit Menu->Preferences->ActionScript->ActionScript 3.0 Settings...->"+" to add new directory to classpath. Click the crosshairs to find the as3glue/as3folder. Confirm all dialogs.
- Create a new "Flash File (ActionScript 3.0)". Here are some examples. For each, paste the following code into frame 0 of the Flash project -
- Prints status of input pin #2 to the console:
import net.eriksjodin.arduino.Arduino;
import net.eriksjodin.arduino.events.ArduinoEvent;
// trace out data when it arrives...
function onReceiveDigitalData(e:ArduinoEvent):void {
if(e.pin==2){
trace("Digital pin " + e.pin + " on port: " + e.port +" = " + e.value);
}
}
var a:Arduino = new Arduino("127.0.0.1", 5331);
a.addEventListener(ArduinoEvent.DIGITAL_DATA, onReceiveDigitalData);
a.setPinMode(2, Arduino.INPUT);
a.enableDigitalPinReporting();
- Code example for displaying values of two analog input pins:
// Example to show the value of two Arduino analog input pins
// bjoern@stanford.edu 2/11/08
import net.eriksjodin.arduino.Arduino;
import net.eriksjodin.arduino.events.ArduinoEvent;
// declare callback function when analog inputs change
function onReceiveAnalogData(e:ArduinoEvent):void {
if(e.pin==0) {
slider0.value=e.value;
label0.text=e.value.toString()+" ("+(Math.round(e.value/1023.0*500.0)/100.0).toString()+"V)";
}else if (e.pin==1) {
slider1.value=e.value;
label1.text=e.value.toString()+" ("+(Math.round(e.value/1023.0*500.0)/100.0).toString()+"V)";
}
}
var a:Arduino = new Arduino("127.0.0.1", 5331);
a.addEventListener(ArduinoEvent.ANALOG_DATA, onReceiveAnalogData);
//do not read digital pins
a.disableDigitalPinReporting();
// enable reporting for an analog pins 0 and 1
a.setAnalogPinReporting(0, Arduino.ON);
a.setAnalogPinReporting(1, Arduino.ON);
// this magic line may be needed to get data initially
trace("Firmware version is: " + a.getFirmwareVersion());
- For other uses, consult as3glue/as3/examples/arduino/SimpleIO.as.
Some errors you may encounter along the way:
Comments (0)
You don't have permission to comment on this page.