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