TutorialFlashSetup



Overview

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:

http://cote.cc/blog/interfacing-flash-and-arduino-from-scratch-part-1
http://protolab.pbworks.com/TutorialFlashSetup2009

What you will need:

  1. 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.

  2. Download all necessary files:
  3. 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.

Installation:

  1. 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 the 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).

     

    COM port selection

     

    Also make sure you have selected the right board and port from the "Tools" menu.

    Board selection


    To make sure everything is set up properly, open the "Blink" sketch from the File menu :
     

    Opening the 'blink' sketch


    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.

     

    COM port selection

     

     

  1. 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.

  2. 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.
  3. 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.

  4. 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:
    comm_ports=4
    net_port4=5331
    
    comm_baud=57600
    comm_databits=8
    comm_stopbits=1
    comm_parity=none
    newlines_to_nils=false
    timeout=300        

    Make sure to end the net_port parameter 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 : Firmata.begin(57600);

    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.


    launch the 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

    This serproxy.exe process needs to be running all the time. At least, as long as you want Flash to communicate with your Arduino.

  5. Test your completed installation: To test whether everything is now installed correctly, go through the following steps:
    1. 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.
    2. Start the serproxy application and leave the window running in the background.
    3. 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.
    4. Open cs247_examples/flash/test_arduino.fla in Flash and Run it (Control->Test Movie on CS4).
    5. 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!

Troubleshooting:

  1. 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.

  2. 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.

    at Untitled_fla::MainTimeline/Untitled_fla::frame1()

    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);

  3. 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.

  4. 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.