upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
Public Member Functions
ADXL335 Class Reference

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 = new upm::ADXL335(0, 1, 2);
cout << "Please make sure the sensor is completely still. Sleeping for"
<< " 2 seconds." << endl;
sleep(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;
usleep(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)
 
void acceleration (float *xAccel, float *yAccel, float *zAccel)
 
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
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
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
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.


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