Table of Contents

Class Bmi270AccelerometerGyroscope

Namespace
Iot.Device.Bmi270
Assembly
Iot.Device.Bmi270.dll

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

i2cDevice I2cDevice

The I2C device.

accelerometerRange AccelerometerRange

Initial accelerometer range. Default is +-8g.

gyroscopeRange GyroscopeRange

Initial gyroscope range. Default is +-2000 dps.

accelerometerOdr AccelerometerOutputDataRate

Initial accelerometer output data rate. Default is 100 Hz.

gyroscopeOdr GyroscopeOutputDataRate

Initial 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

int

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

int

Properties

AccelerometerOdr

Gets or sets the accelerometer output data rate.

public AccelerometerOutputDataRate AccelerometerOdr { get; set; }

Property Value

AccelerometerOutputDataRate

AccelerometerScale

Gets or sets the accelerometer full-scale range.

public AccelerometerRange AccelerometerScale { get; set; }

Property Value

AccelerometerRange

GyroscopeOdr

Gets or sets the gyroscope output data rate.

public GyroscopeOutputDataRate GyroscopeOdr { get; set; }

Property Value

GyroscopeOutputDataRate

GyroscopeScale

Gets or sets the gyroscope full-scale range.

public GyroscopeRange GyroscopeScale { get; set; }

Property Value

GyroscopeRange

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

iterations int

Number 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

pinNumber int

Pin number: 1 for INT1, 2 for INT2.

outputEnable bool

True to enable the pin output.

activeHigh bool

True for active-high, false for active-low.

openDrain bool

True 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

auxiliaryDeviceAddress byte

The 7-bit I2C address of the auxiliary device (e.g. 0x10 for BMM150).

manualMode bool

When 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

enableAccelerometer bool

True to store accelerometer data in FIFO.

enableGyroscope bool

True to store gyroscope data in FIFO.

watermarkBytes int

FIFO 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.

stopOnFull bool

True 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

enableActivityRecognition bool

When 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

pinNumber int

Pin number: 1 for INT1, 2 for INT2.

sources DataInterruptSource

Data interrupt sources to map.

MapFeatureInterrupt(int, FeatureInterruptSource)

Maps feature interrupt sources to an interrupt pin.

public void MapFeatureInterrupt(int pinNumber, FeatureInterruptSource sources)

Parameters

pinNumber int

Pin number: 1 for INT1, 2 for INT2.

sources FeatureInterruptSource

Feature interrupt sources to map.

ReadFifo(SpanByte)

Reads raw bytes from the FIFO buffer.

public int ReadFifo(SpanByte buffer)

Parameters

buffer SpanByte

Buffer 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

offset Vector3

The 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()