Acceleration Measurement Using BMA250 and Raspberry Pi

Introduction: Acceleration Measurement Using BMA250 and Raspberry Pi

About: We are a group of makers. We work in IoT, IOS app, android app, embedded design, sensor design, raspberry pi, arduino, beaglebone, particle electron, particle photon, Bluetooth.

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 Dcube Store

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:

You can copy the working code from here also:

<p>import smbus</p><p>import time</p><p># Get I2C busbus = smbus.SMBus(1)</p><p># BMA250 address, 0x18(24)</p><p># Select range selection register, 0x0F(15)</p><p>#		0x03(03)	Set range = +/-2gbus.write_byte_data(0x18, 0x0F, 0x03)</p><p># BMA250 address, 0x18(24)# Select bandwidth register, 0x10(16)</p><p>#		0x08(08)	Bandwidth = 7.81 Hzbus.write_byte_data(0x18, 0x10, 0x08)</p><p>time.sleep(0.5)
</p><p># BMA250 address, 0x18(24)</p><p># Read data back from 0x02(02), 6 bytes</p><p># X-Axis LSB, X-Axis MSB, Y-Axis LSB, Y-Axis MSB, Z-Axis LSB, Z-Axis MSB</p><p>data = bus.read_i2c_block_data(0x18, 0x02, 6)
# Convert the data to 10 bits</p><p>xAccl = (data[1] * 256 + (data[0] & 0xC0)) / 64</p><p>if xAccl > 511 :	</p><p>xAccl -= 1024
yAccl = (data[3] * 256 + (data[2] & 0xC0)) / 64</p><p>if yAccl > 511 :	</p><p>yAccl -= 1024
zAccl = (data[5] * 256 + (data[4] & 0xC0)) / 64</p><p>if zAccl > 511 :	</p><p>zAccl -= 1024</p><p># Output data to screen</p><p>print "Acceleration in X-Axis : %d" % xAccl</p><p>print "Acceleration in Y-Axis : %d" % yAccl</p><p>print "Acceleration in Z-Axis : %d" % zAccl

The code is executed using the following command:

$> python
gt; python

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.

Be the First to Share


    • Block Code Contest

      Block Code Contest
    • Game Design: Student Design Challenge

      Game Design: Student Design Challenge
    • Make it Glow Contest

      Make it Glow Contest