Turn: http://blog.csdn.net/yangqicong11/article/details/26571787
Is Raspberry Pi able to use the serial port? The answer is yes. The specific method is as follows:
1. The third, fourth, and fifth ports in the first row of Raspberry Pi are respectively, that is, ports 6, 8, and 10 are respectively, TX and Rx, respectively, and connected to the connected device. Note that the TX of Raspberry Pi is connected to the RX from the device, and the RX of Raspberry Pi is connected to the TX of Raspberry Pi.
2. There is only one serial port on Raspberry Pi. The system uses it as the debugging port by default, so it cannot be programmed and used as a common serial port. You need to remove the configuration of the debugging port before using it. Two files need to be modified here
2.1 enter the following command on the terminal for modification:
[Plain]View plaincopyprint?
- Sudo nano/boot/cmdline.txt
sudo nano /boot/cmdline.txt
Delete the red part after logging = 0 console = ttyama0, 115200 kgdboc = ttyama0, 115200 console = tty1 root =/dev/mmcblk0p2 rootfstype = ext4 elevator = deadline rootwait is deleted, save and exit dwc_otg.lpm_enable = 0 console = tty1 root =/dev/mmcblk0p2 rootfstype = ext4 elevator = deadline rootwait 2.2 Modify/etc/inittab and enter the following command on the terminal:
[Plain]View plaincopyprint?
- Sudo nano/etc/inittab
sudo nano /etc/inittab
After opening, comment out the last line and add a # sign before it. # T0: 23: respawn:/sbin/Getty-l ttyama0 115200 VT100
3. After modification, you need to install a mini-com on Raspberry Pi. Here, mini-com is a serial debugging tool on the Linux platform, which is equivalent to a serial debugging assistant on Windows.
3.1 run the following command to install minicom:
[Plain]View plaincopyprint?
- Sudo apt-Get install minicom
sudo apt-get install minicom
3.2 after installation, You need to configure minicom. The configuration file requires the root permission. Otherwise, the configuration parameters cannot be saved. Enter the following command in the command line:
[Plain]View plaincopyprint?
- Sudo passwd Root
sudo passwd root
After executing this command, the system will prompt you to enter the root password twice, enter the password you want to set, and then execute
[Plain]View plaincopyprint?
- Sudo passwd -- Unlock Root
sudo passwd --unlock root
In this way, the root account is unlocked.
3.3 switch to the root account, open the command line again, and enter the minicom parameter configuration command
[Plain]View plaincopyprint?
- Minicom-S
minicom -s
In Serial Port setup, the third item in the main menu, go to the next menu, select according to the prompt letter of the menu item, and press a to change the serial port device to/dev/ttyama0
, Press e to change the baud rate to 9600 or the expected value. After setting, return to the main menu and select Save setup as DFL.
Then select exit. If it is normal, you can send and receive data through the serial port. Here, my Raspberry Pi is connected to a PC, and I have successfully sent and received data using the serial port debugging software of the PC.
TIPS: press Ctrl + A, and then press Z to view the help of minicom.
Raspberry Pi-serial port configuration method for Raspberry Pi)