In recent years, smart wearable devices have become increasingly integrated into the lives of ordinary people, with products such as smart bracelets, smartwatches, and smart headphones gradually becoming part of our daily routines. These devices offer powerful functions through data interaction and cloud-based communication, significantly transforming our lives and perceptions. MEMS sensors in wearable devices can accurately capture data and provide real-time updates. Inertial measurement units (IMUs), as a type of MEMS sensor, can be used to measure orientation, motion, or gestures.

Bosch’s BMI270 low-power smart sensor can be used in wearable devices. Based on Bosch’s MEMS technology, this sensor significantly improves the offset and sensitivity performance of the accelerometer. In this article, we will introduce how to read accelerometer and gyroscope data from the BMI270 via the SPI interface using an Arduino Nano ESP32 development board.

Required components

  • ● Arduino Nano ESP32 Development Board
  • ● YBX-BMI270 Inertial Measurement Unit Sensor Module ( Taobao Link )
  • ● Connect jumpers
  • ● USB cable

YBX-BMI270 sensor module

The YBX-BMI270 module utilizes Bosch Sensors’ ultra-low-power intelligent inertial measurement unit (IMU) BMI270. Optimized for wearable devices, this IMU provides accurate acceleration and angular rate measurements, along with intelligent on-chip motion-triggered interrupt functionality. It also integrates a 16-bit triaxial gyroscope and a 16-bit triaxial accelerometer. The module supports SPI and I2C interfaces for system integration, enabling rapid connection to controllers such as Arduino and STM32. An onboard power supply chip supports 3.3-5V operation.

Connecting  BMI270 inertial Measurement Sensor to Arduino

The BMI270 features intuitive gesture, context, and activity recognition capabilities, and integrates a plug-and-play pedometer optimized specifically for wrist-worn devices. This IMU is also well-suited for other types of wearable devices, such as ear-worn devices, smart clothing, smart shoes, smart glasses, and ankle straps.

Bosch’s unique Static Component Recalibration (CRT) feature provides built-in gyroscope self-calibration without rotational excitation, saving OEMs valuable time and costs during testing and manufacturing. The BMI270’s embedded plug-and-play functionality helps shorten time-to-market.

Key features

  • ● Employs Bosch’s ultra-low power intelligent inertial measurement unit BMI270
  •     ● 16-bit digital triaxial accelerometer
  •     ● 16-bit digital three-axis gyroscope
  •     ● Current consumption: 685µA (typical)
  •     ● Sensitivity error: ± 0.4%
  •     ● Achieve self-calibration of the gyroscope via the static CRT function:
  • ● SPI and I2C interfaces
  • ● Two independent programmable I/O pins for interrupt and synchronization events.
  • ● Onboard a high-precision DC-DC chip
  • ● LED power indicator
  • ● Supports microcontrollers such as Arduino and STM32

● Dimensions: 24mm x 24mm x 5mm

Hardware connection

The YBX-BMI270 module connects to the Arduino development board via SPI. The hardware connection schematic is shown below:

Connecting  BMI270 inertial Measurement Sensor to Arduino

First, connect the SPI interface. Connect the SCK, MOSI, and MISO pins of the YBX-BMI270 module to pins D13 (SCK), D11 (MOSI), and D12 (MISO) of the Arduino UNO development board, respectively. Connect the chip select pin CSB to D5.

Then connect the VCC pin of the YBX-BMI270 module to the 3.3V pin and the GND pin to any GND pin of the Arduino.

The hardware connection is complete, as shown in the following figure:

Installation library files

Before we can start programming, we need to install the Arduino library files for the BMI270.

The Arduino library manager contains two main Arduino library files for the BMI270: Arduino_BMI270_BMM150 and SparkFun_BMI270_Arduino_Library. The former is primarily used for the BMI270 chip included in the Arduino Nano 33 BLE Sense Rev2 development; therefore, this article mainly uses the library file provided by SparkFun.

You can download it from GitHub: SparkFun BMI270_Arduino_Library . Alternatively, you can search for “BMI270” in your library manager, locate the library file, and then install it.

This library is based on the official BMI2 driver provided by Bosch Sensors and supports easy configuration and recording of accelerometer, gyroscope, and temperature data from the BMI270 chip using SPI or I2C interfaces. It also provides sample code for embedded algorithms such as click, tilt, pedometer, and motion detection.

code

This article uses the Example02_BasicReadingsSPI example provided in the library file. The complete code is shown below:

    #include <SPI.h>
    #include "SparkFun_BMI270_Arduino_Library.h"
    
    // Create a new sensor object
    BMI270 imu;
    
    // SPI parameters
    uint8_t chipSelectPin = 5;
    uint32_t clockFrequency = 100000;
    
    void setup()
    {
        // Start serial
        Serial.begin(115200);
        Serial.println("BMI270 Example 2 - Basic Readings SPI");
    
        // Initialize the SPI library
        SPI.begin();
    
        // Check if sensor is connected and initialize
        // Clock frequency is optional (defaults to 100kHz)
        while(imu.beginSPI(chipSelectPin, clockFrequency) != BMI2_OK)
        {
            // Not connected, inform user
            Serial.println("Error: BMI270 not connected, check wiring and CS pin!");
    
            // Wait a bit to see if connection is established
            delay(1000);
        }
    
        Serial.println("BMI270 connected!");
    }
    
    void loop()
    {
        // Get measurements from the sensor. This must be called before accessing
        // the sensor data, otherwise it will never update
        imu.getSensorData();
    
        // Print acceleration data
        Serial.print("Acceleration in g's");
        Serial.print("\t");
        Serial.print("X: ");
        Serial.print(imu.data.accelX, 3);
        Serial.print("\t");
        Serial.print("Y: ");
        Serial.print(imu.data.accelY, 3);
        Serial.print("\t");
        Serial.print("Z: ");
        Serial.print(imu.data.accelZ, 3);
    
        Serial.print("\t");
    
        // Print rotation data
        Serial.print("Rotation in deg/sec");
        Serial.print("\t");
        Serial.print("X: ");
        Serial.print(imu.data.gyroX, 3);
        Serial.print("\t");
        Serial.print("Y: ");
        Serial.print(imu.data.gyroY, 3);
        Serial.print("\t");
        Serial.print("Z: ");
        Serial.println(imu.data.gyroZ, 3);
    
        // Print 50x per second
        delay(20);
    }

    Compile and upload the code to the Arudino development board. Connect the development board to the computer.

    Run test results

    Open the serial monitor and view the output of the Arduino development board. Rotate the module and observe the changes in the output values.

    This concludes the tutorial on connecting the YBX-BMI270 module using an Arduino development board. If you have any questions, please feel free to reply below this post.

    • Note 1: Because the BMI270 sensor requires configuration of many parameters, the first set of data will appear slowly. Please wait a while.
    • Note 2: The BMI270 requires approximately 8KB of RAM for initialization, therefore it is not suitable for development boards such as the Arduino UNO.

    Original Post

    error: Content is protected !!
    Scroll to Top