Raspberry Pi - Serial Port Method

Experimental preparation

  1. Raspberry Pi motherboard

  2. 8-channel line patrol module

  3. Several Dupont cables

The Raspberry Pi board needs to download the serial communication source code provided in the document, and the Raspberry Pi system needs to open the serial communication interface through raspi-config

Experimental purpose

The content of this experiment is mainly to use the Raspberry Pi main control to receive the data of the 8-channel line patrol module through the serial port.

Experimental wiring

Raspberry Pi8-channel line patrol module
TXRX
RXTX
5v5v
GNDGND

As shown in the figure: image-2024110100001

Open the Raspberry Pi hard serial port (Raspberry Pi 5 does not require this step)

  1. First perform the following operations to map the serial port Enter sudo raspi-config in the terminal

  2. image-2022120500008

  3. image-2022120500009

  4. image-2022120500010

  5. image-2022120500011

  6. Set the hardware serial port to GPIO serial port, edit /boot/config.txt with root privileges.

The command is:

After opening the file, add two lines at the end

image-2022120500013 Save: Ctrl+O, exit: Ctrl+X.

  1. Save and exit, then restart the Raspberry Pi and you can see that the serial ports have been swapped. image-2022120500012 Reference Links: https://blog.iyatt.com/?p=1817

Experimental steps and phenomena

  1. After connecting the wires, run the script

image-2024110100002

 

Experimental source code

This source code only writes numerical data. If you need to parse analog data, you can refer to STM32 serial port parsing