【发布时间】:2016-02-16 09:26:24
【问题描述】:
我想通过串口发送一个字符串:
我有两个树莓派 2。每个都有一个 xbee 模块。我想将数据从一个发送到另一个。它们已正确连接。
为了测试发送数据,我有这个小 Python 脚本:
import serial
ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=.5)
cpt = 0
while True:
ser.write('{}'.format(cpt))
ser.write(' Hello world ! \r\n')
cpt = cpt + 1
我与 minicom 连接的其他树莓派收到了这些数据
world !
8 Hello world !
9 Hello world !
10 Hello world !
11 Hello world !
12 Hello world !
13 Hello world !
14 Hello world !
15 Hello world !
...
输出很奇怪,有时它从 10 开始,有时从 5 开始。在这个输出中,我有单独的单词“world”...
但我只想用这段代码发送一个字符串:
import serial
ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=.5)
ser.write('Hello world ! \r\n')
现在我什么也没收到……我不知道为什么。
大家都知道我的问题吗?
【问题讨论】:
标签: python serial-port raspberry-pi2 zigbee