Raspberry Pi and BMG160 angular rate sensor example

The BMG160 is an ultra-small, digital 3-axis angular rate sensor with a measurement range up to 2000°/s and a digital resolution of 16 bit for consumer electronics applications. The BMG160 allows low-noise measurement of angular rates in 3 perpendicular axes and is designed for use in cellular phones, handhelds, computer peripherals, man-machine interfaces, virtual reality features, remote and game controllers.

With its small footprint of only 3 x 3 mm² the BMG160 is unique in the class of low-noise consumer electronics gyroscopes. The zero-rate offset and offset stability over temperature of the BMG160 are outstanding.

ParameterTechnical data
Digital resolution16 bit
Measurement ranges
(programmable)
± 125 °/s, ± 250 °/s,
± 500 °/s, ± 1000 °/s,
± 2000 °/s
Sensitivity (calibrated)± 125°/s: 262.4 LSB/°/s
± 250°/s: 131.2 LSB/°/s
± 500°/s: 65.5 LSB/°/s
± 1000°/s: 32.8 LSB/°/s
± 2000°/s: 16.4 LSB/°/s
Zero-g offset (typ., over life-time)± 1 °/s
Zero-rate offset over temperature0.015 °/s/K
Noise density (typ.)0.014 °/s/√Hz
Low-pass filter bandwiths (progr.)230, 116, 64, 47, 32,
23, 12 Hz
Date rates (programmable)2000, 1000,
400, 200, 100 Hz
Digital inputs/outputsSPI, I²C,
2x digital interrupts
Supply voltage (VDD)2.4 … 3.6 V
I/0 supply voltage (VDDIO)1.2 … 3.6 V
Temperature range-40 … +85 °C
Current consumption
– full operation
– low-power mode
5.0 mA
2.5 mA
FIFO data buffer100 samples depth
(each axis)
LGA package3 x 3 x 0.95 mm³
Shock resistance10,000 g x 200 μs

 

Connection

Raspberry PIModule
3.3vVcc
GndGnd
SDASDA
SCLSCL

 

Code

# Distributed with a free-will license.
# Use it any way you want, profit or free, provided it fits in the licenses of its associated works.
# BMG160
# This code is designed to work with the BMG160_I2CS I2C Mini Module available from ControlEverything.com.
# https://www.controleverything.com/content/Gyro?sku=BMG160_I2CS#tabs-0-product_tabset-2
import smbus
import time
# Get I2C bus
bus = smbus.SMBus(1)
# BMG160 address, 0x69
# Select range register, 0x0F(15)
# 0x80(128) Configure full scale range = 2000dps
bus.write_byte_data(0x69, 0x0F, 0x80)
# BMG160 address, 0x68(104)
# Select bandwidth register, 0x10(16)
# 0x04(04) Set bandwidth = 200Hz
bus.write_byte_data(0x69, 0x10, 0x04)
time.sleep(0.5)
# BMG160 address, 0x69
# Read data back from 0x02(02), 6 bytes
# X-Axis LSB, X-Axis MSB, Y-Axis LSB, Y-Axis MSB, Z-Axis LSB, Z-Axis MSB
data = bus.read_i2c_block_data(0x69, 0x02, 6)
# Convert the data
xGyro = data[1] * 256 + data[0]
if xGyro > 32767 :
xGyro -= 65536
yGyro = data[3] * 256 + data[2]
if yGyro > 32767 :
yGyro -= 65536
zGyro = data[5] * 256 + data[4]
if zGyro > 32767 :
zGyro -= 65536
# Output data to screen
print "X-Axis of Rotation : %d" %xGyro
print "Y-Axis of Rotation : %d" %yGyro
print "Z-Axis of Rotation : %d" %zGyro

Output

Here is the output

Link

CJMCU-160 Sensortec three axis gyro attitude sensor module BMG160