ESP32_SDK Quick Start
Last updated
Last updated
Please check the below link.
This routine introduces how to use the ESP32 platform IIC protocol, taking JY901S as an example, and then directly print data through the serial port of the ESP development board, 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
First prepare Witte smart standard sensor, here take JY901S as an example, and the wiring method of ESP32 development board:
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
i2c_master_init();//Initialize the print data serial port
WitInit(WIT_PROTOCOL_I2C, 0x50);//Initialize the IIC protocol and set the device address
WitI2cFuncRegister(WitIICWrite, WitIICRead);//Register IIC read and write callback functions
WitRegisterCallBack(SensorDataUpdata);//Register to get the sensor data callback function
AutoScanSensor();//Automatically search for sensors
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 3-axis acceleration, 3-axis angular velocity, 3-axis angle, and 3-axis magnetic field into the specified index array. Finally print it out. In addition, IIC needs to actively read sensor data, so it needs to access the module at intervals.
WitReadReg(AX, 12); //Interval read sensor data
The parameters of the module can be set through the function CmdProcess(); Such as acceleration calibration, magnetic field calibration and modifying baud rate, etc.
Some common API function interfaces are defined in the file wit_c_sdk.c, which only needs to be called.
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 datasheet