【问题标题】:Problems reading data from Arduino over rs485通过 rs485 从 Arduino 读取数据时出现问题
【发布时间】:2020-06-11 22:16:57
【问题描述】:

我编写了一个小程序来在 RasPi 和 Arduino 之间进行通信。我可以完美地从 RasPi 向 Arduino 发送消息。 Arduino 将读取传入的消息,并做出适当的响应。当 RasPi 正在读取 Arduino 消息时会出现问题。

arduino 正在发送“2, 2, 'A', 'B', 'C', (crc)”。我可以通过将第二个 arduino 连接到 rs485 网络来确认这一点。 Python 将其读取为随机乱码,并给了我这个:

b'\xd5'
b'i'
b'\x8a'
b'j'
b'z'
b'\xf6'
b'T'
b'{'
b'\xf6'
b'\x8c'
b'\xe2'
b'\xfe'

Python 代码(不是整个代码,只是相关的):

data = bytearray()
info = ord('A')
data.append(info)

sendMsg(2, len(data), data)
while(True):
  inByte = rs.read()
  print(inByte)

【问题讨论】:

  • 您有硬件问题或波特率不匹配。你是如何连接和设置端口的?

标签: python arduino raspberry-pi rs485


【解决方案1】:

你需要解码数据。

试试

inByte = rs.read().decode('utf-8')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 2013-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-01
    • 1970-01-01
    相关资源
    最近更新 更多