RAspberry Pi and BMA250 acceleration sensor example

The BMA250E is an advanced, ultra-small, triaxial, low-g acceleration sensor with digital interfaces, aiming for low-power consumer electronics applications. Featuring 10 bit digital resolution, the BMA250E allows low-noise measurement of accelerations in 3 perpendicular axes.

A typical module

technical Information

ParameterTechnical data
Digital resolution10 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/outputsSPI & 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 package2 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)

 

Connection

Raspberry PIModule
3.3vVcc
GndGnd
SDASDA
SCLSCL

 

Code

import smbus
import time
# Get I2C bus
bus = smbus.SMBus(1)
# 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

Output

Link

CJMCU-250E BMA250E low g three axis accelerometer sensor module MEMS