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
BMI160
class. First you will need to import the libraries to use the sensorfrom machine import Pin, I2C from micropython_bmi160 import bmi160
Once this is done you can define your
machine.I2C
object 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_SUSPEND
0x10
bmi160.ACC_POWER_NORMAL
0x11
bmi160.POWER_LOWPOWER
0x12
- property acceleration_bandwidth_parameter : str¶
Determines filter configuration (acc_us=0) and averaging for undersampling mode (acc_us=1).
Mode
Value
bmi160.FILTER
0
bmi160.AVERAGING
1
- 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_32
0b0001
25/32 Hzbmi160.BANDWIDTH_25_16
0b0010
25/16 Hzbmi160.BANDWIDTH_25_8
0b0011
25/8 Hzbmi160.BANDWIDTH_25_4
0b0100
25/4 Hzbmi160.BANDWIDTH_25_2
0b0101
25/2 Hzbmi160.BANDWIDTH_25
0b0110
25 Hzbmi160.BANDWIDTH_50
0b0111
50 Hzbmi160.BANDWIDTH_100
0b1000
100 Hzbmi160.BANDWIDTH_200
0b1001
200 Hzbmi160.BANDWIDTH_400
0b1010
400 Hzbmi160.BANDWIDTH_800
0b1011
800 Hzbmi160.BANDWIDTH_1600
0b1100
1600 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_2G
0b0011
bmi160.ACCEL_RANGE_4G
0b0101
bmi160.ACCEL_RANGE_8G
0b1000
bmi160.ACCEL_RANGE_16G
0b1100
- 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_UNDERSAMPLE
0
bmi160.UNDERSAMPLE
1
- 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_NORMAL
0b10
bmi160.GYRO_OSR2
0b01
bmi160.GYRO_OSR4
0b00
- 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_25
0b0110
25 Hzbmi160.BANDWIDTH_50
0b0111
50 Hzbmi160.BANDWIDTH_100
0b1000
100 Hzbmi160.BANDWIDTH_200
0b1001
200 Hzbmi160.BANDWIDTH_400
0b1010
400 Hzbmi160.BANDWIDTH_800
0b1011
800 Hzbmi160.BANDWIDTH_1600
0b1100
1600 Hzbmi160.BANDWIDTH_3200
0b1101
3200 Hz
- property gyro_power_mode : str¶
Mode
Value
bmi160.GYRO_POWER_SUSPEND
0x14
bmi160.GYRO_POWER_NORMAL
0x15
bmi160.GYRO_POWER_FASTSTARTUP
0x17
- 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_2000
0b000
bmi160.GYRO_RANGE_1000
0b001
bmi160.GYRO_RANGE_500
0b010
bmi160.GYRO_RANGE_250
0b011
bmi160.GYRO_RANGE_125
0b100
- 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