huvarda
Posts: 4
Joined: Mon Jan 20, 2020 11:29 am

Problems with serial port and RS232

Mon Jan 20, 2020 12:01 pm

I have an RS232-Serial adaptor and I also have an RS232-USB Cable. I am plugging the RS232-jumper wire into my raspberry pi 3 according to this website:
https://www.instructables.com/id/Read-a ... pberry-Pi/
and I connected the adaptor into the USB0 port.
However it doesnt seem to work at all!
I've disabled the serial console and enabled the serial port in raspi-config
the "enable_uart = 1 line" is in /boot/config.txt
I don't know what is wrong! Can anybody help me troubleshoot this? Thanks in advance!

Paul Hutch
Posts: 449
Joined: Fri Aug 25, 2017 2:58 pm
Location: Blackstone River Valley, MA, USA
Contact: Website

Re: Problems with serial port and RS232

Mon Jan 20, 2020 1:34 pm

There are multiple points of possible failure in that setup. When troubleshooting a system like that I start with loopback tests. First on the Pi's UART, next the TTL to TIA-232 adaptor (RS232-Serial adaptor), and finally on the TIA-232 to USB adapter (RS232-USB Cable). When the system passes all of those troubleshooting tests any further problem will be software related.

This article has more information.
https://medium.com/@amitasinghchauhan/s ... 7e40da9055

huvarda
Posts: 4
Joined: Mon Jan 20, 2020 11:29 am

Re: Problems with serial port and RS232

Mon Jan 20, 2020 2:00 pm

@Paul Hutch
I have performed the loopback test in the link you gave me.
When I run minicom and type nothing shows up.
Is my rpi3 or its serial broken?

hippy
Posts: 6686
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Problems with serial port and RS232

Mon Jan 20, 2020 6:27 pm

According to some reports I have seen, minicom can sometimes be a PITA.

I tend to use my own loop-back tester as below. Edit the last line to be the port being used, link RX and TX on the header pins / DB-9 / whatever, and run with "python myfile.py". If it works you should see "A", "B", "C", etc one per line -

Code: Select all

#!/bin/usr/python2

import serial
import threading
import time

comPort = None

def TransmitThread():
  while comPort:
    for n in range(ord("A"),ord("Z")+1):
      if comPort:
        comPort.write(chr(n))
        time.sleep(1)

def ReceiveThread():
  while comPort:
    if comPort.inWaiting() > 0:
      n = comPort.read(1)
      print( n )
    else:
      time.sleep(0.1)

def LoopbackTest(comPortName, comBaudRate):
  global comPort

  comPort = serial.Serial \
            (
              port=comPortName,
              baudrate=comBaudRate,
              parity=serial.PARITY_NONE,
              stopbits=serial.STOPBITS_ONE,
              bytesize=serial.EIGHTBITS
            )

  threading.Thread(target=TransmitThread).start()
  threading.Thread(target=ReceiveThread).start()

  try:
    while True:
      time.sleep(1)
  except KeyboardInterrupt:
    print("")
  finally:
    comPort = None

if __name__ == "__main__":
  LoopbackTest("/dev/serial0", 9600)
  
And do a "sudo reboot" if you haven't rebooted since making your changes.

Paul Hutch
Posts: 449
Joined: Fri Aug 25, 2017 2:58 pm
Location: Blackstone River Valley, MA, USA
Contact: Website

Re: Problems with serial port and RS232

Tue Jan 21, 2020 1:26 pm

huvarda wrote:
Mon Jan 20, 2020 2:00 pm
@Paul Hutch
I have performed the loopback test in the link you gave me.
When I run minicom and type nothing shows up.
Is my rpi3 or its serial broken?
It may be broken, definitely try hippy's code to rule out a problem with your minicom settings (minicom is a PITA to configure for those not familiar with its last century interface and configuring telephone line modems).

huvarda
Posts: 4
Joined: Mon Jan 20, 2020 11:29 am

Re: Problems with serial port and RS232

Wed Jan 22, 2020 11:51 am

I actually tried it again on a clean Raspbian Buster install and it worked, thanks for the help though!

Return to “Python”