In our tutorial, we will control sensors and actuators from Flash
through the Arduino physical computing platform. Flash cannot talk
directly to the Arduino hardware, so you'll have to install some extra
pieces of software: an Actionscript library for Flash that
sends/receives Arduino commands over a network socket; a proxy server
that translates network packets into serial bytes; and a hardware driver
to connect to the serial port on the Arduino board.
NOTE: the following tutorial was put together with content from two sources, both of which may be helpful in troubleshooting, along with some additional modifications. These are:
What you will need:
- You need a working version of Adobe Flash CS3 or CS4 Professional on your computer. Non-professional CS3 may work, but has not been
tested. Earlier versions of Flash that lack Actionscript 3.0 will definitely not
work. We've experienced some trouble with installing Flash CS3 Pro
Trial on 32bit Vista. Here are instructions for correcting Internal Error 2739 during installation.
- Download all necessary files:
- Arduino IDE: This is the programming environment to
write and upload programs onto your Arduino board. It includes a
"serial proxy" function that marshals messages between Flash's
TCP socket and the virtual serial port. It also comes with a driver
for the USB chip on the Arduino board. The driver creates a virtual
serial port that can be used to exchange messages with the Arduino
board.We are using a pre-release version that's not yet widely
available. Find and install the version suitable for your computer here: Arduino IDE software
- as3glue library: A library for Flash to send/receive Arduino commands over a TCP socket. Download the latest as3glue_v2 zip file from the as3glue Google Code project.
Inside you will find a folder called "Glue". Extract it into your
workspace (e.g., c:/code/ on a PC or /Users/yourusername/Documents on OS
X) - remember where this directory is for the following steps.
- CS247 Examples: A number of examples we will use in the tutorial. Download from bitbucket.org/bjoern/as3glue-examples-cs247 (choose download from the menu bar then zip at the bottom of the page). Also extract into your workspace and remember the path.
- Disable Firewall and Antivirus. Since we are instructing the below software to communicate via ports, it is helpful to disable and system protection software that could potentially block these functions.
- Install Arduino IDE & FTDI Serial driver.
Once downloaded, unzip the file and put the resulting folder in a
convenient location. In theory, you should then be able to double-click
arduino file to launch the IDE. Connect your Arduino board to your computer using the USB cable. Your computer SHOULD recognize the device as new hardware and install the correct drivers. Windows users may need to select the driver if prompted. This is included in the Arduino package in the
drivers\FTDI USB Drivers folder.
Note: If you already had an older version of the
Arduino IDE installed on your computer, you may need to delete your
existing Arduino preferences.txt file. The location of your preferences file is shown under
Arduino->Preferences (OSX) or File->Preferences(Win) in the Arduino
IDE. Write down this path. Close Arduino IDE. Find the preferences.txt file on your drive
and delete it manually (while Arduino is NOT running) - Arduino will
re-create it on the next startup.
Make sure your installation is working correctly so far. Now that your Arduino board is plugged in and the IDE software is running, let's configure
Arduino to use the right serial port. Go to Tools->Serial Port. On
the Mac, choose the entry that reads /dev/cu.usbserial-XXXXXXXX (the example below shows /dev/tty. This will also work, but for connecting to Flash you must use /dev/cu). On
Windows, it's likely the highest COM port number (COM4 for example).
Also make sure you have selected the right board and port from the "Tools" menu.
To make sure everything is set up properly, open the "Blink" sketch from the File menu :
A sketch is simply code that you want the Arduino to run. With the
"Blink" sketch open, go to the File menu and select "Upload to I/O
Board". This will upload the "Blink" code to the unit. After a few
moments, you should see LED (L) blinking on the Arduino.
- Upload Firmata Firmware to your Arduino board ;">Your
board should have come pre-configured with the right Firmata firmware
to talk to as3glue but probably not the latest version. This is provided in the as3glue
package. In the Arduino IDE: Open Glue/arduino/Firmata2/StandardPlusServoFirmata2/StanfardPlusServoFirmata2.pde
and upload it to your attached Arduino board.
- Configure Flash to include as3glue library: You'll have to add the as3glue library to the classpath so Flash can find the files when it compiles your projects.
- What to do: Start Flash. Create a new File (there's
a bug in Flash CS3 where preference changes are not taken over if you
don't have a file open when setting preferences).
- On a PC: Go to Edit Menu->Preferences; on OSX, the Preferences dialog can be found under the "Flash" Menu.
- Within the Preferences dialog, click ActionScript->ActionScript 3.0 Settings...->"+" to add new directory to classpath.
- Click the crosshairs to find the glue/as3 folder. In
Flash CS4, there are three kinds of paths, "Source Path", "Library
Path", and "External library path". You want to add to the "Source Path"
box. There are no crosshairs, use the Folder icon instead.
- Confirm all dialogs.
- See a screencast of step 5.
- Configure Flash Player to trust CS247 examples:
as3Glue uses socket
connections to talk to a serial proxy. By default, SWF files built by
Flex or Flash run in a security sandbox that prevents most socket
communication. If you run your files directly in the Flash IDE, you are
fine. If you want to execute your files outside the Flash IDE (like from within Flash), you have
to modify the "Global Flash Player Trust directory" and add project
directories where restrictions are not enforced.
- In the CS247\tools folder manually edit TrustExampleWin.cfg or TrustExampleMac.cfg (depending on your system)
and follow directions in the file. It will instruct you to edit the path at the bottom of the file to correspond with the location of your as3glue-examples-cs247 folder (for example: C:\code\as3glue-examples-cs247) and copy it into a system folder on your computer. Edit this file BEFORE copying it into the system folder since the file becomes read-only once copied. Also remember that if you change the location of your arduino code later you must also update the path in the .cfg file.
- Configure the serial proxy:
We're almost there... But as it is now, there is no way for Flash to
talk directly to the USB/serial port. In order to bridge this gap, we
need to install the SerialProxy application. What it does is forward
serial input and output to and from a network socket connection that
Flash can use. A serial proxy is bundled with as3glue (serproxy) however, Tinker.it released an updated version under the name TinkerProxy 2.0. It is the same software with bug fixes. I strongly encourage you to use.
Select tinkerproxy-2.0.zip from the download menu and unzip the package to your computer. You will see an executable file for both Windows and Mac but before running it, you need to modify the
serproxy.cfg file to match your system. Edit your file so it corresponds to the right COM port and TCP/IP port. For
example, on a Windows system, Arduino may be on COM port 4 and serproxy is
listening for connections on TCP/IP port 5331 (on a Mac these will likely be COM port 1 and TCP/IP port 5331).
NOTE: Avoid using wordpad for editing this file since it will sometimes add additional character to the file without your knowing. Best to use textedit (mac) or notepad (pc). Your file should essentially look like this:
Make sure to end the
with the matching COM port number. Depending on your Firmata version, the baud rate could be 115200 or 57600 but in the software we have described above it will likely be 57600. You can confirm that by looking at the
standard_firmata.pde code in the Arduino IDE. Simply look for a
setup() routine near the end of the code. Inside it, you should find the following line which will tell you the speed to use :
OSX: in the case of Mac installations you will also have to include the lines: serial_device1=/dev/cu.usbserial-XXXXXXXX (to match the same as listed in the Arduino IDE). Do this by removing the "#" in front of the code line.
serproxy application. If everything went well, you should see a command prompt window with something like :
Serproxy - (C)1999 Stefano Busti, (2005) David A. Mellis - Waiting for clients
serproxy.exe process needs to be running all the time. At least, as long as you want Flash to communicate with your Arduino.
- Test your completed installation: To test whether everything is now installed correctly, go through the following steps:
- Make sure your Arduino board is plugged in via USB. Start the IDE software and make sure it is configured to use the right serial port as described above. Leave this window running in the background.
- Start the serproxy application and leave the window running in the background.
- Open cs247_examples/flash/test_arduino.as in Flash. Edit cs247_examples/test_arduino.fla and edit the line var arduino:Arduino = new Arduino("127.0.0.1",11100); to reflect your TCP/IP port. In the examples given above this has been 5331 so this line should instead read var arduino:Arduino = new Arduino("127.0.0.1",5331); Save this file.
- Open cs247_examples/flash/test_arduino.fla in Flash and Run it (Control->Test Movie on CS4).
- In the Flash window, you should see a message like this:
At the same time, the serial proxy window should have printed: server thread launched
You are ready to go!
- I can't find /dev/tty.usbserial-XXXXXX on Mac or USB Serial PORT (COMx) on Windows:
Your FTDI USB driver is not installed correctly. Re-install and reboot to be safe.
- I get "Error #2031: Socket Error." when trying to run test_arduino.fla.:
If you get the following error in the Flash output window
Error #2044: Unhandled IOErrorEvent:. text=Error #2031: Socket Error.
The Flash cannot connect to Arduino's Serial Proxy. Make sure the
proxy is running and that the port listed in the Arduino IDE (5331 for example) is
the same port as in this Flash source code line:
var arduino:Arduino = new Arduino("127.0.0.1",5331);
- I get the Error 1046: Type was not found or was not a compile-time constant:ArduinoEvent. when trying to run test_arduino.fla:
Flash cannot find the as3glue library. Please check and
repeat step 5. It seems that there might be a bug in Flash CS3 where
settings get lost if you do not have an Actionscript file open when you
change the settings. Also, if Flash crashes after you changes
Preferences, those changes are lost.
- I see "Socket connected!" when running test_arduino.fla, but don't see the "Firmware version: 2" message.
Reason: you either have the wrong firmware running on your Arduino
board or something went wrong during the upload of Firmata. Check and repeat step 4.