Adafruit LIS331 Arduino Driver
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Adafruit_LIS331 Class Reference

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

#include <Adafruit_LIS331.h>

Inheritance diagram for Adafruit_LIS331:
Adafruit_H3LIS331 Adafruit_LIS331HH

Public Member Functions

 Adafruit_LIS331 (TwoWire *Wi=&Wire)
 Instantiates a new LIS331 class in I2C. More...
 
 Adafruit_LIS331 (int8_t cspin, SPIClass *theSPI=&SPI)
 Instantiates a new LIS331 class using hardware SPI. More...
 
 Adafruit_LIS331 (int8_t cspin, int8_t mosipin, int8_t misopin, int8_t sckpin)
 Instantiates a new LIS331 class using software SPI. More...
 
uint8_t getDeviceID (void)
 Get Device ID from LIS331_REG_WHOAMI. More...
 
bool configIntDataReady (uint8_t irqnum=1, bool activelow=true, bool opendrain=true)
 Setup the INT1 or INT2 pin to trigger when new data is ready. More...
 
void read (void)
 Reads x y z values at once.
 
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 enableHighPassFilter (bool filter_enabled, lis331_hpf_cutoff_t cutoff=LIS331_HPF_0_0025_ODR, bool use_reference=false)
 Enables the high pass filter and/or slope filter. More...
 
void setHPFReference (int8_t reference)
 Set the reference value to offset measurements when using the High-pass filter. More...
 
int8_t getHPFReference (void)
 Gets the current high-pass filter reference/offset. More...
 
void HPFReset (void)
 Zero the measurement offsets while the high-pass filter is enabled when not using a reference. More...
 
bool setLPFCutoff (lis331_lpf_cutoff_t cutoff)
 Set the Low Pass Filter cutoff frequency. Useful for removing high frequency noise while sensing orientation using the acceleration from gravity. More...
 
void setDataRate (lis331_data_rate_t dataRate)
 Sets the data rate for the LIS331 (affects power consumption) More...
 
lis331_data_rate_t getDataRate (void)
 Gets the data rate for the LIS331 (affects power consumption) More...
 
lis331_mode_t getMode (void)
 Return the current power mode from the current data rate. More...
 
lis331_mode_t getMode (lis331_data_rate_t rate)
 Return the current power mode from a given data rate value. More...
 

Public Attributes

int16_t x
 
int16_t y
 
int16_t z
 

Protected Member Functions

virtual void _scaleValues (void)
 Scale the acceleration measuremets from their raw value to milli-g depending on the current measurement range.
 
void writeRange (uint8_t range)
 Set the measurement range for the sensor. More...
 
uint8_t readRange (void)
 Get the measurement range. More...
 

Protected Attributes

float x_g
 
float y_g
 
float z_g
 
Adafruit_I2CDevice * i2c_dev = NULL
 Pointer to I2C bus interface.
 
Adafruit_SPIDevice * spi_dev = NULL
 Pointer to I2C bus interface.
 

Detailed Description

Class that stores state and functions for interacting with Adafruit_LIS331.

Constructor & Destructor Documentation

◆ Adafruit_LIS331() [1/3]

Adafruit_LIS331::Adafruit_LIS331 ( TwoWire *  TheWire = &Wire)

Instantiates a new LIS331 class in I2C.

Parameters
TheWireoptional wire object

◆ Adafruit_LIS331() [2/3]

Adafruit_LIS331::Adafruit_LIS331 ( int8_t  cspin,
SPIClass *  theSPI = &SPI 
)

Instantiates a new LIS331 class using hardware SPI.

Parameters
cspinnumber of CSPIN (Chip Select)
*theSPIoptional parameter contains spi object

◆ Adafruit_LIS331() [3/3]

Adafruit_LIS331::Adafruit_LIS331 ( int8_t  cspin,
int8_t  mosipin,
int8_t  misopin,
int8_t  sckpin 
)

Instantiates a new LIS331 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)

Member Function Documentation

◆ getDeviceID()

uint8_t Adafruit_LIS331::getDeviceID ( void  )

Get Device ID from LIS331_REG_WHOAMI.

Returns
WHO AM I value

◆ configIntDataReady()

bool Adafruit_LIS331::configIntDataReady ( uint8_t  irqnum = 1,
bool  activelow = true,
bool  opendrain = true 
)

Setup the INT1 or INT2 pin to trigger when new data is ready.

Parameters
irqnumThe interrupt number/pin to configure
activelowThe polarity of the pin. true: active low false: active high
opendrainThe pinmode for the given interrupt pin. true: open drain. Connects to GND when activated false: push-pull: connects to VCC when activated
Returns
true
false

◆ getEvent()

bool Adafruit_LIS331::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_LIS331::getSensor ( sensor_t *  sensor)

Gets the sensor_t data.

Parameters
*sensorsensor that we want to write data into

◆ enableHighPassFilter()

void Adafruit_LIS331::enableHighPassFilter ( bool  filter_enabled,
lis331_hpf_cutoff_t  cutoff = LIS331_HPF_0_0025_ODR,
bool  use_reference = false 
)

Enables the high pass filter and/or slope filter.

Parameters
filter_enabledWhether to enable the slope filter (see datasheet)
cutoffThe frequency below which signals will be filtered out
use_referenceSelects if the reference value set by setReference should be used

See section 4 of the LIS331DLH application note for more information

https://www.st.com/content/ccc/resource/technical/document/application_note/b5/8e/58/69/cb/87/45/55/CD00215823.pdf/files/CD00215823.pdf/jcr:content/translations/en.CD00215823.pdf

◆ setHPFReference()

void Adafruit_LIS331::setHPFReference ( int8_t  reference)

Set the reference value to offset measurements when using the High-pass filter.

Parameters
referenceThe offset amount. The conversion of reference to milli-g depends on the selected range:
  • Full scale Reference mode LSB value (mg) 6g/100g ~16mg 12g/200g ~31mg 24g/400g ~63mg

◆ getHPFReference()

int8_t Adafruit_LIS331::getHPFReference ( void  )

Gets the current high-pass filter reference/offset.

Returns
int8_t The current reference value. See enableHighPassFilter and setHPFReference for more information.

◆ HPFReset()

void Adafruit_LIS331::HPFReset ( void  )

Zero the measurement offsets while the high-pass filter is enabled when not using a reference.

See enableHighPassFilter and setHPFReference for more information.

◆ setLPFCutoff()

bool Adafruit_LIS331::setLPFCutoff ( lis331_lpf_cutoff_t  cutoff)

Set the Low Pass Filter cutoff frequency. Useful for removing high frequency noise while sensing orientation using the acceleration from gravity.

Will not work when sensor is in Normal mode because the LPF cutoff bits are used to set the ODR while in Normal mode.

Parameters
cutoffThe frequency above which signals will be ignored.
Returns
true: success false: cuttoff frequency was not set because the

◆ setDataRate()

void Adafruit_LIS331::setDataRate ( lis331_data_rate_t  data_rate)

Sets the data rate for the LIS331 (affects power consumption)

Parameters
data_rateThe new data rate to set.

◆ getDataRate()

lis331_data_rate_t Adafruit_LIS331::getDataRate ( void  )

Gets the data rate for the LIS331 (affects power consumption)

Returns
Returns Data Rate value

◆ getMode() [1/2]

lis331_mode_t Adafruit_LIS331::getMode ( void  )

Return the current power mode from the current data rate.

Returns
lis331_mode_t The currently set power mode

◆ getMode() [2/2]

lis331_mode_t Adafruit_LIS331::getMode ( lis331_data_rate_t  data_rate)

Return the current power mode from a given data rate value.

Parameters
data_rateThe lis331_data_rate_t to return the lis331_mode_t for
Returns
lis331_mode_t

◆ writeRange()

void Adafruit_LIS331::writeRange ( uint8_t  range)
protected

Set the measurement range for the sensor.

Parameters
rangeThe measurement range to set

◆ readRange()

uint8_t Adafruit_LIS331::readRange ( void  )
protected

Get the measurement range.

Returns
uint8_t The measurement range

Member Data Documentation

◆ x

int16_t Adafruit_LIS331::x

x axis value

◆ y

int16_t Adafruit_LIS331::y

y axis value

◆ z

int16_t Adafruit_LIS331::z

z axis value

◆ x_g

float Adafruit_LIS331::x_g
protected

x_g axis value (calculated by selected range)

◆ y_g

float Adafruit_LIS331::y_g
protected

y_g axis value (calculated by selected range)

◆ z_g

float Adafruit_LIS331::z_g
protected

z_g axis value (calculated by selected scale)


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