Home Code Arduino and BMA250 acceleration sensor

Arduino and BMA250 acceleration sensor

by shedboy71
[lebox id="1"]

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

Parameter Technical data
Digital resolution 10 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/outputs SPI & 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 package 2 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

 

Arduino Module
3.3v Vcc
Gnd Gnd
A4 SDA
A5 SCL

 

Code

[codesyntax lang=”cpp”]

// Distributed with a free-will license.
// Use it any way you want, profit or free, provided it fits in the licenses of its associated works.
// BMA250
// This code is designed to work with the BMA250_I2CS I2C Mini Module available from ControlEverything.com.
// https://www.controleverything.com/content/Accelorometer?sku=BMA250_I2CS#tabs-0-product_tabset-2

#include <Wire.h>

// BMA250 I2C address is 0x18(24)
#define Addr 0x18

void setup()
{
  // Initialise I2C communication as MASTER
  Wire.begin();
  // Initialise 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
  float xAccl = ((data[1] * 256.0) + (data[0] & 0xC0)) / 64;
  if (xAccl > 511)
  {
    xAccl -= 1024;
  }
  float yAccl = ((data[3] * 256.0) + (data[2] & 0xC0)) / 64;
  if (yAccl > 511)
  {
    yAccl -= 1024;
  }
  float zAccl = ((data[5] * 256.0) + (data[4] & 0xC0)) / 64;
  if (zAccl > 511)
  {
    zAccl -= 1024;
  }
  
  // Output data to the serial monitor
  Serial.print("Acceleration in X-Axis :");
  Serial.println(xAccl);
  Serial.print("Acceleration in Y-Axis :");
  Serial.println(yAccl);
  Serial.print("Acceleration in Z-Axis :");
  Serial.println(zAccl) ; 
}

[/codesyntax]

Link

Share
[lebox id="2"]

You may also like

Leave a Comment