STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
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:
[legend]
Collaboration diagram for Adafruit_LIS3DH:
[legend]

Public Member Functions

 Adafruit_LIS3DH (TwoWire *Wi=&Wire)
 Instantiates a new LIS3DH class in I2C.
 Adafruit_LIS3DH (int8_t cspin, SPIClass *theSPI=&SPI, uint32_t frequency=LIS3DH_DEFAULT_SPIFREQ)
 Instantiates a new LIS3DH class using hardware SPI.
 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.
bool begin (uint8_t addr=LIS3DH_DEFAULT_ADDRESS, uint8_t nWAI=0x33)
 Setups the HW (reads coefficients values, etc.).
uint8_t getDeviceID (void)
 Get Device ID from LIS3DH_REG_WHOAMI.
bool haveNewData (void)
 Check to see if new data available.
bool enableDRDY (bool enable_drdy=true, uint8_t int_pin=1)
 Enable or disable the Data Ready interupt.
void read (void)
 Reads x y z values at once.
int16_t readADC (uint8_t a)
 Read the auxilary ADC.
lis3dh_mode_t getPerformanceMode (void)
 Gets the performance mode for the LIS3DH.
void setPerformanceMode (lis3dh_mode_t mode)
 Sets the performance mode for the LIS3DH.
void setRange (lis3dh_range_t range)
 Sets the g range for the accelerometer.
lis3dh_range_t getRange (void)
 Gets the g range for the accelerometer.
void setDataRate (lis3dh_dataRate_t dataRate)
 Sets the data rate for the LIS3DH (controls power consumption).
lis3dh_dataRate_t getDataRate (void)
 Gets the data rate for the LIS3DH (controls power consumption).
bool getEvent (sensors_event_t *event)
 Gets the most recent sensor event.
void getSensor (sensor_t *sensor)
 Gets the sensor_t data.
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.
uint8_t getClick (void)
 Get uint8_t for single or double click.
uint8_t readAndClearInterrupt (void)
 Get uint8_t for INT1 source and clear interrupt.
void configureHighGInterrupt (uint8_t ths, uint8_t dur)
 Configure INT1 for high-G threshold interrupt with high-pass filter.

Public Attributes

int16_t x
 x axis value
int16_t y
 y axis value
int16_t z
 z axis value
float x_g
 x_g axis value (calculated by selected range)
float y_g
 y_g axis value (calculated by selected range)
float z_g
 z_g axis value (calculated by selected range)

Private Attributes

TwoWire * I2Cinterface
SPIClass * SPIinterface
Adafruit_I2CDevice * i2c_dev = NULL
 Pointer to I2C bus interface.
Adafruit_SPIDevice * spi_dev = NULL
 Pointer to SPI bus interface.
uint8_t _wai
int8_t _cs
int8_t _mosi
int8_t _miso
int8_t _sck
int8_t _i2caddr
int32_t _sensorID
uint32_t _frequency = LIS3DH_DEFAULT_SPIFREQ

Detailed Description

Class that stores state and functions for interacting with Adafruit_LIS3DH.

Definition at line 368 of file Adafruit_LIS3DH.h.

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

Definition at line 41 of file Adafruit_LIS3DH.cpp.

References _cs, _miso, _mosi, _sck, _sensorID, and I2Cinterface.

◆ 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

Definition at line 55 of file Adafruit_LIS3DH.cpp.

References _cs, _frequency, _miso, _mosi, _sck, _sensorID, and SPIinterface.

◆ 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

Definition at line 79 of file Adafruit_LIS3DH.cpp.

References _cs, _frequency, _miso, _mosi, _sck, and _sensorID.

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

Definition at line 97 of file Adafruit_LIS3DH.cpp.

References _cs, _frequency, _i2caddr, _miso, _mosi, _sck, _wai, enableDRDY(), getDeviceID(), i2c_dev, I2Cinterface, LIS3DH_DATARATE_400_HZ, LIS3DH_REG_CTRL1, LIS3DH_REG_CTRL4, LIS3DH_REG_TEMPCFG, setDataRate(), spi_dev, and SPIinterface.

◆ configureHighGInterrupt()

void Adafruit_LIS3DH::configureHighGInterrupt ( uint8_t ths,
uint8_t dur )

Configure INT1 for high-G threshold interrupt with high-pass filter.

Sets up CTRL_REG2 (HPF for INT1), performs the mandatory REFERENCE dummy read to zero the HPF baseline (prevents spurious interrupt at startup), programs INT1_CFG for high-event detection on all three axes (OR mode), writes threshold and duration registers, routes IA1 to the INT1 pin via CTRL_REG3, and latches the interrupt in CTRL_REG5 until INT1_SRC is read.

Parameters
thsINT1_THS value (7-bit). LSB size depends on full-scale range: ±2g=16mg, ±4g=32mg, ±8g=62mg, ±16g=186mg per datasheet.
durINT1_DUR value (7-bit). Each count = 1/ODR.

Definition at line 365 of file Adafruit_LIS3DH.cpp.

References i2c_dev, LIS3DH_REG_CTRL2, LIS3DH_REG_CTRL3, LIS3DH_REG_CTRL5, LIS3DH_REG_INT1CFG, LIS3DH_REG_INT1DUR, LIS3DH_REG_INT1THS, LIS3DH_REG_REFERENCE, and spi_dev.

◆ 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

Definition at line 423 of file Adafruit_LIS3DH.cpp.

References i2c_dev, LIS3DH_REG_CTRL3, and spi_dev.

Referenced by begin().

◆ getClick()

uint8_t Adafruit_LIS3DH::getClick ( void )

Get uint8_t for single or double click.

Returns
register LIS3DH_REG_CLICKSRC

Definition at line 345 of file Adafruit_LIS3DH.cpp.

References i2c_dev, LIS3DH_REG_CLICKSRC, and spi_dev.

◆ getDataRate()

lis3dh_dataRate_t Adafruit_LIS3DH::getDataRate ( void )

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

Returns
Returns Data Rate value

Definition at line 555 of file Adafruit_LIS3DH.cpp.

References i2c_dev, LIS3DH_REG_CTRL1, and spi_dev.

◆ getDeviceID()

uint8_t Adafruit_LIS3DH::getDeviceID ( void )

Get Device ID from LIS3DH_REG_WHOAMI.

Returns
WHO AM I value

Definition at line 159 of file Adafruit_LIS3DH.cpp.

References i2c_dev, LIS3DH_REG_WHOAMI, and spi_dev.

Referenced by begin().

◆ 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

Definition at line 570 of file Adafruit_LIS3DH.cpp.

References _sensorID, read(), x_g, y_g, and z_g.

◆ getPerformanceMode()

lis3dh_mode_t Adafruit_LIS3DH::getPerformanceMode ( void )

Gets the performance mode for the LIS3DH.

Returns
Returns performance mode value

Definition at line 486 of file Adafruit_LIS3DH.cpp.

References i2c_dev, LIS3DH_MODE_HIGH_RESOLUTION, LIS3DH_MODE_LOW_POWER, LIS3DH_MODE_NORMAL, LIS3DH_REG_CTRL1, LIS3DH_REG_CTRL4, and spi_dev.

Referenced by read().

◆ getRange()

lis3dh_range_t Adafruit_LIS3DH::getRange ( void )

Gets the g range for the accelerometer.

Returns
Returns g range value

Definition at line 528 of file Adafruit_LIS3DH.cpp.

References i2c_dev, LIS3DH_REG_CTRL4, and spi_dev.

Referenced by read().

◆ getSensor()

void Adafruit_LIS3DH::getSensor ( sensor_t * sensor)

Gets the sensor_t data.

Parameters
*sensorsensor that we want to write data into

Definition at line 593 of file Adafruit_LIS3DH.cpp.

References _sensorID.

◆ haveNewData()

bool Adafruit_LIS3DH::haveNewData ( void )

Check to see if new data available.

Returns
true if there is new data available, false otherwise

Definition at line 169 of file Adafruit_LIS3DH.cpp.

References i2c_dev, LIS3DH_REG_STATUS2, and spi_dev.

◆ read()

◆ 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

Definition at line 247 of file Adafruit_LIS3DH.cpp.

References adc(), i2c_dev, LIS3DH_REG_OUTADC1_L, reg, and spi_dev.

◆ readAndClearInterrupt()

uint8_t Adafruit_LIS3DH::readAndClearInterrupt ( void )

Get uint8_t for INT1 source and clear interrupt.

Returns
register LIS3DH_REG_INT1SRC

Definition at line 408 of file Adafruit_LIS3DH.cpp.

References i2c_dev, LIS3DH_REG_INT1SRC, and spi_dev.

◆ 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)

Definition at line 290 of file Adafruit_LIS3DH.cpp.

References i2c_dev, LIS3DH_REG_CLICKCFG, LIS3DH_REG_CLICKTHS, LIS3DH_REG_CTRL3, LIS3DH_REG_CTRL5, LIS3DH_REG_TIMELATENCY, LIS3DH_REG_TIMELIMIT, LIS3DH_REG_TIMEWINDOW, and spi_dev.

◆ setDataRate()

void Adafruit_LIS3DH::setDataRate ( lis3dh_dataRate_t dataRate)

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

Parameters
dataRatedata rate value

Definition at line 542 of file Adafruit_LIS3DH.cpp.

References i2c_dev, LIS3DH_REG_CTRL1, and spi_dev.

Referenced by begin().

◆ 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

Definition at line 449 of file Adafruit_LIS3DH.cpp.

References delay(), i2c_dev, LIS3DH_MODE_HIGH_RESOLUTION, LIS3DH_MODE_LOW_POWER, LIS3DH_MODE_NORMAL, LIS3DH_REG_CTRL1, LIS3DH_REG_CTRL4, and spi_dev.

◆ setRange()

void Adafruit_LIS3DH::setRange ( lis3dh_range_t range)

Sets the g range for the accelerometer.

Parameters
rangerange value

Definition at line 513 of file Adafruit_LIS3DH.cpp.

References delay(), i2c_dev, LIS3DH_REG_CTRL4, and spi_dev.

Member Data Documentation

◆ _cs

int8_t Adafruit_LIS3DH::_cs
private

Definition at line 422 of file Adafruit_LIS3DH.h.

Referenced by Adafruit_LIS3DH(), Adafruit_LIS3DH(), Adafruit_LIS3DH(), and begin().

◆ _frequency

uint32_t Adafruit_LIS3DH::_frequency = LIS3DH_DEFAULT_SPIFREQ
private

Definition at line 427 of file Adafruit_LIS3DH.h.

Referenced by Adafruit_LIS3DH(), Adafruit_LIS3DH(), and begin().

◆ _i2caddr

int8_t Adafruit_LIS3DH::_i2caddr
private

Definition at line 424 of file Adafruit_LIS3DH.h.

Referenced by begin().

◆ _miso

int8_t Adafruit_LIS3DH::_miso
private

Definition at line 422 of file Adafruit_LIS3DH.h.

Referenced by Adafruit_LIS3DH(), Adafruit_LIS3DH(), Adafruit_LIS3DH(), and begin().

◆ _mosi

int8_t Adafruit_LIS3DH::_mosi
private

Definition at line 422 of file Adafruit_LIS3DH.h.

Referenced by Adafruit_LIS3DH(), Adafruit_LIS3DH(), Adafruit_LIS3DH(), and begin().

◆ _sck

int8_t Adafruit_LIS3DH::_sck
private

Definition at line 422 of file Adafruit_LIS3DH.h.

Referenced by Adafruit_LIS3DH(), Adafruit_LIS3DH(), Adafruit_LIS3DH(), and begin().

◆ _sensorID

int32_t Adafruit_LIS3DH::_sensorID
private

◆ _wai

uint8_t Adafruit_LIS3DH::_wai
private

Definition at line 420 of file Adafruit_LIS3DH.h.

Referenced by begin().

◆ i2c_dev

Adafruit_I2CDevice* Adafruit_LIS3DH::i2c_dev = NULL
private

◆ I2Cinterface

TwoWire* Adafruit_LIS3DH::I2Cinterface
private

Definition at line 414 of file Adafruit_LIS3DH.h.

Referenced by Adafruit_LIS3DH(), and begin().

◆ spi_dev

Adafruit_SPIDevice* Adafruit_LIS3DH::spi_dev = NULL
private

◆ SPIinterface

SPIClass* Adafruit_LIS3DH::SPIinterface
private

Definition at line 415 of file Adafruit_LIS3DH.h.

Referenced by Adafruit_LIS3DH(), and begin().

◆ x

◆ x_g

float Adafruit_LIS3DH::x_g

x_g axis value (calculated by selected range)

Definition at line 409 of file Adafruit_LIS3DH.h.

Referenced by getEvent(), and read().

◆ y

◆ y_g

float Adafruit_LIS3DH::y_g

y_g axis value (calculated by selected range)

Definition at line 410 of file Adafruit_LIS3DH.h.

Referenced by getEvent(), and read().

◆ z

◆ z_g

float Adafruit_LIS3DH::z_g

z_g axis value (calculated by selected range)

Definition at line 411 of file Adafruit_LIS3DH.h.

Referenced by getEvent(), and read().


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