Raspberry Pi UART使用速記


原文链接: Raspberry Pi UART使用速記

树莓派3b+串口配置_唐传林的博客-CSDN博客
默认用户名是pi,密码是raspberry

要先從 raspi-config 將 serial 選成 no
再從 /boot/config.txt 加入 enable_uart=1, 就可以透過 /dev/ttyAMA0 通訊
/boot/config.txt 加入 dtoverlay=miniuart-bt
*if you want to change the blutooth to miniuart port(bad)

dtoverlay=pi3-miniuart-bt

*if you want to disable the blutooth(good)

dtoverlay=pi3-disable-bt

Raspberry Pi UART使用速記

Pi 3 內建 WiFi 和 Bluetooth, 完全是一片美意, 可是在使用上要注意幾個地方

  1. 如果要能從序列埠登入到 Pi, 需要從 raspi-config 將 serial 選成 yes
    並且在 /boot/config.txt 加入 dtoverlay=pi3-disable-bt 停用內建的 Bluetooth

  2. 那如果停用了不就浪費錢了嗎?
    可以在 /boot/config.txt 加入 dtoverlay=pi3-miniuart-bt 將 Pi 3 Bluetooth 移到 mini-UART (ttyS0)
    另外還要加上 core_freq=250

  3. 如果想用序列埠(UART)和其他硬體通訊, 例如 GSM, HC-05, LoRa, GPS 等怎麼辦?
    要先從 raspi-config 將 serial 選成 no
    再從 /boot/config.txt 加入 enable_uart=1, 就可以透過 /dev/ttyAMA0 通訊

以上環境是 Pi 3 + 2016-05-29.img

更多overlay 的說明可以參考:
https://github.com/raspberrypi/linux/tree/rpi-4.1.y/arch/arm/boot/dts/overlays

參考資料:
http://raspberrypi.stackexchange.com/questions/45570/how-do-i-make-serial-work-on-the-raspberry-pi3

lidar

It indicate that the serial port is used to output console information. It is not what we intend to (console is linked to serial0 by default, baud rate 115200), we want to use it connect to peripheral device, so it is need to disable console:

sudo nano /boot/cmdline.txt

dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait

sudo reboot

Let's check the mapping:

ls -l /dev
#serial0 -> ttyS0
#serial1 -> ttyAMA0

Change the mapping:

sudo nano /boot/config.txt

Add a line:

dtoverlay=miniuart-bt

Reboot:

sudo reboot

Check the mapping again:

ls -l /dev
#serial0 -> ttyAMA0
#serial1 -> ttyS0

Let's check Raspberry Pi's GPIO first:

Rpi3_GPIO

Connection is as follow:

Raspberry Pi 4TFmini
+5V5V(RED)
GNDGND(BLACK)
TXD0RX(WHITE)
RXD0TX(GREEN)

Step 1 - Install Raspbian Jessie onto a SD card and boot the Pi when connected to a network Login via terminal or desktop and shell Configure the system with:

sudo raspi-config

Expand filesystem and enable serial on advanced page, exit and reboot.

Step 2 -this won't necessary if you have jessie new release Update the system with:

sudo apt-get update

sudo apt-get upgrade

Step 3 - Device Tree settings as below:

Add device tree to /boot/config.txt to disable the Raspberry Pi 3 bluetooth.

sudo nano /boot/config.txt

Add at the end of the file

*if you want to change the blutooth to miniuart port(bad)

dtoverlay=pi3-miniuart-bt

*if you want to disable the blutooth(good)

dtoverlay=pi3-disable-bt

Exit the editor saving your changes.

Step 4 - reboot the pi

sudo reboot

step 5 -

a)to disable the Serial Console edit the file using

sudo nano /boot/cmdline.txt

remove the word phase "console=serial0,115200" or "console=ttyAMA0,115200"

Exit and save your changes

b)to Enable the Serial Console edit the file using

sudo nano /boot/cmdline.txt

Change the file to the following:

dwc_otg.lpm_enable=0 console=tty1 console=serial0(or ttyAMA0),115200 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait

Exit and save your changes

Step 6 - reboot the pi

sudo reboot
`