Arduino, Adobe Flash and Playstation 3 sixaxis

Hi everyone, I'm new here so be gentle :slight_smile:

I recently purchased a USB host shield from circuits@home and have connected it to my arduino and written a very small sketch that prints the accelerometer and gyroscope values to the serial port. I want to use that information to control a movie clip eg if the sixaxis has value 'n' along the x axis and value 'n' along the y axis, then show a particular movieclip.

I know that I need to use a proxy, but my question is concerning the formatting of the data from the arduino. Currently my sketch just does this;

Serial.print ("accx = ");
Serial.println(accx);

Which does just what it should when viewed in the arduino IDE but does that mean that I can simply address "accx" in the actionscript? How will flash distinguish between the values for the accelerometer x axis and the y axis?

Maybe this is an actionscript question but any pointers would be very useful for me.

Many thanks,

Dai

To do it this way you would have to figure out how to do a serial read in actionscript. I have not been able to do this yet, or know if it is possible.

Another way would be to use as3Glue and read in the analog input values directly into actionscript. Then let actionscript do all the computing.

Okay, so I decided to try as3glue as you suggested. Everything appears to be connected fine, I receive the firmware version etc when tested. When I try the simple IO example that comes with as3glue it traces a LOT of data then gradually freezes and crashes Flash. If I use some of the custom examples that come with the protolabs as3glue package (for example the graph) then there is no response no matter which position the controller is in...

Can as3glue be used with the usb host shield from circuits at home? Anybody have any experience interfacing with Flash in this way maybe have any ideas where I'm going wrong?

Just in case anybody else finds this useful, I didn't make any progress with as3glue but returned to my original sketch. Using some ActionScript from Adam Martin it was possible to do serial read with serproxy.

I now get the acc X, Y and Z values in Flash as well as the gyro Z values.

Just in case anybody finds this useful I have posted below.

 /*
 * AnalogToSerial
 * by Adam Martin (University of Wales Newport)
 *
 * A simple demonstration of how to read an analog pin and send that data
 * to a computer connected to the USB port.
 * Note that this example does not implement any 'flow control', so may
 * cause problems on the host computer whan reading this data continuously
 *
 * Use in conjunction with analogtoserial.pde (arduino) and serproxy
 */

// Create an instance of the XML socket so we can recieve the data passed by serproxy
//   Note that we are not using XML, it just so happens that the XML socket in flash 
//   can handle non XML data too

var socket:XMLSocket = new XMLSocket();
var sensors:Array;

// Socket creation failed
if (!socket.connect("127.0.0.1", 5331)) {
      trace("Could not create socket!");
}
// Confirmation of aconnection between serproxy and flash 
socket.onConnect = function(success:Boolean) {
      if (success) {
            trace("socket connection success!");
      } else {
            trace("socket connection failed!");
      }
};

// Called automaticaly each time a null charater is sent from arduino
socket.onData = function(serialData:String) {
      trace("socket data='" + serialData + "'"); // Print the data on output window

      sensors = serialData.split(",");

      // Send a character (any one) to the arduino, it will then send back the next 
      // set of sensor values, which in turn triggers this 'onData' method (a big loop)
      
      socket.send("x");

};