# ADXL345 and Adafruit libraries issues

**URL:** <https://forum.arduino.cc/t/adxl345-and-adafruit-libraries-issues/415242>\
**Category:** Programming\
**Created:** [October 26, 2016, 9:27pm UTC](https://forum.arduino.cc/t/adxl345-and-adafruit-libraries-issues/415242 "2016-10-26T21:27:14Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![theo\_vador](https://avatars.discourse-cdn.com/v4/letter/t/b5ac83/32.png) [@theo\_vador](https://forum.arduino.cc/u/theo_vador)\
**Post date:** [October 26, 2016, 9:27pm UTC](https://forum.arduino.cc/t/adxl345-and-adafruit-libraries-issues/415242/1 "2016-10-26T21:27:14Z")

</div>

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:

```cpp
//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);
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [October 27, 2016, 5:06am UTC](https://forum.arduino.cc/t/adxl345-and-adafruit-libraries-issues/415242/2 "2016-10-27T05:06:30Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![theo\_vador](https://avatars.discourse-cdn.com/v4/letter/t/b5ac83/32.png) [@theo\_vador](https://forum.arduino.cc/u/theo_vador)\
**Post date:** [October 27, 2016, 5:17am UTC](https://forum.arduino.cc/t/adxl345-and-adafruit-libraries-issues/415242/3 "2016-10-27T05:17:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [October 27, 2016, 8:43am UTC](https://forum.arduino.cc/t/adxl345-and-adafruit-libraries-issues/415242/4 "2016-10-27T08:43:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![theo\_vador](https://avatars.discourse-cdn.com/v4/letter/t/b5ac83/32.png) [@theo\_vador](https://forum.arduino.cc/u/theo_vador)\
**Post date:** [October 27, 2016, 2:38pm UTC](https://forum.arduino.cc/t/adxl345-and-adafruit-libraries-issues/415242/5 "2016-10-27T14:38:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![theo\_vador](https://avatars.discourse-cdn.com/v4/letter/t/b5ac83/32.png) [@theo\_vador](https://forum.arduino.cc/u/theo_vador)\
**Post date:** [October 27, 2016, 2:48pm UTC](https://forum.arduino.cc/t/adxl345-and-adafruit-libraries-issues/415242/6 "2016-10-27T14:48:00Z")

</div>

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...

```cpp
//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);
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [October 27, 2016, 3:25pm UTC](https://forum.arduino.cc/t/adxl345-and-adafruit-libraries-issues/415242/7 "2016-10-27T15:25:50Z")

</div>

well looks like you are using [that library](https://github.com/adafruit/Adafruit_ADXL345)

`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:

```cpp
/* 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

---

<div class="post-metadata">

**Author:** ![theo\_vador](https://avatars.discourse-cdn.com/v4/letter/t/b5ac83/32.png) [@theo\_vador](https://forum.arduino.cc/u/theo_vador)\
**Post date:** [October 27, 2016, 4:45pm UTC](https://forum.arduino.cc/t/adxl345-and-adafruit-libraries-issues/415242/8 "2016-10-27T16:45:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 10:08pm UTC](https://forum.arduino.cc/t/adxl345-and-adafruit-libraries-issues/415242/9 "2021-05-05T22:08:50Z")

</div>


