Skip to main content

BHI385 Smart IMU - Step Counter and Multi-Tap Detection

This page covers the BHI385's activity recognition sensors: the cumulative step counter and the multi-tap gesture detector.


Step counter​

The step counter virtual sensor uses an adaptive pedometer algorithm in the firmware to count footsteps cumulatively. The count increments automatically as the sensor detects walking or running patterns; it resets to zero on power-off.

void setup()
{
// ... begin() and loadFirmware() as above ...

imu.enableStepCounter(100.0f);
}

void loop()
{
if (imu.update())
{
if (imu.stepUpdated())
{
Serial.print("Steps: ");
Serial.println(imu.getStepCount());
}
imu.clearUpdatedFlags();
}
delay(100);
}
Serial monitor Step Counter readings
Serial monitor Step Counter output

imu.enableStepCounter()

Enables the low-power step counter virtual sensor. The firmware increments the cumulative step count each time a footstep-like acceleration signature is detected. The count persists across enable/disable cycles but resets on power-off.

Returns value: true if the sensor was configured successfully

Function parameters:

TypeNameDescription
floatrateHzSensor update rate in Hz. Default: 100.0f

imu.getStepCount()

Returns the current cumulative step count as reported by the firmware step counter. Valid after update() returns with stepUpdated() true.

Returns value: Cumulative step count as uint32_t


Multi-tap detection​

The multi-tap sensor detects sharp, brief acceleration impulses and classifies them as single, double, or triple taps. You configure which tap types to detect via a bitmask before enabling the sensor.

void setup()
{
// ... begin() and loadFirmware() as above ...

// Detect double taps only
imu.enableMultiTapDetect(BHI385_TAP_DOUBLE, 100.0f);
}

void loop()
{
if (imu.update())
{
if (imu.tapUpdated())
{
if (imu.getTapType() == BHI385_TAP_SINGLE) Serial.println("Single tap!");
if (imu.getTapType() == BHI385_TAP_DOUBLE) Serial.println("Double tap!");
if (imu.getTapType() == BHI385_TAP_TRIPLE) Serial.println("Triple tap!");
}
imu.clearUpdatedFlags();
}
}

imu.enableMultiTapDetect()

Enables the multi-tap detection virtual sensor. Writes the tap-type bitmask to the firmware parameter page before activating the sensor, so only the requested tap types generate events. Use BHI385_TAP_ALL to detect single, double, and triple taps simultaneously.

Returns value: true if the parameter write and sensor configuration both succeeded

Function parameters:

TypeNameDescription
uint8_ttapMaskOR-combined bitmask of tap types to detect: BHI385_TAP_SINGLE (1), BHI385_TAP_DOUBLE (2), BHI385_TAP_TRIPLE (4), or BHI385_TAP_ALL (7). Default: BHI385_TAP_ALL
floatrateHzSensor update rate in Hz. Default: 100.0f

imu.getTapType()

Returns the tap type reported in the most recent multi-tap event. Matches one of the bhi385TapType enum values: BHI385_TAP_SINGLE, BHI385_TAP_DOUBLE, or BHI385_TAP_TRIPLE. Valid after update() returns with tapUpdated() true.

Returns value: Tap type as uint8_t (bhi385TapType enum value)