教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 文库大全 > 专业资料 >

树莓派如何采集RS485数据

来源:网络收集 时间:2025-12-28
导读: 本文描述了树莓派采集RS485数据的方法和测试案例 树莓派如何采集RS485数据 1、 RS485介绍 RS485是有线传输串行数据的标,支持同时传输485总线上的多点数据。传输速率为10Mbps,传输距离可达50英尺。传输速率为100Kbps时,传输距离可达4000英尺。 RS485总线通

本文描述了树莓派采集RS485数据的方法和测试案例

树莓派如何采集RS485数据

1、 RS485介绍

RS485是有线传输串行数据的标,支持同时传输485总线上的多点数据。传输速率为10Mbps,传输距离可达50英尺。传输速率为100Kbps时,传输距离可达4000英尺。 RS485总线通常为4芯或2芯,现在普遍采用2芯总线。一条总线最多支持32个设备。总线之间还可以串接,从而支持成百以上的节点。

RS485主要技术规格如下:

2、 RS485和树莓派的连接

目前有一种RS485 Shield的设备,可以直接连接到树莓派上。硬件连接图如下:

本文描述了树莓派采集RS485数据的方法和测试案例

本文描述了树莓派采集RS485数据的方法和测试案例

3、 配置

Update source list

$ sudo apt-get update

Install python-pip $ sudo apt-get install python-pip Use 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 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 serial

If there is no error , then the two libraries are installed correctly.

本文描述了树莓派采集RS485数据的方法和测试案例

We need to configure file /boot/cmdline.txt to remove the kernel booting information and debug message:

$ sudo nano / boot / cmdline.txt You 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 rootwait

Remove “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 / inittab

and comment out ” T0: 23: respawn :/ sbin / getty-L ttyAMA0 115200 vt100″

Restart Raspberry Pi:

$ sudo reboot

Now you can use / dev/ttyAMA0 like the regular COM port.

4、 测试代码

Test code(serial_test.py) : 1

2

3

4

5

6

7

8

9

10

11

12

13 import serial port = ”/dev/ttyAMA0″ usart = serial.Serial(port,9600) usart.flushInput() print (“serial test: BaudRate = 9600″) usart.write(“please enter the character:\r”) while True:

本文描述了树莓派采集RS485数据的方法和测试案例

14

15

16

17

18

19

20

21

22

23

24 25

if( usart.inWaiting()>0 ) : receive = usart.read(1) print ”receive: ”,receive usart.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 9600

本文描述了树莓派采集RS485数据的方法和测试案例

After running serial_test.py, enter the characters in the X-CTU:

…… 此处隐藏:679字,全部文档内容请下载后查看。喜欢就下载吧 ……
树莓派如何采集RS485数据.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wenku/51255.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)