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.
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 ?!
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
}
}
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...
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...
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?