Pages: [1]   Go Down
Author Topic: Flash + Arduino  (Read 2101 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 42
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

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:

Code:
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:

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
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 74
Arduino as a way of life
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

Wisconsin, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 27
Arduino Intrigued
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Monterey CA
Offline Offline
Sr. Member
****
Karma: 1
Posts: 323
Addicted to Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Current Projects:                    Arduinos:
Security Robot Tank               Uno
Security Robot II 4WD            Mega2560

http://mobilewill.blogspot.com

Wisconsin, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 27
Arduino Intrigued
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-razz
So if anyone can post any help on the subject, I will greatly appreciate it smiley
Logged

Monterey CA
Offline Offline
Sr. Member
****
Karma: 1
Posts: 323
Addicted to Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Current Projects:                    Arduinos:
Security Robot Tank               Uno
Security Robot II 4WD            Mega2560

http://mobilewill.blogspot.com

Enschede - The Netherlands
Offline Offline
Jr. Member
**
Karma: 0
Posts: 75
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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/
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 95
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Enschede - The Netherlands
Offline Offline
Jr. Member
**
Karma: 0
Posts: 75
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Nope. No idea how to solve this  smiley-sad 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
Logged

Enschede - The Netherlands
Offline Offline
Jr. Member
**
Karma: 0
Posts: 75
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 95
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@ 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!
Logged

Enschede - The Netherlands
Offline Offline
Jr. Member
**
Karma: 0
Posts: 75
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: