ADXL345 and Adafruit libraries issues

As mentioned in another post, I’m working on a large rocket (1m30) and I need safe parachute electronic, so I’m using an accelerometer ADXL345 to detect the launch then wait and open the hatch. After that a light blinks in case I’ve to find it in the forest near the launch site…
I’m working on for 2 hours so good luck to find the problem(s).

The code:

//libraries
#include <Wire.h>
#include <Adafruit_ADXL345_U.h>
#include <Adafruit_Sensor.h>
#include <Servo.h>

//ADXL setup
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);
accel.setRange(ADXL345_RANGE_8_G);
int x, y, z;

//define leds
#define LedR 2
#define LedG 3
#define LedB 4
#define LedW 5

//Servo setup
Servo servo1;
int pos = 0;

//VOID
//SETUP
void setup() {

  //PinMode
  pinMode(LedR, OUTPUT);
  pinMode(LedG, OUTPUT);
  pinMode(LedB, OUTPUT);
  pinMode(LedW, OUTPUT);

  //verif ADXL
  if (accel.begin())
  {
    digitalWrite(LedW, HIGH);
    while (1);
    }

  //Servo setup
  servo1.attach(9);
  servo1.write(0);
  delay(15);

  //Ready
  delay(1000);
  digitalWrite(LedR, HIGH);
}

//VOID
//LOOP
void loop() {

  //ADXL val
  accel.readAccel(&x, &y, &z);

  //IF statement
  if (x > 20)
  {
    servo1.write(90);
    digitalWrite(LedB, HIGH);
    delay(2000);
    digitalWrite(LedG, HIGH);
    delay(10000);
    while (1);
    {
      digitalWrite(LedW, HIGH);
      delay(500);
      digitalWrite(LedW, LOW);
      delay(500);
    }
  }
}

Well you should tell us what the problem is.

First thing I would change though is move the line accel.setRange(ADXL345_RANGE_8_G); in the setup() after calling accel.begin()

And of course having while (1)[b][color=red];[/color][/b] {...} in the middle of your loop is a recipe for total failure… ( get rid of that stupid semi colon)

ok thanks I'll change that but here's what it say.

Bryce-18-2.3:9: error: 'accel' does not name a type
Bryce-18-2.3.ino: In function 'void loop()':
Bryce-18-2.3:54: error: 'class Adafruit_ADXL345_Unified' has no member named 'readAccel'
'accel' does not name a type

Is this before or after doing the change I suggest? ... come on...

Sorry I had to go yesterday, so that was before. I am changing that right now

OK, so here it is it still say : ‘class Adafruit_ADXL345_Unified’ has no member named ‘readAccel’
and it don’t know at all what that mean and how to get rid of that…

//libraries
#include <Wire.h>
#include <Adafruit_ADXL345_U.h>
#include <Adafruit_Sensor.h>
#include <Servo.h>

//ADXL setup
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);
int x, y, z;

//define leds
#define LedR 1
#define LedG 2
#define LedB 3
#define LedW 4

//Servo setup
Servo servo1;
int pos = 0;

//VOID
//SETUP
void setup() {

  //PinMode
  pinMode(LedR, OUTPUT);
  pinMode(LedG, OUTPUT);
  pinMode(LedB, OUTPUT);
  pinMode(LedW, OUTPUT);

  //verif ADXL
  accel.setRange(ADXL345_RANGE_8_G);
  if (accel.begin())
  {
    while (1){
      digitalWrite(LedW, HIGH);
      }
    }

  //Servo setup
  servo1.attach(9);
  servo1.write(0);
  delay(15);

  //Ready
  delay(1000);
  digitalWrite(LedR, HIGH);
}

//VOID
//LOOP
void loop() {

  //ADXL val
  accel.readAccel(&x, &y, &z);

  //IF statement
  if (x) > 20)
  {
    servo1.write(90);
    digitalWrite(LedB, HIGH);
    delay(2000);
    digitalWrite(LedG, HIGH);
    delay(10000);
    while (1)
    {
      digitalWrite(LedW, HIGH);
      delay(500);
      digitalWrite(LedW, LOW);
      delay(500);
    }
  }
}

well looks like you are using that library

Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);creates an instance of that Adafruit_ADXL345_Unified class and that class does not have any method called readAccel... not sure where you got that code but it does not apply to that library.

you should use a method that exists and you can find that in the examples:

/* Get a new sensor event */ 
  sensors_event_t event; 
  accel.getEvent(&event);
  x= event.acceleration.x;
  y= event.acceleration.y;
  z= event.acceleration.z;

  /* Display the results (acceleration is measured in m/s^2) */
  Serial.print("acceleration X: "); Serial.print(event.acceleration.x); Serial.print("  ");
  Serial.print("acceleration Y: "); Serial.print(event.acceleration.y); Serial.print("  ");
  Serial.print("acceleration Z: "); Serial.print(event.acceleration.z); Serial.println(" m/s^2 ");

hope this helps

That's it, I looked a bit all over the place so that's possible I took a line from another library :wink:
Thanks