I2C LIS3LV02DQ Accelerometer
 

To enable I2C on the Arduino Mini, details from http://research.techkwondo.com/blog/julian/279:

Wire/TWI (I2C) on the Arduino Mini

Getting TWI working on the Arduino Mini (Although the Arduino and Arduino Mini share a name, they don't share the same processor. The Arduino Mini uses an ATmega168, while the Arduino..normal.. uses an ATmega8. You'll need to recompile/re-"verify" the Wire library files in order to get TWI to work on the ATmega168/Arduino Mini. There's a thing or two you'll have to do by hand to get this to work, and you'll need to do it each time you move code that's using the Wire library to a different processor. In other words, when you decide to port the code to the ATmega8, or you put an ATmega16 in your Arduino, or whatever — you'll need to recompile these libraries. Here's the drill:

Navigate in a file browser or command prompt to the root of your Arduino file hierarchy. Then go into:

lib/targets/libraries/Wire/
delete Wire.o

lib/targets/libraries/Wire/utility
delete twi.o

Once you've done this, make one modification to the header file twi.h in lib/targets/libraries/Wire/utility. Look around line 27 for a commented out line like this:

//#define ATMEGA8

Un-comment it (take out the "//" in the front.) This'll ensure that the internal pull-up resistors on the ATmega8 are enabled when you're developing for the normal Arduino. You'll only need to make this change to twi.h once and for all. Future builds of Arduino should have this fixed.

For those who are curious — pull-up resistors are required on the TWI lines — SCL and SDA. You may use your own external pull-ups, but enabling the internal ones saves you the hassle. But, I don't think you'll do much harm if you have the internal one's enabled and use external ones. But, generally you'll want to avoid having both internal and external pull-ups.)



Modified code with all three axis enabled:

#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);
}