刚开始工作的树莓Pi与安卓的东西,有一个传感器,通过RS485电缆输出,我想把输出馈送到树莓Pi,探索,但没有适当的解决方案,同样,如果任何人做了这类事情之前,您可以指导我通过使用转换器或使用MAX485进行连接
将RS485的输出转换为RPi的最佳方法是什么?如何实现这一目标?提前感谢
发布于 2017-08-28 10:21:09
大多数硬件上的UART接口都与这些类型的传感器兼容。默认情况下,板/模块上的通用异步收发器引脚工作在TTL logic levels。RS-232和RS-485等电气标准使用相同的基本协议,但会修改信号线的输出电压和配置。
所以在您的例子中,您只需要找到一个在TTL和RS-485之间的转换器,就像您提到的MAX485。将其连接到您主板上的任何可用的Peripheral I/O APIs,并使用相同的UART从安卓的东西与它通信。
发布于 2017-08-28 01:38:49
我不熟悉Android的东西,但希望这能为你指明正确的方向……我在覆盆子Pi上使用USB to 485 converter和minimalmodbus python library取得了很大的成功。请看下面我过去使用过的一些示例代码。这是非常基础的,但应该能让你入门。
import minimalmodbus
import serial
usbDevice = '/dev/ttyUSB0'
modbusSlaveID = 1
# can be 'ascii' or 'rtu'
modbusFormat = 'rtu'
registerToRead = 64
# 3 is for Holding Registers, 4 is for Input Registers
functionCode = 3
# initialize the device
device = minimalmodbus.Instrument(usbDevice, modbusSlaveID, modbusFormat)
# set the various options, which will depend on the device you are communicating with
device.debug = True
device.serial.baudrate = 9600
device.serial.bytesize = 8
device.serial.parity = serial.PARITY_NONE
device.serial.stopbits = 1
device.serial.timeout = 2 # seconds
print device.read_register(registerToRead, functioncode=functionCode)附注:这是我的第一个答案,希望我做对了…
https://stackoverflow.com/questions/45907043
复制相似问题