MicroPython BMI160 Library¶
bmi160¶
MicroPython Driver for the Bosch BMI160 Acc/Gyro Sensor
Author(s): Jose D. Montoya
-
class micropython_bmi160.bmi160.BMI160(i2c, address: int =
0x69)[source]¶ Driver for the BMI160 Sensor connected over I2C.
- Parameters:¶
- Raises:¶
RuntimeError – if the sensor is not found
Quickstart: Importing and using the device
Here is an example of using the
BMI160class. First you will need to import the libraries to use the sensorfrom machine import Pin, I2C from micropython_bmi160 import bmi160Once this is done you can define your
machine.I2Cobject and define your sensor objecti2c = I2C(1, sda=Pin(2), scl=Pin(3)) bmi160 = bmi160.BMI160(i2c)Now you have access to the attributes
accx, accy, accz = bmi.acceleration gyrox, gyroy, gyroz = bmi.gyro- acc_power_mode(value: int) None[source]¶
Mode
Value
bmi160.ACC_POWER_SUSPEND0x10bmi160.ACC_POWER_NORMAL0x11bmi160.POWER_LOWPOWER0x12
- property acceleration_bandwidth_parameter : str¶
Determines filter configuration (acc_us=0) and averaging for undersampling mode (acc_us=1).
Mode
Value
bmi160.FILTER0bmi160.AVERAGING1
- property acceleration_output_data_rate : str¶
Define the output data rate in Hz is given by \(100/2^(8-accodr)\) The output data rate is independent of the power mode setting for the sensor
Configurations without a bandwidth number are illegal settings and will result in an error code in the Register (0x02) ERR_REG.
At startup this is setup at 100 Hz
Mode
Value
bmi160.BANDWIDTH_25_320b000125/32 Hzbmi160.BANDWIDTH_25_160b001025/16 Hzbmi160.BANDWIDTH_25_80b001125/8 Hzbmi160.BANDWIDTH_25_40b010025/4 Hzbmi160.BANDWIDTH_25_20b010125/2 Hzbmi160.BANDWIDTH_250b011025 Hzbmi160.BANDWIDTH_500b011150 Hzbmi160.BANDWIDTH_1000b1000100 Hzbmi160.BANDWIDTH_2000b1001200 Hzbmi160.BANDWIDTH_4000b1010400 Hzbmi160.BANDWIDTH_8000b1011800 Hzbmi160.BANDWIDTH_16000b11001600 Hz
- property acceleration_range : str¶
The register allows the selection of the accelerometer g-range. Changing the range of the accelerometer does not clear the data ready bit in the Register (0x1B) STATUS. It is recommended to read the Register (0x04-0x17) DATA after the range change to remove a stall data ready bit from before the range change.
Mode
Value
bmi160.ACCEL_RANGE_2G0b0011bmi160.ACCEL_RANGE_4G0b0101bmi160.ACCEL_RANGE_8G0b1000bmi160.ACCEL_RANGE_16G0b1100
- property acceleration_undersample : str¶
The undersampling parameter is typically used in low power mode. When acc_us is set to ‘0’ and the accelerometer is in low-power mode, it will change to normal mode. If the acc_us is set to ‘0’ and a command to enter low-power mode is sent to the Register (0x7E) CMD, this command is ignored.
Mode
Value
bmi160.NO_UNDERSAMPLE0bmi160.UNDERSAMPLE1
- error_code() None[source]¶
The register is meant for debug purposes, not for regular verification if an operation completed successfully.
Fatal Error: Error during bootup. Broken hardware(e.g.NVM error, see ASIC spec for details).This flag will not be cleared after reading the register.The only way to clear the flag is a POR.
Error flags (bits 7:4) store error event until they are reset by reading the register.
- property gyro_bandwidth_parameter : str¶
- The gyroscope bandwidth coefficient defines the 3 dB cutoff frequency
of the low pass filter for the sensor data.
When the filter mode is set to normal (gyr_bwp=0b10), the gyroscope data is sampled at equidistant points in the time, defined by the gyroscope output data rate parameter (gyr_odr). The output data rate can be configured in one of eight different valid ODR configurations going from 25Hz up to 3200Hz.
When the filter mode is set to OSR2 (gyr_bwp=0b01), both stages of the digital filter are used and the data is oversampled with an oversampling rate of 2. That means that for a certain filter configuration, the ODR has to be 2 times higher than in the normal filter mode. Conversely, for a certain filter configuration, the filter bandwidth will be the approximately half of the bandwidth achieved for the same ODR in the normal filter mode. For example, for ODR=50Hz we will have a 3dB cutoff frequency of 10.12Hz.
When the filter mode is set to OSR4 (gyr_bwp=0b000), both stages of the digital filter are used and the data is oversampled with an oversampling rate of 4. That means that for a certain filter configuration, the ODR has to be 4 times higher than in the normal filter mode. Conversely, for a certain filter configuration, the filter bandwidth will be approximately 4 times smaller than the bandwidth achieved for the same ODR in the normal filter mode. For example, for ODR=50Hz we will have a 3dB cutoff frequency of 5.06Hz.
Mode
Value
bmi160.GYRO_NORMAL0b10bmi160.GYRO_OSR20b01bmi160.GYRO_OSR40b00
- property gyro_output_data_rate : str¶
Define the output data rate in Hz is given by \(100/2^(8-gyroodr)\) The output data rate is independent of the power mode setting for the sensor
Configurations without a bandwidth number are illegal settings and will result in an error code in the Register (0x02) ERR_REG.
Warning
Lower ODR values than 25Hz are not allowed. If they are used they result in an error code in Register (0x02) ERR_REG.
At startup this is setup at 100 Hz
Mode
Value
bmi160.BANDWIDTH_250b011025 Hzbmi160.BANDWIDTH_500b011150 Hzbmi160.BANDWIDTH_1000b1000100 Hzbmi160.BANDWIDTH_2000b1001200 Hzbmi160.BANDWIDTH_4000b1010400 Hzbmi160.BANDWIDTH_8000b1011800 Hzbmi160.BANDWIDTH_16000b11001600 Hzbmi160.BANDWIDTH_32000b11013200 Hz
- property gyro_power_mode : str¶
Mode
Value
bmi160.GYRO_POWER_SUSPEND0x14bmi160.GYRO_POWER_NORMAL0x15bmi160.GYRO_POWER_FASTSTARTUP0x17
- property gyro_range : str¶
The register allows the selection of the gyro g-range. Changing the range of the accelerometer does not clear the data ready bit in the Register (0x1B) STATUS. It is recommended to read the Register (0x04-0x17) DATA after the range change to remove a stall data ready bit from before the range change.
Mode
Value
bmi160.GYRO_RANGE_20000b000bmi160.GYRO_RANGE_10000b001bmi160.GYRO_RANGE_5000b010bmi160.GYRO_RANGE_2500b011bmi160.GYRO_RANGE_1250b100
- property temperature : int¶
The temperature is disabled when all sensors are in suspend mode. The output word of the 16-bit temperature sensor is valid if the gyroscope is in normal mode, i.e. gyr_pmu_status=0b01. The resolution is typically \(1/2^9\) K/LSB.
If the gyroscope is in normal mode (see Register (0x03) PMU_STATUS), the temperature is updated every 10 ms (+-12%). If the gyroscope is in suspend mode or fast-power up mode, the temperature is updated every 1.28 s aligned :return: int