blimputils.accelerometer
accelerometer.py
Module for the Bosch-Sensortec BMI270 accelerometer sensor. This file provides the class BMI270 for interacting with the accelerometer functionality of the BMI270 sensor via I2C.
- class blimputils.accelerometer.Accelerometer(i2c_addr=104)
Bases:
object
Bosch BMI270 sensor class for accelerometer and gyroscope data.
Provides methods to initialize, configure, and read data from the BMI270 sensor using I2C communication.
- Parameters:
i2c_addr (int, optional) – The I2C address of the BMI270 sensor. Defaults to
I2C_PRIM_ADDR
.- Raises:
RuntimeError – If the I2C bus is not found.
- read_register(register_address) int
Read a byte from the specified register address.
- Parameters:
register_address (int) – The address of the register to read from.
- Returns:
The byte value read from the register.
- Return type:
int
- write_register(register_address, byte_data) None
Write a byte to the specified register address.
- Parameters:
register_address (int) – The address of the register to write to.
byte_data (int) – The byte value to write to the register.
- load_config_file() None
Load the configuration file to the BMI270 sensor.
This initializes the sensor. If already initialized, it prints a message. Otherwise, it performs the initialization sequence.
- set_mode(mode='performance') None
Set the power mode of the BMI270 sensor.
Configures accelerometer and gyroscope for different power modes.
- Parameters:
mode (str, optional) – The desired power mode. Defaults to “performance”.
- Options mode:
"low_power"
: Low power mode."normal"
: Normal mode."performance"
: Performance mode.
- print_read_register(register_address, output_format='bin') None
Read and print the value of a register in binary or hexadecimal format.
- Parameters:
register_address (int) – The address of the register to read.
output_format (str, optional) – The format for printing the register value. Defaults to
BINARY
.
- Options output_format:
BINARY
: Print in binary format.HEXADECIMAL
: Print in hexadecimal format.
- print_write_register(register_address, byte_data, output_format='bin') None
Write to a register and print its value before and after the write.
- Parameters:
register_address (int) – The address of the register to write to.
byte_data (int) – The byte value to write.
output_format (str, optional) – The format for printing the register value. Defaults to
BINARY
.
- Options output_format:
BINARY
: Print in binary format.HEXADECIMAL
: Print in hexadecimal format.
- enable_aux() None
Enable the auxiliary sensor interface (AUX_IF).
- disable_aux() None
Disable the auxiliary sensor interface (AUX_IF).
- enable_acc() None
Enable the accelerometer.
- disable_acc() None
Disable the accelerometer.
- enable_temp() None
Enable the temperature sensor.
- disable_temp() None
Disable the temperature sensor.
- enable_fifo_header() None
Enable the FIFO header.
- disable_fifo_header() None
Disable the FIFO header.
Note: ODR of all enabled sensors needs to be identical when FIFO header is disabled.
- enable_data_streaming() None
Enable data streaming mode.
In this mode, data will not be stored in FIFO.
- disable_data_streaming() None
Disable data streaming mode.
In this mode, data will be stored in FIFO.
- enable_acc_filter_perf() None
Enable accelerometer filter performance (performance optimized).
- disable_acc_filter_perf() None
Disable accelerometer filter performance (power optimized).
- set_acc_range(range=0) None
Set the accelerometer measurement range.
- Parameters:
range (int, optional) – The desired accelerometer range. Defaults to
ACC_RANGE_2G
.- Options range:
ACC_RANGE_2G
: ±2gACC_RANGE_4G
: ±4gACC_RANGE_8G
: ±8gACC_RANGE_16G
: ±16g
- set_gyr_range(range=0) None
Set the gyroscope measurement range.
- Parameters:
range (int, optional) – The desired gyroscope range. Defaults to
GYR_RANGE_2000
.- Options range:
GYR_RANGE_2000
: ±2000 dps (degrees per second)GYR_RANGE_1000
: ±1000 dpsGYR_RANGE_500
: ±500 dpsGYR_RANGE_250
: ±250 dpsGYR_RANGE_125
: ±125 dps
- set_acc_odr(odr=9) None
Set the accelerometer Output Data Rate (ODR).
- Parameters:
odr (int, optional) – The desired accelerometer ODR. Defaults to
ACC_ODR_200
(200 Hz).- Options odr:
ACC_ODR_1600
: 1600 HzACC_ODR_800
: 800 HzACC_ODR_400
: 400 HzACC_ODR_200
: 200 HzACC_ODR_100
: 100 HzACC_ODR_50
: 50 HzACC_ODR_25
: 25 Hz
- set_acc_bwp(bwp=2) None
Set the accelerometer Bandwidth Parameter (BWP).
- Parameters:
bwp (int, optional) – The desired accelerometer BWP. Defaults to
ACC_BWP_NORMAL
.- Options bwp:
ACC_BWP_OSR4
: OSR4 filterACC_BWP_OSR2
: OSR2 filterACC_BWP_NORMAL
: Normal filterACC_BWP_CIC
: CIC filterACC_BWP_RES16
: ReservedACC_BWP_RES32
: ReservedACC_BWP_RES64
: ReservedACC_BWP_RES128
: Reserved
- get_sensor_time() int
Get the sensor’s internal timestamp.
- Returns:
The 24-bit sensor timestamp.
- Return type:
int
- get_raw_acc_data() ndarray
Get raw accelerometer data (X, Y, Z).
Reads LSB and MSB for each axis and combines them.
- Returns:
A NumPy array containing raw [X, Y, Z] accelerometer values as int16.
- Return type:
np.ndarray
- get_raw_temp_data() int
Get raw temperature data from the sensor.
Reads LSB and MSB for temperature and converts to a signed 16-bit integer.
- Returns:
The raw temperature value as a signed 16-bit integer.
- Return type:
int
- get_xyz() ndarray
Get calibrated accelerometer data (X, Y, Z) in m/s².
Reads raw accelerometer data and converts it to physical units (m/s²) based on the current accelerometer range.
- Returns:
A NumPy array containing calibrated [X, Y, Z] acceleration in m/s².
- Return type:
np.ndarray
- get_x() float
Get the calibrated accelerometer data for the X-axis in m/s².
- Returns:
The X-axis acceleration in m/s².
- Return type:
float
- get_y() float
Get the calibrated accelerometer data for the Y-axis in m/s².
- Returns:
The Y-axis acceleration in m/s².
- Return type:
float
- get_z() float
Get the calibrated accelerometer data for the Z-axis in m/s².
- Returns:
The Z-axis acceleration in m/s².
- Return type:
float
- get_t() float
Get the temperature in degrees Celsius.
Reads raw temperature data and converts it to °C using a fixed formula.
- Returns:
The temperature in degrees Celsius.
- Return type:
float