BMA180 Three-Axis Accelerometer Demo Test with Arduino

Posted by: Chao Category: Sensing and Actuating Tags: , , , , , , , , Comments: 8

BMA180 Three-Axis Accelerometer Demo Test with Arduino

They are a lot of postures sensors are available on our sites, such as ITG3200、ADXL345、ADXL335、HMC5883L、MPU6050、BMP085、MMA7361, and these ICs are more used on flying control, now we did some simple test with the Bosch BMA180 module.

Bosch BMA180 three axis digital accelerometer module has great performance than many others, it provides 14 bits digital output via a four-wires SPI jack or two-wires IIC (I2C) jack. Testing range can be set to ±1g, 1.5g, 2g, 4g, 8g, or 16g.

Further functions such as programmerable wake up, high or low g detection, water detection, slope detection, self-detection. This sensor has two operation modes: low filter, low power. BMA180 use a very tiny 3x3mm 12 pins LGA package, and it can works between 1.62 till 3.6V VDD and 1.2V till 3.6V VDDIO power, normally it only consume 650uA in standard mode.

Application

BMA 180 is a high performance three axis digital accelerometer sensor, aiming at low power consumer market.

Due to the high precision, it widely uses in Sen-Ses, motion, shock and vibration in cell phone, PDA and computer, human and machin e interface, face recognition, virtual reality or game control.

Please read more information on our BMA180 product page here, and check the datasheet in the product page too.

Pin Map of BMA 180

Compare BMA 180 with ADXL 345

Wiring

Wire the BMA180 module to Arduino

Demo code

after the wiring, now we can put the following demo codes into your arduino.

[c]
#include

void setup()
{
Serial.begin(115200);
Wire.begin();

Serial.println("Demo started, initializing sensors");

AccelerometerInit();
// GyroInit();

Serial.println("Sensors have been initialized");
}

void AccelerometerInit()
{
Wire.beginTransmission(0x40); // address of the accelerometer
// reset the accelerometer
Wire.send(0x10);
Wire.send(0xB6);
Wire.endTransmission();
delay(10);

Wire.beginTransmission(0x40); // address of the accelerometer
// low pass filter, range settings
Wire.send(0x0D);
Wire.send(0x10);
Wire.endTransmission();

Wire.beginTransmission(0x40); // address of the accelerometer
Wire.send(0x20); // read from here
Wire.endTransmission();
Wire.requestFrom(0x40, 1);
byte data = Wire.receive();
Wire.beginTransmission(0x40); // address of the accelerometer
Wire.send(0x20);
Wire.send(data & 0x0F); // low pass filter to 10 Hz
Wire.endTransmission();

Wire.beginTransmission(0x40); // address of the accelerometer
Wire.send(0x35); // read from here
Wire.endTransmission();
Wire.requestFrom(0x40, 1);
data = Wire.receive();
Wire.beginTransmission(0x40); // address of the accelerometer
Wire.send(0x35);
Wire.send((data & 0xF1) | 0x04); // range +/- 2g
Wire.endTransmission();
}

void AccelerometerRead()
{
Wire.beginTransmission(0x40); // address of the accelerometer
Wire.send(0x02); // set read pointer to data
Wire.endTransmission();
Wire.requestFrom(0x40, 6);

// read in the 3 axis data, each one is 16 bits
// print the data to terminal
Serial.print("Accelerometer: X = ");
short data = Wire.receive();
data += Wire.receive() << 8;
Serial.print(data);
Serial.print(" , Y = ");
data = Wire.receive();
data += Wire.receive() << 8;
Serial.print(data);
Serial.print(" , Z = ");
data = Wire.receive();
data += Wire.receive() << 8;
Serial.print(data);
Serial.println();
}

/*void GyroInit()
{
Wire.beginTransmission(0x69); // address of the gyro
// reset the gyro
Wire.send(0x3E);
Wire.send(0x80);
Wire.endTransmission();

Wire.beginTransmission(0x69); // address of the gyro
// low pass filter 10 Hz
Wire.send(0x16);
Wire.send(0x1D);
Wire.endTransmission();

Wire.beginTransmission(0x69); // address of the gyro
// use internal oscillator
Wire.send(0x3E);
Wire.send(0x01);
Wire.endTransmission();
}

void GyroRead()
{
Wire.beginTransmission(0x69); // address of the gyro
Wire.send(0x1D); // set read pointer
Wire.endTransmission();

Wire.requestFrom(0x69, 6);

// read in 3 axis of data, 16 bits each, print to terminal
short data = Wire.receive() << 8;
data += Wire.receive();
Serial.print("Gyro: X = ");
Serial.print(data);
Serial.print(" , Y = ");
data = Wire.receive() << 8;
data += Wire.receive();
Serial.print(data);
Serial.print(" , Z = ");
data = Wire.receive() << 8;
data += Wire.receive();
Serial.print(data);
Serial.println();
} */

void loop()
{
AccelerometerRead();
// GyroRead();

delay(500); // slow down output
}
[/c]

From the arduino monitor, we can see the output from the sensor looks like this.

Share this post

Comments (8)

  • ml Reply

    this code dont work arduino + html code.please check the code

    July 17, 2012 at 8:10 pm
  • tevada Reply

    It error
    “‘amp’ was not declared in this scope”

    on this line
    “Wire.send(data & 0x0F); // low pass filter to 10 Hz”

    September 25, 2012 at 7:59 am
    • Chao Reply

      Hi Tevada,

      Try both Arduino 22 version and Arduino 1.0 version, it could be a problem of the IIC library.

      September 25, 2012 at 9:49 am
  • Tevada Reply

    I have used both Arduino 0.22 and 1.0, it can’t work.
    error
    “‘amp’ was not declared in this scope”

    September 25, 2012 at 7:03 pm
  • Aletzandre Reply

    Got the same prob, and I’ve got the latest Arduino version. =/

    sketch_oct15a.cpp: In function ‘void AccelerometerInit()’:
    sketch_oct15a:37: error: ‘amp’ was not declared in this scope

    October 15, 2012 at 11:24 pm
  • En Reply

    #include

    void setup()
    {
    Serial.begin(115200);
    Wire.begin();

    Serial.println(“Demo started, initializing sensors”);

    AccelerometerInit();
    // GyroInit();

    Serial.println(“Sensors have been initialized”);
    }

    void AccelerometerInit()
    {
    Wire.beginTransmission(0x40); // address of the accelerometer
    // reset the accelerometer
    Wire.write(0x10);
    Wire.write(0xB6);
    Wire.endTransmission();
    delay(10);

    Wire.beginTransmission(0x40); // address of the accelerometer
    // low pass filter, range settings
    Wire.write(0x0D);
    Wire.write(0x10);
    Wire.endTransmission();

    Wire.beginTransmission(0x40); // address of the accelerometer
    Wire.write(0x20); // read from here
    Wire.endTransmission();
    Wire.requestFrom(0x40, 1);
    byte data = Wire.read();
    Wire.beginTransmission(0x40); // address of the accelerometer
    Wire.write(0x20);
    Wire.write(data & 0x0F); // low pass filter to 10 Hz
    Wire.endTransmission();

    Wire.beginTransmission(0x40); // address of the accelerometer
    Wire.write(0x35); // read from here
    Wire.endTransmission();
    Wire.requestFrom(0x40, 1);
    data = Wire.read();
    Wire.beginTransmission(0x40); // address of the accelerometer
    Wire.write(0x35);
    Wire.write((data & 0xF1) | 0x04); // range +/- 2g
    Wire.endTransmission();
    }

    void AccelerometerRead()
    {
    Wire.beginTransmission(0x40); // address of the accelerometer
    Wire.write(0x02); // set read pointer to data
    Wire.endTransmission();
    Wire.requestFrom(0x40, 6);

    // read in the 3 axis data, each one is 16 bits
    // print the data to terminal
    Serial.print(“Accelerometer: X = “);
    short data = Wire.read();
    data += Wire.read() << 8;
    Serial.print(data);
    Serial.print(" , Y = ");
    data = Wire.read();
    data += Wire.read() << 8;
    Serial.print(data);
    Serial.print(" , Z = ");
    data = Wire.read();
    data += Wire.read() << 8;
    Serial.print(data);
    Serial.println();
    }

    /*void GyroInit()
    {
    Wire.beginTransmission(0x69); // address of the gyro
    // reset the gyro
    Wire.send(0x3E);
    Wire.send(0x80);
    Wire.endTransmission();

    Wire.beginTransmission(0x69); // address of the gyro
    // low pass filter 10 Hz
    Wire.send(0x16);
    Wire.send(0x1D);
    Wire.endTransmission();

    Wire.beginTransmission(0x69); // address of the gyro
    // use internal oscillator
    Wire.send(0x3E);
    Wire.send(0x01);
    Wire.endTransmission();
    }

    void GyroRead()
    {
    Wire.beginTransmission(0x69); // address of the gyro
    Wire.send(0x1D); // set read pointer
    Wire.endTransmission();

    Wire.requestFrom(0x69, 6);

    // read in 3 axis of data, 16 bits each, print to terminal
    short data = Wire.receive() << 8;
    data += Wire.receive();
    Serial.print("Gyro: X = ");
    Serial.print(data);
    Serial.print(" , Y = ");
    data = Wire.receive() << 8;
    data += Wire.receive();
    Serial.print(data);
    Serial.print(" , Z = ");
    data = Wire.receive() << 8;
    data += Wire.receive();
    Serial.print(data);
    Serial.println();
    } */

    void loop()
    {
    AccelerometerRead();
    // GyroRead();

    delay(500); // slow down output
    }

    October 19, 2012 at 4:53 am
  • Ian Day Reply

    The problem here is with the ‘curley’ speech marks on the comments sent to the Serial Monitor.

    Make these the normal quotation marks i.e. ” ” and the programme will compile with no issue.

    Ian.

    December 29, 2014 at 9:18 pm
  • poulbran Reply

    Can you believe that guys used these and awesome PID loops on the early quadcopters.

    September 12, 2016 at 8:15 am

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.