upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Public Member Functions

API for the ADXL335 3-Axis Analog Accelerometer. More...

Detailed Description

UPM module for the ADXL335 3-axis analog accelerometer. This was tested on a Grove 3-axis Analog Accelerometer. It uses 3 analog pins, one for each axis: X, Y, and Z.

adxl335.jpg
// Instantiate an ADXL335 accelerometer on analog pins A0, A1, and A2
upm::ADXL335 accel(0, 1, 2);
cout << "Please make sure the sensor is completely still. Sleeping for"
<< " 2 seconds." << endl;
upm_delay(2);
cout << "Calibrating..." << endl;
accel.calibrate();
while (shouldRun) {
int x, y, z;
float aX, aY, aZ;
accel.values(&x, &y, &z);
cout << "Raw Values: X: " << x << " Y: " << y << " Z: " << z << endl;
accel.acceleration(&aX, &aY, &aZ);
cout << "Acceleration: X: " << aX << "g" << endl;
cout << "Acceleration: Y: " << aY << "g" << endl;
cout << "Acceleration: Z: " << aZ << "g" << endl;
cout << endl;
upm_delay_us(200000);
}

Public Member Functions

 ADXL335 (int pinX, int pinY, int pinZ, float aref=ADXL335_DEFAULT_AREF)
 
 ~ADXL335 ()
 
void setZeroX (float zeroX)
 
void setZeroY (float zeroY)
 
void setZeroZ (float zeroZ)
 
void values (int *xVal, int *yVal, int *zVal)
 
std::vector< int > values ()
 
void acceleration (float *xAccel, float *yAccel, float *zAccel)
 
std::vector< float > acceleration ()
 
void calibrate ()
 

Constructor & Destructor Documentation

ADXL335 ( int  pinX,
int  pinY,
int  pinZ,
float  aref = ADXL335_DEFAULT_AREF 
)

ADXL335 constructor

Parameters
pinXAnalog pin to use for X-axis
pinYAnalog pin to use for Y-axis
pinZAnalog pin to use for Z-axis
arefAnalog reference voltage; default is 5.0v
~ADXL335 ( )

ADXL335 destructor

Member Function Documentation

void setZeroX ( float  zeroX)
inline

Sets the "zero" value of the X-axis, determined through calibration

Parameters
zeroX"Zero" value of the X-axis
void setZeroY ( float  zeroY)
inline

Sets the "zero" value of the Y-axis, determined through calibration

Parameters
zeroY"Zero" value of the Y-axis
void setZeroZ ( float  zeroZ)
inline

Sets the "zero" value of the Z-axis, determined through calibration

Parameters
zeroZ"Zero" value of the Z-axis

Here is the call graph for this function:

void values ( int *  xVal,
int *  yVal,
int *  zVal 
)

Gets the analog values for the 3 axes

Parameters
xValPointer to the returned X-axis value
yValPointer to the returned Y-axis value
zValPointer to the returned Z-axis value
std::vector< int > values ( )

Gets the analog values for the 3 axes

Returns
std::vector of x, y, z analog acceleration values

Here is the caller graph for this function:

void acceleration ( float *  xAccel,
float *  yAccel,
float *  zAccel 
)

Gets the acceleration along all 3 axes

Parameters
xAccelPointer to returned X-axis value
yAccelPointer to returned Y-axis value
zAccelPointer to returned Z-axis value
std::vector< float > acceleration ( )

Gets the acceleration along all 3 axes

Returns
std::vector of x, y, z acceleration values

Here is the caller graph for this function:

void calibrate ( )

While the sensor is still, measures the X-axis, Y-axis, and Z-axis values and uses those values as the zero values.

Here is the caller graph for this function:


The documentation for this class was generated from the following files: