0

I am getting b'\x00\x00\x00 ... ' together with the data I want. For example, my Arduino is writing 'hello raspberry' to RPi. At the RPi, it receives 'b'\x00\x00\x00 ... hello raspberry\r\n '. Why?

Here's my coding at RPi:

ser=serial.Serial(port='/dev/ttyS0', baudrate=9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_TWO, bytesize=serial.EIGHTBITS)

while True:
    x = ser.readline()
    print(x)

Whereas at Arduino Mega:

void setup()
{
    Serial3.begin(9600);
}

void loop()
{
    Serial3.println("hello raspberry");
}
8
  • 1
    Please show the Arduino code. It's hard to see the mistake otherwise.
    – joan
    Commented Jun 21, 2018 at 12:39
  • 1
    The Arduino IDE serial terminal may not show null bytes, so they may be there in both cases. How many stopbits is "WO"? I'm not a python user, but a quick glance at the docs implies this is supposed to be an actual number (ONE in this case).
    – goldilocks
    Commented Jun 21, 2018 at 12:40
  • @goldilocks If the OP is using '/dev/ttyS0' it makes no difference, because this is fixed, and only affects sending. On recent Raspbian '/dev/serial0' should be used.
    – Milliways
    Commented Jun 21, 2018 at 12:48
  • It's the same even after I change the parity to TWO. Actually, what's all parity about? Any good documentation / reference for me to read? Commented Jun 21, 2018 at 15:46
  • 1
    This may have nothing to do with your problem but the mini UART only supports 1 start and 1 stop bit and you should use /dev/serial0 in all code. See How-do-i-make-serial-work-on-the-raspberry-pi3 Unless you list your code who knows?
    – Milliways
    Commented Jun 22, 2018 at 4:36

1 Answer 1

2

Your question is poor in detail. We are currently having difficulty reading your mind, but making a few assumptions leads me to suggest this might help:

ser=serial.Serial(port='/dev/ttyS0', baudrate=9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS)

If it doesn't, please read the comments, read the referenced documents in the comments, and edit your question.

2
  • What else of detail you want? Commented Jun 22, 2018 at 2:38
  • Nothing if this fixes your problem. If it doesn't, please show us the Python code, and explain what the defaults are for the Arduino Mega: stop bits & parity.
    – Seamus
    Commented Jun 23, 2018 at 2:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.