资源预览内容
第1页 / 共4页
第2页 / 共4页
第3页 / 共4页
第4页 / 共4页
亲,该文档总共4页全部预览完了,如果喜欢就下载吧!
资源描述
树莓派 RS485 调试指南QQ 9230562891、硬件准备2、操作系统环境设置We need to modify two files: /boot/cmdline.txt and /etc/inittab. Modify /boot/cmdline.txt: Replace the original content: dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait With: dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait Modify /etc/inittab: Comment out the last line of /etc/inittab. To comment out, it simply addess a #. $ sudo vi /etc/inittab 1. T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100 Save the changes, and reboot. We will get an UART with baud rate of 115200. 3、驱动及相关软件设置Sudo apt-get install python-pipSudo apt-get install serial-python$ pythonimport RPi.GPIOimport serialIf there is no error , then the two libraries are installed correctly.退出:ctrl+d或 exit()如果在执行 import 时不报错,则认为这两个库已经正确安装。4、RS485 测试连线图如下:RS485-RS232 的转换器有 3 个接口,A 、B 、接地。其中 A 口是 TR+,B 口是 TR-。管脚定义如下:转换器的 A 口连 RS485 shield 的 A 口。转换器的 B 口连 RS485 shield 的 B 口。我们测试的方法是:PC 机通过 USB 转 232 连 232 模块, 232 模块通过转换后接入到RS485 shield。PC 机上启动超级终端,输入字符,在树莓派上能看到,就说明 RS485 Shield 能正确处理输入信号。启动超级终端,设置波特率为 9600,控制流无、数据位 8、停止位 1、奇偶校验位无。在树莓派上运行 python 程序。源代码及运行方法如下:piraspberrypi:$ cat *.pyimport serialport=/dev/ttyAMA0usart=serial.Serial(port,9600)usart.flushInput()print(serial test Baudrae = 9600)usart.write(please enter the character:r)while True:if (usart.inWaiting()0):receive = usart.read()print ( receive:),receiveusart.write(r)usart.write( send:)usart.write(r)usart.write(receive)usart.write(r)运行该程序:Sudo ./serial_test.py运行结果如下:在超级终端中输入的字符全部在树莓派上显示了。说明 RS485 shield 能够收到信号,并正确识别。
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号