| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

FirmataAndFlash

Page history last edited by Bjoern Hartmann 15 years, 3 months ago

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.

  1. Your Arduino board should already run the Firmata Firmware.
  2. Download the as3glue project from http://code.google.com/p/as3glue/ The file is called Glue.zip
  3. Unzip Glue.zip. The rest of the instructions will assume that that directory is as3glue.
  4. 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.
    1. 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).
    2. 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
      
    3. TODO: We need a working MAC example.
    4. Launch serproxy.exe. On Vista, you have to unblock the program to give it permission to open a socket.
  5. 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.
  6. 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 -
    1. 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();
      
    2. 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());
      
    3. For other uses, consult as3glue/as3/examples/arduino/SimpleIO.as.

Some errors you may encounter along the way:

  • In Flash, got socket error
    Error #2044: Unhandled IOErrorEvent:. text=Error #2031: Socket Error.
    at Untitled_fla::MainTimeline/Untitled_fla::frame1()
    
    Reason was that serproxy.cfg listed "net_port1=5331" (i.e., net_portindex), instead of net_port19 (i.e., net_portComPortNumber)
  • SerialProxy reports "Failed to open comm port connection refused": SerialProxy does not like to use high COM ports on Windows. I had to reshuffle my port from COM19 to COM3.
  • arduino.enableDigitalPinReporting() seems to generate events even if pin is set to output.
  • There's quite a bit of latency if you use trace() statements. Instead of using trace(), print output to dynamic text fields in your movieclip.

 

Comments (0)

You don't have permission to comment on this page.