hej forum,
although the firmata library is extensively documented, i haven't been able to find a solution to my simple problem. so sorry, if i missed the solution somewhere / am double posting...
i am trying to send simple messages from processing to arduino, using the firmata library. i guess i could just read the serial port directly, but i like the idea of being able to use firmate for string callbacks, in stead of constantly checking and parsing the serial port in my main loop.
anyways, i can't figure out how to send a string(!) ... from http://firmata.org/wiki/Protocol#Control_Messages_Expansion i can see that sending a string needs the command 0x71 --- how is this sent?? what is the format? i would think:
serialPort.write(byte(71)+"my string here");
from processing should do the trick. but no. :-/
here is my arduino code, when sending the above nothing happens (AKA tx flashes so i receive data, but LED 13 nevers goes on, so i am never in stringCallback())
//firmata test
#include <Firmata.h>
void stringCallback(char *myString)
{
Firmata.sendString(myString);
digitalWrite(13,HIGH);
delay(50);
digitalWrite(13,LOW);
}
void sysexCallback(byte command, byte argc, byte*argv)
{
Serial.print(START_SYSEX, BYTE);
Serial.print(command, BYTE);
for(byte i=0; i<argc; i++) {
Serial.print(argv[i], BYTE);
}
Serial.print(END_SYSEX, BYTE);
}
void setup()
{
pinMode(13,OUTPUT);
Firmata.setFirmwareVersion(0, 1);
Firmata.attach(STRING_DATA, stringCallback);
Firmata.attach(START_SYSEX, sysexCallback);
Firmata.begin(57600);
}
void loop()
{
while(Firmata.available()) {
Firmata.processInput();
}
}
and here is my processing sketch
import processing.serial.*;
Serial serialPort;
void setup() {
// List all the available serial ports:
println(Serial.list());
serialPort = new Serial(this, Serial.list()[0], 57600);
}
void draw () {
}
void mousePressed() {
serialPort.write(byte(71)+"my string here");
}
void serialEvent (Serial myPort) {
while (serialPort.available() > 0) {
int inByte = serialPort.read();
print(char(inByte));
}
}
the sysEx callback seems to work, as i, when launching my sketch, get a return string printed in my processing output with some weird ASCII characters and then the name of my arduino sketch....
hmmm?
/j