0

I'm not understanding what's going on with my Uno. I have a very simple piece of code. no peripherals are connected. Just a bare genuine uno. I program in VisualMicro for Visual Studio.

void setup()
{
    Serial.begin(115200);

    char stringy[9] = { 0x7E, 0x00, 0x05, 0x08, 0x01, 0x44, 0x33, 0x04, 0x7B };

    for (int i = 0; i < 9; i++) {

        Serial.print(stringy[i]);
        //delay(300);
    }

    Serial.println("");
    Serial.print("done");
}

void loop()
{
    while (1) {  }
}

Without a delay of around 250msec or greater in the for loop, I don't get all the characters. In fact, without the delay, the code doesn't even finish executing. I only get the first character '~'. It doesn't seem to matter what my baud rate is.

This code runs fine without a delay on my Nano. What could possibly be the issue?

3
  • Your program works as expected on my Uno. Commented Sep 15, 2017 at 20:51
  • Weird. You get the whole array of gibberish in your serial pane? I'm starting to think its just a difference in compilers. Commented Sep 15, 2017 at 20:55
  • Not the serial pane (I'm not using the IDE). I typed stty -F /dev/ttyACM0 raw 115200 && hd -n 15 /dev/ttyACM0 on the Linux console and got 00000000 7e 00 05 08 01 44 33 04 7b 0d 0a 64 6f 6e 65 |~....D3.{..done| (hd is a hexdump utility). Commented Sep 15, 2017 at 21:06

1 Answer 1

1

You are printing the unprintable.

Do you think it should print:

~0581,34{

or

0x7E 0x00 0x05 0x08 0x01 0x44 0x33 0x04 0x7B 

What you will get is

tilde
null
enquiry
backspace
start of heading
comma
three
end of transmission
open brace

I think you can call

Serial.print(stringy[i], HEX);

To see the number you put in come out.

1
  • I expect it to come out gibberish, like this: ~ D3 { (three of those white spaces actually show as strange characters that I can't paste here.) The actual content of the array is an Xbee AT command, and I designed this as an experiment to see why it's not working. See, when I use the Xbee library with the nano and monitor the serial output without the xbee connected, ~ D3 { is what I see. But on the Uno, all I get out is ~. In this experiment I was trying to replicate the output with serial.print(), and the result is the same. Commented Sep 15, 2017 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.