Adafruit ADXL345 Arduino Library
Public Member Functions | List of all members
Adafruit_ADXL345_Unified Class Reference

Class to interact with the ADXL345 accelerometer. More...

#include <Adafruit_ADXL345_U.h>

Inheritance diagram for Adafruit_ADXL345_Unified:

Public Member Functions

 Adafruit_ADXL345_Unified (int32_t sensorID=-1)
 Instantiates a new ADXL345 class. More...
 
 Adafruit_ADXL345_Unified (uint8_t clock, uint8_t miso, uint8_t mosi, uint8_t cs, int32_t sensorID=-1)
 Instantiates a new ADXL345 class in SPI mode. More...
 
bool begin (uint8_t addr=ADXL345_DEFAULT_ADDRESS)
 Setups the HW (reads coefficients values, etc.) More...
 
void setRange (range_t range)
 Sets the g range for the accelerometer. More...
 
range_t getRange (void)
 Gets the g range for the accelerometer. More...
 
void setDataRate (dataRate_t dataRate)
 Sets the data rate for the ADXL345 (controls power consumption) More...
 
dataRate_t getDataRate (void)
 Gets the data rate for the ADXL345 (controls power consumption) More...
 
bool getEvent (sensors_event_t *)
 Gets the most recent sensor event. More...
 
void getSensor (sensor_t *)
 Fill a sensor_t struct with information about the sensor. More...
 
uint8_t getDeviceID (void)
 Reads the device ID (can be used to check connection) More...
 
void writeRegister (uint8_t reg, uint8_t value)
 Writes one byte to the specified destination register. More...
 
uint8_t readRegister (uint8_t reg)
 Reads one byte from the specified register. More...
 
int16_t read16 (uint8_t reg)
 Reads two bytes from the specified register. More...
 
int16_t getX (void)
 Gets the most recent X axis value. More...
 
int16_t getY (void)
 Gets the most recent Y axis value. More...
 
int16_t getZ (void)
 Gets the most recent Z axis value. More...
 

Detailed Description

Class to interact with the ADXL345 accelerometer.

Constructor & Destructor Documentation

◆ Adafruit_ADXL345_Unified() [1/2]

Adafruit_ADXL345_Unified::Adafruit_ADXL345_Unified ( int32_t  sensorID = -1)

Instantiates a new ADXL345 class.

Parameters
sensorIDA unique ID to use to differentiate the sensor from others

◆ Adafruit_ADXL345_Unified() [2/2]

Adafruit_ADXL345_Unified::Adafruit_ADXL345_Unified ( uint8_t  clock,
uint8_t  miso,
uint8_t  mosi,
uint8_t  cs,
int32_t  sensorID = -1 
)

Instantiates a new ADXL345 class in SPI mode.

Parameters
clockThe pin number for SCK, the SPI ClocK line
misoThe pin number for MISO, the SPI Master In Slave Out line
mosiThe pin number for MOSI, the SPI Master Out Slave In line
csThe pin number for CS, the SPI Chip Select line
sensorIDA unique ID to use to differentiate the sensor from others

Member Function Documentation

◆ begin()

bool Adafruit_ADXL345_Unified::begin ( uint8_t  i2caddr = ADXL345_DEFAULT_ADDRESS)

Setups the HW (reads coefficients values, etc.)

Parameters
i2caddrThe I2C address to begin communication with
Returns
true: success false: a sensor with the correct ID was not found

◆ setRange()

void Adafruit_ADXL345_Unified::setRange ( range_t  range)

Sets the g range for the accelerometer.

Parameters
rangeThe new range_t to set the accelerometer to

◆ getRange()

range_t Adafruit_ADXL345_Unified::getRange ( void  )

Gets the g range for the accelerometer.

Returns
The current range_t value

◆ setDataRate()

void Adafruit_ADXL345_Unified::setDataRate ( dataRate_t  dataRate)

Sets the data rate for the ADXL345 (controls power consumption)

Parameters
dataRateThe dataRate_t to set

◆ getDataRate()

dataRate_t Adafruit_ADXL345_Unified::getDataRate ( void  )

Gets the data rate for the ADXL345 (controls power consumption)

Returns
The current data rate

◆ getEvent()

bool Adafruit_ADXL345_Unified::getEvent ( sensors_event_t *  event)

Gets the most recent sensor event.

Parameters
eventPointer to the event object to fill
Returns
true: success

◆ getSensor()

void Adafruit_ADXL345_Unified::getSensor ( sensor_t *  sensor)

Fill a sensor_t struct with information about the sensor.

Parameters
sensorPointer to a sensor_t struct to fill

◆ getDeviceID()

uint8_t Adafruit_ADXL345_Unified::getDeviceID ( void  )

Reads the device ID (can be used to check connection)

Returns
The Device ID of the connected sensor

◆ writeRegister()

void Adafruit_ADXL345_Unified::writeRegister ( uint8_t  reg,
uint8_t  value 
)

Writes one byte to the specified destination register.

Parameters
regThe address of the register to write to
valueThe value to set the register to

◆ readRegister()

uint8_t Adafruit_ADXL345_Unified::readRegister ( uint8_t  reg)

Reads one byte from the specified register.

Parameters
regThe address of the register to read from
Returns
The single byte value of the requested register

◆ read16()

int16_t Adafruit_ADXL345_Unified::read16 ( uint8_t  reg)

Reads two bytes from the specified register.

Parameters
regThe address of the register to read from
Returns
The two bytes read from the sensor starting at the given address

◆ getX()

int16_t Adafruit_ADXL345_Unified::getX ( void  )

Gets the most recent X axis value.

Returns
The raw int16_t unscaled x-axis acceleration value

◆ getY()

int16_t Adafruit_ADXL345_Unified::getY ( void  )

Gets the most recent Y axis value.

Returns
The raw int16_t unscaled y-axis acceleration value

◆ getZ()

int16_t Adafruit_ADXL345_Unified::getZ ( void  )

Gets the most recent Z axis value.

Returns
The raw int16_t unscaled z-axis acceleration value

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