Python_SDK Quick Start

Python_SDK quick start

Applicable Model

WT61

WT61P

WT901

WT901B

WT931

Routine download

Links to download sample programs

https://github.com/WITMOTION/WitStandardProtocol_JY901

Noun introduction

Wit-motion private protocol: Wit-motion protocol for short, is the protocol used by Wit-motion sensors, usually TTL or 232 level sensors use Wit-motion protocol; the protocol stipulates that the sensor returns data packets starting with 55, each packet The size is fixed at 11 bytes, and the host computer sends data packets beginning with FF AA;

Protocol description

Register read and write operation instructions:

Read command: 0xff + 0xaa +0x27 + register (2 bytes), a total of 5 bytes, the returned data starts with 0x55 + 0x5f, the middle is data, and the last byte is checksum.

WIT command: 0xff + 0xaa + register (1 byte) + value (2 bytes), a total of 5 bytes

Routine introduction

This routine introduces how to use Python to develop a host computer to connect to a Wit-motion protocol sensor, 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

Routine directory

The figure below is the routine directory, and the arrows indicate the files that need to be referenced

Initialize the device

Open the JY901S.py file and import the file in the above picture as shown in the figure:

In if __name__ == '__main__': The device model is initialized here, and the protocol and data processing method used are specified. And the callback method when the sensor data is updated, as shown in the figure:

DeviceModel (device model): DeviceModel object, representing the sensor in the program, can interact with the sensor data, this object will automatically solve the sensor data, how to obtain the sensor data through the DeviceModel object will be introduced later

turn on the device

Open the device and directly call the openDevice() method of the device model, as shown in the figure

turn off the device

Close the device and directly call the closeDevice() method of the device model, as shown in the figure

Receive sensor data

Since the device model settles the sensor data, we only need to get the data in the onUpdate method, as shown in the figure below:

Record data

Call the startRecord() method in the current file to start recording, then get the data in the onUpdate method according to the write flag, and write it to the file

Finally, call the endRecord() method to end the record and close the file. As shown below:

Read sensor configuration

After opening the device, you can call the readConfig(device) method to obtain the configuration information, as shown below:

To read the configuration information of a register, the function readConfig(regAddr,regCount) of the device model can be called,

The first parameter regAddr of this function: the starting register address; the second parameter regCount: the number of registers (note that it must be consecutive register addresses). As shown above: 0x02=data content; 0x03=return rate; 0x04=communication rate. So calling device.readReg(0x02,3) returns the corresponding value as shown below:

For other configuration information, please refer to the sensor manual

Set sensor configuration

After opening the device, you can call the setConfig(device) method to set the configuration information, as shown below:

To set the value of a register, call the writeReg(regAddr,sValue) method of the device model. This method has two parameters: the first parameter: register address; the second parameter: the written value.

Calling steps: unlock -> write register -> save

Note: When writing multiple registers, there must be a certain interval (usually 50~100 milliseconds)

Please refer to the sensor manual for setting other configuration information

Acceleration Calibration

After opening the device, you can call the AccelerationCalibration() method of the device model to perform accelerative calibration, as shown in the figure below:

It takes more than 5 seconds to execute this method

Magnetic Field Calibration

After turning on the device, magnetic field calibration requires three steps:

1. You can call the BeginFiledCalibration() method of the device model to start calibration

2. Please rotate slowly around the XYZ axis respectively

3. Call the EndFiledCalibration() method of the device model to end the calibration, as shown in the figure below:

Precautions

💡 If the serial port number and volatility set by the user are incorrect, the sample program will not be able to receive data normally!

Last updated