lis3lv02dq over I2C

Hey

Currently trying to connect using I2C to this accelerometer (the lis3lv02dq). I have been having problems getting the send and return to work, so I simplified my code down until I could get it working. Afterwards, I'd concentrate on getting the details from it.

My wiring is:

  • 3.3v to VDD
  • analog 4 to SDA
  • analog 5 to SCL
  • digital 9 to CS

Right now, I'm just asking it for its physical address, which the datasheet said ought to be 3A. Currently it just returns ááá, if I serial.println as a DEC or HEX.

Here's the code:

#include <Wire.h>

#define i2cLIS 0x1D

void setup ()
{
pinMode(9, OUTPUT);
digitalWrite(9, HIGH);

Wire.begin(); // join i2c bus (address optional for master)

Serial.begin(9600);

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

void loop()
{
//------------

byte whoI;

//------------
Wire.beginTransmission(i2cLIS);
Wire.send(0x0F);
Wire.endTransmission();

Wire.requestFrom(i2cLIS, 1);
if(Wire.available())
{
whoI = Wire.receive();

}

Serial.println(whoI, DEC);

delay(1000);

}

Any thoughts on what might be the problem?

Okay, have done some debugging steps.

When I attempt to print from within if(Wire.available()){ }, it does not show up.

IN so far as I can tell there is a problem with this section of my code, or anything before it required to ID the data required, and request it.

Currently, the below Code does not print '1':

void loop()
{
//------------

byte whoI;

//------------
Wire.beginTransmission(i2cLIS);
Wire.send(0x0F);
Wire.endTransmission();

Wire.requestFrom(i2cLIS, 1);
if(Wire.available())
{
// whoI = Wire.receive();
Serial.println(1);
}

delay(1000);

}

I decided that hooking it up to SPI would be a good alternative, so I used the code given on http://www.nearfuturelaboratory.com/2006/09/22/arduino-and-the-lis3lv02dq-triple-axis-accelerometer/.

It doesn't read, but returns a 'who am i' code of [0].

I know I'm really asking a lot out of ignorance (this is my first non-pentometer/photoresistor/simple things project), but what debugging steps would you recommend going through to get to the bottom of this?

:smiley: Pay no heed, I think I've just found a loose connection. Gosh durn it!

Hey

Currently trying to connect using I2C to this accelerometer (the lis3lv02dq). I have been having problems getting the send and return to work, so I simplified my code down until I could get it working. Afterwards, I'd concentrate on getting the details from it.

My wiring is:

  • 3.3v to VDD
  • analog 4 to SDA
  • analog 5 to SCL
  • digital 9 to CS

Right now, I'm just asking it for its physical address, which the datasheet said ought to be 3A. Currently it just returns ááá, if I serial.println as a DEC or HEX.

Here's the code:

Quote:
#include <Wire.h>

#define i2cLIS 0x1D

void setup ()
{
pinMode(9, OUTPUT);
digitalWrite(9, HIGH);

Wire.begin(); // join i2c bus (address optional for master)

Serial.begin(9600);

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

void loop()
{
//------------

byte whoI;

//------------
Wire.beginTransmission(i2cLIS);
Wire.send(0x0F);
Wire.endTransmission();

Wire.requestFrom(i2cLIS, 1);
if(Wire.available())
{
whoI = Wire.receive();

}

Serial.println(whoI, DEC);

delay(1000);

}

Any thoughts on what might be the problem?

Icilian,

The line of code..."Wire.send(0x21); // CTRL_REG1 (20h)"......

You use 0x21 for your address parameter, but in your comment you state control register address "CTRL_REG1(20h).

This is a problem, because the code is actually addressing the CTRL_REG2 register, and then you plug 87h into that address and you are NOT activating anything, you are setting your Full Scale to +-6g, enabling Data_Ready generation, setting the SPI interface to 3-wire, and setting the Data Alignment Selection to 16-bit left justified.

Try using, "Wire.send(0x20); // CTRL_REG1 (20h)", instead.

Cheers! :slight_smile:

Argh! What a clutz I am!

:smiley: thanks a lot Jshwaa!

Argh! What a clutz I am!

thanks a lot Jshwaa!

Not a problem. :slight_smile: Did it work now?

Aha, I should have said that! Yes, it did.

After I discovered it had some loose connections, I soldered in legs, and it worked fine. Then I saved the version of the sketch with the mistake your caught in it, and it broke all over again.

Thanks to you, I still have most of my hair left! That was driving me crazy.