esp8266 和 cp2102 不工作!为什么?
import serial
sp="/dev/ttyUSB0"
port = serial.Serial(sp)
while True:
port.write("AT+RST")
rcv = port.read(10)
print rcv
我按了“AT+RST”[Enter],后面没有“READY”。
esp8266 和 cp2102 不工作!为什么?
import serial
sp="/dev/ttyUSB0"
port = serial.Serial(sp)
while True:
port.write("AT+RST")
rcv = port.read(10)
print rcv
我按了“AT+RST”[Enter],后面没有“READY”。
确保在命令末尾包含 CRLF (\r\n) 字符。在我弄清楚之前,我浪费了一天的时间。我得到了命令的本地回显,但由于我从未发送过 \r\n 我不会再获得任何数据。以下是使用 pyserial 在 Python 中作为基本终端对我有用的方法:
import serial
import time
ser = serial.Serial('/dev/tty.usbserial-A8004xaO', 115200, timeout=2.5)
while True:
cmd = raw_input("> ");
ser.write(cmd + "\r\n")
ret = ser.read(len(cmd)) # eat echo
time.sleep( 0.2 )
while ( ser.inWaiting() ):
ret = ser.readline().rstrip()
print ret
打开串行端口时,您没有设置波特率。默认值可能不适合 ESP8266。