Go Down

Topic: Serial monitor characters not displayed correctly (Read 22668 times) previous topic - next topic

numlo

Hello!
I have a problem with my serial port/monitor. My readings are replaced with small squares that are printed one after another. Sometimes I get a y with 2 dots above it.

Any suggestions?

Thanks!

GrooveFlotilla

#1
Aug 18, 2010, 03:51 pm Last Edit: Aug 18, 2010, 03:52 pm by GrooveFlotilla Reason: 1
Quote
Any suggestions?

Post your code.

You're almost certainly printing things like null or non-printing (< 0x20)characters, but without seeing anything, we're just guessing.
Some people are like Slinkies.

Not really good for anything, but they bring a smile to your face when pushed down the stairs.

PaulS

Also verify that the baud rate shown in the lower right corner of the Serial Monitor matches the value in the Serial.begin() statement in the sketch.

The y with 2 dots is what you get when you try to print a -1, which implies that you are reading data when there is no data to read.
The art of getting good answers lies in asking good questions.

numlo

Thank you for the quick replies!

I have checked the baud rate and it's 9600 everywhere. Port settings, serial monitor and code.
I have tried different codes that used to work and now none of them do.

Here is one from the internet.
Code: [Select]
int photocellPin = 0;     // the cell and 10K pulldown are connected to a0
int photocellReading;     // the analog reading from the analog resistor divider

void setup(void) {
 // We'll send debugging information via the Serial monitor
 Serial.begin(9600);  
}

void loop(void) {
 photocellReading = analogRead(photocellPin);  
 
 Serial.print("Analog reading = ");
 Serial.print(photocellReading);     // the raw analog reading
 
 // We'll have a few threshholds, qualitatively determined
 if (photocellReading < 10) {
   Serial.println(" - Dark");
 } else if (photocellReading < 200) {
   Serial.println(" - Dim");
 } else if (photocellReading < 500) {
   Serial.println(" - Light");
 } else if (photocellReading < 800) {
   Serial.println(" - Bright");
 } else {
   Serial.println(" - Very bright");
 }
 delay(1000);
}


All my codes worked until now.

The one thing that I did was toggle between an Atmega 168 and an Atmega 8 that I just purchased. Another strange thing is that the Atmega 8 is working fine but when I try to use the Atmega 168 I get the wrong micro controller error. Yes, I have switched boards from the settings from Atmega 8 to Atmega 168.

Can it be a board problem? I will try tomorrow with a different one.

RuggedCircuits

The microcontroller has to have its fuses programmed to use the right oscillator (internal vs. external). I believe by default the internal oscillator frequency is 8 MHz while the Arduino code expects 16 MHz.

So try changing your baud rate to 19200 in Serial.begin() which, if I'm right about your processor running at 8 MHz, should get you an effective speed of 9600 bps.

Of course, the right answer is to program the fuses correctly for the oscillator you're using.

--
Check out our new shield: http://www.ruggedcircuits.com/html/gadget_shield.html

numlo

Thank you for your suggestion. It still does not work. It does the same thing on the 19200. I am now trying with the "Hello world!" code and all I get is squares.

Code: [Select]
void setup() {
 Serial.begin(9600);
}

void loop() {
 Serial.println("Hello World!");
}


I did not get to try with a new board. I still find it strange that I cannot use my Atmega 168 anymore. No matter what I do I get the same "Wrong micro controller" error.

I wonder if I try on a fresh Arduino install on another computer if it will work.

If you guys have any more suggestions I will happily try them and post the results.

   

numlo

#6
Aug 20, 2010, 10:10 am Last Edit: Aug 20, 2010, 10:11 am by numlo Reason: 1
Tried it on another computer with the same board and atmega. Same result. Squares.

Decided to try with the bray terminal. Same thing. I started changing baud rates in the terminal and I got the Hello world at 600 baud. A thing that I've noticed is that it does not always write the Hello wold! message correctly. I did not get to change the Serial.begin(9600); to Serial.begin(600); Maybe this is why.

Here is what I mean:
Code: [Select]
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello Worìä!
Hellï ×ïòì䡍?Èåììï ×ïòì䡍?ÈåììïÕK±'?
Hello World!
HelÛ
º½É±'
Hello World!
Hello World!
Hello World!
Hello World!
HåììïÕK±'?
?Èåììï ×ïòì䡍?Èåììï ×ïòì䡍Hello Wïòìd!
Hello World!
Hello5Heìlo World!
Hello World¡
Hello Wïòld!
Hellï World!
Hållo World!Hello Worìd!
Hello World!
Hello World!
Hello Wïòld!
Hellï World!
Hållo World!Hello Worìd!
Hellï World!
Hello World!Hello Worìd!
Hello World!
Hållo World!Hello Woòld!
Hellï World!
Hello Worlä!
Hello World!
Hållo World!
Hello Wïòld!
Helìo World!
Hello Worlä!
Hello World!


If I switch to other low baud rates I get a lot of simbols:

Code: [Select]
¡0

Á1xà?à?þ?<0>?fþ?

?`Ï
Áñ`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0><0>
8ÿx
øøxð?x<0>øx<0>?x
<0>

ø<0>?x<0>x<0>xàx
?x<0>øx<0>øxÿøx<0><0>
8ÿx
øøxð?x<0>øx<0>?x
<0>

ø<0>?x<0>x<0>xàx
?x<0>øx<0>øxÿøx<0><0>
8ÿx
øøxð?x<0>øx<0>?x
<0>

ø<0>?x<0>x<0>xàx
?x<0>øx<0>øxÿøx<0><0>
8ÿx
øøxð?x<0>øx<0>?x
<0>

ø<0>?x<0>ð??<0><0>?<0>??<0><0>??<0><0>??<0><0>?<0><0><0>???<0>?<0>??<0>?????<0><0>???????<0><0>?<0>??<0><0>??<0><0>??<0><0>?<0><0><0>???<0>?<0>??<0>?????<0><0>???????<0><0>?<0>??<0><0>??<0><0>??<0><0>?<0><0><0>???<0>?<0>??<0>?????<0><0>???????<0><0>?<0>??<0><0>??<0><0>??<0><0>?<0><0><0>???<0>?<0>??<0>?????<0><0>???????<0><0>?<0>??<0><0>??<0><0>??<0><0>?<0><0><0>???<0>?<0>??<0>?????<0><0>???????<0><0>?<0>??<0><0>??<0><0>??<0><0>?<0><0><0>???<0>?<0>??<0>?????<0><0>???????<0><0>?<0>??<0><0>??<0><0>??<0><0>?<0><0><0>???<0>?<0>??<0>?????<0><0>???????<0><0>?<0>??<0><0>??<0><0>??<0><0>?<0><0><0>???<0>?<0>??<0>?????<0><0>???????<0><0>?<0>??<0><0>??<0><0>??<0><0>?<0><0><0>???<0>?<0>??<0>?????<0><0>???????<0><0>?<0>??<0><0>??<0><0>??<0><0>?<0><0><0>???<0>?<0>??<0>?????<0><0>???????<0><0>?<0>??<0><0>??<0><0>??<0><0>?<0><0><0>???<0>?<0>??<0>?????<0><0>???????<0><0>?<0>??<0><0>??<0><0>??<0><0>?<0><0><0>???<0>?<0>??<0>?????<0><0>???????<0><0>?<0>??<0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0><0


The symbol change as I change increase the baud rate.

All of this was done with an atmega8. I still can't get the atmega168 to work. Maybe I damaged the 168. I don't know.

Any ideas?

Thanks!

PaulS

The baud rates that the Arduino supports are in fixed steps (300, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, and 115200). You can expect reliable results will different values.
The art of getting good answers lies in asking good questions.

numlo

I am wondering why things have changed. It used to work just fine. Another thing I've noticed is that my readings from the sensors are all wrong now.

If I change the baud rate to 19200 than the 600 baud rate stops working and the 1200 starts working.

Something has happened. I don't what.

AWOL

Have you disabled the external clock and set the internal one by accident?
Is there a mismatch between the baud rate you set in the Arduino and the rate that works with the serial monitor, in an integer ratio like 2:1 or 1:2?

numlo

@AWOL I have no idea how to toggle between the internal and external clock so I might have done this accidentally. I don't know. A link on this subject would be appreciated.

This might make sense because one of the codes I use measures time and it was wrong. Results with an Atmega168 were correct and the results with the Atmega8 are wrong. And the Atmega168 does not work anymore.

Thank you!

numlo

Partially solved the problem when I installed the bootloader on the Atmega8. I use the parallel programmer so I did not think of this until now. The Atmega16 had the bootloader installed.

My sensor data is measured and displayed correctly. The only problem I have is that most of the time I have to reset the Arduino for it to work. If I don't I get all kind of symbols on the serial monitor or It won't display any data at all.

Go Up