-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_serial.py
More file actions
33 lines (26 loc) · 921 Bytes
/
test_serial.py
File metadata and controls
33 lines (26 loc) · 921 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import serial
import time
import sys
try:
print("Opening serial connection to ESP32...")
ser = serial.Serial('/dev/ttyACM0', 115200, timeout=0.1)
print('Serial opened successfully')
print("Testing ESP32 communication...")
for i in range(20):
# Try different commands
commands = [b'\r\n', b'AT\r\n', b'help\r\n', b'\x03'] # Last one is Ctrl+C
ser.write(commands[i % len(commands)])
time.sleep(0.1)
data = ser.read(1000)
if data:
print(f'Response {i}: {data.decode("utf-8", errors="ignore")}')
else:
print(f'No response {i}')
time.sleep(0.2)
ser.close()
print("Serial test completed")
except serial.SerialException as e:
print(f'Serial error: {e}')
print("Device likely disconnected during test")
except Exception as e:
print(f'Unexpected error: {e}')