Go Down

Topic: LIS3DH Works Temporarily, Then Crashes (Read 734 times) previous topic - next topic

grahamerica

Hello,

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.

Thanks

robtillaart

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

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

grahamerica

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?

robtillaart

Does the datasheet say anything about time between reads?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

robtillaart

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)

Code: (not tested) [Select]
#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()
{
  Serial.begin(9600);
  while (!Serial); // wait for serial port to connect. Needed for native USB port only
  Serial.println(__FILE__);
  Serial.println("LIS3DH test!");

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

  lis.setRange(LIS3DH_RANGE_8_G);
  Serial.print("Range = ");
  range = 2 << lis.getRange();
  Serial.print(range);
  Serial.println("G");

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

void loop()
{
  sensors_event_t event;
  lis.getEvent(&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);
  Serial.println();

  blink(50);
}

void blink(int d)
{
  digitalWrite(13, HIGH);
  delay(d);
  digitalWrite(13, LOW);
  delay(d);
}
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

grahamerica

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.


grahamerica

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

robtillaart

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?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

grahamerica

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.

robtillaart

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

grahamerica

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?

robtillaart

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

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up