TutorialFlashSetup2009


 

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.

 

Before the Tutorial

Complete these steps BEFORE comming to the tutorial - we have a packed schedule and not enough time to walk everyone through the software setup.

 

  1. You need a working version of Adobe Flash CS3 Professional on your computer. Non-professional CS3 may work, but has not been tested. Flash CS4 Professional 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:
    1. 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.

       

    2. Mac Windows
      Download arduino-0013-mac-serproxy-dist20090101.zip Download arduino-0013-win-serproxy-dist20090102.zip
       
    3. 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.
    4. CS247 Examples: A number of examples we will use in the tutorial. Download from bitbucket.org/bjoern/as3glue-examples-cs247 (choose download->zip from the menu bar). Also extract into your workspace and remember the path.

  3. Install Arduino IDE & FTDI Serial driver. Unzip the Arduino IDE into your Applications folder. Then look for the FTDI driver in subdirectory Arduino/drivers. Run the installer for your platform. If you have trouble finding this file, you can also get the latest "VCP driver" from FTDIchip.com.

    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 (mac) or File->Preferences 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.

  4. [ Optional: Upload Firmata Firmware to your Arduino board] Your board should have come pre-configured with the right Firmata firmware to talk to as3glue. If not, use the Firmware provided in the as3glue package: Open Glue/arduino/Firmata2/StandardPlusServoFirmata2/StanfardPlusServoFirmata2.pde in Arduino and upload it to your attached Arduino board.
  5. 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 as3glue/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.
  6. [Optional: 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, you have to modify the "Global Flash Player Trust directory" and add project directories where restrictions are not enforced.

    • Run either tools\AddTrustedDirectoryMac.app (os x) or tools\AddTrustedDirectoryWin.vbs (windows) and choose the directory containing the CS247 examples. These scripts try to automatically generate a file with the right contents in you Flash Player Trust directory.
    • If these scripts fail, you'll have to manually edit TrustExampleWin.cfg or TrustExampleMac.cfg and follow directions in the file.
  7. Test your installation: To test whether everything is now installed correctly, go through the following steps:
    1. Start the Arduino IDE.
    2. Make sure your Arduino board is plugged in via USB. Now configure Arduino to use the right serial port. Go to Tools->Serial Port. On the Mac, choose the entry that reads /dev/tty.usbserial-XXXXXXXX. On Windows, it's likely the highest COM port number. To verify, go to Control Panel->System->Hardware->Device manager, open tree node "Ports (COM & LPT)". Look for "USB Serial Port (COMx)". Note the value of x. Select that value in the Arduino list.

    3. Configure the serial proxy (Tools->Network Serial Proxy->...) as follows:

    4. Start the Arduino serial proxy by clicking on this icon:

      (The first  have to unblock the program to give it permission to open a socket. On Mac OSX, you'll get a warning about launching a program downloaded from the internet. Again, you'll have to give permission.)

      In the bottom status bar, you'll now see a speed dropdown box and a black output console. Set the speed to 115200:

      Keep the Arduino environment running in the background - you'll need the network serial proxy to run while you're working in Flash.

    5. Open cs247_examples/test_arduino.fla (not .as) in Flash. Run it (Control->Test Movie on CS4).
    6. In the Flash window, you should see a message like this:
      
      
      At the same time, the Arduino IDE should have printed this: <localhost> connected.

      You are ready to go.

 

Troubleshooting:

 

  1. I can't find /dev/tty.usbserial-XXXXXX on Mac or USB Serial PORT (COMx) on Windows:

    Reason: 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 status bar is the same port as in this Flash source code line:

    var arduino:Arduino = new Arduino("127.0.0.1",11100);

  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:

    Reason: 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. In Arduino, select File->Sketchbook->Examples->Library-Firmara->StandardFirmata. Then click the upload button to transfer the firmware onto your board. (Note: Servos will not work with StandardFirmata. Fix later.) You can test your firmware using the network proxy in the IDE  - it prints out all bytes received from Arduino before they are sent on to Flash. When you reset your Arduino, Firmata should send the following bytes:

    <arduino> 0xF9

    <arduino> 0x02

    <arduino> 0x00

    If you don't see these three bytes, then there is a problem with your Firmata firmware. (Also check serial speed)