Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize UART with Python in Raspberry Pie

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "how raspberry pie uses Python to achieve UART". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "how to use Python to achieve UART in raspberry pie".

First, raspberry pie needs to install python-serial, and Raspbian also needs to activate UART in raspi-config.

Then modify the file 1:sudo nano / boot/cmdline.txt to delete the red part:

Dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

Eventually become: dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

Then modify the file 2:sudo nano / etc/inittab to comment on the last line:

# T0:23:respawn:/sbin/getty-L ttyAMA0 115200 vt100

Example:

The configuration method of the module HM-10: when the Bluetooth module is not connected to the Bluetooth 4.0device, use the serial port debugging tool minicom, copy the command, paste it in the tool and send it to the module. See the manual of the module for details. Bluetooth 4.0devices such as mobile phones are connected to the module by app, and finally the BLE Bluetooth serial port from the module company is used to debug the assistant app.

Uart is used to communicate with the module BT_demo.py for writing programs.

Import serialimport timeser = serial.Serial ('/ dev/ttyAMA0', 115200, timeout=1) # ser = serial.Serial ('COM3', 115200, timeout=1) print ser.isOpen () words= "abcd" while 1: getchr = ser.read () # print getchr if getchr = =' hype: ser.write (words) time.sleep (5) ser.close ()

An error occurred during debugging:

If Android app sends characters that are unsuccessful, for example, click and send a long string:

1, maybe the serial port on the raspberry pie is not open, Raspbian is opened in raspi-config, and confirm that the serial port file modification configuration is normal.

2, because the module is connected first and then the program is run, the correct thing is to run the program first and then connect the module.

If the transceiver does not respond, or the code is garbled, make sure that the connection is correct and whether the rate matches.

The above is all the content of the article "how to use Python to achieve UART in raspberry pie". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report