Skip to content

Instantly share code, notes, and snippets.

@RoyBellingan
Last active March 19, 2025 19:03
Show Gist options
  • Save RoyBellingan/d9b719a17578c65edd72a06a66596a17 to your computer and use it in GitHub Desktop.
Save RoyBellingan/d9b719a17578c65edd72a06a66596a17 to your computer and use it in GitHub Desktop.
rs485.py
import serial
import serial.rs485
import time
ser = serial.Serial(
#For iot Basic afaik is this one, for the advanced should be the USB0
port='/dev/ttyS2',
baudrate=9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1
)
ser.rs485_mode = serial.rs485.RS485Settings(
rts_level_for_tx=True, # RTS high during transmission
rts_level_for_rx=False, # RTS low during reception
delay_before_tx=0,
delay_before_rx=0
)
byte_delay = 10 / 9600 # ~0.00104 seconds
while True:
ser.write(b'\x54')
ser.flush()
time.sleep(byte_delay)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment