Specific class for the ADXL345 Accelerometer.
More...
#include <ADXL345.h>
Specific class for the ADXL345 Accelerometer.
An enumeration to define the gravity range of the sensor.
Enumerator |
---|
PLUSMINUS_2_G |
plus/minus 2g
|
PLUSMINUS_4_G |
plus/minus 4g
|
PLUSMINUS_8_G |
plus/minus 8g
|
PLUSMINUS_16_G |
plus/minus 16g
|
plus/minus 16g
Definition: ADXL345.h:47
plus/minus 2g
Definition: ADXL345.h:44
plus/minus 4g
Definition: ADXL345.h:45
plus/minus 8g
Definition: ADXL345.h:46
The resolution of the sensor. High is only available in +/- 16g range.
Enumerator |
---|
NORMAL |
NORMAL 10-bit resolution.
|
HIGH |
HIGH 13-bit resolution.
|
NORMAL 10-bit resolution.
Definition: ADXL345.h:51
HIGH 13-bit resolution.
Definition: ADXL345.h:52
exploringBB::ADXL345::ADXL345 |
( |
BusDevice * |
busDevice | ) |
|
The constructor for the ADXL345 accelerometer object. It passes the bus number and the device address (with is 0x53 by default) to the constructor of I2CDevice. All of the states are initialized and the registers are updated.
- Parameters
-
I2CBus | The bus number that the ADXL345 device is on - typically 0 or 1 |
I2CAddress | The address of the ADLX345 device (default 0x53, but can be altered) |
130 this->device = busDevice;
131 this->accelerationX = 0;
132 this->accelerationY = 0;
133 this->accelerationZ = 0;
136 this->registers = NULL;
140 this->updateRegisters();
plus/minus 16g
Definition: ADXL345.h:47
#define POWER_CTL
Definition: ADXL345.cpp:53
HIGH 13-bit resolution.
Definition: ADXL345.h:52
virtual int writeRegister(unsigned int registerAddress, unsigned char value)=0
exploringBB::ADXL345::~ADXL345 |
( |
| ) |
|
|
virtual |
void exploringBB::ADXL345::displayPitchAndRoll |
( |
int |
iterations = 600 | ) |
|
|
virtual |
Useful debug method to display the pitch and roll values in degrees on a single standard output line
- Parameters
-
iterations | The number of 0.1s iterations to take place. |
188 while(count < iterations){
189 cout <<
"Pitch:"<< this->
getPitch() <<
" Roll:" << this->
getRoll() <<
" \r"<<flush;
virtual float getPitch()
Definition: ADXL345.h:78
virtual int readSensorState()
Definition: ADXL345.cpp:149
virtual float getRoll()
Definition: ADXL345.h:79
virtual short exploringBB::ADXL345::getAccelerationX |
( |
| ) |
|
|
inlinevirtual |
75 {
return accelerationX; }
virtual short exploringBB::ADXL345::getAccelerationY |
( |
| ) |
|
|
inlinevirtual |
76 {
return accelerationY; }
virtual short exploringBB::ADXL345::getAccelerationZ |
( |
| ) |
|
|
inlinevirtual |
77 {
return accelerationZ; }
virtual float exploringBB::ADXL345::getPitch |
( |
| ) |
|
|
inlinevirtual |
71 {
return this->range; }
73 {
return this->resolution; }
virtual float exploringBB::ADXL345::getRoll |
( |
| ) |
|
|
inlinevirtual |
int exploringBB::ADXL345::readSensorState |
( |
| ) |
|
|
virtual |
Read the sensor state. This method checks that the device is being correctly read by using the device ID of the ADXL345 sensor. It will read in the accelerometer registers and pass them to the combineRegisters() method to be processed.
- Returns
- 0 if the registers are successfully read and -1 if the device ID is incorrect.
151 if(*this->registers!=0xe5){
152 perror(
"ADXL345: Failure Condition - Sensor ID not Verified");
155 this->accelerationX = this->combineRegisters(*(registers+
DATAX1), *(registers+
DATAX0));
156 this->accelerationY = this->combineRegisters(*(registers+
DATAY1), *(registers+
DATAY0));
157 this->accelerationZ = this->combineRegisters(*(registers+
DATAZ1), *(registers+
DATAZ0));
160 this->calculatePitchAndRoll();
#define DATAZ1
Definition: ADXL345.cpp:63
RESOLUTION
The resolution of the sensor. High is only available in +/- 16g range.
Definition: ADXL345.h:50
#define DATAX1
Definition: ADXL345.cpp:59
#define DATA_FORMAT
Definition: ADXL345.cpp:57
#define DATAX0
Definition: ADXL345.cpp:58
#define DATAZ0
Definition: ADXL345.cpp:62
RANGE
An enumeration to define the gravity range of the sensor.
Definition: ADXL345.h:43
#define BUFFER_SIZE
The ADXL345 has 0x40 registers (0x01 to 0x1C are reserved and should not be accessed) ...
Definition: ADXL345.h:31
virtual unsigned char * readRegisters(unsigned int number, unsigned int fromAddress=0)=0
#define DATAY0
Definition: ADXL345.cpp:60
#define DATAY1
Definition: ADXL345.cpp:61
Set the ADXL345 gravity range according to the RANGE enumeration
- Parameters
-
range | One of the four possible gravity ranges defined by the RANGE enumeration |
Set the ADXL345 resolution according to the RESOLUTION enumeration
- Parameters
-
resolution | either HIGH or NORMAL resolution. HIGH resolution is only available if the range is set to +/- 16g |
178 this->resolution = resolution;
The documentation for this class was generated from the following files:
- /home/molloyd/exploringBB/library/sensor/ADXL345.h
- /home/molloyd/exploringBB/library/sensor/ADXL345.cpp