Adafruit ADXL343 Library
Public Member Functions | Protected Attributes | List of all members
Adafruit_ADXL343 Class Reference

#include <Adafruit_ADXL343.h>

Inheritance diagram for Adafruit_ADXL343:

Public Member Functions

 Adafruit_ADXL343 (int32_t sensorID)
 Instantiates a new ADXL343 class. More...
 
 Adafruit_ADXL343 (int32_t sensorID, TwoWire *wireBus)
 Instantiates a new ADXL343 class. More...
 
 Adafruit_ADXL343 (uint8_t clock, uint8_t miso, uint8_t mosi, uint8_t cs, int32_t sensorID=-1)
 Instantiates a new ADXL343 class in software SPI mode. More...
 
 Adafruit_ADXL343 (uint8_t cs, SPIClass *theSPI, int32_t sensorID=-1)
 Instantiates a new ADXL343 class in hardware SPI mode. More...
 
bool begin (uint8_t i2caddr=ADXL343_ADDRESS)
 Setups the HW (reads coefficients values, etc.) More...
 
void setRange (adxl34x_range_t range)
 Sets the g range for the accelerometer. More...
 
adxl34x_range_t getRange (void)
 Sets the g range for the accelerometer. More...
 
void setDataRate (adxl3xx_dataRate_t dataRate)
 Sets the data rate for the ADXL343 (controls power consumption) More...
 
adxl3xx_dataRate_t getDataRate (void)
 Sets the data rate for the ADXL343 (controls power consumption) More...
 
bool getEvent (sensors_event_t *)
 Gets the most recent sensor event. More...
 
void getSensor (sensor_t *)
 Gets the sensor_t data. More...
 
uint8_t getDeviceID (void)
 Read the device ID (can be used to check connection) More...
 
void writeRegister (uint8_t reg, uint8_t value)
 Writes 8-bits to the specified destination register. More...
 
uint8_t readRegister (uint8_t reg)
 Reads 8-bits from the specified register. More...
 
int16_t read16 (uint8_t reg)
 Reads 16-bits from the specified register. More...
 
bool enableInterrupts (int_config cfg)
 Enables (1) or disables (0) the interrupts on the specified interrupt pin. More...
 
bool mapInterrupts (int_config cfg)
 'Maps' the specific interrupt to either pin INT1 (bit=0), of pin INT2 (bit=1). More...
 
uint8_t checkInterrupts (void)
 Reads the status of the interrupt pins. Reading this register also clears or deasserts any currently active interrupt. More...
 
void getTrimOffsets (int8_t *x, int8_t *y, int8_t *z)
 Retrieves the X Y Z trim offsets, note that they are 4 bits signed but we use int8_t to store and 'extend' the sign bit! More...
 
void setTrimOffsets (int8_t x, int8_t y, int8_t z)
 Sets the X Y Z trim offsets, note that they are 4 bits signed but we use int8_t to store and 'extend' the sign bit! 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...
 
bool getXYZ (int16_t &x, int16_t &y, int16_t &z)
 Reads 3x16-bits from the x, y, and z data register. More...
 

Protected Attributes

Adafruit_SPIDevice * spi_dev = NULL
 BusIO SPI device.
 
Adafruit_I2CDevice * i2c_dev = NULL
 BusIO I2C device.
 
TwoWire * _wire = NULL
 I2C hardware interface.
 
SPIClass * _spi = NULL
 SPI hardware interface.
 
int32_t _sensorID
 User-set sensor identifier.
 
adxl34x_range_t _range
 cache of range
 
uint8_t _clk
 SPI software clock.
 
uint8_t _do
 SPI software data out.
 
uint8_t _di
 SPI software data in.
 
uint8_t _cs
 SPI software chip select.
 

Detailed Description

Driver for the Adafruit ADXL343 breakout.

Constructor & Destructor Documentation

◆ Adafruit_ADXL343() [1/4]

Adafruit_ADXL343::Adafruit_ADXL343 ( int32_t  sensorID)

Instantiates a new ADXL343 class.

Parameters
sensorIDAn optional ID # so you can track this sensor, it will tag sensorEvents you create.

◆ Adafruit_ADXL343() [2/4]

Adafruit_ADXL343::Adafruit_ADXL343 ( int32_t  sensorID,
TwoWire *  wireBus 
)

Instantiates a new ADXL343 class.

Parameters
sensorIDAn optional ID # so you can track this sensor, it will tag sensorEvents you create.
wireBusTwoWire instance to use for I2C communication.

◆ Adafruit_ADXL343() [3/4]

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

Instantiates a new ADXL343 class in software SPI mode.

Parameters
clockThe SCK pin
misoThe MISO pin
mosiThe MOSI pin
csThe CS/SSEL pin
sensorIDAn optional ID # so you can track this sensor, it will tag sensorEvents you create.

◆ Adafruit_ADXL343() [4/4]

Adafruit_ADXL343::Adafruit_ADXL343 ( uint8_t  cs,
SPIClass *  theSPI,
int32_t  sensorID = -1 
)

Instantiates a new ADXL343 class in hardware SPI mode.

Parameters
csThe CS/SSEL pin
theSPISPIClass instance to use for SPI communication.
sensorIDAn optional ID # so you can track this sensor, it will tag sensorEvents you create.

Member Function Documentation

◆ begin()

bool Adafruit_ADXL343::begin ( uint8_t  i2caddr = ADXL343_ADDRESS)

Setups the HW (reads coefficients values, etc.)

Parameters
i2caddrThe 7-bit I2C address to find the ADXL on
Returns
True if the sensor was successfully initialised.

◆ setRange()

void Adafruit_ADXL343::setRange ( adxl34x_range_t  range)

Sets the g range for the accelerometer.

Parameters
rangeThe range to set, based on adxl34x_range_t

◆ getRange()

adxl34x_range_t Adafruit_ADXL343::getRange ( void  )

Sets the g range for the accelerometer.

Returns
The adxl34x_range_t value corresponding to the sensors range

◆ setDataRate()

void Adafruit_ADXL343::setDataRate ( adxl3xx_dataRate_t  dataRate)

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

Parameters
dataRateThe data rate to set, based on adxl3xx_dataRate_t

◆ getDataRate()

adxl3xx_dataRate_t Adafruit_ADXL343::getDataRate ( void  )

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

Returns
The current data rate, based on adxl3xx_dataRate_t

◆ getEvent()

bool Adafruit_ADXL343::getEvent ( sensors_event_t *  event)

Gets the most recent sensor event.

Parameters
eventPointer to the sensors_event_t placeholder
Returns
True of the read request was successful.

◆ getSensor()

void Adafruit_ADXL343::getSensor ( sensor_t *  sensor)

Gets the sensor_t data.

Parameters
sensorPointer to the sensor_t placeholder.

◆ getDeviceID()

uint8_t Adafruit_ADXL343::getDeviceID ( void  )

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

Returns
The 8-bit device ID

◆ writeRegister()

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

Writes 8-bits to the specified destination register.

Parameters
regThe register to write to
valueThe value to write to the register

◆ readRegister()

uint8_t Adafruit_ADXL343::readRegister ( uint8_t  reg)

Reads 8-bits from the specified register.

Parameters
regregister to read
Returns
The results of the register read request

◆ read16()

int16_t Adafruit_ADXL343::read16 ( uint8_t  reg)

Reads 16-bits from the specified register.

Parameters
regThe register to read two bytes from
Returns
The 16-bit value read from the reg starting address

◆ enableInterrupts()

bool Adafruit_ADXL343::enableInterrupts ( int_config  cfg)

Enables (1) or disables (0) the interrupts on the specified interrupt pin.

Parameters
cfgThe bitfield of the interrupts to enable or disable.
Returns
True if the operation was successful, otherwise false.

◆ mapInterrupts()

bool Adafruit_ADXL343::mapInterrupts ( int_config  cfg)

'Maps' the specific interrupt to either pin INT1 (bit=0), of pin INT2 (bit=1).

Parameters
cfgThe bitfield of the interrupts to enable or disable.
Returns
True if the operation was successful, otherwise false.

◆ checkInterrupts()

uint8_t Adafruit_ADXL343::checkInterrupts ( void  )

Reads the status of the interrupt pins. Reading this register also clears or deasserts any currently active interrupt.

Returns
The 8-bit content of the INT_SOURCE register.

◆ getTrimOffsets()

void Adafruit_ADXL343::getTrimOffsets ( int8_t *  x,
int8_t *  y,
int8_t *  z 
)

Retrieves the X Y Z trim offsets, note that they are 4 bits signed but we use int8_t to store and 'extend' the sign bit!

Parameters
xPointer to the x offset, from -5 to 4 (internally multiplied by 8 lsb)
yPointer to the y offset, from -5 to 4 (internally multiplied by 8 lsb)
zPointer to the z offset, from -5 to 4 (internally multiplied by 8 lsb)

◆ setTrimOffsets()

void Adafruit_ADXL343::setTrimOffsets ( int8_t  x,
int8_t  y,
int8_t  z 
)

Sets the X Y Z trim offsets, note that they are 4 bits signed but we use int8_t to store and 'extend' the sign bit!

Parameters
xThe x offset, from -5 to 4 (internally multiplied by 8 lsb)
yThe y offset, from -5 to 4 (internally multiplied by 8 lsb)
zThe z offset, from -5 to 4 (internally multiplied by 8 lsb)

◆ getX()

int16_t Adafruit_ADXL343::getX ( void  )

Gets the most recent X axis value.

Returns
The 16-bit signed value for the X axis

◆ getY()

int16_t Adafruit_ADXL343::getY ( void  )

Gets the most recent Y axis value.

Returns
The 16-bit signed value for the Y axis

◆ getZ()

int16_t Adafruit_ADXL343::getZ ( void  )

Gets the most recent Z axis value.

Returns
The 16-bit signed value for the Z axis

◆ getXYZ()

bool Adafruit_ADXL343::getXYZ ( int16_t &  x,
int16_t &  y,
int16_t &  z 
)

Reads 3x16-bits from the x, y, and z data register.

Parameters
xreference to return x acceleration data
yreference to return y acceleration data
zreference to return z acceleration data
Returns
True if the operation was successful, otherwise false.

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