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");
}
  • 1
    Please show the Arduino code. It's hard to see the mistake otherwise. – joan Jun 21 '18 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 Jun 21 '18 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 Jun 21 '18 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? – iSeeDeadPeople Jun 21 '18 at 15:46
  • The code shown doesn't tell us much. I'll guess you're using pySerial? If so, it looks like the code you have shown was copied and pasted from somewhere. I don't see a definition for the value "STOPBITS_WO"... where did you get that? - do you define it somewhere? You've gotten good feedback in the Comments above. Suggest you incorporate that feedback, edit your question, read pySerial docs, RS232 basics and parity – Seamus Jun 21 '18 at 18:37
  • @Seamus 7 , I thought 'import serial' obviously means that it's from pySerial? Oh, my keyboard alphabet 'T' is having some sensitivity problem. Thanks for pointing out. – iSeeDeadPeople Jun 22 '18 at 02:37
  • 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 Jun 22 '18 at 04:36
  • Consider debugging Arduino and RPi separately before you connect them together. – Dmitry Grigoryev Jun 25 '18 at 10:58

1 Answers1

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.

Seamus
  • 21,900
  • 3
  • 33
  • 70