Raspberry Pi uses UART serial port and serial device communication

Source: Internet
Author: User


Raspberry Pi Hardware version:

Second-generation B +


Raspberry Pi System version

[Email protected] @raspberrypi: ~# Lsb_release-ano LSB modules is available. Distributor ID:RaspbianDescription:Raspbian Gnu/linux 8.0 (Jessie) Release:8.0codename:jessie



Modified files: vim/boot/cmdline.txt

Change it to the following [email protected]:~# cat/boot/cmdline.txtdwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype= Ext4 Elevator=deadline Fsck.repair=yes rootwait


Restart Raspberry Pi:

[Email protected]:~# reboot



Connect the Raspberry Pi serial port to the other serial devices.

Raspberry Pi Gnd-to-GND serial device

Raspberry Pi Txd---RXD serial device

Raspberry Pi Txd---RXD serial device


Use Pyserial[email protected]:~# apt-get install python-serial a character content "return " echo program, plus " return  "baud rate:9600[email protected]:~# vim python_serial.py# -*- coding:  utf-8 -*  import serial  import time  #  Open Serial   ser  = serial. Serial ("/dev/ttyama0",  9600)   def main ():      while  true:          #  get receive buffer characters            count = ser.inwaiting ()            if count != 0:               #  read content and Echo                recv = ser.read (count) + ".... return\n\n"           &Nbsp;   ser.write (recv)           #  Emptying 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: [email protected]:~# python python_serial.py


Test diagram

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/7E/42/wKiom1b6eOOQap13AAAnFhLMWx0506.png "title=" 1459255314.png "alt=" Wkiom1b6eooqap13aaanfhlmwx0506.png "/>


This article is from the "Soul Bucket" blog, please be sure to keep this source http://990487026.blog.51cto.com/10133282/1758182

Raspberry Pi uses UART serial port and serial device communication

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.