I am pretty sure I've found a serious bug in the Serial library - for some reason it writes some numbers but not others. In particular, whenever you try to write the number 3, nothing is sent, but other numbers like 0,1,2, and 4 get sent ok. hex 13 is also sent ok, so it's not just down to certain bits being set. I know this is bizarre but I have done a pretty conclusive test and it looks like this is what's happening.
This code works (prints alternating 0x04's and 0x83's):
void setup() {
Serial.begin(19200);
}
void loop() {
unsigned int valOut; // print out the results from a strike
unsigned char cOut;
cOut=0x04;
Serial.write(cOut);
cOut=0x83;
Serial.write(cOut);
delay(random(MINDEL,MAXDEL));
}
But this doesn't:
void setup() {
Serial.begin(19200);
}
void loop() {
unsigned int valOut; // print out the results from a strike
unsigned char cOut;
cOut=0x03;
Serial.write(cOut);
cOut=0x83;
Serial.write(cOut);
delay(random(MINDEL,MAXDEL));
}
It just prints a series of 83 characters with no 03's at all:
The MINDEL MAXDEL bit was my cut and paste error in copying the code. They are both defined as 250.
I got a reply in my original thread pointing out that 0x03 is ctrl-C, so the problem may be caused by the way the serial port is set up, not the arduino library. Sorry about this.