45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
"""UART Diagnostic - finds the correct serial port for Quectel M66."""
|
|
import glob
|
|
import time
|
|
|
|
try:
|
|
import serial
|
|
except ImportError:
|
|
print("ERROR: pyserial not installed. Run: pip install pyserial")
|
|
exit(1)
|
|
|
|
# Discover all serial ports
|
|
ports = sorted(glob.glob("/dev/ttyS*") + glob.glob("/dev/ttyAMA*") + glob.glob("/dev/serial*"))
|
|
print(f"Available serial ports: {ports}\n")
|
|
|
|
baudrates = [9600, 115200, 19200, 38400, 57600, 4800]
|
|
|
|
for port in ports:
|
|
for baud in baudrates:
|
|
try:
|
|
ser = serial.Serial(port, baud, timeout=1.5)
|
|
ser.reset_input_buffer()
|
|
ser.write(b"AT\r\n")
|
|
time.sleep(0.5)
|
|
response = b""
|
|
while ser.in_waiting:
|
|
response += ser.read(ser.in_waiting)
|
|
time.sleep(0.1)
|
|
ser.close()
|
|
resp_text = response.decode("ascii", errors="ignore").strip()
|
|
if resp_text:
|
|
status = "OK" if "OK" in resp_text else "RESPONSE"
|
|
print(f" ✅ {port} @ {baud} -> {status}: {repr(resp_text)}")
|
|
else:
|
|
print(f" ❌ {port} @ {baud} -> No response")
|
|
except Exception as e:
|
|
print(f" ⚠️ {port} @ {baud} -> Error: {e}")
|
|
|
|
print("\n--- Done ---")
|
|
print("If no port responded, check:")
|
|
print(" 1. Modem power (M66 needs stable 3.8V-4.2V VBAT)")
|
|
print(" 2. TX/RX wiring (Pi TX -> M66 RX, Pi RX -> M66 TX)")
|
|
print(" 3. GND connection between Pi and M66")
|
|
print(" 4. On Pi 5: add 'dtoverlay=uart0-pi5' to /boot/firmware/config.txt")
|