【问题标题】:Connecting RS485 output to Raspberry Pi[Android Things]将 RS485 输出连接到树莓派[Android Things]
【发布时间】:2017-08-27 16:29:36
【问题描述】:

刚开始使用 Android 开发 Raspberry Pi,有一个通过 RS485 电缆提供输出的传感器,我想将该输出馈送到 Raspberry Pi,经过探索但没有合适的解决方案,如果有人做过这种在您指导我使用转换器或使用 MAX 485 建立连接之前的东西

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

【问题讨论】:

    标签: android raspberry-pi3 gpio android-things rs485


    【解决方案1】:

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

    所以在你的情况下,你只需要在 TTL 和 RS-485 之间找到一个转换器,比如你提到的 MAX485。将其连接到板上任何可用的 UART,并使用相同的 Peripheral I/O APIs 从 Android Things 与其通信。

    【讨论】:

      【解决方案2】:

      我不熟悉 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)
      

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-09-15
        • 2017-08-27
        • 2017-10-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多