Library Reference

Constructor:

Adafruit_ADXL345(int32_t sensorID = -1)

Constructs an instance of the ADXL345 device driver object. 'sensorID' is a device identifier. It will be returned in the sensor_event in each call to getEvent(). The sensorID has no effect on the operation of the driver or device, but is useful in managing sensor events in systems with multiple sensors.

Initialization()

bool begin(void)

The begin() function initializes communication with the device. The return value is 'true' if it succeeds in connecting to the ADXL345.

Sensor Details:

void getSensor(sensor_t*);

The getSensor() function returns basic information about the sensor. For details about the sensor_t structure, refer to the ReadMe file for the Adafruit Sensor Library.

Getting and Setting the operating range:

void setRange(range_t range)

The setRange() function sets the operating range for the sensor. Higher values will have a wider measurement range. Lower values will have more sensitivity.

Valid range constants are:

  • ADXL345_RANGE_16_G
  • ADXL345_RANGE_8_G
  • ADXL345_RANGE_4_G
  • ADXL345_RANGE_2_G (default value)
range_t getRange(void);

The getRange() function returns the current operating range as set by setRange()

Getting and Setting the Data Rate:

void setDataRate(dataRate_t dataRate);

The setDataRate() function sets the rate at which the sensor output is updated. Rates above 100 Hz will exhibit increased noise. Rates below 6.25 Hz will be more sensitive to temperature variations. See the data sheet for details.

Valid data rate constants are:

  • ADXL345_DATARATE_3200_HZ
  • ADXL345_DATARATE_1600_HZ
  • ADXL345_DATARATE_800_HZ
  • ADXL345_DATARATE_400_HZ
  • ADXL345_DATARATE_200_HZ
  • ADXL345_DATARATE_100_HZ
  • ADXL345_DATARATE_50_HZ
  • ADXL345_DATARATE_25_HZ
  • ADXL345_DATARATE_12_5_HZ
  • ADXL345_DATARATE_6_25HZ
  • ADXL345_DATARATE_3_13_HZ
  • ADXL345_DATARATE_1_56_HZ
  • ADXL345_DATARATE_0_78_HZ
  • ADXL345_DATARATE_0_39_HZ
  • ADXL345_DATARATE_0_20_HZ
  • ADXL345_DATARATE_0_10_HZ (default value)
dataRate_t getDataRate(void);

The getDataRate() function returns the current data rate as set by setDataRate().

Reading Sensor Events:

void getEvent(sensors_event_t*);

The getEvent() function returns the next available reading in the form of a sensor_event. The sensor_event contains the sensor_id as passed to the constructor as well as the X, Y and Z axis readings from the accelerometer. For more information about sensor_events, see the ReadMe file for the Adafruit Sensor Library.
This guide was first published on Mar 26, 2013. It was last updated on Nov 18, 2018. This page (Library Reference) was last updated on May 04, 2015.