LIS3DH Works Temporarily, Then Crashes


I’m having a pretty weird problem with Adafruit’s LIS3DH sensor breakout board. I have it hooked up to an Adalogger 32u4, and after working for a couple minutes, giving me acceleration readings over I2C, it crashed. The reset button doesn’t seem to work, and Windows says it can’t identify the device.

I have soldered together the exact same setup 6 times, 3 of which work perfectly and 3 give similar problems. Occasionally they will work for a couple minutes, but then they will crash.

Is there something I could be doing wrong? I attached the code I was running.


accelerometertesting.ino (1.09 KB)

I2C needs pull up resistors (but sometimes they work without) do you have them?

I thought that this board had internal pull up resistors, but it doesn't. I tried 4.7k and it worked for a bit longer than usual, maybe 5 minutes, but then gave a bunch of "0m/s" measurements and crashed. I tried a 2.2k resistor and it doesn't seem to be working. Am I just using the wrong values?

Does the datasheet say anything about time between reads?

Looking at your code I see you use the String class which is famous of fragmenting memory.
Try this variation of the sketch without the String class (and some minor edits)

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

float xacc = 0;
float yacc = 0;
float zacc = 0;

int range = 0;

Adafruit_LIS3DH lis = Adafruit_LIS3DH();

#define LIS3DH_ADDRESS  0x18      // change this to 0x19 for alternative i2c address

void setup()
  while (!Serial); // wait for serial port to connect. Needed for native USB port only
  Serial.println("LIS3DH test!");

  if (! lis.begin(LIS3DH_ADDRESS)) {
    Serial.print("LIS3DH_ADDRESS: ");
    Serial.println(" failed.");
    while (1)
  Serial.println("LIS3DH found!");

  Serial.print("Range = ");
  range = 2 << lis.getRange();

  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);

void loop()
  sensors_event_t event;

  xacc = event.acceleration.x;
  yacc = event.acceleration.y;
  zacc = event.acceleration.z;

  float totalacc = pow(xacc,2) + pow(yacc,2) + pow(zacc,2);

  Serial.print(xacc, 1);
  Serial.print(", ");
  Serial.print(yacc, 1);
  Serial.print(", ");
  Serial.print(zacc, 1);
  Serial.print(", ");
  Serial.print(totalacc, 2);


void blink(int d)
  digitalWrite(13, HIGH);
  digitalWrite(13, LOW);

Thank you for the replies!

The datasheet says it can handle data reads up to 5kHz.

I tried your code, but it seems to be failing earlier, it outputs "LIS3DH test!" and then freezes. Sometimes after 30 mins or so it will say it failed to find the sensor. I also tried an I2C scanner and sometimes it can't find the sensor.

Could I have fried the sensors in some way by not using the pull up resistors before?

Frying can allways happen, although a missing pull up would be strange.
However your remark popped some thoughts related to power.

Is the breakout meant for 5V or 3.3V?

How do you power the system?

From your PC or battery?

It has a voltage regulator, so 3-5V is fine but I am using 3V. And I was powering it via USB from a PC.

try using 4 or 5 V

This board, called Adalogger, can only do 3V3. Would connecting 3V3 to the Vin instead of 3V pin make a difference? Skipping the voltage regulator?

10% difference is not very much but still enough to give it a try.