I’m using the messenger library and its working for integers now. But when parsing a string… no good. I’d like to share what I have tried so far.
At now, I am using my own code in arduino (not firmata as before) + serproxy + Beltran Berrocal’s arduino.as class (which is in as2) to get flash and arduino communication.
//INTEGER…(this is working, thanks a lot Kasper Kamperman and people here for that!!)
my arduino runs this
#include <Messenger.h>
int id = 0; <--- default
Messenger message = Messenger();
void messageReady() {
while ( message.available() ) {
id = message.readInt();
}
}
void setup() {
Serial.begin(9600);
message.attach(messageReady);
}
void loop() {
while ( Serial.available() ) message.process(Serial.read());
Serial.println(id);
}
now flash can send any 2, 3… digits int ID (a.send(“456”+chr(13))) it will replace default 0.
This is working fine. In flash it outputs “456” as I needed.
//CHARACTERS…(NEED HELP HERE) 
Now, for the chars… I am trying to use the message.readChar() (messenger library), but not succefully…
Here are a few things I’ve tried… I’ve read a lot but I’ve not much experience:
char str[10]; //the string "works out" will come from flash --> a.send("works out" + chr(13));
void setup() {
Serial.begin(9600);
}
void loop() {
delay(1000);
int i = 0;
while ( Serial.available() ){
str[i] = Serial.read();
i++;
}
Serial.println(str); //<--- WEIRD! if I comment this line, nothing prints. So its reading itself?.
}
The code above produces the following strange output in flash, when interval = 500 ms (half what arduino is working).
This is the closer I’ve got to get a whole string response from arduino.
** Arduino ** Connecting to 127.0.0.1:5332 . . .
** Arduino ** Connection established.
Arduino says :
Arduino says : [ch833]out
Arduino says : out
Arduino says : works out
$oun
Arduino says : works out
'ouh
Now, this other code uses the Messenger library, but I cant make it work. Its very funny why it does print more than two characters…
I am leaving some commented lines which I alternatively tried.
#include <Messenger.h>
char str[100]; //the string "works out" will come from flash --> a.send("works out" + chr(13);
Messenger message = Messenger();
void messageReady(){
//Serial.print("return: ");
//int i = 0;
while ( message.available() ){
//str[i] = message.readChar();
//i++;
Serial.print(message.readChar()); //<--- it is receiving, or storying only 2 characters as showing in the flash output
}
Serial.print(";");
//Serial.print(13,BYTE);
}
void setup() {
Serial.begin(9600);
message.attach(messageReady);
}
void loop() {
delay(1000);
while ( Serial.available() ) message.process(Serial.read());
Serial.println(str); //<--- if I comment this line, nothing prints. So its reading itself?.
}
The code above produces the following strange output in flash, when interval = 500 ms (half what arduino is working).
** Arduino ** Connecting to 127.0.0.1:5332 . . .
** Arduino ** Connection established.
Arduino says : [ch763]wo;
Arduino says : wo;wo;wo;
Arduino says : wo;wo;
which is still buggy, but more stable than the code before where no messenger methods were used.
I’ll have some lunch. I’m trying to solve this issue psychopathly, hehe.
Thanks so much for the attention and directions
Btp~