Go Down

Topic: Garbage using serial functions in Arduino Due (Read 8 times) previous topic - next topic

Palliser

Does anybody know if Arduino Due has some issues with the Serial.print function?

I am running the following sketch taken from http://arduino.cc/en/Serial/Available :

Code: [Select]
int incomingByte = 0;   // for incoming serial data

void setup() {
        Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
}

void loop() {

        // send data only when you receive data:
        if (Serial.available() > 0) {
                // read the incoming byte:
                incomingByte = Serial.read();

                // say what you got:
                Serial.print("I received: ");
                Serial.println(incomingByte, DEC);
        }
}


and every time I invoke the serial monitor or any other like Hyperterminal, I am getting garbage in the first two lines like:

I??¥Ù?: 255
I r

I??¥Ù?'?Ê?j
I reã

I??¥Ù??Ê?j
I reÿ

I ran the same sketch in my UNO and no garbage came up!

Thanks!

cyclegadget


I forget which board I had the problem with but, I had to put a delay() in setup to give the serial monitor a chance to come up before the board tried to communicate.

In my case, I think I was printing from the board early in the sketch.

spcomputing



I forget which board I had the problem with but, I had to put a delay() in setup to give the serial monitor a chance to come up before the board tried to communicate.

In my case, I think I was printing from the board early in the sketch.


Leonardo?  For that board it was:

Code: [Select]
// while the serial stream is not open, do nothing:
   while (!Serial) ;


...or a delay(1) after a serial print.  That said, since this is going through the 16u2, it should not be full speed (FIFO) through the USB and overloading the port buffer.  Curious...

Palliser

I tried delay(10) after the serial prints but the garbage still. The interesting that the garbage only shows up when the terminal window is open. If I press the reset button, no more garbage. It could be may machine. I will try to test it in another computer.

fat16lib

#4
Dec 01, 2012, 04:11 pm Last Edit: Dec 01, 2012, 04:23 pm by fat16lib Reason: 1
Edit: after I posted the stuff below, I changed the baud rate on your sketch to 115200 in Serial.begin.  Now the garbage looks like this:

Quote

DDÄI recei?é 0
I received: 0


I have the same problem with many sketches.  The problem also involves Serial.read(), there is garbage when you use Serial.available().

In your sketch, it appears to execute the code after this if statement:
Code: [Select]
if (Serial.available() > 0) {

Your output is garbled stuff from these print calls:
Code: [Select]

 Serial.print("I received: ");
 Serial.println(incomingByte, DEC);


Note how often you get "I re" as part of the garbage.  The 255 suggests you read 0XFF.

Go Up