好文档就是一把金锄头!
欢迎来到金锄头文库![会员中心]
电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

树莓派如何采集RS485数据.docx

6页
  • 卖家[上传人]:平***
  • 文档编号:13879794
  • 上传时间:2017-10-26
  • 文档格式:DOCX
  • 文档大小:411.01KB
  • / 6 举报 版权申诉 马上下载
  • 文本预览
  • 下载提示
  • 常见问题
    • 树莓派如何采集 RS485 数据1、 RS485 介绍RS485 是有线传输串行数据的标,支持同时传输 485 总线上的多点数据传输速率为10Mbps,传输距离可达 50 英尺传输速率为 100Kbps 时,传输距离可达 4000 英尺RS485 总线通常为 4 芯或 2 芯,现在普遍采用 2 芯总线一条总线最多支持 32 个设备总线之间还可以串接,从而支持成百以上的节点RS485 主要技术规格如下:RS485 specification overviewAttribute SpecificationCabling Multi-dropNumber of devices 32 transmitters32 receiversCommunications modes half duplexMaximum distance 4000 feet @ 100 kbpsMaximum data rate 10 Mbps @ 50 feetSignalling BalancedMark (data = 1)condition1.5 V to 5 V (B greater than A)Space (data = 0)condition1.5 V to 5 V (A greater than B>Driver output current capability250 mA2、 RS485 和树莓派的连接目前有一种 RS485 Shield 的设备,可以直接连接到树莓派上。

      硬件连接图如下:3、 配置Update source list$ sudo apt-get updateInstall python-pip$ sudo apt-get install python-pipUse pip to install WiringPi (WiringPi is designed for raspberry pi to behave similarly to that of the wiring library under Arduino. After this library is installed,c or shell or python can use the function to configure and control GPIOs directly. :$ sudo pip install wiringpiInstalled the associated library files of serial ports :$ sudo apt-get install python-serial.Test whether the GPIO library and the serial library is installed or not:$ python$ import RPi.GPIO$ import serialIf there is no error , then the two libraries are installed correctly. We need to configure file ‘/boot/cmdline.txt’ to remove the kernel booting information and debug message:$ sudo nano / boot / cmdline.txtYou can see the following information:dwc_otg.lpm_enable = 0 console = ttyAMA0, 115200 kgdboc = ttyAMA0, 115200 console = tty1 root = / dev/mmcblk0p2 rootfstype = ext4 elevator = deadline rootwaitRemove “console = ttyAMA0, 115200 kgdboc = ttyAMA0, 115200″ so that the information becomes:dwc_otg.lpm_enable = 0 console = tty1 root = / dev/mmcblk0p2 rootfstype = ext4 elevator = deadline rootwaitDisable log in from the serial port:$ sudo nano / etc / inittaband comment out ” T0: 23: respawn :/ sbin / getty-L ttyAMA0 115200 vt100″Restart Raspberry Pi:$ sudo rebootNow you can use / dev/ttyAMA0 like the regular COM port.4、 测试代码Test code(serial_test.py) :12345678910111213import serialport = ”/dev/ttyAMA0″usart = serial.Serial(port,9600)usart.flushInput()print (“serial test: BaudRate = 9600″)usart.write(“please enter the character:\r”)while True:141516171819202122232425if( usart.inWaiting()>0 ) :receive = usart.read(1)print ”receive: ”,receiveusart.write(“ send: ’”)usart.write(receive)usart.write(“‘\r”)6、基于 RS232 转 RS485 的测试例程硬件连接方式:硬件管脚对应关系:RS485 Shield ‘A’-> RS232-RS485 converter ‘ T/R + ‘RS485 Shield ‘B’-> RS232-RS485 converter ‘ T/R- ‘RS485 Shield ‘GND’ -> RS232-RS485 converter’ GND ‘After the wiring is done, launch a serial terminal. We use X-CTU in our case, and set the baud rate to 9600After running serial_test.py, enter the characters in the X-CTU:。

      点击阅读更多内容
      关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
      手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
      ©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.