Arduino MEAG 2560 with BMA020

Hello, I know that there is a search to get infos about this, but I get no answer about my question. I have connected a BMA020 to my Arduino Mega 2560:

But SCL is 21 and SDA is 20 on the MEGA and I connected not to D12, I connected to 5V.

With the sketch

#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.write(address);
    Wire.endTransmission();
    Wire.requestFrom(ACCELEROMETER, 1);
    
	  val = Wire.read();
    
    Wire.endTransmission();
    return val;
}

I got this code from an other topic here. The BMA020 do something, but I think it is not right. The output from the sketch is this:

Y: 1      11111000
Z: 1000001      110110
X: 1000001      111
Y: 1000001      11111000
Z: 1000001      110110
X: 1000001      111
Y: 10000001      11111000
Z: 1      110110
X: 10000001      111
Y: 10000001      11111000
Z: 1      110110
X: 10000001      111
Y: 1000001      11111000
Z: 1000001      110110
X: 10000001      111
Y: 1000001      11111000
Z: 1000001      110110
X: 10000001      111
Y: 1000001      11111000
Z: 1000001      110110
X: 10000001      111
Y: 1      11111000
Z: 1      110110
X: 10000001      111
Y: 1000001      11111000
Z: 1      110110
X: 1000001      111
Y: 1000001      11111000
Z: 1      110110
X: 10000001      111
Y: 10000001      11111000
Z: 1      110110
X: 1000001      111
Y: 1000001      11111000

Could it be right? If I move the senor, it look like there is no change in the output.

Is there someone to help me?

I have a WMP+ and I have already testet it with my MEGA. So I want to test the BMA020 how it works and then I want to combine both sensors. So if someone have a example (connection and sketch) for this, I will be very happy.

There are so many info about both sensors and arduino, but in consumption of the MultiWii boards. I don´t want to use this boards.

Regards,
loby

  1. I'm not very familiar with the Wire library, however from the documentation, I can't see any reason for the second "Wire.endTransmission();" call in function accRead(). What happens if you remove it?

  2. The data sheet says you can read all 6 registers in one go. If you request 6 bytes starting at address 0x02, what data do you get back?

Hi dc42,
ok I changed it in this way:

#include <Wire.h>

#define ACCELEROMETER 0x38 

#define X_OUT1	   0x02

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


void loop() {
    Serial.print("All: ");
    Serial.println((unsigned int)accRead(X_OUT1), BIN);
    delay(100);
}

byte accRead(byte address){
    byte val = 0x00;
    Wire.beginTransmission(ACCELEROMETER);
    Wire.write(address);
    Wire.endTransmission();
    Wire.requestFrom(ACCELEROMETER, 6);
    
	  val = Wire.read();
    
    Wire.endTransmission();
    return val;
}

and the result is this

All: 1
All: 1000001
All: 1000001
All: 10000001
All: 1000001
All: 10000001
All: 10000001
All: 10000001
All: 1000001
All: 10000001
All: 11000001
All: 1000001
All: 10000001
All: 1000001
All: 1
All: 11000001
All: 10000001
All: 1
All: 10000001
All: 10000001
All: 1000001
All: 1000001
All: 1000001
All: 10000001
All: 1000001
All: 1000001
All: 1000001
All: 10000001
All: 1000001
All: 1000001
All: 1000001
All: 1000001
All: 1000001
All: 1000001
All: 10000001
All: 11000001
All: 1000001
All: 1000001
All: 10000001
All: 10000001
All: 1000001
All: 1000001
All: 1000001
All: 1000001
All: 10000001
All: 10000001

My problem ist that it seem to get connected to the sensor and there is something to read form it. I have to say that in this period which shows the result above, I didn't move the sensor. For me it is confusing that the values change so much although I do not move this thing.

Is it right, that I could say there is a connection to the sensor or it is possible that I get values from what ever?

Regards,
loby

But SCL is 21 and SDA is 20 on the MEGA and I connected not to D12, I connected to 5V.

What does this mean? Show how you have actually connected the thing to the Arduino - a decent photo would probably be best.

I still think you should try removing the second call to Wire.endTransmission().

Hi PaulS,

I have problems to add a picture here, so I try this:
This is how I connect the BMA020 to the Arduino MEAG 2560:

BMA020 PINs Arduino
UIN / Pullup / CSB to 5 Volt
ENABLE
INT
GND

SCK to SCL (21)
SDI to SDA (20)
SDO / GND to GND

My last tests today give me the opinion that I get values form the sensor and they change if I move it, but I think they are confuse.
Here my last sketch for that:

#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));
    Serial.print ("      ");
    Serial.print((unsigned int)accRead(X_OUT2));
    Serial.println();  
    Serial.print("Y: ");
    Serial.print((unsigned int)accRead(Y_OUT1));
    Serial.print ("      ");
    Serial.print((unsigned int)accRead(Y_OUT2));
    Serial.println();  
    Serial.print("Z: ");
    Serial.print((unsigned int)accRead(Z_OUT1));
    Serial.print ("      ");
    Serial.print((unsigned int)accRead(Z_OUT2)); 
    Serial.println();
    delay(200);
}

byte accRead(byte address){
    byte val = 0x00;
    Wire.beginTransmission(ACCELEROMETER);
    Wire.write(address);
    Wire.endTransmission();
    Wire.requestFrom(ACCELEROMETER, 6);
    
	  val = Wire.read();
    
    Wire.endTransmission();
    return val;
}

Now I get this result:

X: 1      8
Y: 65      247
Z: 193      53
X: 193      7
Y: 129      247
Z: 1      54
X: 1      8
Y: 1      247
Z: 65      54
X: 1      8
Y: 65      247
Z: 193      53
X: 65      8
Y: 1      247
Z: 1      54
X: 193      7
Y: 129      247
Z: 193      53
X: 193      7
Y: 65      247
Z: 193      53
X: 193      7
Y: 65      247
Z: 1      54
X: 1      8
Y: 65      247
Z: 1      54
X: 1      8
Y: 129      247
Z: 1      54
X: 193      7
Y: 65      247
Z: 193      53
X: 1      8
Y: 65      247
Z: 129      54
X: 1      8
Y: 65      247
Z: 193      53
X: 1      8
Y: 65      247
Z: 193      53
X: 1      8
Y: 1      247
Z: 65      54

My problem is that the values are umping in my eyes because in the time of this values I didn't move the sensor. And at last I am not able to interpret the values. The datasheet give me no idea about this because my understanding is to low.

Thank you
Regards,
loby

@dc42: I delete the second Wire.endTransmission(). The output looks like this now:

X: 65      6
Y: 193      249
Z: 1      55
X: 129      6
Y: 129      249
Z: 65      55
X: 129      6
Y: 1      250
Z: 1      55
X: 129      6
Y: 193      249
Z: 1      55
X: 193      6
Y: 1      250
Z: 193      54
X: 193      6
Y: 65      250
Z: 1      55
X: 193      6
Y: 65      250
Z: 1      55
X: 129      6
Y: 193      249
Z: 1      55
X: 193      6
Y: 193      249
Z: 1      55
X: 129      6
Y: 193      249
Z: 129      55
X: 129      6
Y: 1      250
Z: 1      55

I think not much difference.

@PaulS: Here a link to a video of my wiring:

OK, to see if you are getting sensible values you need to interpret the values according to the data sheet meinemullemaus.de. Try this:

#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

int x_acc = 0, y_acc = 0, z_acc = 0;

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

int convert(uint8_t loByte, uint8_t hiByte)
{
   int temp = (int)(signed char)hiByte;
   return (int)(((unsigned int)temp << 2) | ((unsigned int)loByte >> 6));
}

void accRead(){
    uint8_t regs[6];
    Wire.beginTransmission(ACCELEROMETER);
    Wire.write(X_OUT1);
    Wire.endTransmission();
    Wire.requestFrom(ACCELEROMETER, 6);
    for (uint8_t i = 0; i < 6; ++i)
    {
       regs[i] = Wire.read();
    }
    x_acc = convert(regs[0], regs[1]);
    y_acc = convert(regs[2], regs[3]);
    z_acc = convert(regs[4], regs[5]);
}

Then in loop() print out the values of x_acc, y_acc and z_acc.

Hi dc42,

here is the result

X: 27
Y: -30
Z: 218
X: 29
Y: -31
Z: 217
X: 28
Y: -30
Z: 215
X: 26
Y: -30
Z: 219
X: 26
Y: -29
Z: 218
X: 31
Y: -33
Z: 217
X: 28
Y: -30
Z: 215
X: 26
Y: -30
Z: 216
X: 25
Y: -31
Z: 217
X: 28
Y: -32
Z: 218
X: 26
Y: -31
Z: 216
X: 27
Y: -30
Z: 219
X: 27
Y: -32
Z: 216
X: 26
Y: -32
Z: 217
X: 26
Y: -31
Z: 219
X: 26
Y: -34

It look much better. I saw X and Y changing by turning the sensor. Only the Z value is not conclusive for me. I the example I don#t move the sensor. Have I calibrate the sensor at the start?
What do you think?

Regards,
loby

Ok, Z is the turn in the plateau of the BMA020. I think it could not give values like X and Z. But what shows Z. Is this a difference?
Sorry, I am sure the answer is in the datasheet, but I have problems to understand.

Thank you
Regards,
loby

The Z reading may be caused by gravity. What happens if you turn the sensor upside down, or on one side?

ok, up side down I get roughly -230, normal position 230, so the same but in negative. If I turn it to one side I get roughly 0. Ok, I get value to deal with, but I think they are strange. To work with them is ok, I could calibrate the software to this, but I there is a possibility to understand it will be great.

now I found an artikel about this sensor and there is the info about the Z. It is the normal gravity that cause this value. I am actually not abel to interpret the 230 but I will search for that.

loby:
now I found an artikel about this sensor and there is the info about the Z. It is the normal gravity that cause this value. I am actually not abel to interpret the 230 but I will search for that.

Gravity and acceleration are indistinguishable according to Einstein. The datasheet for that sensor at meinemullemaus.de says that with the default settings, the sensitivity is between 166 and 346 per 1g in the z-axis. So that Z-axis reading is well within the specification.

The datasheet also says that the offsets in the readings may be up to +/- 0.22g. So the x and y axis readings you are getting at zero acceleration are also within tolerance. Of course, if the sensor is tilted, the x and y axes will sense gravity as well.

Hi dc42,

thank you very much! Now I understand it. Sorry, but the datasheet is to difficult to read for me. I always tried to find all new information I got in this datasheet, but I loose. Ok, so I could handle this values in my project.
Again, thank you.

Regards,
loby