Problem managing libraries

Hi everyone,
I am trying to create a multiple sensor with audio and I am using a Teensy 4.1 with Audio shield, a ECG AD8232 and the accelerometer LIS3DH. I have a main code B3_V2.ino that posses numerous class (Sensors,LIS3DH, AudioShield etc.) When I try to compile, the accelerometer can not initialize. But when I test the example code provided by the library, it works fine. I do not understand why and I suppose it is due to library management but I have upload the library and the rest of the file are as presented below

and my code for the accelerometer :

#include "Arduino.h"
#include "LIS3DH.h"

// Used for software SPI
#define LIS3DH_CLK 27
#define LIS3DH_MISO 39
#define LIS3DH_MOSI 26
// Used for hardware & software SPI
#define LIS3DH_CS 37

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

LIS3DH::LIS3DH()
{

  Serial.println("LIS3DH test!");
  if (!lis.begin(0x18))
  { // change this to 0x19 for alternative i2c address
    Serial.println("Couldnt start LIS3DH");
    while (1)
      yield();
  }
  // lis.setDataRate(LIS3DH_DATARATE_50_HZ);
  Serial.print("Data rate set to: ");
  switch (lis.getDataRate())
  {
  case LIS3DH_DATARATE_1_HZ:
    Serial.println("1 Hz");
    break;
  case LIS3DH_DATARATE_10_HZ:
    Serial.println("10 Hz");
    break;
  case LIS3DH_DATARATE_25_HZ:
    Serial.println("25 Hz");
    break;
  case LIS3DH_DATARATE_50_HZ:
    Serial.println("50 Hz");
    break;
  case LIS3DH_DATARATE_100_HZ:
    Serial.println("100 Hz");
    break;
  case LIS3DH_DATARATE_200_HZ:
    Serial.println("200 Hz");
    break;
  case LIS3DH_DATARATE_400_HZ:
    Serial.println("400 Hz");
    break;

  case LIS3DH_DATARATE_POWERDOWN:
    Serial.println("Powered Down");
    break;
  case LIS3DH_DATARATE_LOWPOWER_5KHZ:
    Serial.println("5 Khz Low Power");
    break;
  case LIS3DH_DATARATE_LOWPOWER_1K6HZ:
    Serial.println("16 Khz Low Power");
    break;
  }

  xvar = 0;
  yvar = 0;
  zvar = 0;
}

void LIS3DH::acquire()
{
  lis.read();

  // Serial.print("fin LIS3DH   : ");
  // Serial.println(micros());

  sensors_event_t event;
  lis.getEvent(&event);

  xvar = event.acceleration.x;
  yvar = event.acceleration.y;
  zvar = event.acceleration.z;
}

Does the compilation succeed ?

Yes it does when I compile everything is Ok but when I open the serial monitor it says

"Couldnt start LIS3DH"

However, when I replace the correct pin in the example acceldemo the accelerometer is detected and it works fine...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.