CM Panel technical documentation Buy
The image displayed below illustrates the locations of the J15 serial port connector
and SW1 dip switch
The operational mode of the serial port can be selected through a 4-position DIP switch.
Serial port is visible in Linux as /dev/ttyAMA0 device
.
Check the file /boot/config.txt
to see if these lines are present:
# RS232/RS485/RS422 port on /dev/ttyAMA0
force_turbo=1
dtoverlay=uart0,txd0_pin=36,rxd0_pin=37,pin_func=6
If not insert them and reboot.
Dip switch positions:
SW1 1 OFF
SW1 2 OFF
SW1 3 OFF
SW1 4 OFF
Pinout:
J15 2 RXD
J15 3 GND
J15 6 TXD
Dip switch positions:
SW1 1 ON
SW1 2 OFF
SW1 3 OFF=No termination - ON=120 ohm termination
SW1 4 OFF=Normal - ON=Limited slew rate limited
Pinout:
J15 2 A
J15 3 GND
J15 4 B
J15 5 Y
J15 6 Z
Dip switch positions:
SW1 1 ON
SW1 2 ON
SW1 3 OFF=No termination - ON=120 ohm termination
SW1 4 OFF=Normal - ON=Limited slew rate limited
Pinout:
J15 3 GND
J15 5 A
J15 6 B
import RPi.GPIO as GPIO
import serial
import time
DE_pin = 38 # Driver enable pin
GPIO.setmode(GPIO.BCM)
GPIO.setup(DE_pin, GPIO.OUT)
ser = serial.Serial('/dev/ttyAMA0', 115200)
def send_data(data):
GPIO.output(DE_pin, GPIO.HIGH) # Enable sending mode
ser.write(data.encode()) # Send data
ser.flush() # Ensure all data is sent
GPIO.output(DE_pin, GPIO.LOW) # Disable sending mode
try:
send_data("Hello from RS485") # Send a string
finally:
GPIO.cleanup() # Clean up GPIO on exit