Arduino系列仅适用于油灰,不适用于pySeri

2024-10-03 13:26:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试着和一个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()

Tags: import命令portserialsleeparduinoprowrite
1条回答
网友
1楼 · 发布于 2024-10-03 13:26:21

我真是个白痴,我忘了给我发送的字符串加回车符和换行符。在

我浪费了两个小时,因为我忘了在字符串的末尾添加\r\n。 谢谢你,贾森哈珀指出了我的愚蠢。在

我希望你能从我花了2个小时在显示屏上写“嗨”这件事中找到乐趣。在

相关问题 更多 >