LSM6DSL Class
- ID: lsm6dsl
- Name: Digital 3-axis Accelerometer and Gyroscope
- Category: accelerometer gyro
- Manufacturer: stmicro
- Connection: i2c spi gpio
- Link: http://www.st.com/en/mems-and-sensors/lsm6dsl.html
The LSM6DSL is a system-in-package featuring a 3D digital accelerometer and a 3D digital gyroscope performing at 0.65 mA in high performance mode and enabling always-on low-power features for an optimal motion experience for the consumer.
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
- LSM6DSL
- update
- getChipID
- getAccelerometer
- getAccelerometer
- getGyroscope
- getGyroscope
- getTemperature
- init
- reset
- setAccelerometerODR
- setAccelerometerFullScale
- setGyroscopeODR
- setGyroscopeFullScale
- setHighPerformance
- setInterruptActiveHigh
- setInterruptPushPull
- getStatus
- setAccelerometerOffsets
- installISR
- uninstallISR
- readReg
- readRegs
- writeReg
Methods
LSM6DSL
-
bus
-
addr
-
cs
LSM6DSL 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:
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
getGyroscope
-
x
-
y
-
z
Return gyroscope data in degrees per second (DPS). 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
getGyroscope
()
Std::vector float
Return gyroscope data in degrees per second 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
init
-
acc_odr
-
acc_fs
-
gyr_odr
-
gyr_fs
Initialize the device and start operation. This function is called from the constructor, so it will not need to be called by a user unless the device is reset. It sets the accelerometer and gyroscope ODR and FS modes, and enables BDU, register auto-increment, and high performance mode.
Parameters:
-
acc_odr
LSM6DSL_XL_ODR_TOne of the LSM6DSL_XL_ODR_T values
-
acc_fs
LSM6DSL_XL_FS_TOne of the LSM6DSL_XL_FS_T values
-
gyr_odr
LSM6DSL_G_ODR_TOne of the LSM6DSL_G_ODR_T values
-
gyr_fs
LSM6DSL_G_FS_TOne of the LSM6DSL_G_FS_T values
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.
setAccelerometerODR
-
odr
Set the output data rate (ODR) of the accelerometer
Parameters:
-
odr
LSM6DSL_XL_ODR_TOne of the LSM6DSL_XL_ODR_T values
setAccelerometerFullScale
-
fs
Set the full scale (FS) of the accelerometer. This device supports a full scale of 2, 4, 8, and 16G.
Parameters:
-
fs
LSM6DSL_XL_FS_TOne of the LSM6DSL_XL_FS_T values
setGyroscopeODR
-
odr
Set the output data rate (ODR) of the gyroscope
Parameters:
-
odr
LSM6DSL_G_ODR_TOne of the LSM6DSL_G_ODR_T values
setGyroscopeFullScale
-
fs
Set the full scale (FS) of the gyroscope
Parameters:
-
fs
LSM6DSL_G_FS_TOne of the LSM6DSL_G_FS_T values
setHighPerformance
-
enable
Enable accelerometer and gyroscope high performance modes. These are further defined by the respective ODR settings to allow low power, and normal/high-performance modes. This is enabled by default in init() .
Parameters:
-
enable
Booleantrue to enable high performance mode, false otherwise
setInterruptActiveHigh
-
high
Indicate whether the interrupt should be active high (default) or active low. See the datasheet for details.
Parameters:
-
high
Booleantrue 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
Booleantrue for push-pull, false for open-drain
getStatus
()
Number
Return the contents of the status register
Returns:
A bitmask of values from LSM6DSL_STATUS_BITS_T
setAccelerometerOffsets
-
x
-
y
-
z
-
weight
Set accelerometer offsets for each axis. In the case of X and Y, the offsets will be internally added before being placed into the output registers. For the Z offset, the value will be subtracted before being placed into the output registers. The weight is used to determine the weighing of the offset bits. All offsets must be in the range of -127 to 127.
Parameters:
-
x
NumberX axis offset in the range -127 to 127
-
y
NumberY axis offset in the range -127 to 127
-
z
NumberZ axis offset in the range -127 to 127
-
weight
BooleanWhen true, the the offset will be weighted at 2^-6 g/LSB, when false the weighting will be 2^-10 g/LSB
installISR
-
intr
-
gpio
-
level
-
isr
-
arg
install an interrupt handler
Parameters:
-
intr
LSM6DSL_INTERRUPT_PINS_TOne of the LSM6DSL_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
LSM6DSL_INTERRUPT_PINS_TOne of the LSM6DSL_INTERRUPT_PINS_T values specifying which interrupt pin you are removing
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
Numberundefined
-
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