We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › flash (as3) to processing to arduino
Page Index Toggle Pages: 1
flash (as3) to processing to arduino (Read 3484 times)
flash (as3) to processing to arduino
Nov 17th, 2008, 3:20am
 
hello

i recently decided to communicate to arduino via processing. that worked really well, using the arduino library for processing (http://www.arduino.cc/playground/Interfacing/Processing).

i also used as3 to communicate with processing, using the xml socket object in flash, that worked pretty well too.

so i thought i would create myself a processing app to forward the info from flash to arduino. the only problem i encounter is when the data is received from flash, processing seems unable to parse it properly.

i would gladly join a zip of my project, but i dont see that option with my post, so here's the processing code:


// --- --- --- imports --- --- --- //
import processing.net.*;
import processing.serial.*;
import cc.arduino.*;


// --- --- --- variables --- --- --- //
Arduino arduino;
int qtyArduinoDigPins = 13;
int port = 8080;
Server server;
Client client;
byte endByte = 0;
String input;
int pinInput;
String valueInput;


// --- --- --- setup --- --- --- //
void setup (){
 size (320, 240);
 println(Arduino.list());
 arduino = new Arduino(this, Arduino.list()[0], 115200);
 for (int i = 0; i <= 13; i++) {
   arduino.pinMode(i, Arduino.OUTPUT);
 }
 server = new Server (this, port);
 loop ();
}

void draw () {
 readDataFromFlash ();
}

void loop () {
 
}


// --- --- --- functions --- --- --- //
void sendDataToFlash (String dataToFlash) {
 server.write (dataToFlash);
 /*
 the trick is this next line that sends the "0" termination byte unaltered and alone,
 this way it doesn't get evaluated with the other variables being sent
 */
 server.write (endByte);
 /*
 "endByte" is the termination byte, which Flash's XMLSocket uses to figure out when a transmission stream has ended.
 This also means that any variables that are being sent as zero bytes need to be shifted (say +1, for example)
 and evaluated in Flash accordingly, or else Flash will kill the transmission there  
 */
}

void readDataFromFlash () {
 client = server.available ();
 if (client != null) {
   println("- readDataFromFlash -");
   input = client.readString ();
   String[] dataToArduino = new String[2];
   dataToArduino = split(input, ",");
   println("dataToArduino.length: " + dataToArduino.length);
   println("dataToArduino[0]: " + dataToArduino[0]);
   println("dataToArduino[1]: " + dataToArduino[1]);
   
   pinInput = int(dataToArduino[0]);
   println("pinInput: " + pinInput);
   
   valueInput = dataToArduino[1];
   println("valueInput: " + valueInput);
   println("(valueInput == low): " + (valueInput == "low"));
   println("(valueInput == high): " + (valueInput == "high"));
   
   /*
   if (valueInput == "low") {
     println("write Arduino.LOW to pin " + pinInput);
     arduino.digitalWrite(pinInput, Arduino.LOW);
   } else if (valueInput == "high") {
     println("write Arduino.HIGH to pin " + pinInput);
     arduino.digitalWrite(pinInput, Arduino.HIGH);
   }
   */
 }
}


basically, what is wrong is when i try to do that:

println("valueInput: " + valueInput);
println("(valueInput == low): " + (valueInput == "low"));
println("(valueInput == high): " + (valueInput == "high"));

even if valueInput equals to "low", both the println after trace false. any clue for that?
Re: flash (as3) to processing to arduino
Reply #1 - Nov 17th, 2008, 12:57pm
 
probably the post would more fit into the integration section, but what you can do:

1)
try to println the "client.readString ()", if you are using the xml socket then an xml string should come out, so you have to parse it additionaly before you handle your protocols (maybe you would try the binary socket of as3 instead).

2)
if you are using processing only as a bridge between flash and arduino then i suggest you try the arduino library for as3 in combination with the tcp serial proxy (available on the arduino site. the library works with the standard firmata v.1 thus you don't have to deal with all the serial - tcp conversation anymore since it is already done by the serial proxy and the library.    
Re: flash (as3) to processing to arduino
Reply #2 - Nov 17th, 2008, 3:00pm
 
thanks for the quick response, i'll follow your numbering to reply:

1) what do you mean by "you have to parse it additionaly before you handle your protocols"? i send an array to processing from flash {pin, value} and processing reads it properly:
  input = client.readString ();
  println("input: " + input);    // traces input: 1,high
then when i split it into an array:
  String[] dataToArduino = new String[2];
  dataToArduino = split(input, ",");
i can read both indexes from the array but cant make comparisons...

2) i have looked into as3glue, but i did not find documentation for  the serial proxy and could not use it
Re: flash (as3) to processing to arduino
Reply #3 - Nov 17th, 2008, 3:56pm
 
try valueInput.equals("low") instead of valueInput == "low"

i guess you already use the binary socket, otherwise you would need to parse the xml string coming from flash

basicly the serial proxy only needs to be started, there is a configuration file where you can set the baudrate etc
(this of course depends on which proxy you use).

Re: flash (as3) to processing to arduino
Reply #4 - Nov 18th, 2008, 2:46am
 
unfortunately the valueInput.equals("high") did not provide any good results either

println(valueInput);                   // traces: high
println(valueInput.equals("high"));    // traces: false
println(valueInput == "high");         // traces: false

i'm not concerned so much about the interaction with the arduino but more on the interaction with flash. if i create functions in processing that require data from flash, i feel im screwed right now.

i must say i am using an xml socket, i am sending an array through it:

var pin:uint = 1;
var value:String = "high";
var data:Array = [1, "high"];
_socket.send (data);

in the meantime i'll try with the serial proxy
Re: flash (as3) to processing to arduino
Reply #5 - Nov 18th, 2008, 10:40am
 
sorry about the xml socket, always thought that the xml socket can only be used to send xml objects.

just some thoughts, could it be that there is a space inside the string you are comparing to, like ' high' or 'high ' ?







Re: flash (as3) to processing to arduino
Reply #6 - Nov 18th, 2008, 2:38pm
 
no worries, i use the xml socket because that's the best way i found to communicate with max msp.

no there is tho space before or after "high". i did try this:

input = client.readString ();
dataToArduino = split(input, ",");
pinInput = int(dataToArduino[0]);
valueInput = input.substring((input.indexOf(",")+1), (input.length() - 1));

and that did work... for a while. i did get an error for array out of bound a one point. i just tested it again, and it worked.

but what do i do in the case when i need to pass multiple parameters to my function in processing? i think that it qualifies as a bug in processing if i cannot make comparisons with the values in an array.
Re: flash (as3) to processing to arduino
Reply #7 - Jan 29th, 2009, 2:32am
 
Im new to processing but have been using flash for a few years.  

How exactly do I use the XML socket in as3 to send varibles to processing?
Re: flash (as3) to processing to arduino
Reply #8 - Apr 4th, 2009, 7:52am
 
Can you post the flash code to send data to processing.
Thank a lot.
Page Index Toggle Pages: 1