Problems to get data from Bosch BMA020

Hi there,

I'am just trying to get the acceleration data's from my BMA020. I want to receive the data like in this table:
http://www.mikrocontroller.net/articles/BMA020#Speicheraufteilung
from 02h to 07h. But I have not too much experience with the arduino and the I²C bus.
Maybe someone can help me to handle this little project.
I think I have connected the wires correct, but my code is wrong.

Here it is:

#include <Wire.h>

byte data[6];
boolean ack = 0;
int BMA_x;

void setup()
{
Wire.begin();
Serial.begin(9600);
Serial.println("- Läuft -");
delay (500);
}

void loop ()
{

Wire.beginTransmission (0x38);
Wire.send(0b0);
ack = Wire.receive();
Wire.send(0x02);
ack = Wire.receive();
Wire.endTransmission();

Wire.requestFrom (0x38,6);
Wire.send(0x02);

for (int i=0; i<6 ;i++){

data*=Wire.receive();*

  • }*

  • Serial.print("data_0:");*

  • Serial.println(data[0], BIN ); *

  • Serial.print("data_1:");*

  • Serial.println(data[1], BIN );*

  • Serial.print("data_2:");*

  • Serial.println(data[2], BIN);*

  • Serial.print("data_3:");*

  • Serial.println(data[3], BIN); *

  • Serial.print("data_4:");*

  • Serial.println(data[4], BIN);*

  • Serial.print("data_5:");*

  • Serial.println(data[5], BIN);*

  • Serial.println("");*

  • delay (1500);*

}[/quote]
I receive from the serial:
> - Läuft -
> data_0:10
> data_1:10010
> data_2:1000001
> data_3:101
> data_4:1000001
> data_5:11111000
>
> data_0:10
> data_1:10010
> data_2:10000001
> data_3:101
> data_4:1
> data_5:11111000
>
> data_0:10
> data_1:10010
> data_2:1000001
> data_3:101
> data_4:11000001
> data_5:11110111
>
> data_0:10
> data_1:10010
> data_2:11000001
> data_3:11
> data_4:1
> data_5:10000
data 2, 3, 4, 5, are looking good (they change when I move the sensor), but data at 0 and 1 don't change.
I think I can handle the calculating to decimal when I have got the right binary numbers.
Thank you for your help!

Wire.send(0b0); => Wire.send(0xb0); typo ??

Serial.print("data_0:");
Serial.println(data[0], DEC); // thats decimal

Serial.print("data_0:");
Serial.println(data[0], HEX); // or hexadecimal

I've made my code according to the datasheet of the BMA (see on page 35 in the attached file)

Wire.beginTransmission (0x38); // (=slave adress 0111000)
Wire.send(0b0); // then RW binary 0 (=0b0)
ack = Wire.receive(); // now I want to receive the ACK bit

The following code differs from the shematic in the datasheet, but I have tried It several times and with this code I receive the mentioned answers from the BMA.

datasheetBMA020.pdf (578 KB)

Hello Freddy,

try to use the attached code which seems to work properly. It is a collection of different sources: Put the different axes of the little board in a vertical position with arrow up and arrow down - one after the other - and you should get a value of ~250 + or - on the terminal. This is just the gravitation for the default setting of +/- 2g.

Bye
Folker

bma020.pde (1.14 KB)

Hi Folker,

many thanks for your help, but I have already solved this problem.
Now I have uploaded your program on my arduino. Then I've compared the result of your's with the conclusion of mine and it is still the same :slight_smile:

So we have the evidence, the data are correct.

regards,
Freddy