Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » Interface BMI160 with Raspberry Pi Pico & MicroPython
Raspberry Pi Pico Projects

Interface BMI160 with Raspberry Pi Pico & MicroPython

Mamtaz AlamBy Mamtaz AlamUpdated:February 2, 20255 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
Interface BMI160 with Raspberry Pi Pico & MicroPython
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

Overview

In this tutorial, we will be interfacing the BMI160 Accelerometer & Gyroscope with the Raspberry Pi Pico using MicroPython. The BMI160 is a small, low-power, low-noise 16-bit inertial measurement unit that integrates a 3-axis accelerometer and a 3-axis gyroscope. It provides precise motion sensing for applications like augmented reality, fitness tracking, and indoor navigation.

This tutorial provides detailed information about the BMI160 Accelerometer Gyroscope Module, including its specifications and technical details. First, we will interface the BMI160 with a Raspberry Pi Pico and then write a MicroPython code to convert the accelerometer raw values to Acceleration and Tilt Angles (Pitch & Roll).


Bill of Materials

We will need the following components for this tutorial. You can purchase all the components from the given links.

S.N.Components NameQuantityPurchase Link
1Raspberry Pi Pico1Amazon | AliExpress
2BMI160 Accelerometer Gyroscope1Amazon | AliExpress
3Connecting Wires10Amazon | AliExpress
4Breadboard1Amazon | AliExpress




BMI160 3 Axis Accelerometer & Gyroscope

The BMI160 is a high-performance, small, and ultra-low-power 16-bit Inertial Measurement Unit (IMU) that combines a 3-axis accelerometer and a 3-axis gyroscope in a single package.

BMI160 Gyroscope Accelerometer
Fig: Front & Back of BMI160

It is designed to deliver accurate and reliable motion sensing for a wide range of applications, such as augmented reality, indoor navigation, wearable devices, and gaming. The sensor offers advanced features like motion detection, step counting, and gesture recognition, making it versatile for modern technology needs.

The BMI160 supports both I2C and SPI interfaces for communication, making it compatible with a variety of microcontrollers and processors. It has a compact footprint of just 2.5 x 3.0 x 0.8 mm³, which is smaller than many competing IMUs, such as the MPU6050, and is well-suited for space-constrained devices like wearables. Refer to Bosch BMI160 Datasheet for more information.

Technical Specifications of BMI160

  • Operating Voltage: 1.71 – 3.6 V (Breakout Board operates between 3.2V~6V)
  • Power Consumption:
    • Gyroscope: 900 µA (full operation)
    • Gyroscope + Accelerometer: 950 µA (full operation)
    • Accelerometer: 180 µA (full operation)
    • Suspend Mode: 3 µA
    • Motion Detection: 200 µA
  • Acceleration Range: ±2g/±4g/±8g/±16g
  • Gyroscopes Range: ±125°/s,±250°/s,±500°/s,±1000°/s,±2000°/s
  • Acceleration Zero-g Offset: ±40mg
  • Gyroscopes Zero-g Offset: ±10°/s
  • Interfaces:
    • Primary: I2C or SPI
    • Secondary: High-speed SPI for optical image stabilization
  • Noise Density:
    • Accelerometer: 180 µg/√Hz
    • Gyroscope: 0.008 °/s/√Hz
  • Programmable Frequency: 25/32Hz~1600Hz
  • 6D Detection and Location
  • 16-bit Data Output
  • Shock Resistance: 1000gx 200us
  • 2 Independent Programmable Interrupt Generators
  • In-built 1024 Byte FIFO

Applications of BMI160

  • Augmented Reality: Tracks motion for virtual environments.
  • Indoor Navigation: Supports step counting and positioning.
  • Mobile Devices: For smartphones and smartwatches.
  • Wearables: Powers fitness and health devices.
  • Gaming: Tracks motion in controllers.
  • Cameras: Stabilizes images.
  • Drones & Toys: Enables motion sensing.



Pinout of BMI160

BMI160 Gyroscope Accelerometer Pinout
Fig: Pinout of BMI160 Gyroscope Accelerometer Module
Pin Name Description
VIN VIN Power input pin. Accepts 3.3V to 5V and steps it down for the BMI160 using an onboard regulator.
3.3V 3.3V Regulated 3.3V output pin.
GND GND Ground pin. Connect to the ground of your system.
OCS OCS Optional Chip Select for secondary SPI interface (used in optical image stabilization).
INT1 INT1 Interrupt pin 1. Used for motion events or data-ready notifications.
INT2 INT2 Interrupt pin 2. An additional interrupt pin for more advanced use cases.
SCL/SCX SCL or SCX I2C clock line when using I2C communication. Acts as SPI clock (SCX) in SPI mode.
SDA/SDX SDA or SDX I2C data line when using I2C communication. Acts as SPI data (SDX) in SPI mode.
CS CS Chip Select pin for SPI communication. Used to select the BMI160 during SPI transactions.
SA0 SA0 I2C address selection pin. Connect to GND for address 0x68 or to 3.3V for 0x69.

Interfacing BMI160 with Raspberry Pi Pico

Let us interface the BMI160 Gyroscope Accelerometer module with Raspberry Pi Pico Board. We can either use the module in SPI Mode or in I2C Mode. For this tutorial, we are using the I2C Mode as it just requires 2 wires.

Here is an interfacing circuit diagram for the connection between BMI160 and Raspberry Pi Pico Board.

Interface BMI160 with Raspberry Pi Pico & MicroPython

BMI160 Pin Raspberry Pi Pico Description
3.3V 3.3V Power input for the BMI160.
GND GND Ground connection.
SCL GP1 I2C Clock line.
SDA GP0 I2C Data line.
SA0 GND Sets I2C address to 0x68.

BMI160 Raspberry Pi Pico Connection

You can use a breadboard to connect the BMI160 with Raspberry Pi Pico as per the circuit diagram.



MicroPython Code

After hardware connection is done, now lets write an MicroPython Code to read the Raw Acceleration and Gyroscope Data from BMI160 Module & Raspberry Pi Pico. We will use some mathematical equations to convert the raw values into acceleration and gyroscopic value.

Raw values are converted to 𝑚/𝑠^2 using the formula:

Sensitivity for ±2g is 16384 LSB/g. Adjust if you use a different range.

The angle of rotation around the X-axis is called as Pitch which is calculated using the following formula:

The angle of rotation around the Y-axis is called as Roll which is calculated using the following formula:

This code uses a Raspberry Pi Pico to interface with the BMI160 sensor via I2C. It measures acceleration in m/s² and calculates tilt angles (pitch and roll). Auto-calibration is performed to remove offsets. Accurate readings are printed continuously.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
from machine import I2C, Pin
import math
import time
 
# Constants
BMI160_I2C_ADDR = 0x68
ACCEL_SENSITIVITY = 16384.0  # ±2g sensitivity for the accelerometer in LSB/g
 
# Initialize I2C with specified pins
i2c = I2C(0, scl=Pin(1), sda=Pin(0), freq=400000)
 
def write_register(addr, reg, data):
    """Write data to a register."""
    i2c.writeto_mem(addr, reg, bytes([data]))
 
def read_register(addr, reg, length):
    """Read data from a register."""
    return i2c.readfrom_mem(addr, reg, length)
 
def initialize_bmi160():
    """Initialize the BMI160 sensor."""
    # Set accelerometer to normal mode
    write_register(BMI160_I2C_ADDR, 0x7E, 0x11)  # ACC_NORMAL_MODE
    time.sleep(0.1)
 
def read_raw_acceleration():
    """Read raw acceleration data."""
    data = read_register(BMI160_I2C_ADDR, 0x12, 6)  # Read accel data
    ax_raw = int.from_bytes(data[0:2], 'little') - (1 << 16 if data[1] & 0x80 else 0)
    ay_raw = int.from_bytes(data[2:4], 'little') - (1 << 16 if data[3] & 0x80 else 0)
    az_raw = int.from_bytes(data[4:6], 'little') - (1 << 16 if data[5] & 0x80 else 0)
    return ax_raw, ay_raw, az_raw
 
def auto_calibrate():
    """Perform auto-calibration to remove noise or error."""
    print("Starting auto-calibration...")
    num_samples = 100
    ax_offset = 0
    ay_offset = 0
    az_offset = 0
 
    for _ in range(num_samples):
        ax_raw, ay_raw, az_raw = read_raw_acceleration()
        ax_offset += ax_raw
        ay_offset += ay_raw
        az_offset += az_raw
        time.sleep(0.01)  # Small delay between readings
 
    # Calculate average offsets
    ax_offset //= num_samples
    ay_offset //= num_samples
    az_offset //= num_samples
 
    # Assuming the sensor is stable, Z-axis should measure 1g (gravity)
    az_offset -= int(ACCEL_SENSITIVITY)
 
    print("Auto-calibration completed.")
    print("Offsets - X: {}, Y: {}, Z: {}".format(ax_offset, ay_offset, az_offset))
 
    return ax_offset, ay_offset, az_offset
 
def read_acceleration(ax_offset, ay_offset, az_offset):
    """Read raw acceleration data, apply offsets, and convert to m/s²."""
    ax_raw, ay_raw, az_raw = read_raw_acceleration()
    ax = ((ax_raw - ax_offset) / ACCEL_SENSITIVITY) * 9.81  # Convert to m/s²
    ay = ((ay_raw - ay_offset) / ACCEL_SENSITIVITY) * 9.81  # Convert to m/s²
    az = ((az_raw - az_offset) / ACCEL_SENSITIVITY) * 9.81  # Convert to m/s²
    return ax, ay, az
 
def calculate_tilt_angles(ax, ay, az):
    """Calculate pitch and roll angles from acceleration."""
    pitch = math.atan2(ay, math.sqrt(ax**2 + az**2)) * 180.0 / math.pi
    roll = math.atan2(-ax, az) * 180.0 / math.pi
    return pitch, roll
 
# Initialize BMI160
initialize_bmi160()
print("BMI160 Initialized")
 
# Perform auto-calibration
ax_offset, ay_offset, az_offset = auto_calibrate()
 
while True:
    try:
        # Read acceleration values
        ax, ay, az = read_acceleration(ax_offset, ay_offset, az_offset)
 
        # Calculate tilt angles
        pitch, roll = calculate_tilt_angles(ax, ay, az)
 
        # Print acceleration values
        print("Acceleration (m/s²):")
        print("  X: {:.2f} m/s², Y: {:.2f} m/s², Z: {:.2f} m/s²".format(ax, ay, az))
 
        # Print tilt angles
        print("Tilt Angles:")
        print("  Pitch: {:.2f}°, Roll: {:.2f}°".format(pitch, roll))
        print("=" * 50)
 
    except OSError as e:
        print("I2C Error: ", e)
 
    time.sleep(0.1)


Copy the above code in Thonny IDE editor window. Then run the code.

When the module is placed on a stable surface without any movements and vibrations, it gives following results.

The acceleration in x and y axis is zero but in z axis it shows 9.81. This is due to the gravitational pull of the earth. Similarly pitch and roll angles are almost zero.

To observe the change in acceleration and tilt angles, shake or tremble the module. You will observe the massive change in acceleration and tilt angles readings.

The tilt angle will only vary when the BMI160 is rotated in all 3 different axis.

BMI160 MicroPython Code Raspberry Pi Pico

This is how you can interface BMI160 Accelerometer Gyroscope Module with Raspberry Pi Pico using the MicroPython code.


Video Tutorial & Guide

BMI160 Accelerometer Gyroscope | BMI160 vs MPU6050 | Usage with Arduino, ESP32 & RPI Pico
Watch this video on YouTube.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleESP32 with BMI160 Accelerometer & Gyroscope Sensor
Next Article Stopwatch using ESP32 & LCD with Start, Stop & Reset Button

Related Posts

ADXL375 Accelerometer with Raspberry Pi Pico & MicroPython

ADXL375 Accelerometer with Raspberry Pi Pico & MicroPython

Updated:July 24, 2025
Shift Register 74HC595 with Raspberry Pi Pico & MicroPython

Shift Register 74HC595 with Raspberry Pi Pico & MicroPython

Updated:February 2, 202513K
Interfacing XBee Module with Raspberry Pi Pico & MicroPython

Interfacing XBee Module with Raspberry Pi Pico & MicroPython

Updated:February 2, 20253K
Modbus RTU with Raspberry Pi Pico & Micropython

Modbus RTU with Raspberry Pi Pico & MicroPython

Updated:February 2, 20258K
AD8495 K-Type Thermocouple Amplifier Raspberry Pi Pico

AD8495 K-Type Thermocouple Amplifier Raspberry Pi Pico

Updated:February 2, 20252K
LM35 Temperature Sensor with Raspberry Pi Pico MicroPython

LM35 Temperature Sensor with Raspberry Pi Pico MicroPython

Updated:February 2, 20254K
Add A Comment

CommentsCancel reply

Latest Posts
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

May 31, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

February 1, 2026
Top Posts & Pages
  • How to use INA226 DC Current Sensor with Arduino
    How to use INA226 DC Current Sensor with Arduino
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
  • How to use Modbus RTU with ESP32 to read Sensor Data
    How to use Modbus RTU with ESP32 to read Sensor Data
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • How to use INA219 DC Current Sensor Module with Arduino
    How to use INA219 DC Current Sensor Module with Arduino
  • Designing of MPPT Solar Charge Controller using Arduino
    Designing of MPPT Solar Charge Controller using Arduino
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • IoT Based Electricity Energy Meter using ESP32 & Blynk
    IoT Based Electricity Energy Meter using ESP32 & Blynk
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (204)
    • ESP32 MicroPython (7)
    • ESP32 Projects (81)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.