Acceleration Sensor BMA020

Thank you wayneft for your information. The communication works now.
I changed my sketch to the following one:

#include <Wire.h>

#define ACCELEROMETER 0x38 

#define X_OUT1	   0x02 
#define X_OUT2	   0x03
#define Y_OUT1	   0x04 
#define Y_OUT2	   0x05
#define Z_OUT1	   0x06 
#define Z_OUT2	   0x07


void setup() {
    Wire.begin();
    Serial.begin(9600);
}


void loop() {
    Serial.print("X: ");
    Serial.print((unsigned int)accRead(X_OUT1), BIN);
    Serial.print ("      ");
    Serial.print((unsigned int)accRead(X_OUT2), BIN);
    Serial.println();  
    Serial.print("Y: ");
    Serial.print((unsigned int)accRead(Y_OUT1), BIN);
    Serial.print ("      ");
    Serial.print((unsigned int)accRead(Y_OUT2), BIN);
    Serial.println();  
    Serial.print("Z: ");
    Serial.print((unsigned int)accRead(Z_OUT1), BIN);
    Serial.print ("      ");
    Serial.print((unsigned int)accRead(Z_OUT2), BIN); 
    Serial.println();
    delay(100);
}

byte accRead(byte address){
    byte val = 0x00;
    Wire.beginTransmission(ACCELEROMETER);
    Wire.send(address);
    Wire.endTransmission();
    Wire.requestFrom(ACCELEROMETER, 1);
    
	  val = Wire.receive();
    
    Wire.endTransmission();
    return val;
}

This sketch works correctly, the only question i have is, why is the adress 0X38 and not 0x70 as described in the datasheet?

Thank you very much.

the only question i have is, why is the adress 0X38 and not 0x70 as described in the datasheet?

It's actually both. The 8 bit address is 0x70 for a write operation and 0x71 for a read operation. Since the Arduino knows that bit 0 will toggle between 0 and 1 it has you only enter the 7 bit address (8 bit shifted to the right by one) for all I2C devices.

Hello Norbert,

I try to run the sensor with your code, but I have some problems translating the output to decimal numbers. Can you please explain what you do to read the values?

The communication is working. If i read the address 0x00 it returns a 2.

Thanks

Dear all,

isn't there anyone outside who got this sensor running? :~

BR,
Barni

Post your code and tell us what problem you're having.

hey everybody,

i spend the last days getting to learn arduino (uno), made some things work and now im trying to learn i2c with the wire library.

my goal is to read the acceleration values from the bosch bma020, so exactly what has been discussed in this topic - it just doesnt want to work!

i wired the ardunio correctly to the bma as shown here:

its all connected to 5v which should be ok since the IC has internal converter.

i attached pullups to the data and clock line vs vcc (tried 2k and 7.5 k) - nothing helps.

all i get back from the i2c bus are zeros. it stops giving me zeros when i disconnect vcc from the ciruit.

i took the sourcecode from above an modified it to see, if the 0x00 adress gives back a 2 - it doesnt :frowning:

it would be great if somebody could take a look at my code an tell me, if i did something obviously wrong. if not the ic has to be broken...

here is my code:

/*
 *  Arduino analog input 5 - I2C SCL
 *  Arduino analog input 4 - I2C SDA
*/

#include <Wire.h>

#define ACCELEROMETER 0x38

#define Test_OUT   0x00
#define X_OUT1	   0x02
#define X_OUT2	   0x03
#define Y_OUT1	   0x04 
#define Y_OUT2	   0x05
#define Z_OUT1	   0x06 
#define Z_OUT2	   0x07


void setup() {

    Wire.begin();
    Serial.begin(9600);
}


void loop() {

    Serial.println();  
    Serial.print("Signal on Device Address ");
    Serial.print(ACCELEROMETER, HEX);
    Serial.print(" in Register No ");    
    Serial.print(Test_OUT, HEX);
    Serial.print(" is: ");       
    Serial.print((unsigned int)accRead(Test_OUT), BIN);
    Serial.println();  
/*    Serial.print("X: ");
    Serial.print((unsigned int)accRead(X_OUT1), BIN);    
    Serial.print ("      ");
    Serial.print((unsigned int)accRead(X_OUT2), BIN);
    Serial.println();  
    Serial.print("Y: ");
    Serial.print((unsigned int)accRead(Y_OUT1), BIN);
    Serial.print ("      ");
    Serial.print((unsigned int)accRead(Y_OUT2), BIN);
    Serial.println();  
    Serial.print("Z: ");
    Serial.print((unsigned int)accRead(Z_OUT1), BIN);
    Serial.print ("      ");
    Serial.print((unsigned int)accRead(Z_OUT2), BIN); 
    Serial.println();
*/    
    delay(500);
}

byte accRead(byte address){
    byte val = 0x00;
    Wire.beginTransmission(ACCELEROMETER);
         
    Wire.send(address);

    Wire.endTransmission();
    
    Wire.requestFrom(ACCELEROMETER, 1);
 
    val = Wire.receive();
 
    return val;
}

here is what comes from the serial montior:

Signal on Device Address 38 in Register No 0 is: 0

Thanks!!!

PS:

i removed the last Wire.endTransmission() because this tutorial says it is not neccesary:

(which is a really good tutorial for newbies like me :wink: )

cheers

dom

PPS:

i have to correct myself - Of Course the ic itself can NOT handle 5v - however i use the IC on a breakout board deliverd/made by elv which has the level translator on board.

Well if you're confident you have it wired up correctly and the above code is not returning a 2 then there may be something wrong with the sensor. I can see that your link has additional pins on the breakout board. Do you have a link to that schematic by any chance?

hey thanks for the quick answer.

i made a quick drawing of the circuit how i connected arduino and the bma020, you can see an edit it here:

http://www.dz863.com/drawsch_1353.html
(i attached it as jpg as well).

for the bma020 on the board made by elv, i also attached an image that shows the layout of the board.

thanks for your help!!

BMA020 on Arduino.jpg

woops, forgot the +5v in the circuit, its of course on the line with the two pullup-resistors :wink:

Ok... I wrote a little programm to run through all possible i2c adresses und requesting de 0 register... None of them returns a 2(what the bma020) is supposed to do....so it seems that the bma is not communicating on the bus at all.

Is there mistake in the wiring or the code i posted above? Its really starting to drive me crazy ,)

Try downloading the sketch here (I2CScanner: Arduino as I2C bus scanner – todbot blog) as it will tell you if it's communicating with your device. If not then recheck your wiring.

well... the sketch works fine, the i2c not... no adresses found :frowning:

i checked port a4 and a5, they are both ok and give 5v on digital write.

i check the power to the bma020 an every wire transmitts the voltage as its supposed to.

so in my opinion there are two possible answers:

  1. my bma020 ist broken
  2. there is a mistake in my circuit.

for the second point i made the schematic of my circuit here:

http://www.dz863.com/drawsch_1354.html

and uploaded a photo of the board wiring...(please dont laugh :wink: )

it would be great if you could take a look at those two and verify they are ok... then i can porbabaly buy a new bma020...

I have a feeling your problem may be the solder jumper J1 on the board. Looking over the schematic it looks like J1 should be shorted to provide logic level translation on the I2C lines. Looking at the picture of your board it looks like the jumper is open. Is there any documentation for the board that specifies if the jumper should be open or shorted?

hey wayneft,

the documentation / manufactureres website says that you close J1 when you are using exactly 2.5V.
which makes sense because then youve got 2.5V on Upullup. if you use 5V like me it should be left open.
which makes sense as well, because then the 2.5V come from the "Linearregler (2,5V)" from the upper right corner in the schematic...

yesterday i bought a wii mote plus with some gyros in it which communicates over i2c as well. ill let you know if this works :wink:

if not, probably there is something with my arduino?!

cheers!

dom

ok, i got the wmplus sensor on my arduino and everything works finde on the i2c bus, giving me yaw, roll etc...

so it really seems to be a broken bma020....

thanks everybody for your great help, i learned a lot - ill get a new bm020 and let you know if it works!

cheers!

finally!!!

today my new bma 020 arrived and this time everything works, i can scan the address on i2c an receive a lot of 1 and 0 using the script above...

next step will be to make real numbers out of it...

sorry for bothering you with my hardware issues and thanks again for the great help!

dom

Glad to hear it!