Arduino 系列仅适用于 PuTTY,不适用于 pySerial
Arduino serial only works with PuTTY and not pySerial
我正在尝试通过串口与 Arduino Pro Micro 通信。我在 Python 中使用 pySerial 发送命令。
pySerial 不工作,但这在 PuTTY 中工作。
# Import libraries
import serial
from time import sleep
# Global Variables
port = 'COM5'
baudrate = 9600
arduino = serial.Serial( port, baudrate, timeout=0 )
# Start Serial interface
try:
print("Connecting to Arduino on: " + port + " (" + str(baudrate) + ")")
sleep(3)
arduino.write( b'cs 4' )
arduino.write( b'dt 0 0 hi' )
arduino.flushOutput()
finally:
arduino.close()
我真是个白痴,我忘了在发送的字符串中添加回车符 return 和换行符。
我浪费了两个小时,因为我忘了在字符串的末尾添加\r\n
。
谢谢@jasonharper 指出我的愚蠢。
我花了 2 个小时在显示器上写 'hi',希望您能从中找到乐趣。
我正在尝试通过串口与 Arduino Pro Micro 通信。我在 Python 中使用 pySerial 发送命令。
pySerial 不工作,但这在 PuTTY 中工作。
# Import libraries
import serial
from time import sleep
# Global Variables
port = 'COM5'
baudrate = 9600
arduino = serial.Serial( port, baudrate, timeout=0 )
# Start Serial interface
try:
print("Connecting to Arduino on: " + port + " (" + str(baudrate) + ")")
sleep(3)
arduino.write( b'cs 4' )
arduino.write( b'dt 0 0 hi' )
arduino.flushOutput()
finally:
arduino.close()
我真是个白痴,我忘了在发送的字符串中添加回车符 return 和换行符。
我浪费了两个小时,因为我忘了在字符串的末尾添加\r\n
。
谢谢@jasonharper 指出我的愚蠢。
我花了 2 个小时在显示器上写 'hi',希望您能从中找到乐趣。