2
votes

I have an Arduino program running that sets the Serial baud to 19200. I want to extract the serial data using the PySerial library. However, PySerial only seems to be working when the baud rate is at 115200.

This is how my Arduino setup() looks like:

void setup() {
  // put your setup code here, to run once:
  Serial.begin(19200);
  XBee.begin(19200);// was 9600
}

This is how the PySerial code looks when set at 19200:

with serial.Serial('COM19', 19200) as ser:
    x = ser.read(8)          # 6 works for reading in 2 variables
    print(x)

Output:

b'\xf3\xea\xf6\xea\xea\xf8'

b'\xf8\xf6\xf3\xfc\xfc\xfc'

This is how the PySerial code looks when set at 115200:

with serial.Serial('COM19', 115200) as ser:
    x = ser.read(8)          # 6 works for reading in 2 variables
    print(x)

Output:

b'70\r\n72'

b'72\r\n70'

Does anyone know why it only works with 115200 and not 19200? Or what I can do to convert that datatype into a decimal number?

Thanks

1
I had similar problem once. I faced it because my devices turned out to have different baudrates. Looks like your Arduino has baudrate 115200. May it be the case? - Poolka
yes, it was! I had to slow it down to 9600 - Mauricio

1 Answers

2
votes

Baud rate is dependent on the device. It essentially determines the data rate between devices. You would need to check your XBee model's datasheet to determine compatible baud rates. Typically, 9600 and 115200 are commonly used as the use of non-standard baud rates varies by product.