Beaglebone and BMG160 angular rate sensor example in python

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.

Parameter Technical data
Digital resolution 16 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 temperature 0.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/outputs SPI, 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 buffer 100 samples depth
(each axis)
LGA package 3 x 3 x 0.95 mm³
Shock resistance 10,000 g x 200 μs

Parts Required

Name Link
Beaglebone BeagleBone Black TI AM335x Cortex-A8 development BB-Black Rev.C
BMG160 CJMCU-160 Sensortec three axis gyro attitude sensor module BMG160
Connecting wire Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire

Connection

Beaglebone Module
3.3v – P9.3 Vcc
Gnd – P9.1 Gnd
SDA – P9.20 SDA
SCL – P9.19 SCL

Code

This is a python example, I used  the cloud9 IDE

[codesyntax lang=”python”]

# 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(2)

# BMG160 address, 0x69(104)
# Select range register, 0x0F(15)
#		0x80(128)	Configure full scale range = 2000dps
bus.write_byte_data(0x69, 0x0F, 0x80)
# BMG160 address, 0x69(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(104)
# 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

[/codesyntax]

 

Output

Here are a couple of runs moving the sensor around

debian@beaglebone:/var/lib/cloud9/$ python BMG160.py
X-Axis of Rotation : 1
Y-Axis of Rotation : 4
Z-Axis of Rotation : 1
debian@beaglebone:/var/lib/cloud9/$ python BMG160.py
X-Axis of Rotation : -95
Y-Axis of Rotation : 50
Z-Axis of Rotation : 130
debian@beaglebone:/var/lib/cloud9/$ python BMG160.py
X-Axis of Rotation : -27
Y-Axis of Rotation : -33
Z-Axis of Rotation : -33

Link

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here