首页 文章

将RS485输出连接到Raspberry Pi [Android Things]

提问于
浏览
0

刚刚开始研究带有Android东西的Raspberry Pi,有一个通过RS485电缆提供输出的传感器,我想将该输出提供给Raspberry Pi,探索但没有得到适当的解决方案,如果有人在你之前做过这种事情可以指导我使用转换器或使用MAX 485进行连接

从RS485到RPi的输出的最佳方法是什么?如何实现?提前致谢

2 回答

  • 1

    大多数硬件上的UART接口与这些类型的传感器兼容 . 默认情况下,电路板/模块上的UART引脚工作在TTL logic levels . 像 RS-232RS-485 这样的电气标准使用相同的基本协议,但修改输出电压和信号线的配置 .

    因此,在您的情况下,您只需要找到TTL和RS-485之间的转换器,就像您提到的MAX485一样 . 将其连接到电路板上的任何可用UART,并使用相同的Peripheral I/O APIs与Android Things进行通信 .

  • 0

    我不熟悉Android Things,但希望这会指出你正确的方向......我在Raspberry Pi上使用USB to 485 converterminimalmodbus 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)
    

    附:这是我的第一个答案,希望我做得对...

相关问题