Introduction: Acceleration Measurement Using BMA250 and Particle Photon

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 Particle photon.

Step 1: Hardware Required:

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

1. BMA250

2. Particle Photon

3. I2C Cable

4. I2C Shield for Particle Photon

Step 2: Hardware Hookup:

The hardware hookup section basically explains the wiring connections required between the sensor and the particle photon. 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: Code to Measure Acceleration:

Lets start with the particle code now.

While using the sensor module with the arduino, we include application.h and spark_wiring_i2c.h library. "application.h" and spark_wiring_i2c.h library contains the functions which facilitate the i2c communication between the sensor and the particle.

The entire particle code is given below for the convenience of the user:

#include<application.h>

#include<spark_wiring_i2c.h>

// BMA250 I2C address is 0x18(24)

#define Addr 0x18

int xAccl = 0, yAccl = 0, zAccl = 0;

void setup()

{

// Set variable

Particle.variable("i2cdevice","BMA250");

Particle.variable("xAccl",xAccl);

Particle.variable("yAccl",yAccl);

Particle.variable("zAccl",zAccl);

// Initialize I2C communication as MASTER

Wire.begin();

// Initialize serial communication, set baud rate = 9600

Serial.begin(9600);

// Start I2C Transmission

Wire.beginTransmission(Addr);

// Select range selection register

Wire.write(0x0F);

// Set range +/- 2g

Wire.write(0x03);

// Stop I2C Transmission

Wire.endTransmission();

// Start I2C Transmission

Wire.beginTransmission(Addr);

// Select bandwidth register

Wire.write(0x10);

// Set bandwidth 7.81 Hz

Wire.write(0x08);

// Stop I2C Transmission

Wire.endTransmission();

delay(300);} void loop()

{

unsigned int data[0];

// Start I2C Transmission

Wire.beginTransmission(Addr);

// Select Data Registers (0x02 − 0x07)

Wire.write(0x02);

// Stop I2C Transmission

Wire.endTransmission();

// Request 6 bytes

Wire.requestFrom(Addr, 6);

// Read the six bytes

// xAccl lsb, xAccl msb, yAccl lsb, yAccl msb, zAccl lsb, zAccl msb

if(Wire.available() == 6)

{

data[0] = Wire.read();

data[1] = Wire.read();

data[2] = Wire.read();

data[3] = Wire.read();

data[4] = Wire.read();

data[5] = Wire.read();

}

delay(300);

// 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 dashboard

Particle.publish("Acceleration in X-Axis :", String(xAccl));

delay(1000);

Particle.publish("Acceleration in Y-Axis :", String(yAccl));

delay(1000);

Particle.publish("Acceleration in Z-Axis :", String(zAccl));

delay(1000);

}

Particle.variable() function creates the variables to store the output of the sensor and Particle.publish() function displays the output on the dashboard of the site.

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

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.

Comments