欢迎来到天天文库
浏览记录
ID:34776760
大小:444.95 KB
页数:6页
时间:2019-03-10
《树莓派如何采集rs485数据》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、树莓派如何采集RS485数据1、RS485介绍RS485是有线传输串行数据的标,支持同时传输485总线上的多点数据。传输速率为10Mbps,传输距离可达50英尺。传输速率为100Kbps时,传输距离可达4000英尺。RS485总线通常为4芯或2芯,现在普遍采用2芯总线。一条总线最多支持32个设备。总线之间还可以串接,从而支持成百以上的节点。RS485主要技术规格如下:RS485specificationoverviewAttributeSpecificationCablingMulti-dropNumberofdevices32transmitt
2、ers32receiversCommunicationsmodeshalfduplexMaximumdistance4000feet@100kbpsMaximumdatarate10Mbps@50feetSignallingBalancedMark(data=1)condition1.5Vto5V(BgreaterthanA)Space(data=0)condition1.5Vto5V(AgreaterthanB>Driveroutputcurrentcapability250mA2、RS485和树莓派的连接目前有一种RS485Shield的设备
3、,可以直接连接到树莓派上。硬件连接图如下:1、配置Updatesourcelist$sudoapt-getupdateInstallpython-pip$sudoapt-getinstallpython-pipUsepiptoinstallWiringPi(WiringPiisdesignedforraspberrypitobehavesimilarlytothatofthewiringlibraryunderArduino. Afterthislibraryis installed,c orshellorpythoncanusethe func
4、tiontoconfigureandcontrolGPIOsdirectly. :$sudopipinstallwiringpiInstalledthe associatedlibraryfilesofserialports:$sudoapt-getinstallpython-serial.TestwhethertheGPIOlibraryandtheseriallibraryisinstalledornot:$python$importRPi.GPIO$importserialIfthereisnoerror,thenthetwolibrari
5、esareinstalledcorrectly.Weneedtoconfigure file‘/boot/cmdline.txt’toremovethekernelbootinginformationanddebugmessage:$sudonano/boot/cmdline.txtYoucanseethefollowinginformation:dwc_otg.lpm_enable=0console=ttyAMA0,115200kgdboc=ttyAMA0,115200console=tty1root=/dev/mmcblk0p2rootfst
6、ype=ext4elevator=deadlinerootwaitRemove“console=ttyAMA0,115200kgdboc=ttyAMA0,115200″sothattheinformationbecomes:dwc_otg.lpm_enable=0console=tty1root=/dev/mmcblk0p2rootfstype=ext4elevator=deadlinerootwaitDisableloginfromtheserialport:$sudonano/etc/inittabandcommentout”T0:23:re
7、spawn:/sbin/getty-LttyAMA0115200vt100″RestartRaspberryPi:$sudorebootNowyoucanuse/dev/ttyAMA0liketheregularCOMport.1、测试代码Testcode(serial_test.py) :12345678910111213importserial port=”/dev/ttyAMA0″ usart=serial.Serial(port,9600) usart.flushInput() print(“serialtest:BaudRate=960
8、0″) usart.write(“pleaseenterthecharacter:r”) whileTrue:141516171819
此文档下载收益归作者所有