Hi,
this is probably a newbie question, but I would really appreciate any pointers to help me take the next step in solving a "mysterious" problem I have with serial transfer of a binary data file (190 bytes) from Mac -> Arduino.
I have tried to search this forum and the net, but I haven't found anything similar. That's why I think it's me and not the platform...
In short, I am trying to transfer a binary file, using 9600bps, from a Procesing Sketch to my Arduino. Once it didn't work immediately I started debugging and I have now discovered that even if I just echo what I receive in the Arduino back, the data gets "corrupted" all the time. Please see the log sample and code below.
To make it dead simple I just send one byte at a time to the Arduino and then echo them back as soon as I read them. Should be fine, right?
Serial transfers of sketches etc. work perfectly, so I am a bit at a loss. Any ideas, anyone?
Thanks/Anders
____ DEBUG OUTPUT (from Processing sketch)
Wrote byte: -1 hex: FF
Wrote byte: -1 hex: FF
Wrote byte: 1 hex: 01
Wrote byte: 2 hex: 02
Wrote byte: 54 hex: 36
Wrote byte: -1 hex: FF
Wrote byte: -1 hex: FF
Wrote byte: 1 hex: 01
Wrote byte: 66 hex: 42
Wrote byte: 117 hex: 75
Wrote byte: 115 hex: 73
Wrote byte: 115 hex: 73
...
Read byte val: -1 hex: FF
Read byte, val: -1 hex: FF
Read byte, val: 1 hex: 01
Read byte, val: 2 hex: 02
Read byte, val: 54 hex: 36
Read byte, val: -1 hex: FF
Read byte, val: -1 hex: FF
Read byte, val: 1 hex: 01
Read byte, val: 65 hex: 41 <<<<< WHAT? Should be value 66 (see above)
Read byte, val: 115 hex: 73 <<<<< CORRUPT FROM HERE ON
Read byte, val: 3 hex: 03
Read byte, val: 23 hex: 17
...
____ CODE THAT SENDS (Processing)
byte b[] = loadBytes("binary.file");
for(int i = 0; i < b.length; i++) {
myPort.write(b*);*
println("Wrote byte:\t"+b_+"\thex: "+hex(b*));
}_
____ CODE THAT RECEIVES AND ECHOS BACK (Arduino)
_// Read one byte and acknowledge by sending it back*
//
byte ACKRead() {
* while(Serial.available() < 1) {
// wait for data*
* }
byte b = Serial.read();
Serial.write(b);
return b;
}[/size][/font]*_