Beaglebone and BMA250 acceleration sensor example in Python

The BMA250E is a triaxial, low-g acceleration sensor with digital output for consumer applications.

It allows measurements of acceleration in three perpendicular axes. An evaluation circuitry (ASIC) converts the output of a micromechanical acceleration-sensing structure (MEMS) that works according to the differential capacitance principle.Package and interfaces of the BMA250E have been defined to match a multitude of hardware requirements.

Since the sensor features an ultra-small footprint and a flat package it is ingeniously suited for mobile applications.

The BMA250E offers a variable VDDIO voltage range from 1.2V to 3.6V and can be programmed to optimize functionality, performance and power consumption in customer specific applications.

A typical module

technical Information

Parameter Technical data
Digital resolution 10 bit
Resolution
(in ±2g range)
3.9 mg
Measurement ranges
(programmable)
±2 g, ±4 g, ±8 g, ±16 g
Sensitivity (calibrated) ±2 g: 256 LSB/g
±4 g: 128 LSB/g
±8 g: 64 LSB/g
±16 g: 32 LSB/g
Zero-g offset (typ., over life-time) ±80 mg
Noise density (typ.) 400 μg/√Hz
Bandwidths (programmable) 1000 Hz … 8 Hz
Digital inputs/outputs SPI & I²C, 2x digital interrupt pins
Supply voltage (VDD) 1.62 V … 3.6 V
I/0 supply voltage (VDDIO) 1.2 V … 3.6 V
Temperature range -40 … +85°C
Current consumption
– full operation
– low-power mode
130 μA (@ 2 kHz data rate)
6.5 μA (@ 40 Hz data rate)
LGA package 2 x 2 x 0.95 mm³
Interrupts – Data-ready (e. g. for processor synchronization)
– Any-motion (slope) detection (e. g. for wake-up)
– Tap sensing (e. g. for tap-sensitive UI control)
– Orientation change recognition (e. g. for portrait/landscape switching)
– Flat detection (e. g. for position sensitive switching)
– Low-g / high-g detection (e. g. for shock and free-fall detection)
– No-motion (e.g. for power saving)

 

Parts Required

Name Link
Beaglebone BeagleBone Black TI AM335x Cortex-A8 development BB-Black Rev.C
BMA250 BMA250E Three-Axis Accelerometer Sensor Module
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

[codesyntax lang=”python”]

import smbus
import time

# Get I2C bus
bus = smbus.SMBus(2)

# BMA250 address, 0x18(24)
# Select range selection register, 0x0F(15)
#		0x03(03)	Set range = +/-2g
bus.write_byte_data(0x19, 0x0F, 0x03)
# BMA250 address, 0x18(24)
# Select bandwidth register, 0x10(16)
#		0x08(08)	Bandwidth = 7.81 Hz
bus.write_byte_data(0x19, 0x10, 0x08)

time.sleep(0.5)

# BMA250 address, 0x18(24)
# 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(0x19, 0x02, 6)

# Convert the data to 10 bits
xAccl = (data[1] * 256 + (data[0] & 0xC0)) / 64
if xAccl > 511 :
	xAccl -= 1024

yAccl = (data[3] * 256 + (data[2] & 0xC0)) / 64
if yAccl > 511 :
	yAccl -= 1024

zAccl = (data[5] * 256 + (data[4] & 0xC0)) / 64
if zAccl > 511 :
	zAccl -= 1024

# Output data to screen
print "Acceleration in X-Axis : %d" % xAccl
print "Acceleration in Y-Axis : %d" % yAccl
print "Acceleration in Z-Axis : %d" % zAccl

[/codesyntax]

Output

You can see a few runs, moving the sensor below

debian@beaglebone:/var/lib/cloud9/$ python bma250.py
Acceleration in X-Axis : 143
Acceleration in Y-Axis : 192
Acceleration in Z-Axis : 99
debian@beaglebone:/var/lib/cloud9/$ python bma250.py
Acceleration in X-Axis : 143
Acceleration in Y-Axis : 188
Acceleration in Z-Axis : 105
debian@beaglebone:/var/lib/cloud9/$ python bma250.py
Acceleration in X-Axis : 158
Acceleration in Y-Axis : 176
Acceleration in Z-Axis : 39
debian@beaglebone:/var/lib/cloud9/$ python bma250.py
Acceleration in X-Axis : 152
Acceleration in Y-Axis : 199
Acceleration in Z-Axis : -41

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here