[英]Connecting RS485 output to Raspberry Pi[Android Things]
剛開始使用Android的東西在Raspberry Pi上工作,有一個通過RS485電纜提供輸出的傳感器,我想將該輸出提供給Raspberry Pi,進行了探索,但沒有合適的解決方案,如果有人在您之前做過這種事情可以指導我通過使用轉換器或MAX 485進行連接
從RS485輸出到RPi的最佳方法是什么? 如何實現? 提前致謝
大多數硬件上的UART接口與這些類型的傳感器兼容。 默認情況下,板/模塊上的UART引腳以TTL邏輯電平運行 。 RS-232和RS-485等電氣標准使用相同的基本協議,但是會修改輸出電壓和信號線的配置。
因此,在您的情況下,您只需要在TTL和RS-485之間找到一個轉換器,例如您提到的MAX485。 將其連接到板上的任何可用UART,並使用相同的外設I / O API從Android Things與之通信。
我對Android Things不熟悉,但是希望這會為您指明正確的方向...在Raspberry Pi上使用USB到485轉換器和minimalmodbus python庫 ,我已經取得了很多成功。 請參閱以下有關我過去使用過的示例代碼。 這是非常基本的,但應該可以幫助您入門。
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)
ps這是我的第一個答案,希望我做對了...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.