Introduction: Acceleration Measurement Using BMA250 and Particle Photon

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 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:

<p>#include<application.h> </p><p>#include<spark_wiring_i2c.h></p><p> // BMA250 I2C address is 0x18(24)</p><p>#define Addr 0x18</p><p>int xAccl = 0, yAccl =  0, zAccl = 0;</p><p>void setup()</p><p>{    </p><p>// Set variable    </p><p>Particle.variable("i2cdevice","BMA250");    </p><p>Particle.variable("xAccl",xAccl);   </p><p>Particle.variable("yAccl",yAccl);    </p><p>Particle.variable("zAccl",zAccl);        </p><p>// Initialize I2C communication as MASTER     </p><p>Wire.begin();    </p><p>// Initialize serial communication, set baud rate = 9600    </p><p>Serial.begin(9600);</p><p>// Start I2C Transmission    </p><p>Wire.beginTransmission(Addr);    </p><p>// Select range selection register    </p><p>Wire.write(0x0F);    </p><p>// Set range +/- 2g    </p><p>Wire.write(0x03);    </p><p>// Stop I2C Transmission    </p><p>Wire.endTransmission();</p><p>// Start I2C Transmission    </p><p>Wire.beginTransmission(Addr);    </p><p>// Select bandwidth register    </p><p>Wire.write(0x10);    </p><p>// Set bandwidth 7.81 Hz    </p><p>Wire.write(0x08);    </p><p>// Stop I2C Transmission    </p><p>Wire.endTransmission();    </p><p>delay(300);}void loop()</p><p>{    </p><p>unsigned int data[0];    </p><p>// Start I2C Transmission    </p><p>Wire.beginTransmission(Addr);    </p><p>// Select Data Registers (0x02 − 0x07)    </p><p>Wire.write(0x02);    </p><p>// Stop I2C Transmission    </p><p>Wire.endTransmission();        </p><p>// Request 6 bytes     </p><p>Wire.requestFrom(Addr, 6);        </p><p>// Read the six bytes     </p><p>// xAccl lsb, xAccl msb, yAccl lsb, yAccl msb, zAccl lsb, zAccl msb    </p><p>if(Wire.available() == 6)    </p><p>{        </p><p>data[0] =;        </p><p>data[1] =;        </p><p>data[2] =;        </p><p>data[3] =;        </p><p>data[4] =;        </p><p>data[5] =;    </p><p>}    </p><p>delay(300);        </p><p>// Convert the data to 10 bits    </p><p>xAccl = ((data[1] * 256) + (data[0] & 0xC0)) / 64;    </p><p>if (xAccl > 511)    </p><p>{        </p><p>xAccl -= 1024;    </p><p>}        </p><p>yAccl = ((data[3] * 256) + (data[2] & 0xC0)) / 64;    </p><p>if (yAccl > 511)    </p><p>{        </p><p>yAccl -= 1024;    </p><p>}        </p><p>zAccl = ((data[5] * 256) + (data[4] & 0xC0)) / 64;    </p><p>if (zAccl > 511)    </p><p>{        </p><p>zAccl -= 1024;    </p><p>}      </p><p>// Output data to dashboard    </p><p>Particle.publish("Acceleration in X-Axis :", String(xAccl));    </p><p>delay(1000);    </p><p>Particle.publish("Acceleration in Y-Axis :", String(yAccl));    </p><p>delay(1000);    </p><p>Particle.publish("Acceleration in Z-Axis :", String(zAccl));    </p><p>delay(1000);</p><p>}</p>

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.