Linux_C_SDK_HWT9053Modbus on board Serial port and 3 in 1 serial port
Last updated
Last updated
Update software repositor
Command line input:
sudo apt-get update sudo apt-getpgrade
Install the wiringpi library
Command line input:
sudo apt-get install wiringpi
Check if the installation is successful
Command line input:
gpio -v
View serial port mapping
Command line input:
ls -l /dev/ttyserial*
If the following two situations occur: Step 2 configuration is required
Map ttyAMA0 to serial0
Method one:
â‘ Click on the Raspberry logo in the upper left corner -> Preferences -> Raspberry Pi Configuration
â‘¡Click "Interfaces"
â‘¢ After checking the "Serial Port option", click "OK"
That is:
â‘£ Click "yes" to restart the Raspberry Pi
Method Two:
â‘ Press and hold" ctrl+Alt+T" to open the terminal
② command line input:
sudo raspi-config
The following interface appears, select "Interface Options" and press "Enter"
â‘¢ Select "I6 Serial Port" and press "Enter"
â‘£ Select "<No>, press "Enter"
⑤ Choose"<Yes>",press"Enter"
â‘¥ After the following interface appears, selec<Ok> , and then press the "Esc" key to exit the page
⑦ Reboot the Raspberry Pi
command line input:
reboot
Check whether the serial port is mapped successfully
ls -l /dev/serial*
As can be seen from the above figure, serial0 is mapped to ttyAMA0 after configuration, indicating that the configuration is successful.
Hardware connection
â‘ Wiring problem (this example uses Raspberry Pi 3b+ as an example)
Find the pinout diagram of the Raspberry Pi model you are using
â‘¡ Wiring connection
Prepare WitMotion sensor HWT9053-485 sensor and 485 to TTL adapter board
Enter the specified folder to compile and run the program
Command line input:
cd ~/linux_sdk cd ./HWT9053modbus gcc ./*.c -lwiringPi ./a.out /dev/ttyAMA0
View running results
Prompt information and returned sensor parameter data appear
Shake the sensor, the parameters of the sensor will be sent back and displayed in real time, indicating that the debugging is successful!
Operation steps of 3 in 1 serial port
Wiring connection
Prepare WitMotion sensor HWT9053-485 and 3 in 1 adapter
HWT9053-485 3 in 1 adapter
VCC <----------------------------------------> VCC
A <-------------------------------------------> A
B <-------------------------------------------> B
GN <-----------------------------------------> GND
View the serial port file under the device file
Command line input:
ls -l /dev/ttyUSB*
Plug the 3-in-1 into the serial port of the Raspberry Pi, and enter the above command again: ls -l /dev/ttyUSB*
The extra serial port file is the serial port file we are looking for (ttyUSB0)
Enter the specified folder to compile and run the program
Command line input:
cd ~/linux_sdk cd ./HWT9053modbus gcc ./*.c -lwiringPi ./a.out /dev/ttyUSB0
View running results
Prompt information and returned sensor parameter data appear
Shake the sensor, the parameters of the sensor will be sent back and displayed in real time, indicating that the debugging is successful!
Please reference to the sensor datasheet.
Case one:
Case two: