title | update | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
MaixPy qmi8658 Driver Instructions |
|
QMI8658 is an Inertial Measurement Unit (IMU) chip that integrates a three-axis gyroscope and a three-axis accelerometer. It provides high-precision attitude, motion, and position data, making it suitable for various applications requiring accurate motion detection, such as drones, robots, game controllers, and virtual reality devices. QMI8658 features low power consumption, high stability, and high sensitivity.
Using QMI8658 in MaixPy is straightforward; you only need to know which I2C bus your platform's QMI8658 is mounted on. The onboard QMI8658 on the MaixCAM Pro is mounted on I2C-4.
Example:
from maix import ext_dev, pinmap, err, time
### Enable I2C
# ret = pinmap.set_pin_function("PIN_NAME", "I2Cx_SCL")
# if ret != err.Err.ERR_NONE:
# print("Failed in function pinmap...")
# exit(-1)
# ret = pinmap.set_pin_function("PIN_NAME", "I2Cx_SDA")
# if ret != err.Err.ERR_NONE:
# print("Failed in function pinmap...")
# exit(-1)
QMI8658_I2CBUS_NUM = 4
imu = ext_dev.qmi8658.QMI8658(QMI8658_I2CBUS_NUM,
mode=ext_dev.imu.Mode.DUAL,
acc_scale=ext_dev.imu.AccScale.ACC_SCALE_2G,
acc_odr=ext_dev.imu.AccOdr.ACC_ODR_8000,
gyro_scale=ext_dev.imu.GyroScale.GYRO_SCALE_16DPS,
gyro_odr=ext_dev.imu.GyroOdr.GYRO_ODR_8000)
while True:
data = imu.read()
print("\n-------------------")
print(f"acc x: {data[0]}")
print(f"acc y: {data[1]}")
print(f"acc z: {data[2]}")
print(f"gyro x: {data[3]}")
print(f"gyro y: {data[4]}")
print(f"gyro z: {data[5]}")
print(f"temp: {data[6]}")
print("-------------------\n")
Initialize the QMI8658 object according to your needs, and then call read()
to get the raw data read from the QMI8658.
If the mode
parameter is set to DUAL
, the data returned by read()
will be [acc_x, acc_y, acc_z, gyro_x, gyro_y, gyro_z, temp]
. If mode
is set to only one of ACC or GYRO, it will return only the corresponding [x, y, z, temp]
. For example, if ACC is selected, read()
will return [acc_x, acc_y, acc_z, temp]
.
For detailed information on the QMI8658 API, please refer to the QMI8658 API Documentation