Class Bmi270AccelerometerGyroscope
BMI270 6-axis IMU - accelerometer and gyroscope.
[Interface("BMI270 accelerometer and gyroscope")]
public class Bmi270AccelerometerGyroscope
- Inheritance
-
Bmi270AccelerometerGyroscope
Constructors
Bmi270AccelerometerGyroscope(I2cDevice, AccelerometerRange, GyroscopeRange, AccelerometerOutputDataRate, GyroscopeOutputDataRate)
Initializes a new instance of the Bmi270AccelerometerGyroscope class. Performs the full initialization sequence including config file upload.
public Bmi270AccelerometerGyroscope(I2cDevice i2cDevice, AccelerometerRange accelerometerRange = AccelerometerRange.Range8G, GyroscopeRange gyroscopeRange = GyroscopeRange.Range2000Dps, AccelerometerOutputDataRate accelerometerOdr = AccelerometerOutputDataRate.Odr100Hz, GyroscopeOutputDataRate gyroscopeOdr = GyroscopeOutputDataRate.Odr200Hz)
Parameters
i2cDeviceI2cDeviceThe I2C device.
accelerometerRangeAccelerometerRangeInitial accelerometer range. Default is +-8g.
gyroscopeRangeGyroscopeRangeInitial gyroscope range. Default is +-2000 dps.
accelerometerOdrAccelerometerOutputDataRateInitial accelerometer output data rate. Default is 100 Hz.
gyroscopeOdrGyroscopeOutputDataRateInitial gyroscope output data rate. Default is 200 Hz.
Fields
DefaultI2cAddress
The default I2C address for the BMI270 sensor (SDO connected to GND).
public const int DefaultI2cAddress = 104
Field Value
SecondaryI2cAddress
The secondary I2C address for the BMI270 sensor (SDO connected to VDDIO). This is the address used on the M5Stack CoreS3.
public const int SecondaryI2cAddress = 105
Field Value
Properties
AccelerometerOdr
Gets or sets the accelerometer output data rate.
public AccelerometerOutputDataRate AccelerometerOdr { get; set; }
Property Value
AccelerometerScale
Gets or sets the accelerometer full-scale range.
public AccelerometerRange AccelerometerScale { get; set; }
Property Value
GyroscopeOdr
Gets or sets the gyroscope output data rate.
public GyroscopeOutputDataRate GyroscopeOdr { get; set; }
Property Value
GyroscopeScale
Gets or sets the gyroscope full-scale range.
public GyroscopeRange GyroscopeScale { get; set; }
Property Value
Methods
Calibrate(int)
Calibrates the gyroscope by calculating the offset values. Keep the sensor still and in a fixed position during calibration.
public Vector3 Calibrate(int iterations)
Parameters
iterationsintNumber of samples to average.
Returns
- Vector3
The calculated offset vector.
ConfigureInterruptPin(int, bool, bool, bool)
Configures an interrupt output pin (INT1 or INT2).
public void ConfigureInterruptPin(int pinNumber, bool outputEnable = true, bool activeHigh = true, bool openDrain = false)
Parameters
pinNumberintPin number: 1 for INT1, 2 for INT2.
outputEnableboolTrue to enable the pin output.
activeHighboolTrue for active-high, false for active-low.
openDrainboolTrue for open-drain, false for push-pull.
DisableFifo()
Disables the FIFO buffer.
public void DisableFifo()
DisableStepCounter()
Disables the step counter and activity recognition features.
public void DisableStepCounter()
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
EnableAuxiliaryI2c(byte, bool)
Enables the BMI270 auxiliary I2C master interface to communicate with a secondary sensor (e.g. BMM150 magnetometer) on the auxiliary bus.
public void EnableAuxiliaryI2c(byte auxiliaryDeviceAddress, bool manualMode = true)
Parameters
auxiliaryDeviceAddressbyteThe 7-bit I2C address of the auxiliary device (e.g. 0x10 for BMM150).
manualModeboolWhen true, configures manual-access mode where reads/writes are triggered by setting AUX_RD_ADDR or AUX_WR_ADDR/DATA. This is the mode used by Bmm150I2cBmi270. Default is true.
EnableFifo(bool, bool, int, bool)
Enables the FIFO buffer for accelerometer and/or gyroscope data.
public void EnableFifo(bool enableAccelerometer, bool enableGyroscope, int watermarkBytes = 0, bool stopOnFull = false)
Parameters
enableAccelerometerboolTrue to store accelerometer data in FIFO.
enableGyroscopeboolTrue to store gyroscope data in FIFO.
watermarkBytesintFIFO watermark level in bytes. When the FIFO fill level reaches this value, a watermark interrupt can be generated. Set to 0 to disable watermark. Max 8191.
stopOnFullboolTrue to stop writing when FIFO is full, false to overwrite oldest data.
EnableStepCounter(bool)
Enables the built-in step counter feature. The step count is accumulated in internal registers and can be read via GetStepCount().
public void EnableStepCounter(bool enableActivityRecognition = false)
Parameters
enableActivityRecognitionboolWhen true, also enables activity recognition (still/walking/running). Activity can be read via GetActivity().
FlushFifo()
Flushes (clears) all data from the FIFO buffer.
public void FlushFifo()
GetAccelerometer()
Reads the current accelerometer values, scaled to g.
[Telemetry]
public Vector3 GetAccelerometer()
Returns
- Vector3
Acceleration vector in g.
GetActivity()
Reads the current recognized activity type.
Activity recognition must be enabled via EnableStepCounter(bool) with
enableActivityRecognition = true.
[Telemetry]
public ActivityType GetActivity()
Returns
- ActivityType
The current activity type.
GetDataInterruptStatus()
Reads the data interrupt status register.
public DataInterruptSource GetDataInterruptStatus()
Returns
- DataInterruptSource
Active data interrupt sources.
GetFeatureInterruptStatus()
Reads the feature interrupt status register. Reading this register clears the latched interrupt status.
public FeatureInterruptSource GetFeatureInterruptStatus()
Returns
- FeatureInterruptSource
Active feature interrupt sources.
GetFifoByteCount()
Gets the number of bytes currently stored in the FIFO buffer.
public int GetFifoByteCount()
Returns
- int
Number of bytes available in the FIFO.
GetGyroscope()
Reads the current gyroscope values, scaled to degrees per second (dps).
[Telemetry]
public Vector3 GetGyroscope()
Returns
- Vector3
Angular rate vector in dps.
GetInternalTemperature()
Reads the internal temperature sensor.
[Telemetry]
public Temperature GetInternalTemperature()
Returns
- Temperature
Temperature of the sensor die.
GetStepCount()
Reads the current step count from the step counter output registers. The step counter must be enabled via EnableStepCounter(bool) first.
[Telemetry]
public int GetStepCount()
Returns
- int
The accumulated step count since the last reset.
MapDataInterrupt(int, DataInterruptSource)
Maps data interrupt sources to an interrupt pin.
public void MapDataInterrupt(int pinNumber, DataInterruptSource sources)
Parameters
pinNumberintPin number: 1 for INT1, 2 for INT2.
sourcesDataInterruptSourceData interrupt sources to map.
MapFeatureInterrupt(int, FeatureInterruptSource)
Maps feature interrupt sources to an interrupt pin.
public void MapFeatureInterrupt(int pinNumber, FeatureInterruptSource sources)
Parameters
pinNumberintPin number: 1 for INT1, 2 for INT2.
sourcesFeatureInterruptSourceFeature interrupt sources to map.
ReadFifo(SpanByte)
Reads raw bytes from the FIFO buffer.
public int ReadFifo(SpanByte buffer)
Parameters
bufferSpanByteBuffer to read FIFO data into.
Returns
- int
Number of bytes actually read.
Remarks
In headerless mode with accelerometer + gyroscope enabled, each frame is 12 bytes: 6 bytes accelerometer (X,Y,Z as 16-bit little-endian) followed by 6 bytes gyroscope (X,Y,Z as 16-bit little-endian).
ResetStepCounter()
Resets the step counter to zero.
public void ResetStepCounter()
SetGyroscopeOffset(Vector3)
Sets the gyroscope offset compensation registers.
public void SetGyroscopeOffset(Vector3 offset)
Parameters
offsetVector3The offset vector (raw values).
Sleep()
Puts the sensor into suspend mode (low power).
public void Sleep()
WakeUp()
Wakes the sensor from suspend mode.
public void WakeUp()