Go Down

Topic: Acceleration Sensor BMA020 (Read 6424 times) previous topic - next topic

Norbert

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:

Code: [Select]

#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

AWOL

Did you remember that the I2C / TWI pins are analogue pins?
Did you use external pullups?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Norbert

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?

AWOL

Do you have access to an oscilloscope?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Norbert

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.

wayneft

#5
Aug 02, 2011, 02:37 am Last Edit: Aug 02, 2011, 02:45 am by wayneft Reason: 1
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.
I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter

Norbert

Thank you wayneft for your information. The communication works now.
I changed my sketch to the following one:
Code: [Select]
#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.

wayneft

Quote
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. 
I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter

Barni

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

Barni

Dear all,

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

BR,
Barni

wayneft

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

Checkout my Open Source GPS Tracker on Kickstarter

domj

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:
http://static.rcgroups.net/forums/attachments/3/0/8/5/3/6/a3730195-245-BMA020%20to%20Arduino%20V1.jpg?d=1295131257

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 :(

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:

Code: [Select]

/*
*  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:

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


Thanks!!!


[/size]

domj

PS:

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

http://tronixstuff.wordpress.com/2010/10/20/tutorial-arduino-and-the-i2c-bus/

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

cheers

dom

domj

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.

wayneft

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?
I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter

Go Up