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