Acceleration Sensor BMA020

HI @ all,

I try to make my BMA020 working on my Arduino. I think all wires are conected properly.
Here is the sketch i have written until now:

#include <Wire.h>


int val = 0;

void setup() {
    Wire.begin();
        
    Serial.begin(9600);
    Serial.print (val);
}
 
void loop() {
  Wire.beginTransmission(0x70);
  Wire.send(0x02);
  //Wire.endTransmission();
  Wire.requestFrom(0x71, 6);
  if (Wire.available()) {
     val = Wire.receive();
   }
  Wire.endTransmission();
  
  Serial.println (val, BIN);
  
  delay(25);
    
 }

The problem is i only get zeros out. Can anybody help me to find out the problem? Here is the Link for the DAtaSheet of the BMA020:

http://dkc3.digikey.com/PDF/Marketing/Bosch_BMA020.pdf

Did you remember that the I2C / TWI pins are analogue pins?
Did you use external pullups?

I don´t use external pullups. I use the Arduino DUemilanove-Board directly to cennect with the BMA020.
Do you mean this doesn´t work? Can you give me some advice how to get this Sensor working?

Do you have access to an oscilloscope?

no i have no acces to an oszilloscope. But i was wrong, the arduino board has external pullups. I think all cables are conectet correctly. The problem must be in the sketch.
The best will be if someone can give me a correct sketch which works with my combination of arduino board and BMA020.

First off that IC is not a 5 volt tolerant device so you need to connect a level translator to bring the IO levels down to the supply voltage you're using on VDDIO.

Secondly, when using I2C you need to use the 7bit address for the IC, which in this case is 0x38. Next you need to uncomment the first Wire.endTransmission, because you need it, and then delete the second Wire.endTransmission() because you don't need it.

Also try reading the value from the Chip ID register, address 0x00, and it should return a 2, that way you know for sure you're communicating with the device.

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