loading

BMA250 is a small, thin, ultralow power, 3-axis accelerometer with high resolution (13-bit) measurement at up to ±16 g. Digital output data is formatted as 16-bit twos complement and is accessible through I2C digital interface. Itmeasures the static acceleration of gravity in tilt-sensing applications, as well as dynamic acceleration resulting from motion or shock. Its high resolution (3.9 mg/LSB) enables measurement of inclination changes less than 1.0°.

In this tutorial we are going to measure the acceleration in all the three perpendicular axes using BMA250 and Raspberry Pi. The sensor has been programmed in python language.

Step 1: Hardware Required:

The materials that we need for accomplishing our goal includes the following hardware components:

1. BMA250

2. Raspberry Pi

3. I2C Cable

4. I2C Shield for Raspberry Pi

5. Ethernet Cable

Step 2: Hardware Hookup:

The hardware hookup section basically explains the wiring connections required between the sensor and the raspberry pi. Ensuring correct connections is the basic necessity while working on any system for the desired output. So, the requisite connections are as follows:

The BMA250 will work over I2C . Here is the example wiring diagram, demonstrating how to wire up each interface of the sensor.

Out-of-the-box, the board is configured for an I2C interface, as such we recommend using this hookup if you’re otherwise agnostic. All you need is four wires!

Only four connections are required Vcc, Gnd, SCL and SDA pins and these are connected with the help of I2C cable.

These connections are demonstrated in the pictures above.

Step 3: Python Code for Acceleration Measurement:

The advantage of using raspberry pi is, that is provides you the flexibility of the programming language in which you want to program the board in order to interface the sensor with it. Harnessing this advantage of this board, we are demonstrating here its programming in the python. Python is one of the easiest programming languages with easiest syntax. The python code for BMA250 can be downloaded from our github community that is Control Everything Community.

As well as for the ease of the users, we are explaining the code here also:

As the first step of coding you need to download the SMBus library in case of python, because this library supports the functions used in the code. So, to download the library you can visit the following link:

https://pypi.python.org/pypi/smbus-cffi/0.5.1

You can copy the working code from here also:

import smbus

import time

# Get I2C busbus = smbus.SMBus(1)

# BMA250 address, 0x18(24)

# Select range selection register, 0x0F(15)

# 0x03(03) Set range = +/-2gbus.write_byte_data(0x18, 0x0F, 0x03)

# BMA250 address, 0x18(24)# Select bandwidth register, 0x10(16)

# 0x08(08) Bandwidth = 7.81 Hzbus.write_byte_data(0x18, 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(0x18, 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

The code is executed using the following command:

$> python BMA250.py

The output of the sensor is shown in the picture above for the reference of the user.

Step 4: Applications:

Accelerometers like BMA250 mostly find its application in the games and display profile switching. This sensor module is also employed in the advanced power management system for mobile applications. BMA250 is a triaxial digital acceleration sensor which is incorporated with an intelligent on-chip motion triggered interrupt controller.