Arduino_SDK Quick Start

Arduino_SDK Quick Start

#The sample code's using board

Arduino Mega-2560 development board

Where to download

Please check the below link to download the sample code.

Routine Introduction

This routine introduces how to use the serial port 1 of the MEGA-2560 platform to connect the HW-97 module, and then perform high-precision Modbus protocol with the serial port of WitMotion HWT9053-485 sensor, and then directly print data through the serial port, receive sensor data and communicate with the sensor;

Before viewing this routine, please read the relevant sensor manual to understand the protocol used by the sensor and the basic functions of the sensor.

How to wiring

Please prepare HWT9053-485 sensor, a 485 to TTL transfer module, MEGA-2560 development board and a serial port 3 in 1 adapter. Please reference to the below wiring:

  • Copy the file wit_c_sdk to the library folder of Arduino's libraries

Paste path: arduino-1.8.15\libraries

After pasting successfully:

  • Use the Arduino software to download the program to the development board


  • Selection of development boards, processors, and serial ports

  • Upload and burn program

Reason for uoloaded item error:

The serial port selection is wrong, the serial port is not selected, or the serial port is occupied

The above prompts show that the program is successfully compiled and downloaded to the development board.

  • Open the serial port debugging assistant, power on, and the following information will be displayed:

You can send corresponding instructions to configure the module through the prompt information.


Modbus is a one-question-one-answer interactive form, so the module needs to be continuously inquired before the data can be returned.

For the introduction of API functions, please read the WIT_C_SDKAPI function documentation.

Serial.begin(115200); //Initialize the print data serial port

RS485_IO_Init(); //485-pin configuration initialization

WitInit(WIT_PROTOCOL_905x_MODBUS, 0x50); //Initialize the high-precision modbus protocol and set the device address

WitSerialWriteRegister(SensorUartSend); //Registers a callback function that writes out data

WitRegisterCallBack(CopeSensorData); //Register to get the sensor data callback function

WitDelayMsRegister(Delayms); //Register millisecond delay function

AutoScanSensor(); //Register millisecond delay function

Receive the sensor's data

Get data

We will create an array to store the read data into the array, and read the corresponding data directly according to the index. Since the module used this time is a high-precision modbus protocol, you need to provide the data start address and the amount of data to be read when you need to ask. For example, the example calls WitReadReg(AX,16) every 300ms; the starting address is AX (acceleration X value) and continuously reads 16 data volumes, and the final effect is to read the 3D acceleration, 3D angular velocity, 3D angle, and 3D magnetic field of the module. The data into the specified index array and temperature. Finally print it out.

WitReadReg(AX, 16);//Interval reading module, the address starts from AX (acceleration X) to read 16 bytes of data. Refer to REG.H register list.

Setting Sensor

The parameters of the module can be set through the function CmdProcess(); Such as acceleration calibration, magnetic field calibration and modifying baud rate etc.

  • Open the serial port assistant, send the command B\r\n, and then observe the phenomenon.

After sending B\r\n, the module will search for the device again, and prompt what baud rate is found. The window displays information prompting that the 115200 baud rate search is successful, and compares the sending instructions described in the HELP prompt information. The baud rate indicates that the setting is correct. Use other commands as needed.

Accelemeter Calibration

Some common API function interfaces are defined in the file wit_c_sdk.c, which only needs to be called.

After sending a\r\n through the serial port assistant, after waiting for about 5 seconds, the X and Y axis angles will be calibrated to a state of about 0 degrees. Acceleration X, Y calibration is about 0g, Z is about 1g.

Magnetic field calibration

The magnetic field calibration needs to be sent to start the calibration first, then rotate around the three axes of the sensor and then end the calibration. First call WitStartMagCali(); to start magnetic field calibration, then rotate the sensor on three axes, and then call WitStopMagCali(); to end the calibration.


Please reference to the sensor's datasheet.

Last updated