receiving serial commands at startup... problems!!
hi!
i have arduino sketch checks @ startup if there's serial connection pc. if so, receives bunch of bytes pc, , goes on normal operation.
on pc, processing sketch counterpart. waits ping arduino, sends needed bytes.
however, having lots of trouble of getting 2 sketches handshake together. know arduino resets processing opens serial port, that's why arduino sends first command, tell processing it's ready , listening.
am losing bytes sending them before arduino ready?
how arduino handle such things?
do have code similar function? send bytes arduino after startup?
see if can me find logical error i'm making here... thanks!
arduino sketch:
processing sketch:
i fail see why eeprom.write commands never reached!
the eeprom fine, when writing inside arduino, works fine. amount of bytes correct, shown outputs i've made on console, both processing's , arduino's.
must communication, somehow!
eagerly awaiting ideas!
i have arduino sketch checks @ startup if there's serial connection pc. if so, receives bunch of bytes pc, , goes on normal operation.
on pc, processing sketch counterpart. waits ping arduino, sends needed bytes.
however, having lots of trouble of getting 2 sketches handshake together. know arduino resets processing opens serial port, that's why arduino sends first command, tell processing it's ready , listening.
am losing bytes sending them before arduino ready?
how arduino handle such things?
do have code similar function? send bytes arduino after startup?
see if can me find logical error i'm making here... thanks!
arduino sketch:
code: [select]
void setup()
{
serial.begin(19200);
serial.flush();
serial.write("!"); // tell pc i'm ready
digitalwrite(13,high); // indicate i'm expecting bytes
delay(3000); // give pc time start sending
if(serial.available()>0) {
// serial communication active ################
digitalwrite(13,low); // bytes starting come in!
// first byte tells arduino how many more expect.
seqlength=serial.read();
eeprom.write(0,seqlength);
for(i=1;i<=seqlength*6*3;i++) { // *3*6 because each sequence step 18 bytes.
while(serial.available()==0)
delay(1);
eeprom.write((byte)i,serial.read());
}
}
}
processing sketch:
code: [select]
void draw() {
string portname = serial.list()[0];
serial = new serial(this, portname, 19200); // open serial connection
while(serial.available()==0) // wait arduinos request
delay(1);
println("arduino says hello!");
serial.write((int)seq.width); // tell arduino how many more bytes expect
// following bytes 6 rgb triplets per sequence... nothing exciting going on here.
color cur;
for(x=0;x<seq.width;x++) {
for(y=0;y<=5;y++) {
cur=get(x,y);
serial.write((int)red(cur));
serial.write((int)green(cur));
serial.write((int)blue(cur));
println(red(cur));
println(green(cur));
println(blue(cur));
}
}
exit(); // run routine once
i fail see why eeprom.write commands never reached!
the eeprom fine, when writing inside arduino, works fine. amount of bytes correct, shown outputs i've made on console, both processing's , arduino's.
must communication, somehow!
eagerly awaiting ideas!

mexduino,
can more specific what's going wrong? was ist los?
does led on pin 13 go out?
looking @ sketches, see possible problems. first, processing sketch on pc sending 1 byte when send length? i haven't looked serial.write() in processing, converting integer (for example, 10) ascii characters ("1" followed "0") before sending.
second, in arduino sketch, change this:
finally, don't know how long takes write byte eeprom. i'd guess it's shorter half millisecond (1 character @ 19200 bps), you'll want make sure that's not bottleneck.
regards,
-mike
can more specific what's going wrong? was ist los?
does led on pin 13 go out?
looking @ sketches, see possible problems. first, processing sketch on pc sending 1 byte when send length? i haven't looked serial.write() in processing, converting integer (for example, 10) ascii characters ("1" followed "0") before sending.
second, in arduino sketch, change this:
code: [select]
while(serial.available()==0)
delay(1);to this:code: [select]
while(serial.available()==0)
;there's no need delay there, , doing make fall character behind every time through loop.finally, don't know how long takes write byte eeprom. i'd guess it's shorter half millisecond (1 character @ 19200 bps), you'll want make sure that's not bottleneck.
regards,
-mike
Arduino Forum > Forum 2005-2010 (read only) > Software > Interfacing > receiving serial commands at startup... problems!!
arduino
Comments
Post a Comment