Serial.print issue

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); 
}

show your arduino
do you connect something on pins RX_0/TX_1?

Same issue:0-8 fine, 9 = "-"

Nothing at all is attached to it.

const int waitT=100;
const int baudRate = 115200;

//VARIABLES
int test=0;

void setup() {
Serial.begin(baudRate);
}

void loop() {

// main code
  Serial.println(test++);
  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.


For some reason when using baud rates over 19200 I don't get a visible print. But this is your code using 19200. Same issue.

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);
}
22:39:57.116 -> 1
22:39:58.119 -> 2
22:39:59.143 -> 3
22:40:00.123 -> 4
22:40:01.118 -> 5
22:40:02.146 -> 6
22:40:03.138 -> 7
22:40:04.135 -> 8
22:40:05.133 -> 9
22:40:06.137 -> 10
22:40:07.151 -> 11

Weird, right? Is it possible I have a faulty Uno? Or a bug in the Mac Arduino IDE software?

@kendrickwallace

Has anyone tried

  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.

Does it display correctly if you type a 9 into the serial monitor?

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)

No idea. I had a similar problem with a project long before the Arduino existed and the issue being apparently restricted to nine reminded me of it.

Do you see the same behavior with IDE 1.8.19?

What happens with baud rate 9600?

I only have the latest version. I will have to try to get an earlier version to test. I'm new.

Baud rate doesn't seem to matter -- same thing happens.

Looks like this is the issue. v 1.8.19 works fine! Hopefully this will get fixed in the latest version.

Thanks!

Ken

I can not confirm your issue with either 1.8.19 or 2.1.0. and I don't think that anyone else sees what you are seeing.

If you uninstall and then reinstall 2.1.0 do you still see the issue?