• sales

    +86-0755-88291180

7. Display ultrasonic distance data User Guide

Display ultrasonic distance data

After CPU Info LCD screen is correctly inserted into the Raspberry Pi, you need to compile and run the program to display it normally. This experiment is used to display ultrasonic distance data.

1.Ultrasonic wiring


2. Install the wringPi library

CPU Info LCD screen is used for data communication through the GPIO port of the Raspberry Pi, so we must install the wiringPi library file.

Enter the following command to install the wringPi library. Users who have already installed the wiringPi library can ignore this step.

cd ~

git clone git://git.drogon.net/wiringPi

cd wiringPi

./build

3.Install Drive

1) Transfer the driver file to the Raspberry Pi

You need to install the Winscp tool on your computer. After connecting to the Raspberry Pi, transfer the cpu_show_distance.zip package from this folder to the pi directory of the Raspberry Pi.

As shown blew, drag and drop cpu_show_distance.zip directly into the Raspberry Pi system.


)Extract file

Open the Raspberry Pi terminal and find the cpu_show_distance.zip file.

Enter command:

ls 


Enter command:

unzip cpu_show_distance.zip


3) Enter the program folder

cd  ~/cpu_show_distance

ls


4)  Compile file

Enter command:

cc -o cpushow_distance pcd8544_rpi.c PCD8544.c  -L/usr/local/lib -lwiringPi


5) Running procedure

Enter command:

./cpushow_distance


The system will prompt Raspberry Pi PCD8544 sysinfo display and display the following on the CPU Info screen.


4.Code analysis

Enter command:

nano pcd8544_rpi.c

This command is to open pcd8544_rpi.c

1) The following sections are the LCD pin settings


The following sections are the ultrasonic pin settings: 


2) Ultrasonic data acquisition


3) Bubble sorting


4The main function is mainly divided into two parts. The front part is the initialization operation of the display screen and the ultrasonic module, and the latter part is a for loop to acquire and display data.


Note: If you have added a boot-up user, first move the xx.desktop file displayed on the 1.6-inch screen in the /home/pi/.config/autostart folder to the pi directory.

If you do not close a program that has already been run, the screen will always change due to conflicts after the program runs.

For example, there is a file driver.desktop that drives a 1.6-inch screen in the /home/pi/.config/autostart folder.


We need to move start.desktop to the pi directory:

Enter command:

mv /home/pi/.config/autostart/start.desktop  /home/pi

Then we can enter command:

sudo reboot

This command is to restart the Raspberry Pi. 

TAG: Raspberry Pi ZERO Camera Raspberry Pi 5 / 4B UPS With PD Trigger Activation Uninterruptible Power Bank Supply 9600mAh 5V/5A 25W Also For Phone/Mini Computer PC ESP32 1.9 inch LCD Capacitive TouchScreen 1.9inch Display ST7789 170x320 for Arduino /Raspberry Pi /Pico Raspberry Pi 5inch Display 1024x600 HDMI Capacitive TouchScreen 5 inch LCD B Wide-Cover For Mini PC ESP32-S3 ETH Camera Development Board PoE RJ45 / OV2640 OV5640 Port / W5500 / Micro-SD Compatible With Raspberry Pi Pico Size Intel BE200 Wireless WLAN Card Gigabit Tri-Band WiFi7 Bluetooth 5.4 M.2 MU-MIMO IEEE 802.11 Onboard ESP32-C6 Development Board A7670E LTE Cat-1 HAT for Raspberry Pi Multi Band 2G GSM / GPRS LBS 1.3inch LCD RP2040-PiZero Game ST7789 Raspberry Pi Pico LCD Display Screen Raspberry Pi MLX90641 Milk V Duo IO Board Tutorial 3D Display Transparent Screen Raspberry Pi 5 PCIe to M.2 Mini NVMe SSD Board (E) With Customized Active Cooler Together ESP32 S3 AI 1.54inch Development Board 1.54 inch TouchScreen Display DeepSeek Raspberry Pi Pico Raspberry Pi IR Thermal Imagi ESP32-S3FH4R2-MINI-Tiny-Stamp-WIFI-Bluetooth5 Raspberry Pi GPS GNSS Expansion Board L76K Beidou (BDS) GLONASS QZSS A-GNSS Also For Jeston Arducam DeepSeek AI Voice Chat ESP32 S3 Development Board 1.85 inch Round LCD 1.85inch Display QMI8658 /MIC /SD /MP3 Audio LVGL For Arduino