0
\$\begingroup\$

I want to communicate between a Raspberry Pi 3 model B and a laptop using a USB to RS-232 cable and this RS-232 to 3.3V TTL converter via the serial module in Python:

enter image description here GND is connected to board pin #6 3.3V is connected from board pin #2 to VCC Rx is connected to board pin #10 Tx is connected to board pin #8

The code I'm executing in the Raspberry is the next one:

port = serial.Serial("/dev/ttyAMA0",\
    baudrate=9600,\
    parity=serial.PARITY_NONE,\
    stopbits=serial.STOPBITS_ONE,\
    bytesize=serial.EIGHTBITS,\
        timeout=3.0)

port.write(b'hello')

And the code I'm executing in the laptop is the next one:

ser = serial.Serial(
    port='COM11',\
    baudrate=9600,\
    parity=serial.PARITY_NONE,\
    stopbits=serial.STOPBITS_ONE,\
    bytesize=serial.EIGHTBITS,\
        timeout=1)

line = ser.read_until()
print(line)

The problem is that in the laptop I receive the next sequence on bytes, and those change depending on an unknown factor:

  • b'\xd0)\xe1\xd3\xf7'
  • b'\xd0+\x13\xd7\xf7'
  • b'\xd0+\xe3\xe1\xf9\xff'
  • b'\xd0+\xe1\xe1\xf3'

Does anybody have an idea why this is happening? Any help is really appreciated

EDIT: ESD discharge magically solved this issue (I think) I was checking if I made the right connections in the Raspberry Pi and accidentally touched some of the pins in the board and received a shock. I really feared that this damaged the Raspberry, but everything seemed ok. After this event I run the program once again and received the right bits every time. I think that this is scary, especially because I didn't intended to damage my board with an ESD. Is this assumption true? I didn't modify anything to any program O_O

\$\endgroup\$
  • 1
    \$\begingroup\$ How about running some off-the-shelf serial terminal (Putty?) on your laptop instead of this code? \$\endgroup\$ – Eugene Sh. Dec 10 '18 at 19:17
  • 1
    \$\begingroup\$ Have you disabled the serial console on your Raspberry Pi? It's on ttyAMA0. Check /boot/cmdline.txt \$\endgroup\$ – Janka Dec 10 '18 at 19:19
  • 1
    \$\begingroup\$ Sounds more likely that you have flaky connections (missing ground?) and fixed that. Or else you had some odd software state, perhaps some background daemon running like brltty which was fighting you for the port. \$\endgroup\$ – Chris Stratton Dec 10 '18 at 19:42
  • 1
    \$\begingroup\$ @ChrisStratton, maybe, I first though that the cables were the guilty ones. The important thing is that it works now :D \$\endgroup\$ – Nightmerker Dec 10 '18 at 19:43
  • 1
    \$\begingroup\$ That doesn't mean it will work tomorrow, however... Either you had a temporary issue which has been corrected, or you still have a real issue and are only being lucky (or from a debugging perspective, unlucky) not to be seeing it at the moment. \$\endgroup\$ – Chris Stratton Dec 10 '18 at 19:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.