Flash + Arduino

I want to send data from Arduino to Flash and the other way around. I already figured out the way from Arduino to flash, I use serproxy and a simple serial print with a delay in Arduino. This is the as3 code:

import flash.utils.Timer;
import fl.transitions.easing.*;
import fl.transitions.Tween;

var arduinoSocket:Socket;

init();

function init()
{
      openArduinoSocket();
}

function openArduinoSocket()
{
      arduinoSocket = new Socket("localhost",5331);
      arduinoSocket.addEventListener(Event.CLOSE, closeHandler);
      arduinoSocket.addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler);
}

function closeHandler(event:Event):void
{
      trace("[Workaround] Socket closed, reopening...");
      openArduinoSocket();
}

function socketDataHandler(event:ProgressEvent):void
{
      arduinoSocket.writeUTFBytes("H");
      var str:String = arduinoSocket.readUTFBytes(arduinoSocket.bytesAvailable);
}

I can not find out how it would work the other way around.
If I edit the socketDataHandler function into this:

function socketDataHandler(event:ProgressEvent):void
{
      arduinoSocket.writeUTFBytes("H");
      var str:String = arduinoSocket.readUTFBytes(arduinoSocket.bytesAvailable);
}

I would expect flash to send an H over the serial connection. If I upload the physicalPixel example to my Arduino and add a simple Serial.println in the beginning the Led does not turn on as I would expect. Here the arduino code:

const int ledPin = 13; // the pin that the LED is attached to
int incomingByte;      // a variable to read incoming serial data into

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  Serial.println("test");
  // see if there's incoming serial data:
  if (Serial.available() > 0) {
    // read the oldest byte in the serial buffer:
    incomingByte = Serial.read();
    // if it's a capital H (ASCII 72), turn on the LED:
    if (incomingByte == 'H') {
      digitalWrite(ledPin, HIGH);
    } 
    // if it's an L (ASCII 76) turn off the LED:
    if (incomingByte == 'L') {
      digitalWrite(ledPin, LOW);
    }
  }
  delay(200);
}

Can anybody help me out? Thanks already

Hi mate!!!

I use to work with flash and arduino all together but, I'll do it with AS2.
So if you want I can help you in AS2 'cause I've never worked in AS3.

I'm actually having trouble with this as well. However, I cannot even get flash to communicate to arduino at all! (ie, no RX light even...).

I'm using Actionscript 3.0,
tinkerproxy (with the configuration file set correctly according to several tutorials I've found... and it makes sense to me too lol)
and an arduino uno with the USB input.

So I'm bumping this post rather than writing a new one-

How can I get flash to communicate with arduino and visa versa?

I would like to know the same, right now I am using tinkerproxy with a PHP telnet class.

What program to you need to do Actionscript?

there are a bunch out there- I use Adobe Flash CS4. Flash is really the only actionscript-utilizing thing I know much about... but I think theres something called Adobe Flex that also uses it- but it is without a lot of the graphical/animation capabilities of Flash (i think...)

Anyways- the fact still stands. There is not a good tutorial of exactly what is required to send a value from flash to arduino and the other way around. They all skip corners and I'm left very confused :stuck_out_tongue:
So if anyone can post any help on the subject, I will greatly appreciate it :slight_smile:

Thanks, I might play with that tonight. I found for people who work in education they can get adobe flash builder (aka flex) for free.

Are you able to telnet to tinkerproxy and get proper responses?

I've made 2 tutorials on this issue. Also to be find in the playground.

I use the Messenger library to do some error detection on strings.

http://www.kasperkamperman.com/blog/arduino-flash-communication-as3-messenger/

http://www.kasperkamperman.com/blog/arduino/arduino-flash-communication-as3/

@ kasperkampermann: have you got a solution to control an arduino uno with flash? if so, would you be so nice and share your solution?

Nope. No idea how to solve this :frowning: I think its related to the new serialchip of the Arduino UNO. Anyone who has a clue please post in this topic:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1291826044

The Firmata included with Arduino 0022 works good with the Arduino UNO (version 0021 not), so thats the solution.
You can upload Standard Firmata.

@ kasperkampermann: thank you for the info. maybe you can help me with one question.

i try to drive a stepper motor form flash connected via a easydriver board. i got it turning already using a (flash)timer. my issue is, that it turns quite slowly even if i set the timer to 1ms. do you know how i can turn it faster with flash?

have a nice day!

@theMPloc I've no idea, think this is hardware related.