Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How does Raspberry pie communicate with Serial Devices using uart Serial Port

Shulou Source: shulou.com Published: 2022-06-01 22:59:59 09月27日 Update

Raspberry pie how to use uart serial port to communicate with serial devices, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Raspberry pie hardware version: second generation B +

Raspberry pie system version

Root@raspberrypiroot@raspberrypi:~# lsb_release-aNo LSB modules are available.Distributor ID:RaspbianDescription:Raspbian GNU/Linux 8.0 (jessie) Release:8.0Codename:jessie

Modify the file: vim / boot/cmdline.txt

Change it to root@raspberrypi:~# cat / boot/cmdline.txtdwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait like this

Restart raspberry pie:

Root@raspberrypi:~# reboot

Connect the serial port of raspberry pie with other serial devices

Raspberry pie GND-- > GND serial port equipment

Raspberry pie TXD-- > RXD serial port equipment

Raspberry pie TXD-- > RXD serial port equipment

Use the pyserialroot@raspberrypi:~# apt-get install python-serial one-character content "return" echo program Add "return" baud rate: 9600root@raspberrypi:~# vim python_serial.py#-*-coding: utf-8-* import serial import time # Open serial port ser = serial.Serial ("/ dev/ttyAMA0" 9600) def main (): while True: # get the receive buffer character count = ser.inWaiting () if count! = 0: # read and echo recv = ser.read (count) + ".... return\ n\ n" ser.write (recv) # clear the receive buffer Ser.flushInput () # necessary software delay time.sleep (0.1) if _ _ name__ ='_ _ main__': try: main () except KeyboardInterrupt: if ser! = None: ser.close () run program: root@raspberrypi:~# python python_serial.py test chart

This is the answer to the question about how raspberry pie uses the uart serial port to communicate with serial devices. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

Tags: Serial port raspberry device content question communication character more version program buffer help buffer solution easy necessary easy boy buddy file Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Redmi Docker Shulou Tech Info Huawei