Adafruit LIS3DH
Public Member Functions | Public Attributes | List of all members
Adafruit_LIS3DH Class Reference

Class that stores state and functions for interacting with Adafruit_LIS3DH. More...

#include <Adafruit_LIS3DH.h>

Inheritance diagram for Adafruit_LIS3DH:

Public Member Functions

 Adafruit_LIS3DH (TwoWire *Wi=&Wire)
 Instantiates a new LIS3DH class in I2C. More...
 
 Adafruit_LIS3DH (int8_t cspin, SPIClass *theSPI=&SPI, uint32_t frequency=LIS3DH_DEFAULT_SPIFREQ)
 Instantiates a new LIS3DH class using hardware SPI. More...
 
 Adafruit_LIS3DH (int8_t cspin, int8_t mosipin, int8_t misopin, int8_t sckpin, uint32_t frequency=LIS3DH_DEFAULT_SPIFREQ)
 Instantiates a new LIS3DH class using software SPI. More...
 
bool begin (uint8_t addr=LIS3DH_DEFAULT_ADDRESS, uint8_t nWAI=0x33)
 Setups the HW (reads coefficients values, etc.) More...
 
uint8_t getDeviceID (void)
 Get Device ID from LIS3DH_REG_WHOAMI. More...
 
bool haveNewData (void)
 Check to see if new data available. More...
 
bool enableDRDY (bool enable_drdy=true, uint8_t int_pin=1)
 Enable or disable the Data Ready interupt. More...
 
void read (void)
 Reads x y z values at once.
 
int16_t readADC (uint8_t a)
 Read the auxilary ADC. More...
 
lis3dh_mode_t getPerformanceMode (void)
 Gets the performance mode for the LIS3DH. More...
 
void setPerformanceMode (lis3dh_mode_t mode)
 Sets the performance mode for the LIS3DH. More...
 
void setRange (lis3dh_range_t range)
 Sets the g range for the accelerometer. More...
 
lis3dh_range_t getRange (void)
 Gets the g range for the accelerometer. More...
 
void setDataRate (lis3dh_dataRate_t dataRate)
 Sets the data rate for the LIS3DH (controls power consumption) More...
 
lis3dh_dataRate_t getDataRate (void)
 Gets the data rate for the LIS3DH (controls power consumption) More...
 
bool getEvent (sensors_event_t *event)
 Gets the most recent sensor event. More...
 
void getSensor (sensor_t *sensor)
 Gets the sensor_t data. More...
 
void setClick (uint8_t c, uint8_t clickthresh, uint8_t timelimit=10, uint8_t timelatency=20, uint8_t timewindow=255)
 Set INT to output for single or double click. More...
 
uint8_t getClick (void)
 Get uint8_t for single or double click. More...
 
uint8_t readAndClearInterrupt (void)
 Get uint8_t for INT1 source and clear interrupt. More...
 

Public Attributes

int16_t x
 
int16_t y
 
int16_t z
 
float x_g
 
float y_g
 
float z_g
 

Detailed Description

Class that stores state and functions for interacting with Adafruit_LIS3DH.

Constructor & Destructor Documentation

◆ Adafruit_LIS3DH() [1/3]

Adafruit_LIS3DH::Adafruit_LIS3DH ( TwoWire *  Wi = &Wire)

Instantiates a new LIS3DH class in I2C.

Parameters
Wioptional wire object

◆ Adafruit_LIS3DH() [2/3]

Adafruit_LIS3DH::Adafruit_LIS3DH ( int8_t  cspin,
SPIClass *  theSPI = &SPI,
uint32_t  frequency = LIS3DH_DEFAULT_SPIFREQ 
)

Instantiates a new LIS3DH class using hardware SPI.

Parameters
cspinnumber of CSPIN (Chip Select)
*theSPIoptional parameter contains spi object
frequencyfrequency of the SPI interface

◆ Adafruit_LIS3DH() [3/3]

Adafruit_LIS3DH::Adafruit_LIS3DH ( int8_t  cspin,
int8_t  mosipin,
int8_t  misopin,
int8_t  sckpin,
uint32_t  frequency = LIS3DH_DEFAULT_SPIFREQ 
)

Instantiates a new LIS3DH class using software SPI.

Parameters
cspinnumber of CSPIN (Chip Select)
mosipinnumber of pin used for MOSI (Master Out Slave In))
misopinnumber of pin used for MISO (Master In Slave Out)
sckpinnumber of pin used for CLK (clock pin)
frequencyfrequency of the SPI interface

Member Function Documentation

◆ begin()

bool Adafruit_LIS3DH::begin ( uint8_t  i2caddr = LIS3DH_DEFAULT_ADDRESS,
uint8_t  nWAI = 0x33 
)

Setups the HW (reads coefficients values, etc.)

Parameters
i2caddri2c address (optional, fallback to default)
nWAIWho Am I register value - defaults to 0x33 (LIS3DH)
Returns
true if successful

◆ getDeviceID()

uint8_t Adafruit_LIS3DH::getDeviceID ( void  )

Get Device ID from LIS3DH_REG_WHOAMI.

Returns
WHO AM I value

◆ haveNewData()

bool Adafruit_LIS3DH::haveNewData ( void  )

Check to see if new data available.

Returns
true if there is new data available, false otherwise

◆ enableDRDY()

bool Adafruit_LIS3DH::enableDRDY ( bool  enable_drdy = true,
uint8_t  int_pin = 1 
)

Enable or disable the Data Ready interupt.

Parameters
enable_drdytrue to enable the given Data Ready interrupt on INT1, false to disable it
int_pinwhich DRDY interrupt to enable; 1 for DRDY1, 2 for DRDY2
Returns
true: success false: failure

◆ readADC()

int16_t Adafruit_LIS3DH::readADC ( uint8_t  adc)

Read the auxilary ADC.

Parameters
adcadc index. possible values (1, 2, 3).
Returns
auxilary ADC value

◆ getPerformanceMode()

lis3dh_mode_t Adafruit_LIS3DH::getPerformanceMode ( void  )

Gets the performance mode for the LIS3DH.

Returns
Returns performance mode value

◆ setPerformanceMode()

void Adafruit_LIS3DH::setPerformanceMode ( lis3dh_mode_t  mode)

Sets the performance mode for the LIS3DH.

The turn-on time to transition to 12-bit mode (high resolution) is set at 7ms, or swtch to 10-bit mode (normal) or to 8-bit mode (low power) is 1ms

Parameters
modemode - low power, normal, high resolution e.g. LIS3DH_MODE_LOW_POWER

◆ setRange()

void Adafruit_LIS3DH::setRange ( lis3dh_range_t  range)

Sets the g range for the accelerometer.

Parameters
rangerange value

◆ getRange()

lis3dh_range_t Adafruit_LIS3DH::getRange ( void  )

Gets the g range for the accelerometer.

Returns
Returns g range value

◆ setDataRate()

void Adafruit_LIS3DH::setDataRate ( lis3dh_dataRate_t  dataRate)

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

Parameters
dataRatedata rate value

◆ getDataRate()

lis3dh_dataRate_t Adafruit_LIS3DH::getDataRate ( void  )

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

Returns
Returns Data Rate value

◆ getEvent()

bool Adafruit_LIS3DH::getEvent ( sensors_event_t *  event)

Gets the most recent sensor event.

Parameters
*eventsensor event that we want to read
Returns
true if successful

◆ getSensor()

void Adafruit_LIS3DH::getSensor ( sensor_t *  sensor)

Gets the sensor_t data.

Parameters
*sensorsensor that we want to write data into

◆ setClick()

void Adafruit_LIS3DH::setClick ( uint8_t  c,
uint8_t  clickthresh,
uint8_t  timelimit = 10,
uint8_t  timelatency = 20,
uint8_t  timewindow = 255 
)

Set INT to output for single or double click.

Parameters
c0 = turn off I1_CLICK 1 = turn on all axes & singletap 2 = turn on all axes & doubletap
clickthreshCLICK threshold value
timelimitsets time limit (default 10)
timelatencysets time latency (default 20)
timewindowsets time window (default 255)

◆ getClick()

uint8_t Adafruit_LIS3DH::getClick ( void  )

Get uint8_t for single or double click.

Returns
register LIS3DH_REG_CLICKSRC

◆ readAndClearInterrupt()

uint8_t Adafruit_LIS3DH::readAndClearInterrupt ( void  )

Get uint8_t for INT1 source and clear interrupt.

Returns
register LIS3DH_REG_INT1SRC

Member Data Documentation

◆ x

int16_t Adafruit_LIS3DH::x

x axis value

◆ y

int16_t Adafruit_LIS3DH::y

y axis value

◆ z

int16_t Adafruit_LIS3DH::z

z axis value

◆ x_g

float Adafruit_LIS3DH::x_g

x_g axis value (calculated by selected range)

◆ y_g

float Adafruit_LIS3DH::y_g

y_g axis value (calculated by selected range)

◆ z_g

float Adafruit_LIS3DH::z_g

z_g axis value (calculated by selected range)


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