Modify lowlatencylogger to work with LIS3DH 3-Axis Accelerometer

Hi All,

I'm trying to get the lowlatencylogger to work with the adafruit LIS3DH accelerometer. I have the adafruit LIS3DH connected to a Mega2560 R3 and the adafruit data logging shield. The logger runs without throwing any errors or warnings, the time value works, but the accelerometer data are constant (0, 32, 257). I suspect that I'm not properly defining struct data_t in UserTypes.h and/or calling them correctly in the acquireData function in UserFunctions.cpp. Since lowlatencylogger is divided into several tabs I'll insert the most likely culprits here and attach the entire sketch if useful. I'm also attaching the adafruit_LIS3DH.h and .cpp for reference and a fritzing of my setup. I've scoured the MPU6050 and ADXL345 examples, but both have some structural differences in the sensors that I can't generalize to my sensor. I'd really appreciate some help.

UserFunctions.cpp (I've used long comments to identify the likely trouble areas)

#include "UserTypes.h"
#include <Adafruit_LIS3DH.h>
#include <Adafruit_Sensor.h>
//#include "lis3dh-motion-detection.h"
// User data functions.  Modify these functions for your data items.

// identify accelerometer
// Used for software SPI ////////////////////* Have I identified the accelerometer correctly in this context? */

#define LIS3DH_CLK 13
#define LIS3DH_MISO 12
#define LIS3DH_MOSI 11
#define LIS3DH_CS 10

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

// Start time for data
static uint32_t startMicros;

// Acquire a data record.
void acquireData(data_t* data) {
  data->time = micros();
  frUs.read();  ////////////////////* I can't figure out how to call the data from struct data_t in UserTypes.h */
 
}

// Print a data record.
void printData(Print* pr, data_t* data) {
  if (startMicros == 0) {
    startMicros = data->time;
  }
  pr->print(data->time- startMicros);
  pr->write(',');
  pr->print(data->x);
  pr->write(',');
  pr->print(data->y);
  pr->write(',');
  pr->println(data->z);
  
}

// Print data header.
void printHeader(Print* pr) {
  startMicros = 0;
  pr->println(F("micros,x,y,z"));
}

// Sensor setup
void userSetup() {
  frUs.setRange(LIS3DH_RANGE_16_G);   // 2, 4, 8 or 16 G!
  frUs.setDataRate(LIS3DH_DATARATE_LOWPOWER_5KHZ);
}

UserTypes.h (I've used long comments to identify the likely trouble areas)

#ifndef UserTypes_h
#define UserTypes_h
#include "Arduino.h"
// User data types.  Modify for your data items.
#define FILE_BASE_NAME "LIS3DH"

struct data_t {
  uint32_t time;
  int16_t x; /**< x axis value */ /* this seems to be how x,y,z are identified in the library but I'm not sure they are identified in a way that can be found in UserFunctions.cpp */
  int16_t y; /**< y axis value */
  int16_t z; /**< z axis value */
  
};
void acquireData(data_t* data);
void printData(Print* pr, data_t* data);
void printHeader(Print* pr);
void userSetup();
#endif  // UserTypes_h

Adafruit_LIS3DH.h (17.1 KB)

Adafruit_LIS3DH.cpp (13.2 KB)

LowLatencyLogger_LIS3DH.ino (19.2 KB)

I forgot to mention that I will eventually be connecting 4 LIS3DHs so I need to use SPI and not I2C.