UPM

The UPM API is a high level sensor library for IoT devices using MRAA. See examples here. Back to index page.
SparkFun sensor images provided under CC BY-NC-SA-3.0.

LIS2DS12 Class

Module: lis2ds12

The LIS2DS12 is an ultra-low-power high performance three-axis linear accelerometer belonging to the "pico" family which leverages on the robust and mature manufacturing processes already used for the production of micromachined accelerometers.
The LIS2DS12 has user-selectable full scales of 2g/4g/8g/16g and is capable of measuring accelerations with output data rates from 1 Hz to 6400 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.
This device requires 1.8v operation.

Methods

LIS2DS12

(
  • bus
  • addr
  • cs
)
Number

LIS2DS12 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 Number

    I2C or SPI bus to use

  • addr Number

    The address for this device. -1 for SPI

  • cs Number

    The gpio pin to use for the SPI Chip Select. -1 for I2C or for SPI with a hardware controlled pin.

Returns:

Number:

update

()

Update the internal stored values from sensor data

getChipID

() Number

Return the chip ID

Returns:

Number:

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:

Std::vector float :

A floating point vector containing x, y, and z in that order

getTemperature

(
  • fahrenheit
)
Number

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

Parameters:

  • fahrenheit Boolean

    true to return data in Fahrenheit, false for Celicus. Celsius is the default.

Returns:

Number:

The temperature in degrees Celsius or Fahrenheit

init

(
  • odr
  • fs
)

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 LIS2DS12_ODR_T

    One of the LIS2DS12_ODR_T values. The default is LIS2DS12_ODR_100HZ

  • fs LIS2DS12_FS_T

    One of the LIS2DS12_FS_T values. The default is LIS2DS12_FS_2G

reset

()

Reset the device as if during a power on reset. All configured values are lost when this happens. You should call init() afterwards, or at least perform the same initialization init() does before continuing.

setODR

(
  • odr
)

Set the output data rate (ODR) of the device

Parameters:

  • odr LIS2DS12_ODR_T

    One of the LIS2DS12_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 LIS2DS12_FS_T

    One of the LIS2DS12_FS_T values

enableHPFiltering

(
  • filter
)

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

Parameters:

  • filter Boolean

    true to enable filtering, false to disable

enableInterruptLatching

(
  • latch
)

Enable or disable interrupt latching. If latching is disabled, pulsed is enabled. See the datasheet for details.

Parameters:

  • latch Boolean

    true to enable latching, false to disable

setInterruptActiveHigh

(
  • high
)

Indicate whether the interrupt should be active high (default) or active low. See the datasheet for details.

Parameters:

  • high Boolean

    true for active high, false for active low

setInterruptPushPull

(
  • pp
)

Indicate whether interrupts are push-pull (default) or open drain. See the datasheet for details.

Parameters:

  • pp Boolean

    true for push-pull, false for open-drain

setInt1Config

(
  • cfg
)

Set interrupt 1 configuration. See the datasheet for details.

Parameters:

  • cfg Number

    A bitmask of values from LIS2DS12_CTRL4_BITS_T

setInt2Config

(
  • cfg
)

Set interrupt 2 configuration. See the datasheet for details.

Parameters:

  • cfg Number

    A bitmask of values from LIS2DS12_CTRL5_BITS_T

getStatus

() Number

Return the contents of the status register

Returns:

Number:

A bitmask of values from LIS2DS12_STATUS_BITS_T

installISR

(
  • intr
  • gpio
  • level
  • isr
  • arg
)

install an interrupt handler

Parameters:

  • intr LIS2DS12_INTERRUPT_PINS_T

    One of the LIS2DS12_INTERRUPT_PINS_T values specifying which interrupt pin you are installing

  • gpio Number

    GPIO pin to use as interrupt pin

  • level Mraa::Edge

    The interrupt trigger level (one of mraa::Edge values). Make sure that you have configured the interrupt pin properly for whatever level you choose.

  • isr Function

    The 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 LIS2DS12_INTERRUPT_PINS_T

    One of the LIS2DS12_INTERRUPT_PINS_T values specifying which interrupt pin you are removing

readReg

(
  • reg
)
Number

Read a register

Parameters:

  • reg Number

    The register to read

Returns:

Number:

The value of the register

readRegs

(
  • reg
  • buffer
  • len
)
Number

Read contiguous registers into a buffer

Parameters:

  • reg Number

    The register to start the read from

  • buffer Uint8_t *

    The buffer to store the results

  • len Number

    The number of registers to read

Returns:

Number:

The number of bytes read

writeReg

(
  • reg
  • val
)

Write to a register

Parameters:

  • reg Number

    The register to write to

  • val Number

    The value to write