upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Public Member Functions | Protected Attributes

API for the LIS3DH 3-axis Accelerometer. More...

Detailed Description

The LIS3DH is an ultra-low-power high performance three-axis linear accelerometer belonging to the "nano" family which leverages on the robust and mature manufacturing processes already used for the production of micromachined accelerometers.

The LIS3DH has user-selectable full scales of 2g/4g/8g/16g and is capable of measuring accelerations with output data rates from 1 Hz to 5300 Hz.

Not all functionality of this chip has been implemented in this driver, however all the pieces are present to add any desired functionality. This driver supports both I2C (default) and SPI operation.

// Instantiate an LIS3DH using default I2C parameters
upm::LIS3DH sensor;
// For SPI, bus 0, you would pass -1 as the address, and a valid pin
// for CS: LIS3DH(0, -1, 10);
// now output data every 250 milliseconds
while (shouldRun) {
float x, y, z;
sensor.update();
sensor.getAccelerometer(&x, &y, &z);
cout << "Accelerometer x: " << x << " y: " << y << " z: " << z << " g" << endl;
// we show both C and F for temperature
cout << "Compensation Temperature: " << sensor.getTemperature() << " C / "
<< sensor.getTemperature(true) << " F" << endl;
cout << endl;
upm_delay_us(250000);
}

Public Member Functions

 LIS3DH (int bus=LIS3DH_DEFAULT_I2C_BUS, int addr=LIS3DH_DEFAULT_I2C_ADDR, int cs=-1)
 
virtual ~LIS3DH ()
 
void init (LIS3DH_ODR_T odr=LIS3DH_ODR_100HZ, LIS3DH_FS_T fs=LIS3DH_FS_2G, bool high_res=true)
 
void enableAxes (bool x_axis_enable, bool y_axis_enable, bool z_axis_enable)
 
void enableBDUMode (bool bdu_enable)
 
void enableLPMode (bool lp_enable)
 
void enableHRMode (bool hr_enable)
 
void enableNormalMode ()
 
void enableHPFiltering (bool filter)
 
void enableInterruptLatching (bool int1_latch, bool int2_latch)
 
void enableADC (bool adc_enable)
 
void enableTemperature (bool temperature_enable)
 
void setODR (LIS3DH_ODR_T odr)
 
void setFullScale (LIS3DH_FS_T fs)
 
void setInterruptActiveHigh (bool high)
 
void setInt1Config (uint8_t cfg)
 
void setInt2Config (uint8_t cfg)
 
uint8_t readReg (uint8_t reg)
 
int readRegs (uint8_t reg, uint8_t *buffer, int len)
 
void writeReg (uint8_t reg, uint8_t val)
 
void update ()
 
uint8_t getChipID ()
 
void getAccelerometer (float *x, float *y, float *z)
 
std::vector< float > getAccelerometer ()
 
float getTemperature (bool fahrenheit=false)
 
uint8_t getStatus ()
 
uint8_t getStatusAux ()
 
void installISR (LIS3DH_INTERRUPT_PINS_T intr, int gpio, mraa::Edge level, void(*isr)(void *), void *arg)
 
void uninstallISR (LIS3DH_INTERRUPT_PINS_T intr)
 

Protected Attributes

lis3dh_context m_lis3dh
 

Constructor & Destructor Documentation

LIS3DH ( int  bus = LIS3DH_DEFAULT_I2C_BUS,
int  addr = LIS3DH_DEFAULT_I2C_ADDR,
int  cs = -1 
)

LIS3DH constructor.

This device can support both I2C and SPI. For SPI, set the addr to -1, and specify a positive integer representing the Chip Select (CS) pin for the cs argument. If you are using a hardware CS pin (like edison with arduino breakout), then you can connect the proper pin to the hardware CS pin on your MCU and supply -1 for cs. The default operating mode is I2C.

Parameters
busI2C or SPI bus to use
addrThe address for this device. -1 for SPI
csThe gpio pin to use for the SPI Chip Select. -1 for I2C or for SPI with a hardware controlled pin.
Exceptions
std::runtime_erroron initialization failure
~LIS3DH ( )
virtual

LIS3DH destructor

Here is the call graph for this function:

Member Function Documentation

void init ( LIS3DH_ODR_T  odr = LIS3DH_ODR_100HZ,
LIS3DH_FS_T  fs = LIS3DH_FS_2G,
bool  high_res = true 
)

Initialize the device and start operation. This function is called from the constructor so will not typically need to be called by a user unless the device is reset.

Parameters
odrOne of the LIS3DH_ODR_T values. The default is LIS3DH_ODR_100HZ
fsOne of the LIS3DH_FS_T values. The default is LIS3DH_FS_2G
high_restrue to enable high resolution mode, false to disable. The default is true.
Exceptions
std::runtime_erroron failure

Here is the call graph for this function:

void enableAxes ( bool  x_axis_enable,
bool  y_axis_enable,
bool  z_axis_enable 
)

Enable or disable specific axes. init() enables all three by default.

Parameters
x_axis_enabletrue to enable X axis, false to disable
y_axis_enabletrue to enable Y axis, false to disable
z_axis_enabletrue to enable Z axis, false to disable
Exceptions
std::runtime_erroron failure

Here is the call graph for this function:

void enableBDUMode ( bool  bdu_enable)

Enable or disable Block Data Update (BDU) mode.

Parameters
bdu_enabletrue to enable BDU mode, false to disable
Exceptions
std::runtime_erroron failure

Here is the call graph for this function:

void enableLPMode ( bool  lp_enable)

Enable or disable Low Power (LP) mode. Checks if mutually exclusive High Resolution (HR) mode is enabled and bails out if yes.

Parameters
lp_enabletrue to enable LP mode, false to disable
Exceptions
std::runtime_erroron failure

Here is the call graph for this function:

void enableHRMode ( bool  hr_enable)

Enable or disable High Resolution (HR) mode. Checks if mutually exclusive Low Power (LP) mode is enabled and bails out if yes.

Parameters
hr_enabletrue to enable HR mode, false to disable
Exceptions
std::runtime_erroron failure

Here is the call graph for this function:

void enableNormalMode ( )

Enable Normal mode by explicitly disabling LP and HR ones. Note that there's no "disable" part as it's generally unknown, which mode we were in previously. To get out of Normal mode, just enable HR or LP one.

Exceptions
std::runtime_erroron failure

Here is the call graph for this function:

void enableHPFiltering ( bool  filter)

Enable high pass filtering of the accelerometer axis data. init() disables this by default. See the datasheet for details.

Parameters
filtertrue to enable filtering, false to disable
Exceptions
std::runtime_erroron failure

Here is the call graph for this function:

void enableInterruptLatching ( bool  int1_latch,
bool  int2_latch 
)

Enable or disable interrupt latching for INT1 and INT2. See the datasheet for details.

Parameters
int1_latchtrue to enable latching for INT1, false to disable
int2_latchtrue to enable latching for INT2, false to disable
Exceptions
std::runtime_erroron failure

Here is the call graph for this function:

void enableADC ( bool  adc_enable)

Enable or disable built-in Analog-to-Digital Converter (ADC).

Parameters
adc_enabletrue to enable ADC, false to disable
Exceptions
std::runtime_erroron failure

Here is the call graph for this function:

void enableTemperature ( bool  temperature_enable)

Enable or disable built-in temperature sensor. It depends on ADC being enabled, so we enable it unconditionally. See datasheet for details.

Parameters
temperature_enabletrue to enable temp sensor, false to disable
Exceptions
std::runtime_erroron failure

Here is the call graph for this function:

void setODR ( LIS3DH_ODR_T  odr)

Set the output data rate (ODR) of the device

Parameters
odrOne of the LIS3DH_ODR_T values
Exceptions
std::runtime_erroron failure

Here is the call graph for this function:

void setFullScale ( LIS3DH_FS_T  fs)

Set the full scale (FS) of the device. This device supports a full scale of 2, 4, 8 and 16G.

Parameters
fsOne of the LIS3DH_FS_T values
Exceptions
std::runtime_erroron failure

Here is the call graph for this function:

void setInterruptActiveHigh ( bool  high)

Indicate whether INT1 and INT2 interrupts should be active high (default) or active low. See the datasheet for details.

Parameters
hightrue for active high, false for active low
Exceptions
std::runtime_erroron failure

Here is the call graph for this function:

void setInt1Config ( uint8_t  cfg)

Set interrupt 1 configuration. See the datasheet for details.

Parameters
cfgA bitmask of values from LIS3DH_CTRL_REG3_BITS_T
Exceptions
std::runtime_erroron failure

Here is the call graph for this function:

void setInt2Config ( uint8_t  cfg)

Set interrupt 2 configuration. See the datasheet for details.

Parameters
cfgA bitmask of values from LIS3DH_CTRL_REG6_BITS_T
Exceptions
std::runtime_erroron failure

Here is the call graph for this function:

uint8_t readReg ( uint8_t  reg)

Read a register

Parameters
regThe register to read
Returns
The value of the register

Here is the call graph for this function:

int readRegs ( uint8_t  reg,
uint8_t *  buffer,
int  len 
)

Read contiguous registers into a buffer

Parameters
regThe register to start the read from
bufferThe buffer to store the results
lenThe number of registers to read
Returns
The number of bytes read
Exceptions
std::runtime_erroron failure

Here is the call graph for this function:

void writeReg ( uint8_t  reg,
uint8_t  val 
)

Write to a register

Parameters
regThe register to write to
valThe value to write
Exceptions
std::runtime_erroron failure

Here is the call graph for this function:

void update ( void  )

Update the internal stored values from sensor data

Exceptions
std::runtime_erroron failure

Here is the call graph for this function:

uint8_t getChipID ( )

Return the chip ID

Returns
The chip ID

Here is the call graph for this function:

void getAccelerometer ( float *  x,
float *  y,
float *  z 
)

Return accelerometer data in gravities. update() must have been called prior to calling this method.

Parameters
xPointer to a floating point value that will have the current x component placed into it
yPointer to a floating point value that will have the current y component placed into it
zPointer to a floating point value that will have the current z component placed into it

Here is the call graph for this function:

std::vector< float > getAccelerometer ( )

Return accelerometer data in gravities in the form of a floating point vector. update() must have been called prior to calling this method.

Returns
A floating point vector containing x, y and z in that order
float getTemperature ( bool  fahrenheit = false)

Return the current measured temperature. Note, this is not ambient temperature. update() must have been called prior to calling this method.

Parameters
fahrenheittrue to return data in Fahrenheit, false for Celicus. Celsius is the default.
Returns
The temperature in degrees Celsius or Fahrenheit

Here is the call graph for this function:

uint8_t getStatus ( )

Return the contents of the status register

Returns
A bitmask of values from LIS3DH_STATUS_REG_BITS_T

Here is the call graph for this function:

uint8_t getStatusAux ( )

Return the contents of the status aux register

Returns
A bitmask of values from LIS3DH_STATUS_REG_AUX_BITS_T

Here is the call graph for this function:

void installISR ( LIS3DH_INTERRUPT_PINS_T  intr,
int  gpio,
mraa::Edge  level,
void(*)(void *)  isr,
void *  arg 
)

Install an interrupt handler

Parameters
intrOne of the LIS3DH_INTERRUPT_PINS_T values specifying which interrupt pin you are installing
gpioGPIO pin to use as interrupt pin
levelThe interrupt trigger level (one of mraa::Edge values). Make sure that you have configured the interrupt pin properly for whatever level you choose.
isrThe interrupt handler, accepting a void * argument
argThe argument to pass the the interrupt handler
Exceptions
std::runtime_erroron failure

Here is the call graph for this function:

void uninstallISR ( LIS3DH_INTERRUPT_PINS_T  intr)

Uninstall a previously installed interrupt handler

Parameters
intrOne of the LIS3DH_INTERRUPT_PINS_T values, specifying which interrupt pin you are removing

Here is the call graph for this function:

Collaboration diagram for LIS3DH:
Collaboration graph
[legend]

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