Linux_C_SDK_HWT9053Modbus on board Serial port and 3 in 1 serial port

Linux_C_SDK_HWT9053Modbus Onboard serial port and 3 in1 serial port usage tutorial

https://github.com/WITMOTION/WitHighModbus_HWT9073485

Install the wiringpi library

  1. Update software repositor

Command line input:

sudo apt-get update sudo apt-getpgrade

  1. Install the wiringpi library

Command line input:

sudo apt-get install wiringpi

  1. Check if the installation is successful

Command line input:

gpio -v

Operation steps of onboard serial port

  1. View serial port mapping

Command line input:

ls -l /dev/ttyserial*

If the following two situations occur: Step 2 configuration is required

  1. 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

  1. 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.

  1. 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

  1. 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

  1. 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

  1. 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

  1. 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)

  1. 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

  1. 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!

More

Please reference to the sensor datasheet.

Last updated