I have a device which sits on pins 10/11 of Arduino UNO. I am trying to send commands from my PC using Arduino to relay my commands to the device via Serial.
The problem is that if I use speed 9600 both for device and USB communication, then my commands gets damaged. Some letters are replaced by strange symbols, etc. The device uses 9600 baud rate.
If I change speed of the PC communication to 4800 (or any speed other than 9600), everything is fine. But I have to use different speeds for the communication.
I am not comfortable with the workaround, because I don't understand what's going on. Could somebody explain why the same serial port speeds causes problems?
Here is my code:
#include <SoftwareSerial.h>
#define rxPin 11
#define txPin 10
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
void setup()
{
digitalWrite(4,HIGH); // 1 - disable
mySerial.begin(9600);
Serial.begin(19200);
while (!Serial) {;} // wait for serial port to connect. Needed for native USB port only
Serial.println("Begin");
}
void loop()
{
if (mySerial.available())
{
char c = mySerial.read();
Serial.write(c);
}
if (Serial.available())
{
char c = Serial.read();
mySerial.write(c);
}
}