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.

LSM303D Class

Module: lsm303d

The LSM303D is an ultra-low-power high-performance system-in-package featuring a 3D digital linear acceleration sensor and a 3D digital magnetic sensor. The LSM303D has linear acceleration full scales of 2g/4g/8g/16g and a magnetic field dynamic range of 50 Gauss.
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 only I2C operation.
This device requires 3.3v operation.

Methods

LSM303D

(
  • bus
  • addr
)
Number

LSM303D constructor
This driver only supports I2C.
Due to the fact that this chip is currently obsolete, we only support minimum functionality.

Parameters:

  • bus Number

    I2C bus to use

  • addr Number

    The I2C address of the device

Returns:

Number:

The device context, or NULL if an error occurred

update

()

Update the internal stored values from sensor data. This method must be called before querying the acceleration, magnetometer, or temperature.

getMagnetometer

(
  • x
  • y
  • z
)

Return magnetometer data in micro-Teslas (uT). 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

getMagnetometer

() Std::vector float

Return magnetometer data in micro-Teslas (uT) 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

getAccelerometer

(
  • x
  • y
  • z
)

Return acceleration 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 acceleration 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

() Number

Return temperature data in degrees Celsius. NOTE: This is not the ambient room temperature. update() must have been called prior to calling this method.

Returns:

Number:

Temperature in degrees Celsius

init

(
  • res
)

Initialize the device and start operation. This function is called from the constructor so it will not typically need to be called by a user unless the device is reset. It will initialize the accelerometer and magnetometer (if enabled) to certain default running modes.

Parameters:

  • res LSM303D_M_RES_T

    One of the LSM303D_M_RES_T values. This value sets the resolution of the magnetometer. At init time, this value is set to LSM303D_M_RES_HIGH.

setAccelerometerFullScale

(
  • fs
)

Set the full scale (sensitivity) value for the accelerometer. This device supports 2G, 4G, 6G, 8G, and 16G full scale modes.

Parameters:

  • fs LSM303D_AFS_T

    One of the LSM303D_AFS_T values

setMagnetometerFullScale

(
  • fs
)

Set the full scale (sensitivity) value for the magnetometer. This device supports 2, 4, 8, and 16 Gauss full scale modes.

Parameters:

  • fs LSM303D_MFS_T

    One of the LSM303D_MFS_T values

setAccelerometerODR

(
  • odr
)

Set the accelerometer output data rate (ODR)

Parameters:

  • odr LSM303D_AODR_T

    One of the LSM303D_AODR_T values. The default set at initialization time is LSM303D_AODR_100HZ.

setMagnetometerODR

(
  • odr
)

Set the magnetometer output data rate (ODR)

Parameters:

  • odr LSM303D_MODR_T

    One of the LSM303D_MODR_T values. The default set at initialization time is LSM303D_MODR_12_5HZ.