ADXL345 libraries problem
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
-
- Posts: 6
- Joined: Wed Feb 06, 2013 9:00 pm
ADXL345 libraries problem
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?
"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?
-
- Posts: 6
- Joined: Wed Feb 06, 2013 9:00 pm
Re: ADXL345 libraries problem
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.
-
- Posts: 6
- Joined: Wed Feb 06, 2013 9:00 pm
Re: ADXL345 libraries problem
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
- adafruit_support_bill
- Posts: 88089
- Joined: Sat Feb 07, 2009 10:11 am
Re: ADXL345 libraries problem
There is a setRange command:
Valid arguments are:
Code: Select all
void setRange(range_t range);
Code: Select all
ADXL345_RANGE_16_G
ADXL345_RANGE_8_G
ADXL345_RANGE_4_G
ADXL345_RANGE_2_G
-
- Posts: 14
- Joined: Thu Nov 10, 2011 5:56 pm
Re: ADXL345 libraries problem
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.
The rest of the library works fine with my ADXL345 sensor.
Regards,
Lapatate
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);
}
Regards,
Lapatate
- adafruit_support_bill
- Posts: 88089
- Joined: Sat Feb 07, 2009 10:11 am
Re: ADXL345 libraries problem
setRange() needs a parameter. See my previous post.
-
- Posts: 6
- Joined: Wed Feb 06, 2013 9:00 pm
Re: ADXL345 libraries problem
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.
void setup(void)
{
setRange(ADXL345_RANGE_8_G);
gets me "setRange' was not declared in this scope"
Thanks for you patience.
-
- Posts: 6
- Joined: Wed Feb 06, 2013 9:00 pm
Re: ADXL345 libraries problem
Code: Select all
void setRange(range_t range){
setRange(ADXL345_RANGE_8_G);
}
- adafruit_support_bill
- Posts: 88089
- Joined: Sat Feb 07, 2009 10:11 am
Re: ADXL345 libraries problem
You do not need to define a function called setRange. It is part of the library already. Delete this code
and add the call to setRange with the desired range parameter to your setup function.
Code: Select all
void setRange(range_t range){
setRange(ADXL345_RANGE_8_G);
}
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);
}
-
- Posts: 6
- Joined: Wed Feb 06, 2013 9:00 pm
Re: ADXL345 libraries problem
I added the call setRange to the example "sensortest" that was provided with the library, exactly as you described:
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?
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);
}
"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?
- adafruit_support_bill
- Posts: 88089
- Joined: Sat Feb 07, 2009 10:11 am
Re: ADXL345 libraries problem
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
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;
};
-
- Posts: 12151
- Joined: Thu Apr 06, 2006 4:21 pm
Re: ADXL345 libraries problem
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?
-
- Posts: 3
- Joined: Sat Mar 23, 2013 8:43 pm
Re: ADXL345 libraries problem
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.
Thanks!
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())
-
- Posts: 3
- Joined: Sat Mar 23, 2013 8:43 pm
Re: ADXL345 libraries problem
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.
Thoughts?
Thanks again!
Code: Select all
accel.setRange(ADXL345_RANGE_16_G);
accel.setDataRate(ADXL345_DATARATE_1600_HZ);
Thanks again!
- adafruit_support_bill
- Posts: 88089
- Joined: Sat Feb 07, 2009 10:11 am
Re: ADXL345 libraries problem
Post the entire sketch you are using.
Please be positive and constructive with your questions and comments.