树莓派如何采集RS485数据.docx_第1页
树莓派如何采集RS485数据.docx_第2页
树莓派如何采集RS485数据.docx_第3页
树莓派如何采集RS485数据.docx_第4页
树莓派如何采集RS485数据.docx_第5页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

树莓派如何采集RS485数据1、 RS485介绍RS485是有线传输串行数据的标,支持同时传输485总线上的多点数据。传输速率为10Mbps,传输距离可达50英尺。传输速率为100Kbps时,传输距离可达4000英尺。RS485总线通常为4芯或2芯,现在普遍采用2芯总线。一条总线最多支持32个设备。总线之间还可以串接,从而支持成百以上的节点。RS485主要技术规格如下:RS485 specification overviewAttributeSpecificationCablingMulti-dropNumber of devices32 transmitters32 receiversCommunications modeshalf duplexMaximum distance4000 feet 100 kbpsMaximum data rate10 Mbps 50 feetSignallingBalancedMark (data = 1)condition1.5 V to 5 V (B greater than A)Space (data = 0)condition1.5 V to 5 V (A greater than BDriver output current capability250 mA2、 RS485和树莓派的连接目前有一种RS485 Shield的设备,可以直接连接到树莓派上。硬件连接图如下:3、 配置 Update source list$ sudo apt-get update Install 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 wiringpi Installed theassociated 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 rootwait Disable 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):12345678910111213141516171819202122232425import serialport = ”/dev/ttyAMA0usart = serial.Serial(port,9600)usart.flushInput()print (“serial test: BaudRate = 9600)usart.write(“please enter the character:r”)while True:if( usart.inWaiting()0 ) :receive = usart.read(1)print ”receive: ”,receiveusart.write(“ send: ”)usart.write(receive)usart.write(“r”)5、 1 x RaspberryPi6、 1 x RS485shieldfor Raspberry Pi7、8、 3 x Male to male jumper wires9、 1 x RS232-RS485 converter10、 1 x 9DB male of serial-to-USB cable:11、12、 Wiring:13、 RS485 Shield A- RS232-RS485 converter T/R + 14、 RS485 Shield B- RS232-RS485 converter T/R- 15、 RS485 Shield GND - RS232-RS485 converter GND 16、17、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:18、 After the wiring is don

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论