Modules
blimp-utils - A Python library for the Falcon Flight embedded controller board.
- class blimputils.Accelerometer(i2c_addr=104)
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.
- disable_acc() None
Disable the accelerometer.
- disable_acc_filter_perf() None
Disable accelerometer filter performance (power optimized).
- disable_aux() None
Disable the auxiliary sensor interface (AUX_IF).
- disable_data_streaming() None
Disable data streaming mode.
In this mode, data will be stored in FIFO.
- disable_fifo_header() None
Disable the FIFO header.
Note: ODR of all enabled sensors needs to be identical when FIFO header is disabled.
- disable_temp() None
Disable the temperature sensor.
- enable_acc() None
Enable the accelerometer.
- enable_acc_filter_perf() None
Enable accelerometer filter performance (performance optimized).
- enable_aux() None
Enable the auxiliary sensor interface (AUX_IF).
- enable_data_streaming() None
Enable data streaming mode.
In this mode, data will not be stored in FIFO.
- enable_fifo_header() None
Enable the FIFO header.
- enable_temp() None
Enable the temperature sensor.
- 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_sensor_time() int
Get the sensor’s internal timestamp.
- Returns:
The 24-bit sensor timestamp.
- Return type:
int
- 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
- 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_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_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
- 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.
- 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.
- 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
- 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
- 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_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_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.
- 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.
- class blimputils.Gyroscope(i2c_addr=104)
Bosch BMI270 sensor class for gyroscope data.
Provides methods to initialize, configure, and read data from the BMI270 sensor’s gyroscope 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.
- disable_aux() None
Disable the auxiliary sensor interface (AUX_IF).
- disable_data_streaming() None
Disable data streaming mode.
In this mode, data will be stored in FIFO.
- disable_fifo_header() None
Disable the FIFO header.
Note: ODR of all enabled sensors needs to be identical when FIFO header is disabled.
- disable_gyr() None
Disable the gyroscope.
- disable_gyr_filter_perf() None
Disable gyroscope filter performance (power optimized).
- disable_gyr_noise_perf() None
Disable gyroscope noise performance (power optimized).
- disable_temp() None
Disable the temperature sensor.
- enable_aux() None
Enable the auxiliary sensor interface (AUX_IF).
- enable_data_streaming() None
Enable data streaming mode.
In this mode, data will not be stored in FIFO.
- enable_fifo_header() None
Enable the FIFO header.
- enable_gyr() None
Enable the gyroscope.
- enable_gyr_filter_perf() None
Enable gyroscope filter performance (performance optimized).
- enable_gyr_noise_perf() None
Enable gyroscope noise performance (performance optimized).
- enable_temp() None
Enable the temperature sensor.
- get_raw_gyr_data() ndarray
Get raw gyroscope data (X, Y, Z).
Reads LSB and MSB for each axis and combines them.
- Returns:
A NumPy array containing raw [X, Y, Z] gyroscope 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_sensor_time() int
Get the sensor’s internal timestamp.
- Returns:
The 24-bit sensor timestamp.
- Return type:
int
- 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
- get_x() float
Get the calibrated gyroscope data for the X-axis in rad/s.
- Returns:
The X-axis angular velocity in rad/s.
- Return type:
float
- get_xyz() ndarray
Get calibrated gyroscope data (X, Y, Z) in rad/s.
Reads raw gyroscope data and converts it to physical units (rad/s) based on the current gyroscope range.
- Returns:
A NumPy array containing calibrated [X, Y, Z] angular velocity in rad/s.
- Return type:
np.ndarray
- get_y() float
Get the calibrated gyroscope data for the Y-axis in rad/s.
- Returns:
The Y-axis angular velocity in rad/s.
- Return type:
float
- get_z() float
Get the calibrated gyroscope data for the Z-axis in rad/s.
- Returns:
The Z-axis angular velocity in rad/s.
- Return type:
float
- 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.
- 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.
- 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
- set_gyr_bwp(bwp=2) None
Set the gyroscope Bandwidth Parameter (BWP).
- Parameters:
bwp (int, optional) – The desired gyroscope BWP. Defaults to
GYR_BWP_NORMAL
.- Options bwp:
GYR_BWP_OSR4
: OSR4 filterGYR_BWP_OSR2
: OSR2 filterGYR_BWP_NORMAL
: Normal filter
- set_gyr_odr(odr=9) None
Set the gyroscope Output Data Rate (ODR).
- Parameters:
odr (int, optional) – The desired gyroscope ODR. Defaults to
GYR_ODR_200
(200 Hz).- Options odr:
GYR_ODR_3200
: 3200 HzGYR_ODR_1600
: 1600 HzGYR_ODR_800
: 800 HzGYR_ODR_400
: 400 HzGYR_ODR_200
: 200 HzGYR_ODR_100
: 100 HzGYR_ODR_50
: 50 HzGYR_ODR_25
: 25 Hz
- 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_mode(mode='performance') None
Set the power mode of the BMI270 sensor.
Configures accelerometer and gyroscope for different power modes. This method primarily affects gyroscope settings relevant to this class.
- Parameters:
mode (str, optional) – The desired power mode. Defaults to “performance”.
- Options mode:
"low_power"
: Low power mode."normal"
: Normal mode."performance"
: Performance mode.
- 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.
- class blimputils.Magnetometer(bus=1, addr=20, retry_init=True, max_retries=10, retry_delay=1.0)
Bosch BMM350 Magnetometer sensor class.
Provides methods to initialize, configure, and read data from the BMM350 sensor using I2C communication. This class handles low-level register interactions, OTP data loading, power mode management, and data compensation.
- Parameters:
bus (int) – The I2C bus number (e.g., 1 for Raspberry Pi’s /dev/i2c-1).
addr (int) – The I2C address of the BMM350 sensor. Defaults to
BMM350_I2C_ADDRESS_PRIMARY
if not provided, but typically specified during instantiation.
- BMM350_GET_BITS(reg_data, mask, pos)
Get specific bits from a register value.
- Parameters:
reg_data (int) – The register value.
mask (int) – The mask for the bits to be retrieved.
pos (int) – The starting position of the bits.
- Returns:
The value of the specified bits.
- Return type:
int
- BMM350_GET_BITS_POS_0(reg_data, mask)
Get specific bits from a register value, assuming bit position 0.
- Parameters:
reg_data (int) – The register value.
mask (int) – The mask for the bits to be retrieved.
- Returns:
The value of the specified bits.
- Return type:
int
- BMM350_SET_BITS(reg_data, bitname_msk, bitname_pos, data)
Set specific bits in a register value.
- Parameters:
reg_data (int) – The original register value.
bitname_msk (int) – The mask for the bits to be set.
bitname_pos (int) – The starting position of the bits.
data (int) – The data to write to the specified bits.
- Returns:
The modified register value.
- Return type:
int
- BMM350_SET_BITS_POS_0(reg_data, mask, data)
Set specific bits in a register value, assuming bit position 0.
- Parameters:
reg_data (int) – The original register value.
mask (int) – The mask for the bits to be set.
data (int) – The data to write to the specified bits.
- Returns:
The modified register value.
- Return type:
int
- bmm350_magnetic_reset_and_wait()
Perform a magnetic reset sequence and wait for completion.
This sequence involves transitioning to suspend mode, issuing magnetic reset commands (BR and FGR), and then optionally restoring the previous normal mode if it was active.
- bmm350_set_powermode(powermode)
Set the power mode of the BMM350 sensor.
Transitions the sensor to the specified power mode (Suspend, Normal, Forced, Forced Fast). Includes necessary delays for mode transitions.
- Parameters:
powermode (int) – The desired power mode.
- Options powermode:
BMM350_SUSPEND_MODE
BMM350_NORMAL_MODE
BMM350_FORCED_MODE
BMM350_FORCED_MODE_FAST
- fix_sign(inval, number_of_bits)
Convert raw data from IC data registers to a signed integer.
This internal API handles the conversion of unsigned ADC values to signed integer representations based on the number of bits.
- Parameters:
inval (int) – The input unsigned integer value.
number_of_bits (int) – The number of bits representing the signed integer.
- Options number_of_bits:
BMM350_SIGNED_8_BIT
BMM350_SIGNED_12_BIT
BMM350_SIGNED_16_BIT
BMM350_SIGNED_21_BIT
BMM350_SIGNED_24_BIT
- Returns:
The signed integer value.
- Return type:
int
- get_chip_id()
Read the chip ID from the BMM350 sensor.
- Returns:
The chip ID value.
- Return type:
int
- get_compass_degree()
Get compass degree (yaw/heading) assuming the sensor’s XY plane is horizontal.
Calculates the yaw angle based on the calibrated X and Y geomagnetic components. The angle is measured counter-clockwise from the sensor’s positive X-axis to the projection of the magnetic field vector in the XY plane.
Note
This calculation is not tilt-compensated; To derive True North heading, apply your real-world declination constant post-function call.
Warning
This function is still in development, due to the complexity associated with hard-iron, soft-iron, and tilt compensation calibration.
- Returns:
Compass degree (0.0 to 360.0 degrees). Returns
BMM350_FLOAT_DATA_ERROR
(e.g., float(‘nan’)) if magnetometer data is invalid.- Return type:
float
- get_data_ready_state()
Get the data ready status from the interrupt status register.
Checks if the DRDY (Data Ready) bit is set, indicating new data is available.
- Returns:
True
if data is ready,False
otherwise.- Return type:
bool
- get_measurement_state_XYZ()
Get the current enable status for X, Y, and Z axes measurements.
- Returns:
A string describing the enable status of each axis.
- Return type:
str
- Options:
“x-axis enabled, y-axis enabled, z-axis enabled.”
“x-axis disabled, y-axis disabled, z-axis disabled.”
- get_operation_mode()
Get the current sensor operation mode.
- Returns:
A string describing the current operation mode.
- Return type:
str
- Options:
“bmm350 is suspend mode!”: Sensor is in suspend mode.
“bmm350 is normal mode!”: Sensor is in normal mode.
“bmm350 is forced mode!”: Sensor is in forced mode.
“bmm350 is forced_fast mode!”: Sensor is in forced-fast mode.
“error mode!”: Unknown or error in power mode status.
- get_rate()
Get the configured data output rate (ODR).
- Returns:
The current ODR in Hertz (Hz).
- Return type:
float
- get_raw_magnetic_data_for_calibration()
Get raw X, Y, Z magnetic data before OTP and software compensations.
This method reads the raw 24-bit ADC values for the X, Y, and Z magnetic axes. It is intended for use during sensor calibration procedures to collect uncompensated data.
- Returns:
A list containing the raw signed integer values for [X, Y, Z]. Returns
None
if the read operation fails or returns insufficient data.- Return type:
list[int] or None
- get_t()
Get the sensor temperature.
This is a convenience method that calls get_xyz (which also calculates temperature) and returns the temperature.
- Returns:
Sensor temperature in degrees Celsius (°C). Returns
BMM350_FLOAT_DATA_ERROR
if data retrieval fails.- Return type:
float
- get_threshold_data()
Get the data that caused a threshold interrupt.
If a threshold interrupt has occurred (checked via get_data_ready_state), this method returns the geomagnetic data components (X, Y, Z) that crossed the configured threshold.
- Returns:
A list of three elements. Each element is the magnetic data for an axis (X, Y, Z) if it triggered the interrupt, otherwise it’s
NO_DATA
. Example: [mag_x, NO_DATA, mag_z] if X and Z triggered the interrupt.- Return type:
list[float or int]
- get_x()
Get the calibrated X-axis geomagnetic data.
This is a convenience method that calls get_xyz and returns only the X component.
- Returns:
Calibrated X-axis magnetic field strength in microTeslas (µT). Returns
BMM350_FLOAT_DATA_ERROR
if data retrieval fails.- Return type:
float
- get_xyz()
Get calibrated geomagnetic data (X, Y, Z) in microTeslas (µT) and update sensor temperature.
This method performs the following steps:
Reads raw 24-bit data for X, Y, Z magnetic axes and temperature.
Applies sign correction to the raw data.
Stores raw LSB values in _raw_mag_data.
Applies user-defined hard iron calibration offsets (_CALIBRATION_HARD_IRON).
Applies user-defined soft iron calibration transformation (_CALIBRATION_SOFT_IRON_TRANSFORM).
Scales the corrected vector to physical units (µT) using _LOCAL_EARTH_FIELD_UT.
Stores the final calibrated X, Y, Z values in _mag_data.
Calculates and updates the sensor temperature in _mag_data.temperature using OTP compensation values.
- return:
List containing calibrated [X_µT, Y_µT, Z_µT]. Returns a list of
BMM350_FLOAT_DATA_ERROR
(e.g., float(‘nan’)) for each component on failure to read sensor data.- rtype:
list[float]
- get_y()
Get the calibrated Y-axis geomagnetic data.
This is a convenience method that calls get_xyz and returns only the Y component.
- Returns:
Calibrated Y-axis magnetic field strength in microTeslas (µT). Returns
BMM350_FLOAT_DATA_ERROR
if data retrieval fails.- Return type:
float
- get_z()
Get the calibrated Z-axis geomagnetic data.
This is a convenience method that calls get_xyz and returns only the Z component.
- Returns:
Calibrated Z-axis magnetic field strength in microTeslas (µT). Returns
BMM350_FLOAT_DATA_ERROR
if data retrieval fails.- Return type:
float
- is_raspberrypi()
Check if the current platform is a Raspberry Pi.
- Returns:
True
if a Raspberry Pi is detected,False
otherwise.- Return type:
bool
- read_reg(reg, len)
Reads a specified number of bytes from a register.
Handles I2C communication, including dummy bytes if required by the BMM350 protocol. Retries on exception.
- Parameters:
reg (int) – The register address to read from.
len (int) – The number of bytes to read (excluding dummy bytes).
- Returns:
A list of bytes read from the register.
- Return type:
list[int]
- self_test()
Perform a sensor self-test by checking enabled axes.
This method reads the axis enable register and reports which axes (X, Y, Z) are currently enabled for measurement. It does not perform a full functional self-test of the sensor hardware.
- Returns:
A string indicating the self-test result based on enabled axes.
- Return type:
str
- Options:
“x y z aix test success”: If X, Y, and Z axes are enabled.
“<axes> aix test success”: If a subset of axes are enabled (e.g., “x y “).
“xyz aix self test fail”: If no axes are enabled.
- sensor_init()
Initialize the BMM350 sensor.
Performs a software reset, verifies the chip ID, downloads OTP compensation data, updates internal compensation parameters, and performs a magnetic reset.
- Returns:
Status of the initialization.
- Return type:
int
- Options:
BMM350_OK
: Initialization successful.BMM350_CHIP_ID_ERROR
: Chip ID mismatch, initialization failed.
- set_data_ready_pin(modes, polarity)
Configure the Data Ready (DRDY) interrupt pin.
Enables or disables the DRDY interrupt and sets its polarity. When enabled, the DRDY pin signals when new data is available.
- Parameters:
modes (int) – Enable or disable the DRDY interrupt.
polarity (int) – Polarity of the DRDY interrupt pin.
- Options modes:
BMM350_ENABLE_INTERRUPT
: Enable DRDY interrupt.BMM350_DISABLE_INTERRUPT
: Disable DRDY interrupt.
- Options polarity:
BMM350_ACTIVE_HIGH
: Active high polarity. Pin goes high on interrupt.BMM350_ACTIVE_LOW
: Active low polarity. Pin goes low on interrupt.
- set_measurement_XYZ(en_x=1, en_y=1, en_z=1)
Enable or disable measurements for X, Y, and Z axes.
Allows individual control over which magnetic axes are active. Disabling an axis will result in invalid data for that axis.
- Parameters:
en_x (int, optional) – Enable state for the X-axis. Defaults to
BMM350_X_EN
.en_y (int, optional) – Enable state for the Y-axis. Defaults to
BMM350_Y_EN
.en_z (int, optional) – Enable state for the Z-axis. Defaults to
BMM350_Z_EN
.
- Options en_x:
BMM350_X_EN
: Enable X-axis measurement.BMM350_X_DIS
: Disable X-axis measurement.
- Options en_y:
BMM350_Y_EN
: Enable Y-axis measurement.BMM350_Y_DIS
: Disable Y-axis measurement.
- Options en_z:
BMM350_Z_EN
: Enable Z-axis measurement.BMM350_Z_DIS
: Disable Z-axis measurement.
- set_operation_mode(modes)
Set the sensor operation mode.
Allows switching between suspend, normal, forced, and forced-fast modes.
- Parameters:
modes (int) – The desired operation mode.
- Options modes:
BMM350_SUSPEND_MODE
: Suspend mode. Minimal current consumption.All registers are accessible. Default after power-on.
BMM350_NORMAL_MODE
: Normal mode. Continuous measurement at the configured ODR.BMM350_FORCED_MODE
: Forced mode. Single measurement, then returns to suspend mode.BMM350_FORCED_MODE_FAST
: Forced mode fast. Single measurement with faster ODR capability (up to 200Hz), then returns to suspend mode.
- set_preset_mode(avg=1, odr=7)
Set a preset measurement mode combining averaging and ODR.
This simplifies sensor configuration for common use cases by setting the number of averages and the output data rate.
- Parameters:
avg (int) – The averaging setting (number of measurements to average).
odr (int, optional) – The desired data output rate. Defaults to
BMM350_DATA_RATE_12_5HZ
.
- Options avg:
BMM350_AVERAGING_NO_AVG
(No averaging)BMM350_AVERAGING_2_AVG
(2 averages)BMM350_AVERAGING_4_AVG
(4 averages)BMM350_AVERAGING_8_AVG
(8 averages)
- Options odr:
BMM350_DATA_RATE_1_5625HZ
BMM350_DATA_RATE_3_125HZ
BMM350_DATA_RATE_6_25HZ
BMM350_DATA_RATE_12_5HZ
BMM350_DATA_RATE_25HZ
BMM350_DATA_RATE_50HZ
BMM350_DATA_RATE_100HZ
BMM350_DATA_RATE_200HZ
BMM350_DATA_RATE_400HZ
- set_rate(rates)
Set the data output rate (ODR) for geomagnetic data.
The ODR determines how frequently new data is available from the sensor when in normal mode.
- Parameters:
rates (int) – The desired data rate identifier.
- Options rates:
BMM350_DATA_RATE_1_5625HZ
(1.5625 Hz)BMM350_DATA_RATE_3_125HZ
(3.125 Hz)BMM350_DATA_RATE_6_25HZ
(6.25 Hz)BMM350_DATA_RATE_12_5HZ
(12.5 Hz, default rate)BMM350_DATA_RATE_25HZ
(25 Hz)BMM350_DATA_RATE_50HZ
(50 Hz)BMM350_DATA_RATE_100HZ
(100 Hz)BMM350_DATA_RATE_200HZ
(200 Hz)BMM350_DATA_RATE_400HZ
(400 Hz)
- set_threshold_interrupt(modes, threshold, polarity)
Configure the threshold interrupt.
Sets up an interrupt that triggers when the geomagnetic value of a channel crosses a defined threshold (either low or high). The threshold value is effectively scaled by 16 internally.
- Parameters:
modes (int) – The type of threshold interrupt.
threshold (int or float) – The threshold value. The actual trigger threshold will be threshold * 16.
polarity (int) – Polarity of the interrupt pin.
- Options modes:
LOW_THRESHOLD_INTERRUPT
: Interrupt when data is below the threshold.HIGH_THRESHOLD_INTERRUPT
: Interrupt when data is above the threshold (Note: current implementation logic for HIGH seems same as LOW, review needed).
- Options polarity:
POLARITY_HIGH
(orBMM350_ACTIVE_HIGH
): Active high.POLARITY_LOW
(orBMM350_ACTIVE_LOW
): Active low.
- soft_reset()
Perform a soft reset on the BMM350 sensor.
Restores the sensor to suspend mode after the soft reset. This involves issuing a soft reset command, disabling OTP, performing a magnetic reset, and finally setting the power mode to suspend. The user needs to manually set the desired operation mode afterwards.
- test_platform()
Detects the platform (Linux or Windows) and initializes the I2C bus accordingly.
For Linux, it attempts to find an i2c-tiny-usb adapter if a standard bus is not found. For Windows, it uses i2c_mp_usb. Prints a message if the platform is not supported.
- update_mag_off_sens()
Update magnetometer offset and sensitivity data from OTP values.
This internal API reads the OTP (One-Time Programmable) memory data and populates the compensation structures (bmm350_sensor.mag_comp) with offset, sensitivity, TCO, TCS, T0, and cross-axis coefficients.
- write_reg(reg, data)
Writes a byte of data to a specified register.
Handles I2C communication errors by printing a message and retrying after a delay.
- Parameters:
reg (int) – The register address to write to.
data (int) – The byte of data to write.
- class blimputils.Motor(in1_pin: int, in2_pin: int, pi_instance: pigpio.pi)
Motor class for controlling a single motor connected via DRV8212p. Assumes pigpio daemon is running (sudo pigpiod). After calling Motor.init(), initialized motor instances are available via Motor.instances dict.
- stop()
Stops the motor immediately and updates current_speed.
- blimputils.init(i2c_bus: int = 1, accel_addr: int | None = 104, gyro_addr: int | None = 104, mag_addr: int | None = 20) Tuple[Accelerometer | None, Gyroscope | None, Magnetometer | None, Dict[str, Motor]]
Initializes the sensors. Motors are initialized separately by calling Motor.init() from the motor module, which populates Motor.instances for the proxies.
- blimputils.cleanup()
Cleans up resources. Calls Motor.cleanup() for pigpio motors.