ESP32_SDK Quick Start

ESP32_SDK quick start

Applicable Model






Routine download

Go to the link below to download the sample

Routine introduction

This routine introduces how to use the serial port 1 of the ESP32 platform to connect to the normal protocol of Wit-motion serial port, and then directly print data through serial port 0, 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

Equipment wiring

First prepare the Wit-motion standard sensor, here we take JY901S as an example, ESP32 development board and a serial port three-in-one module. Wiring:

Physical wiring diagram:

Download the program to the development board, open the serial port debugging assistant at the same time, and power on again, the following information will be displayed:

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


Modules with standard protocols only need to be connected to power and serial lines, and the data will be automatically returned.

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

Usart0_task//Initialize the print data serial port

Usart1_task//Initialize the module data serial port

WitInit(WIT_PROTOCOL_NORMAL, 0x50);//Initialize the standard protocol, set the device address

WitSerialWriteRegister(SensorUartSend);//Register write callback function

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

AutoScanSensor();//Automatically search for sensors

Receive sensor 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. If the module automatically lasts data, the status data update will read the data returned by the sensor, and the final effect is to read the data of the module's 3D acceleration, 3D angular velocity, 3D angle, and 3D magnetic field into the specified index array. Finally print it out.

The following is the print data when the data update is detected.

Set 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 9600 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.

Accelerometer Calibration

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

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.


For other operations, please refer to the sensor manual

Last updated