ADXL345 libraries problem

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
zealoustinkerer
 
Posts: 6
Joined: Wed Feb 06, 2013 9:00 pm

ADXL345 libraries problem

Post by zealoustinkerer »

I downloaded the library for the ADXL345, shortened the folder name and moved it to my libraries folder. Other libraries in the folder work fine. but when trying to run the example "sensortest" I get the following compiling error on Mac:
"In file included from sensortest.pde:3:
/Users/Glen/Documents/Arduino/libraries/Adafruit_ADXL345/Adafruit_ADXL345.h:106: error: expected class-name before '{' token
/Users/Glen/Documents/Arduino/libraries/Adafruit_ADXL345/Adafruit_ADXL345.h:115: error: 'sensors_event_t' has not been declared
/Users/Glen/Documents/Arduino/libraries/Adafruit_ADXL345/Adafruit_ADXL345.h:116: error: 'sensor_t' has not been declared
sensortest.pde: In function 'void displaySensorDetails()':
sensortest:10: error: 'sensor_t' was not declared in this scope
sensortest:10: error: expected `;' before 'sensor'
sensortest:11: error: 'sensor' was not declared in this scope
sensortest.pde: In function 'void loop()':
sensortest:135: error: 'sensors_event_t' was not declared in this scope
sensortest:135: error: expected `;' before 'event'
sensortest:136: error: 'event' was not declared in this scope"

I tried on my linux system and got the error that "Adafruit_sensor.h no such file or directory"

Should there be a file Adafruit_sensor.h in the library along with Adafruit_ADXL345.h and .cpp?

zealoustinkerer
 
Posts: 6
Joined: Wed Feb 06, 2013 9:00 pm

Re: ADXL345 libraries problem

Post by zealoustinkerer »

OK, I found the Adafruit_Sensor library. You might should mention that download of that library is required along with the Adafruit_ADXL345 library. Also the "readme" file in the ADXL library ends with ".md" I changed that to ".txt" to be able to read it. You could make this easier.

zealoustinkerer
 
Posts: 6
Joined: Wed Feb 06, 2013 9:00 pm

Re: ADXL345 libraries problem

Post by zealoustinkerer »

I'd be grateful if anyone can provide guidance on how to change the sensor range from 2 g to 4, 8, and 16 g. Thanks

User avatar
adafruit_support_bill
 
Posts: 88089
Joined: Sat Feb 07, 2009 10:11 am

Re: ADXL345 libraries problem

Post by adafruit_support_bill »

There is a setRange command:

Code: Select all

  void setRange(range_t range);
Valid arguments are:

Code: Select all

  ADXL345_RANGE_16_G
  ADXL345_RANGE_8_G
  ADXL345_RANGE_4_G
  ADXL345_RANGE_2_G

Lapatate
 
Posts: 14
Joined: Thu Nov 10, 2011 5:56 pm

Re: ADXL345 libraries problem

Post by Lapatate »

Hello,

It looks like this is the function I'm looking for to make it run in a differetn sensitivity. What is the way to implement the setRange function? This is how I would do it intuitively by inserting the void setRange rountine with the argument and calling it during the setup or main programm. Maybe it is not the right way to proceed? I checked a couple of other ways but don't get the sensitivity to change. Any help would be appreciated.

Code: Select all

void setRange(range_t ADXL345_RANGE_8_G);

void setup(void) 
{
  Serial.begin(9600);
  Serial.println("Accelerometer Test"); Serial.println("");
  setRange;
  /* Initialise the sensor */
  if(!accel.begin())
  {
    /* There was a problem detecting the ADXL345 ... check your connections */
    Serial.println("Ooops, no ADXL345 detected ... Check your wiring!");
    while(1);
  }
The rest of the library works fine with my ADXL345 sensor.
Regards,
Lapatate

User avatar
adafruit_support_bill
 
Posts: 88089
Joined: Sat Feb 07, 2009 10:11 am

Re: ADXL345 libraries problem

Post by adafruit_support_bill »

setRange() needs a parameter. See my previous post.

zealoustinkerer
 
Posts: 6
Joined: Wed Feb 06, 2013 9:00 pm

Re: ADXL345 libraries problem

Post by zealoustinkerer »

Hate to be a dunce about this, but your guidance - not so clear to me.

void setup(void)
{
setRange(ADXL345_RANGE_8_G);

gets me "setRange' was not declared in this scope"

Thanks for you patience.

zealoustinkerer
 
Posts: 6
Joined: Wed Feb 06, 2013 9:00 pm

Re: ADXL345 libraries problem

Post by zealoustinkerer »

Code: Select all

 void setRange(range_t range){
   setRange(ADXL345_RANGE_8_G);
 }
This compiles, but does not change the range.

User avatar
adafruit_support_bill
 
Posts: 88089
Joined: Sat Feb 07, 2009 10:11 am

Re: ADXL345 libraries problem

Post by adafruit_support_bill »

You do not need to define a function called setRange. It is part of the library already. Delete this code

Code: Select all

void setRange(range_t range){
   setRange(ADXL345_RANGE_8_G);
}
and add the call to setRange with the desired range parameter to your setup function.

Code: Select all

void setup(void) 
{
  Serial.begin(9600);
  Serial.println("Accelerometer Test"); Serial.println("");
  setRange(ADXL345_RANGE_8_G);
  /* Initialise the sensor */
  if(!accel.begin())
  {
    /* There was a problem detecting the ADXL345 ... check your connections */
    Serial.println("Ooops, no ADXL345 detected ... Check your wiring!");
    while(1);
  }

zealoustinkerer
 
Posts: 6
Joined: Wed Feb 06, 2013 9:00 pm

Re: ADXL345 libraries problem

Post by zealoustinkerer »

I added the call setRange to the example "sensortest" that was provided with the library, exactly as you described:

Code: Select all

void setup(void) 
{
  Serial.begin(9600);
  Serial.println("Accelerometer Test"); Serial.println("");
  setRange(ADXL345_RANGE_8_G);
  /* Initialise the sensor */
  if(!accel.begin())
  {
    /* There was a problem detecting the ADXL345 ... check your connections */
    Serial.println("Ooops, no ADXL345 detected ... Check your wiring!");
    while(1);
  }
  
This resulted in the error:
"sensortest.pde: In function 'void setup()':
sensortest:114: error: 'setRange' was not declared in this scope"

The example compiles and runs just fine without the setRange statement, so the library must be installed correctly.

Are you sure that "setRange" is declared in the library?

User avatar
adafruit_support_bill
 
Posts: 88089
Joined: Sat Feb 07, 2009 10:11 am

Re: ADXL345 libraries problem

Post by adafruit_support_bill »

This is from the current .h file in the github repository. There appear to have been recent changes. Make sure yours is up-to-date.
https://github.com/adafruit/Adafruit_ADXL345

Code: Select all

class Adafruit_ADXL345 : public Adafruit_Sensor {
 public:
  Adafruit_ADXL345(int32_t sensorID = -1);
  
  bool       begin(void);
  void       setRange(range_t range);
  range_t    getRange(void);
  void       setDataRate(dataRate_t dataRate);
  dataRate_t getDataRate(void);
  void       getEvent(sensors_event_t*);
  void       getSensor(sensor_t*);

 private:
  int32_t _sensorID;
};

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: ADXL345 libraries problem

Post by adafruit »

zealoustinkerer wrote:I added the call setRange to the example "sensortest" that was provided with the library, exactly as you described:

Code: Select all

void setup(void) 
Are you sure that "setRange" is declared in the library?[/quote]

hi there, just to check, are you using an ADXL345 sensor from adafruit?

dwatts
 
Posts: 3
Joined: Sat Mar 23, 2013 8:43 pm

Re: ADXL345 libraries problem

Post by dwatts »

I just received the ADXL345. I install the current Adafruit_Sensor and Adafruit_ADXL345 libraries from github. I was able to get the sensortest sketch to compile and correctly display x, y and z values. I was not able; however, to adjust the setRange or setDataRate arguments. Below is the code I used. I verified that my version of Adafruit_ADXL345 does define these functions.

Code: Select all

void setup(void) 
{
  Serial.begin(9600);
  Serial.println("Accelerometer Test"); Serial.println("");
  
  setRange(ADXL345_RANGE_16_G);
  setDataRate(ADXL345_DATARATE_3200_HZ);
  
  /* Initialise the sensor */
  if(!accel.begin())
Thanks!

dwatts
 
Posts: 3
Joined: Sat Mar 23, 2013 8:43 pm

Re: ADXL345 libraries problem

Post by dwatts »

It looks like "accel" is what was missing; however, when I compile with just "accel.setRange(ADXL345_RANGE_16_G);", the sketch no longer functions until that code is commented out.

Code: Select all

  accel.setRange(ADXL345_RANGE_16_G);
  accel.setDataRate(ADXL345_DATARATE_1600_HZ);
Thoughts?

Thanks again!

User avatar
adafruit_support_bill
 
Posts: 88089
Joined: Sat Feb 07, 2009 10:11 am

Re: ADXL345 libraries problem

Post by adafruit_support_bill »

Post the entire sketch you are using.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”