我正试着和一个Arduino Pro微控制器通过串行通信。我在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()
我真是个白痴,我忘了给我发送的字符串加回车符和换行符。在
我浪费了两个小时,因为我忘了在字符串的末尾添加
\r\n
。 谢谢你,贾森哈珀指出了我的愚蠢。在我希望你能从我花了2个小时在显示屏上写“嗨”这件事中找到乐趣。在
相关问题 更多 >
编程相关推荐