Pages: [1] 2   Go Down
Author Topic: Acceleration Sensor BMA020  (Read 5726 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 303
Posts: 26354
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 303
Posts: 26354
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you have access to an oscilloscope?
Logged

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

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Worcester, MA
Offline Offline
God Member
*****
Karma: 3
Posts: 623
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: August 01, 2011, 07:45:57 pm by wayneft » Logged

I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Worcester, MA
Offline Offline
God Member
*****
Karma: 3
Posts: 623
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter

Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dear all,

isn't there anyone outside who got this sensor running?  smiley-confuse

BR,
Barni
Logged

Worcester, MA
Offline Offline
God Member
*****
Karma: 3
Posts: 623
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter

Cologne, ger
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino i <3 u
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-sad

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

Cologne, ger
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino i <3 u
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-wink  )

cheers

dom
Logged

Cologne, ger
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino i <3 u
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Worcester, MA
Offline Offline
God Member
*****
Karma: 3
Posts: 623
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter

Pages: [1] 2   Go Up
Jump to: