LIS3DH Accelerometer, I2C, and Arduino Mega 2560

Hi all,

I can’t get my Arduino to recognize an LIS3DH sensor on an Adafruit breakout board using I2C connection. All connections are soldered correctly, and connected to the board as follows:

SDA to SDA 21
SCL to SCL 20
VCC to 5V (the Adafruit breakout has a 3.3V regulator and level-shifting to accept 5V)
GND to GND

After several attempts using multiple scanning programs (one, Nick Gammon’s, that I will post below) that correctly identified another I2C device of mine (confirming that my Arduino works), I checked the voltage from CS to GND (CS needs to be pulled high to indicate I2C) and found it at 2.4 V, so I soldered it to VCC, and now it reads the same 4.84V.

/* 
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
14CORE.com Code Test for 
I2C Scanner
Written by Nick Gammon
Date: 20th April 2011
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
*/

#include <Wire.h> //Include Wire Code Library 

void setup() {
  Serial.begin (115200); // Start Serial Communication at baud rate 115200
  while (!Serial)  
    {
    }

  Serial.println ();
  Serial.println ("I2C Address Scanner. Scanning ...");
  byte count = 0;
  
  Wire.begin();
  for (byte i = 8; i < 120; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      {
      Serial.print ("Found i2c Device Address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {}

The address of the sensor is 0x18 / 0x19.

I am lost now and don’t have an oscilloscope to troubleshoot I2C. Can anyone identify something I’m missing/haven’t checked? What do I do?

Thank you for your help,

Keith

CS on that board already has a pullup to 3.3V and you don't need to attach it to anything for I2C operation. In fact, it won't make any difference if you do, unless you pull CS low.

Something else is wrong. Double check your solder joints and wiring connections.

Thanks for the reply!

The solder joints are good, and the connections on the board seem fine. I checked continuity of the following:

SDA wire end-to-end
SCL wire end-to-end (just in case this 22 awg stranded wire separated in the middle or something)

SCL to Drain of Q1 (BSS138)
SCL to R5
R5 to VCC

SDA to Drain of Q2 (BSS138)
SDA to R4
R4 to VCC

and I chased some of the other connections on the board and found nothing I didn’t expect based on the schematic (attached).

I don’t know where to turn next. Thanks again for your help.

Keith

You haven't described the problem.
If the address scanner detects the device at the proper address, communication is working.

Sorry if it was unclear; the scanner still hasn't picked it up. I just don't know how to troubleshoot further. I have also confirmed that the I2C pins work with another device.

Thanks,

Keith

The module might be defective. Contact Adafruit technical support.

jremington,

Thanks, but I’m not sure if it’s defective. I have two other of the same sensors that I tried and they didn’t work. I even tried SPI connection with the below code, but to no avail.

// Basic demo for accelerometer readings from Adafruit LIS3DH

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_LIS3DH.h>
#include <Adafruit_Sensor.h>

// Used for software SPI
#define LIS3DH_CLK 52
#define LIS3DH_MISO 50
#define LIS3DH_MOSI 51
// Used for hardware & software SPI
#define LIS3DH_CS 53

// software SPI
Adafruit_LIS3DH lis = Adafruit_LIS3DH(LIS3DH_CS, LIS3DH_MOSI, LIS3DH_MISO, LIS3DH_CLK);
// hardware SPI
//Adafruit_LIS3DH lis = Adafruit_LIS3DH(LIS3DH_CS);
// I2C
//Adafruit_LIS3DH lis = Adafruit_LIS3DH();

#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
   #define Serial SerialUSB
#endif

void setup(void) {
#ifndef ESP8266
  while (!Serial);     // will pause Zero, Leonardo, etc until serial console opens
#endif

  Serial.begin(115200);
  Serial.println("LIS3DH test!");
  
//  if (! lis.begin(0x18)) {   // change this to 0x19 for alternative i2c address
//    Serial.println("Couldnt start");
//    while (1);
//  }
//  Serial.println("LIS3DH found!");
  
  lis.setRange(LIS3DH_RANGE_4_G);   // 2, 4, 8 or 16 G!
  
  Serial.print("Range = "); Serial.print(4 << lis.getRange());  
  Serial.println("G");
}

void loop() {
  lis.read();      // get X Y and Z data at once
  // Then print out the raw data
  Serial.print("X:  "); Serial.print(lis.x); 
  Serial.print("  \tY:  "); Serial.print(lis.y); 
  Serial.print("  \tZ:  "); Serial.print(lis.z); 

  /* Or....get a new sensor event, normalized */ 
  sensors_event_t event; 
  lis.getEvent(&event);
  
  /* Display the results (acceleration is measured in m/s^2) */
//  Serial.print("\t\tX: "); Serial.print(event.acceleration.x);
//  Serial.print(" \tY: "); Serial.print(event.acceleration.y); 
// Serial.print(" \tZ: "); Serial.print(event.acceleration.z); 
// Serial.println(" m/s^2 ");

  Serial.println();
 
  delay(200); 
}

Have you soldered the connections on the breakout properly and triple checked, with a magnifying glass and the continuity setting on your DVM, that there are no solder bridges or open joints?