LIS3LV02DQ 3axis SPI/I2C Accelerometer mult read

Anybody been able to get the multiple read/write functionality to work on the LIS3LV02DQ accelerometer from sparkfun?

Deal is your supposed to be able to do an auto incrementing register read by setting the MSB on the base register when you address the chip. However, I cannot get it to work and looking at and example from Near Future Laboratory, they couldn't either.

Yep, This seems to work....

// initialise accelerometer

void AccelSetup(void)
{
Wire.beginTransmission(0x1D);
Wire.send(0x20); // CTRL_REG1 20h
// 11: device on, 01: decimate by 128, 0: normal mode, 111: all axis enabled
Wire.send(0x87); // device on, 40Hz, normal mode, all axis' enabled
Wire.endTransmission();
}

// get the accelerometer values

void GetAccelValues(void)
{
byte bytearray[6]; // low, high;
int cnt;

// trnsmit to device with address 0x1D or 0011101b
// send the sub address for the register we want to read
// this is for the OUTX_L register
// masking the register address with 0x80 enables auto
// increment for subsequent reads

Wire.beginTransmission(0x1D);
Wire.send(0x28|0x80);
Wire.endTransmission();

// now do a transfer reading all six bytes
Wire.requestFrom(0x1D,6);

cnt=0;
while(cnt<6)
{
if(Wire.available())
{
bytearray[cnt]=Wire.receive();
cnt++;
}
}

XAccel=bytearray[1];
XAccel<<=8;
XAccel+=bytearray[0];

YAccel=bytearray[3];
YAccel<<=8;
YAccel+=bytearray[2];

ZAccel=bytearray[5];
ZAccel<<=8;
ZAccel+=bytearray[4];

// z axis acceleration, all set.
// Perfectly still and with the z-axis parallel to the ground, it should be about 1024-ish
// (I find in practice it is around 1019.)

// When the z-axis is orthogonal to the ground, it should be zero.
// 1024 is +1g acceleration, or normal gravity
// 2048 is +2g
// 0 is 0g
}

Hi,

How you plug your I2C LIS3LV02DQ accelerometer on Arduino?

My plan:

On I2C my XYZ value is not ok. :frowning:

Wire.begin
XAccel = 96
YAccel = 162
ZAccel = 230
XAccel = 90
YAccel = 161
ZAccel = 235
XAccel = 101
YAccel = 160
ZAccel = 235
XAccel = 104
YAccel = 164
ZAccel = 236
XAccel = 106
YAccel = 178
ZAccel = 235

I use a Logic Level Converter for convert 3.3V accel to 5V Arduino.

I need help.

thank you

Apart from the large disparity between X and Y, why do you think that's wrong?
Have you tried tilting your accelerometer?

I think is wrong because bloke write in his code:

// When the z-axis is orthogonal to the ground, it should be zero.
// 1024 is +1g acceleration, or normal gravity
// 2048 is +2g
// 0 is 0g

the good value is:
XAccel = 0
YAccel = 0
ZAccel = 1024

and me i not get this good values. :frowning:

Thank you

Have you tried tilting/inverting your accelerometer?

What happens?

My values is:

X = Parallel to the ground
Y = perpandicular to the ground (pointing upward)
Z = Parallel to the ground

Is the best value I can to get with a accelerometer motionless.
Is very difficult to get this value. I must be very very vey precise.

XAccel = 8
YAccel = 42
ZAccel = 11
XAccel = 8
YAccel = 41
ZAccel = 11
XAccel = 8
YAccel = 41
ZAccel = 11
XAccel = 8
YAccel = 41
ZAccel = 12

If i touch at accelerometer and move very little milli-rotation.
visually it is in the same position. And is motionless.
I get this:

XAccel = 7
YAccel = 36
ZAccel = 132
XAccel = 8
YAccel = 36
ZAccel = 132
XAccel = 7
YAccel = 36
ZAccel = 133

The good value for this position is:
XAccel = 0
YAccel = 1024
ZAccel = 0

My value is not good. :frowning:

My accel it is break?

Thank you

Hi,

I found a other Arduino code for my LIS3LV02DQ accelerometer.

#include <Wire.h>

// TWI (I2C) sketch to communicate with the LIS3LV02DQ accelerometer

//Modified code from http://research.techkwondo.com/blog/julian/279
//Thanks Julian.

// Using the Wire library (created by Nicholas Zambetti)
// http://wiring.org.co/reference/libraries/Wire/index.html
// On the Arduino board, Analog In 4 is SDA, Analog In 5 is SCL
// These correspond to pin 27 (PC4/ADC4/SDA) and pin 28 (PC5/ADC5/SCL) on the Atmega8
// The Wire class handles the TWI transactions, abstracting the nitty-gritty to make
// prototyping easy.
 
void setup()

{
 
  Wire.begin(); // join i2c bus (address optional for master)
  Serial.begin(9600);
 
  Serial.println("Wire.begin");

  Wire.beginTransmission(0x1D);
  Wire.send(0x20); // CTRL_REG1 (20h)
  Wire.send(0x87); // Device on, 40hz, normal mode, all axis's enabled
  Wire.endTransmission();

}

void loop()
{

#define i2cID 0x1D
#define outXhigh 0x29
#define outYhigh 0x2B
#define outZhigh 0x2D
#define outXlow 0x28
#define outYlow 0x2A
#define outZlow 0x2C

byte z_val_l, z_val_h, y_val_l, y_val_h, x_val_l, x_val_h;

//----------X Values-----------------------
  int x_val;

//-------------------------------
  Wire.beginTransmission(i2cID);
  Wire.send(outXlow);
  Wire.endTransmission(); 
  
Wire.requestFrom(i2cID, 1);
 while(Wire.available())
 {
   x_val_l = Wire.receive();
 }
 //------------------------------- 
  Wire.beginTransmission(i2cID);
  Wire.send(outXhigh);
  Wire.endTransmission();
   
Wire.requestFrom(i2cID, 1);
if(Wire.available())
 {
   x_val_h = Wire.receive();
 }
//------------------------------- 
 
 
 x_val = x_val_h;
 x_val <<= 8;
 x_val += x_val_l;


//----------Y Values-----------------------
  int y_val;

//-------------------------------
  Wire.beginTransmission(i2cID);
  Wire.send(outYlow);
  Wire.endTransmission(); 
  
Wire.requestFrom(i2cID, 1);
 while(Wire.available())
 {
   y_val_l = Wire.receive();
 }
 //------------------------------- 
  Wire.beginTransmission(i2cID);
  Wire.send(outYhigh);
  Wire.endTransmission();
   
Wire.requestFrom(i2cID, 1);
if(Wire.available())
 {
   y_val_h = Wire.receive();
 }
//------------------------------- 
 
 
 y_val = y_val_h;
 y_val <<= 8;
 y_val += y_val_l;
 
 
 //----------Z Values-----------------------
  int z_val;

//-------------------------------
  Wire.beginTransmission(i2cID);
  Wire.send(outZlow);
  Wire.endTransmission(); 
  
Wire.requestFrom(i2cID, 1);
 while(Wire.available())
 {
   z_val_l = Wire.receive();
 }
 //------------------------------- 
  Wire.beginTransmission(i2cID);
  Wire.send(outZhigh);
  Wire.endTransmission();
   
Wire.requestFrom(i2cID, 1);
if(Wire.available())
 {
   z_val_h = Wire.receive();
 }
//------------------------------- 
 
 
 z_val = z_val_h;
 z_val <<= 8;
 z_val += z_val_l;

//Serial.print("x_val_l= "); Serial.println(x_val_l, DEC);
//Serial.print("x_val_h= "); Serial.println(x_val_h, DEC);
Serial.print("x_val= "); Serial.println(x_val, DEC);

//Serial.print("y_val_l= "); Serial.println(y_val_l, DEC);
//Serial.print("y_val_h= "); Serial.println(y_val_h, DEC);
Serial.print("y_val= "); Serial.println(y_val, DEC);

//Serial.print("z_val_l= "); Serial.println(z_val_l, DEC);
//Serial.print("z_val_h= "); Serial.println(z_val_h, DEC);
Serial.print("z_val= "); Serial.println(z_val, DEC);

  delay(250);
}

X = Parallel to the ground
Y = Parallel to the ground
Z = perpandicular to the ground (pointing upward)

My value is:

x_val= 7
y_val= 7
z_val= 1019
x_val= 7
y_val= 6
z_val= 1020
x_val= 7
y_val= 8
z_val= 1019
x_val= 7
y_val= 9
z_val= 1018

The good value for this position is:
XAccel = 0
YAccel = 0
ZAccel = 1024

Why this code work and the other code not work?
I no understand.

Thank you.

Why this code work and the other code not work?

How can we know?
You never posted your code.

I have some sample code here (Interfacing LIS3LV02DL Using SPI — II – Kerry D. Wong). It is based on LIS3L02DL but the code should be identical as main difference between the Q version and the L version is the packaging.

hi Groove

The other code is the code of bloke (message 2 of this post).

hi AlphaZeta
thank you for your sample :slight_smile:
hi check this!

Now i think the problem is my wire, I must to do tests.
My result is often different for the same accel position.

Hi,
I make tests and just code of this site work on my arduino.
http://sites.google.com/site/beroth/i2clis3lv02dqaccelerometer

The code of bloke (message 2 of this post) not work on my arduino.

Thank you