Complete newbie. I’m having a very strange issue with the Serial.print function. My Arduino will not print the number 9. I get a dash in place of the character 9. Using just a simple counter that increases by 1, you can see the print output below. I’ve tried all kinds of tests, and no matter what the number the “9” is always replace by a “-“ when it prints. Seems like a weird bug, but everything else has worked just fine so far, and it is doing the math correctly. Same thing happens whether the "9" is an integer or a character within a string.
//VARIABLES
int waitT=1000;
int baudRate = 4800;
int test=1;
void setup() {
// SET UP ARDUINO
Serial.begin(baudRate);
}
void loop() {
// main code
Serial.println(test);
test = test+1;
delay(waitT);
}
This is weird.
Try to print exactly '9' or hexa next to each number.
Something with terminal setting or terminal itself? Try PuTTY or some different terminal emulator.
Character nine is tab. I have had problems with this a very long time ago where it confused the hardware I was using. I doubt that this is your issue, but another terminal program would be worth using for testing.
The sketch is compiled without error output and the error is not reproducible on the Arduino UNO.
//VARIABLES
int waitT = 1000;
int baudRate = 4800;
int test = 1;
void setup() {
// SET UP ARDUINO
Serial.begin(baudRate);
}
void loop() {
// main code
Serial.println(test);
test = test + 1;
delay(waitT);
}
Serial.write("9"); // WRITE double quote
Serial.write('9'); // WRITE single quote
Serial.write(9); // WRITE NO quote
Serial.write(-9) // MINUS 9 (or will it be minus minus?)
And another idea... "9" is ASCII 0x39 which is 12 (decimal) away from "-" (dash)... so try to print 0x29 (close parenthesis), 0x49 (upper case I), 0x59 (upper case Y), 0x69 (lower case i), 0x79 (lower case y).... to see if two bits are missing.
Character HT (horizontal tab) is 0x09... which is 0x30 away from "nine" (0x39)... is there a space in the mega328 where the ASCII table is held? (also see post #12)