Skip to content

Commit b5ee85a

Browse files
committed
update for rpi
1 parent 4aa63fd commit b5ee85a

File tree

1 file changed

+12
-2
lines changed
  • RS-232_Pal_Demos/CircuitPython

1 file changed

+12
-2
lines changed

RS-232_Pal_Demos/CircuitPython/code.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,21 @@
33

44
import time
55
import board
6-
import busio
76

87
# baud rate for your device
98
baud = 38400
10-
uart = busio.UART(board.TX, board.RX, baudrate=baud)
9+
# Initialize UART for the CH9328
10+
# check for Raspberry Pi
11+
# pylint: disable=simplifiable-condition
12+
if "CE0" and "CE1" in dir(board):
13+
import serial
14+
15+
uart = serial.Serial("/dev/ttyS0", baudrate=baud, timeout=3000)
16+
# otherwise use busio
17+
else:
18+
import busio
19+
20+
uart = busio.UART(board.TX, board.RX, baudrate=baud)
1121

1222
print("Enter commands to send to the RS-232 device. Press Ctrl+C to exit.")
1323
while True:

0 commit comments

Comments
 (0)