Connect Raspberry Pi 4B with USB to TTL cable

Generally, after we refresh the Raspberry Pi system, we operate by connecting the mouse, keyboard and monitor. After we enable the SSH function, we can use the ssh client for remote access. Is there a more convenient way to connect without connecting external devices?

serial communication

Of course, we can use a USB to TTL cable to connect the Raspberry Pi to the computer. This connection method is usually used to interact with the Raspberry Pi through serial communication (such as UART).

To connect the Raspberry Pi with a USB TTL adapter, you need to connect the TX (transmit) and RX (receive) pins of the adapter to the corresponding pins of the Raspberry Pi. Usually, GPIO pin 8 (BCM14, UART TXD) of Raspberry Pi is used to send data, and GPIO pin 10 (BCM15, UART RXD) is used to receive data.

Once connected, you can use a serial terminal program (such as PuTTY, SecureCRT, Xshell, MobaXterm, Xshell, Teraterm, Minicom, etc.) to communicate with the Raspberry Pi on your computer. Make sure to select the correct serial port and baud rate settings in your terminal program.

Note: Using a USB TTL connection requires some additional setup and configuration, such as enabling serial terminal functionality and disabling console login.

Steps

If you want to access the Raspberry Pi's serial console, you can follow these steps:

1. Prepare USB to TTL adapter cable

Buy a USB-to-serial connection cable, I bought a CH340G module USB-to-TTL flash relay, after connecting to a Windows device, it does not need to be automatically recognized by the driver.

2. Modify the configuration file

Insert the microSD card of the Raspberry Pi into the card reader and connect it to the computer, edit the file in the boot directory of the volume boot/config.txt, and add the following content at the bottom:

enable_uart=1

Check boot/cmdline.txtif there is this parameter in the file console=serial0,115200, if not, please add it

The following is my Raspberry Pi cmdline.txtconfiguration file, because there is this parameter by default, so there is no need to add it.

console=serial0,115200 console=tty1 root=PARTUUID=85ba5a05-02 rootfstype=ext4 fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles usbhid.mousepoll=0

Save the two files after modification, and then insert the microSD card back into the Raspberry Pi.

3. Connect the TTL communication line

Plug the USB-to-serial adapter into the pins on the Raspberry Pi as shown in the picture below (black to GND 引脚 6, white to GPIO 14/ 引脚 8(UART TX), green to GPIO 15/ 引脚 10(UART RX)):

4. Connect to the computer

Insert the USB port of the TTL communication line into the computer, check whether the COM port driver is normal, obtain the correct COM port number, enter the Windows device manager and click on the port to check, we can see that the COM5 port driver is automatically recognized. We can also enter the command in the cmd command modeto view the status of the COM5 port as follows.

C:\Users\anan>mode

Status for device COM5:
-----------------------
    Baud:            19200
    Parity:          None
    Data Bits:       8
    Stop Bits:       1
    Timeout:         OFF
    XON/XOFF:        OFF
    CTS handshaking: OFF
    DSR handshaking: OFF
    DSR sensitivity: OFF
    DTR circuit:     ON
    RTS circuit:     ON


Status for device CON:
----------------------
    Lines:          30
    Columns:        70
    Keyboard rate:  31
    Keyboard delay: 1
    Code page:      65001

5. Communication settings

Putty is a small and easy-to-use SSH connection client, which can be installed and used on all major platforms. After we open Putty, enter the Connection type in the Serial Line box, enter the Speed ​​box, select COM5the setting and click to start the connection.152000SerialOpen

6. Connect communication

Connect the Raspberry Pi to the power supply. After a while, the word Login appears in the terminal. At this time, you can do the same operation as when connecting to the network with ssh. After entering the account password, the login is successful.

At this point, the connection to the Raspberry Pi using the USB-to-TTL serial communication cable is complete. From then on, we can get rid of the shackles of connecting the monitor and keyboard.

Guess you like

Origin blog.csdn.net/no1xium/article/details/131669270