I think I still am doing something wrong. In the example below it seems that the M5 isn't reacting to the commands. Do I have to scan a QR code from the manual first to get it into the proper state?
Example 1:
import serial import time wakeup_cmd = bytes([0x00]) host_mode_cmd = bytes([0x07, 0xC6, 0x04, 0x08, 0x00, 0x8A, 0x08, 0xFE, 0x95]) start_scan_cmd = bytes([0x04, 0xE4, 0x04, 0x00, 0xFF, 0x14]) stop_scan_cmd = bytes([0x04, 0xE5, 0x04, 0x00, 0xFF, 0x13]) print('Open serial port') ser = serial.Serial('COM4', 9600, timeout=1) # Adjust the port name and baud rate as needed try: print('Wake up!') ser.write(wakeup_cmd) time.sleep(0.05) print('Host mode') ser.write(host_mode_cmd) time.sleep(0.5) print('Start scan') ser.write(start_scan_cmd) time.sleep(3) print('Stop scan') ser.write(stop_scan_cmd) time.sleep(1) print('Bytes waiting at serial port: ' + str(ser.in_waiting)) response = ser.read(ser.in_waiting) print("Received:", response.decode()) except Exception as e: print("Error communicating with serial device: ", e) finally: print("Close serial port") ser.close()The output:
Open serial port
Wake up!
Host mode
Start scan
Stop scan
Bytes waiting at serial port: 0
Received:
Close serial port
Doing something simpler doesn't work either:
Example 2:
software_version_cmd = bytes([0x04, 0xA3, 0x04, 0x00, 0xFF, 0x55]) print('Open serial port') ser = serial.Serial('COM4', 9600, timeout=1) # Adjust the port name and baud rate as needed try: print('Wake up!') ser.write(wakeup_cmd) time.sleep(0.05) print('Check software version') ser.write(software_version_cmd) time.sleep(1) print('Bytes waiting at serial port: ' + str(ser.in_waiting)) response = ser.read(ser.in_waiting) print("Received:", response.decode()) except Exception as e: print("Error communicating with serial device: ", e) finally: print("Close serial port") ser.close()The output:
Open serial port
Wake up!
Check software version
Bytes waiting at serial port: 0
Received:
Close serial port