Skip to content

How-To RS232 Serial Port

Description

The Pi-Tron CM4 has an RS232 interface on the front of the device. The serial port itself is realized through a USB-to-Serial converter chip, thus making the interface accessible through the device name ttyUSB and not the Raspberry Pi usual ttyAMA or ttyS interfaces. The same applies to the RS485 interface on the Pi-Tron CM4 which is covered on this page How-To RS485 Serial Port.

pi-tron-cm4-top-rs232

Requirements

  • Development computer with network access to the Pi-Tron CM4 or alternatively connect an HDMI monitor, mouse and keyboard.

  • To login into the Pi-Tron CM4 via network, it is requires that the SSH server is running.

  • The login details are by default: username: pi and password: raspberry

    • Note: The latest version of the Raspberry Pi OS requires the user creating the initial SD card or writing the system to eMMC memory to choose a username and password or the information has to be entered during first boot of the system. The above mentioned defaults may not apply to your situation.
  • 24 volts power supply with 2 pin power plug for the Pi-Tron CM4.
  • Common baud rates are supported, 115200 baud are recommended.

How-To

The RS232 serial port should be available right out of the box, when using Raspberry Pi OS Bullseye or later. If the used system is still Raspberry Pi OS Buster, have a look at the How-To USB page for more information on how to activate the onboard USB Controller of the Compute Module 4.

Identifying the serial ports

Since the Pi-Tron CM4 has two serial ports, the first step is to identify which ttyUSB device is which serial port.

Log into the Pi-Tron CM4 and issue the following command (output shortened):

ls -la /dev/serial/by-path/*

/dev/serial/by-path/platform-fe9c0000.xhci-usb-0:1.3:1.0-port0 -> ../../ttyUSB0
/dev/serial/by-path/platform-fe9c0000.xhci-usb-0:1.3:1.1-port0 -> ../../ttyUSB1

The result from this command shows that one serial port is connected to the onboard USB controllers port "1.3:1.0" and the other one to port "1.3:1.1".

From the electrical wiring and the used USB-to-Serial converter chip, the link between the hardware path and the serial port name is in this instance, that the RS232 interface is accessible via ttyUSB0 and the RS485 port via ttyUSB1.

Note on USB devices

Adding more serial devices to the Pi-Tron CM4 via USB ports, could lead to a change in the device name sequence. Make sure to check the ttyUSB links after every boot. Alternatively have a look at the How-To Device Management page on how to create persistent device names.

Connector X11 Pins

Connector X11 where the RS232 serial port is located as the following pin layout.

pi-tron-cm4-conn-pinout-rs232

Using the RS232 serial port

The echo command can be used to send out and cat to receive data. Of course there are many other options and possibilities, but for this guide we keep it simple.

Send out Hello World!:

echo "Hello World!" > /dev/ttyUSB0

Receive data:

cat < /dev/ttyUSB0


This concludes the How-To RS232 Serial Port. Feel free to connect the Pi-Tron CM4's serial port to a computer for example and establishing a communication connection or try to communicate with another RS232 serial device.

Restrictions

  • Note: USB serial devices of the same type are assigned the same device base name (ttyUSB) and only differentiated through an appended number, which is incremented with each found device. This results in device sequences such as ttyUSB0, ttyUSB1 and so on. Although these devices are connected to the same bus and cannot physically switch their order, the drivers however might change the naming sequence regardless under certain circumstances. If such a behavior cannot be handled in software, have a look at the How-To Device Management page on how to create persistent device names.