Serial monitor garbage

Hi:

Is it normal for the serial monitor to print garbage when baudrate is greater than 9600? Im using this code to read an incremental encoder and I think it would be better to have optimum communication by increasing the baud rate (correct me if Im wrong).

volatile long enc_count = 0;

void setup(){
  
  Serial.begin(14440);
  
  attachInterrupt(0,encoder_isr,CHANGE);
  attachInterrupt(1,encoder_isr,CHANGE);
  
}

void loop(){
  
  noInterrupts () ;
  int Position = enc_count; //read the variable atomically, interrupts deferred 
  interrupts();
  Serial.println(enc_count);
  
}


// 4X encoder resolution
// Channels A|B: Pin: 2|3
void encoder_isr() {
    static int8_t lookup_table[] = {0,-1,1,0,1,0,0,-1,-1,0,0,1,0,1,-1,0};
    static uint8_t enc_val = 0;
    
    enc_val = enc_val << 2;
    enc_val = enc_val | ((PIND & 0b1100) >> 2);
 
    enc_count = enc_count + lookup_table[enc_val & 0b1111];
}

Gilgamesh90:
Is it normal for the serial monitor to print garbage when baudrate is greater than 9600?

No.

...unless you fail to change the baud rate on the serial monitor to match your sketch baud rate.

...
noInterrupts () ;
int Position = enc_count; //read the variable atomically, interrupts deferred
interrupts();
Serial.println( Position );
...

SurferTim:
...unless you fail to change the baud rate on the serial monitor to match your sketch baud rate.

:smiley:

Why only 14400?
Why not as fast as possible , like 115200?

Thanks, I changed the corresponding value on the serial monitor, only the values 14440, 28800, 115200 are not working.

AWOL:
Why only 14400?
Why not as fast as possible , like 115200?

Is there really an improvement in communication increasing the baud rate?

(strangely these values are multiples) are not working.

What does that mean?
14400 is 9600 × 1.5.
115200 is 9600 × 12.

Whilst the Arduino will happily generate 14440, whatever is at the other end may not be too happy with a non standard rate.

Gilgamesh90:
Thanks, I changed the corresponding value on the serial monitor, only the values 14440, 28800,

http://forum.arduino.cc/index.php?topic=252445.0

115200 (strangely these values are multiples) are not working.

115200 works fine. I use it all the time.

Gilgamesh90:
Is there really an improvement in communication increasing the baud rate?

I notice that I can (more) easily overflow the serial monitor if the baud rate is too slow.

in your example it is printing every turn of loop()... the timing of getting through that function is milliseconds, not seconds so you end up sending more data than serial can print at that speed... an overflow.

I've never seen the serial buffer overflow. I have seen it slow up the processing by waiting for the serial port to transmit the data. The slower the baud rate, the longer the delay to send the data.

I'm with Coding Badly. I use 115200 most of the time, unless the data is sent so fast you can't read it fast enough.

Is it normal for the serial monitor to print garbage when baudrate is greater than 9600?

Hi,

Which one are you using?. I have a similar problem with "due".

Regards

vffgaston:

Is it normal for the serial monitor to print garbage when baudrate is greater than 9600?

Hi,

Which one are you using?. I have a similar problem with "due".

Regards

You're using the completely non-standard rate of 14440 too?
Why not go for 14400 instead?

No, as I had problems with the speed (I'm using interrupts), I just tried a couple of times with the highest one and, as I got just garbage, I gave up.

(I asked twice in the forum with no succes)

BAUD_RATE.bmp (1.38 MB)

vffgaston:
No, as I had problems with the speed (I'm using interrupts), I just tried a couple of times with the highest one and, as I got just garbage, I gave up.

Where are you using interrupts? Are you trying to send characters to the serial monitor in the interrupt function?

vffgaston:
No, as I had problems with the speed (I'm using interrupts)

That may be your problem. The hardware serial port also uses interrupts, and the serial interrupt handlers can't run at the same time as your other interrupt handlers. Serial port I/O is timing critical and even quite a small delay might be enough to corrupt the data stream. The higher the serial port speed, the more sensitive it would be to timing errors caused by delays introduced by your other interrupt handlers.

Where are you using interrupts? Are you trying to send characters to the serial monitor in the interrupt function?

No, for a complete different purpose (an encoder). I was using the monitor to debug the software, but it iterferred, so I discarded it.

Regards.

That may be your problem. The hardware serial port also uses interrupts, and the serial interrupt handlers can't run at the same time as your other interrupt handlers. Serial port I/O is timing critical and even quite a small delay might be enough to corrupt the data stream. The higher the serial port speed, the more sensitive it would be to timing errors caused by delays introduced by your other interrupt handlers.

No. that's not the case. I tried it "standalone" (When possible I always try to isolate the code that is failing: This case just the Serial.begin(baud rate) and a single serial.print() instruction. No way)

Thanks. Regards.

I got
Serial.begin(115200)
Serial.print("any text")
to show garbage at the PC serial monitor despite the same such as 115200 being selected,
whenever the ambient environment temperature around a nano v.3 went over 35C

Do other arduino hardware types have the same limitation to ambient temperature?

The good news is that this fault was fully fixed by cooling ambient to 25C.

Do other arduino hardware types have the same limitation to ambient temperature?

Mine one (due): I have not a log of temperatures ;), but sure it fails all the range from 15 ºC to 30 ºC.

No god news. Sorry. :disappointed_relieved:

Regards