Serial event fail when using 115200 as baudrate

Hi !

I am facing a weird problem with the serial event example.

The hardware setup is only a usb to serial converter connected with UART to an arduino pro mini directly with jumper cable.

If I use the example untouched (with 9600 as baudrate), everything works fine and I can see the strings received.
But in my application I need to use the 115200 baudrate. If I change the baudrate from 9600 to 115200 in the example, it just doesn't work and print garbage data sometimes randomly after some string sending.

Did anyone got this kind of problem ?

Thank you in advance,

Regards,

Your Pro Mini is a 3V variant running at 8 MHz?

Have a look at WormFood's AVR Baud Rate Calculator

Why use serialEvent() ?

Yes it's a 3v3 variant.

I want to use serial event to wait for info coming from serial which is connected to a bluetooth module. Is it better to it another way ? Like waiting all the time for a char ?!

Like waiting all the time for a char ?!

Why not? What else would a $3 Pro Mini have to do? But the problem is likely due to an inaccurate Baud rate.

This thread can contain some useful information: Serial Input Basics - updated.

If you're waiting for a single character, you can use something based on one of the below

void loop()
{
  // read from serial
  int c = Serial.read();
  // check if 'A' is received
  if (c == 'A')
  {
    do something
  }
  else
  {
    if (c == -1)
    {
      // there was nothing to read
    }
  }
}

Or

void loop()
{
  if(Serial.available() > 0)
  {
    // read from serial
    byte c = Serial.read();
    // check if character 'a' is received
    if (c == 'a')
    {
      do something
    }
  }
  else
  {
    // there was nothing to read
  }
}

Hey, thanks all for the answers !

I tried the solution without the SerialEvent routine by putting all in the main loop but I am having the same problem, so it's seems that it's a baudrate problem.

Before I used an arduino nano and the 115200 baudrate was working great, and I have also used this baudrate ok for some time with the arduino pro mini without any problem, so that's why I don't understand what's going on...

If communications work at 9600 Baud but not at 115200 Baud, the problem is clearly an inaccurate rate.

That always happens with internal 8 MHz RC oscillators that are not properly calibrated and with many Arduinos using cheap resonators.

So finally I put the bluetooth module in 9600 and the Arduino to 9600. I don't understand why it all fail in 115200 as I used it before without any problem. Maybe it is the cheap oscillator like you said...

Thanks for your help !

Whandall:
Your Pro Mini is a 3V variant running at 8 MHz?

Have a look at WormFood's AVR Baud Rate Calculator

As I have tried to show you in the first reply, 8MHz and 115200 does not work (generally).

Hi Whandall,

As I understand, with the speed 115.2k the error is 8.5% and that's too high and not stable to use. However, there is also a negative percentage. What does it mean? What is the difference between +8.5% and -8.5% error rate?

Thanks in advance.

Regards,

One is faster than nominal the other slower than nominal - look at the difference between actual and
nominal in the table.