LIS3DH Class
- ID: lis3dh
- Name: Digital 3-axis Accelerometer
- Category: accelerometer
- Manufacturer: stmicro
- Connection: i2c spi gpio
- Link: http://www.st.com/en/mems-and-sensors/lis3dh.html
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.
Item Index
Methods
- LIS3DH
- init
- enableAxes
- enableBDUMode
- enableLPMode
- enableHRMode
- enableNormalMode
- enableHPFiltering
- enableInterruptLatching
- enableADC
- enableTemperature
- setODR
- setFullScale
- setInterruptActiveHigh
- setInt1Config
- setInt2Config
- readReg
- readRegs
- writeReg
- update
- getChipID
- getAccelerometer
- getAccelerometer
- getTemperature
- getStatus
- getStatusAux
- installISR
- uninstallISR
Methods
LIS3DH
-
bus
-
addr
-
cs
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:
-
bus
NumberI2C or SPI bus to use
-
addr
NumberThe address for this device. -1 for SPI
-
cs
NumberThe gpio pin to use for the SPI Chip Select. -1 for I2C or for SPI with a hardware controlled pin.
Returns:
init
-
odr
-
fs
-
high_res
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:
-
odr
LIS3DH_ODR_TOne of the LIS3DH_ODR_T values. The default is LIS3DH_ODR_100HZ
-
fs
LIS3DH_FS_TOne of the LIS3DH_FS_T values. The default is LIS3DH_FS_2G
-
high_res
Booleantrue to enable high resolution mode, false to disable. The default is true.
enableAxes
-
x_axis_enable
-
y_axis_enable
-
z_axis_enable
Enable or disable specific axes. init() enables all three by default.
Parameters:
-
x_axis_enable
Booleantrue to enable X axis, false to disable
-
y_axis_enable
Booleantrue to enable Y axis, false to disable
-
z_axis_enable
Booleantrue to enable Z axis, false to disable
enableBDUMode
-
bdu_enable
Enable or disable Block Data Update (BDU) mode.
Parameters:
-
bdu_enable
Booleantrue to enable BDU mode, false to disable
enableLPMode
-
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_enable
Booleantrue to enable LP mode, false to disable
enableHRMode
-
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_enable
Booleantrue to enable HR mode, false to disable
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.
enableHPFiltering
-
filter
Enable high pass filtering of the accelerometer axis data. init() disables this by default. See the datasheet for details.
Parameters:
-
filter
Booleantrue to enable filtering, false to disable
enableInterruptLatching
-
int1_latch
-
int2_latch
Enable or disable interrupt latching for INT1 and INT2. See the datasheet for details.
Parameters:
-
int1_latch
Booleantrue to enable latching for INT1, false to disable
-
int2_latch
Booleantrue to enable latching for INT2, false to disable
enableADC
-
adc_enable
Enable or disable built-in Analog-to-Digital Converter (ADC).
Parameters:
-
adc_enable
Booleantrue to enable ADC, false to disable
enableTemperature
-
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_enable
Booleantrue to enable temp sensor, false to disable
setODR
-
odr
Set the output data rate (ODR) of the device
Parameters:
-
odr
LIS3DH_ODR_TOne of the LIS3DH_ODR_T values
setFullScale
-
fs
Set the full scale (FS) of the device. This device supports a full scale of 2, 4, 8 and 16G.
Parameters:
-
fs
LIS3DH_FS_TOne of the LIS3DH_FS_T values
setInterruptActiveHigh
-
high
Indicate whether INT1 and INT2 interrupts should be active high (default) or active low. See the datasheet for details.
Parameters:
-
high
Booleantrue for active high, false for active low
setInt1Config
-
cfg
Set interrupt 1 configuration. See the datasheet for details.
Parameters:
-
cfg
NumberA bitmask of values from LIS3DH_CTRL_REG3_BITS_T
setInt2Config
-
cfg
Set interrupt 2 configuration. See the datasheet for details.
Parameters:
-
cfg
NumberA bitmask of values from LIS3DH_CTRL_REG6_BITS_T
readReg
-
reg
Read a register
Parameters:
-
reg
NumberThe register to read
Returns:
The value of the register
readRegs
-
reg
-
buffer
-
len
Read contiguous registers into a buffer
Parameters:
-
reg
NumberThe register to start the read from
-
buffer
Uint8_t *The buffer to store the results
-
len
NumberThe number of registers to read
Returns:
The number of bytes read
writeReg
-
reg
-
val
Write to a register
Parameters:
-
reg
NumberThe register to write to
-
val
NumberThe value to write
update
()
Update the internal stored values from sensor data
getChipID
()
Number
Return the chip ID
Returns:
The chip ID
getAccelerometer
-
x
-
y
-
z
Return accelerometer data in gravities. update() must have been called prior to calling this method.
Parameters:
-
x
Float *Pointer to a floating point value that will have the current x component placed into it
-
y
Float *Pointer to a floating point value that will have the current y component placed into it
-
z
Float *Pointer to a floating point value that will have the current z component placed into it
getAccelerometer
()
Std::vector float
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
getTemperature
-
fahrenheit
Return the current measured temperature. Note, this is not ambient temperature. update() must have been called prior to calling this method.
Parameters:
-
fahrenheit
Booleantrue to return data in Fahrenheit, false for Celicus. Celsius is the default.
Returns:
The temperature in degrees Celsius or Fahrenheit
getStatus
()
Number
Return the contents of the status register
Returns:
A bitmask of values from LIS3DH_STATUS_REG_BITS_T
getStatusAux
()
Number
Return the contents of the status aux register
Returns:
A bitmask of values from LIS3DH_STATUS_REG_AUX_BITS_T
installISR
-
intr
-
gpio
-
level
-
isr
-
arg
Install an interrupt handler
Parameters:
-
intr
LIS3DH_INTERRUPT_PINS_TOne of the LIS3DH_INTERRUPT_PINS_T values specifying which interrupt pin you are installing
-
gpio
NumberGPIO pin to use as interrupt pin
-
level
Mraa::EdgeThe interrupt trigger level (one of mraa::Edge values). Make sure that you have configured the interrupt pin properly for whatever level you choose.
-
isr
FunctionThe interrupt handler, accepting a void * argument
-
arg
Void *The argument to pass the the interrupt handler
uninstallISR
-
intr
Uninstall a previously installed interrupt handler
Parameters:
-
intr
LIS3DH_INTERRUPT_PINS_TOne of the LIS3DH_INTERRUPT_PINS_T values, specifying which interrupt pin you are removing