I2C LSM9DS1 RaspberryPI C++ Library
LSM9DS1 Class Reference

Main class for the LSM9DS1 acceleromter which manages the data acquisition via pigpio and calls the main program via a callback handler. More...

#include <LSM9DS1.h>

Public Member Functions

 LSM9DS1 (DeviceSettings deviceSettings=DeviceSettings())
 LSM9DS1 class constructor. More...
 
void begin (GyroSettings gyroSettings=GyroSettings(), AccelSettings accelSettings=AccelSettings(), MagSettings magSettings=MagSettings(), TemperatureSettings temperatureSettings=TemperatureSettings())
 Initializes the gyro, accelerometer, magnetometer and starts the acquistion. More...
 
void end ()
 Ends the data acquisition and closes all IO.
 
void setCallback (LSM9DS1callback *cb)
 Sets the callback which receives the samples at the sampling rate. More...
 
bool accelAvailable ()
 Polls the accelerometer status register to check if new data is available. More...
 
bool gyroAvailable ()
 Polls the gyroscope status register to check if new data is available. More...
 
bool tempAvailable ()
 Polls the temperature status register to check if new data is available. More...
 
bool magAvailable (lsm9ds1_axis axis=ALL_AXIS)
 Polls the magnetometer status register to check if new data is available. More...
 
int16_t readGyro (lsm9ds1_axis axis)
 Read a specific axis of the gyroscope. More...
 
int16_t readAccel (lsm9ds1_axis axis)
 Read a specific axis of the accelerometer. More...
 
int16_t readMag (lsm9ds1_axis axis)
 Read a specific axis of the magnetometer. More...
 
void magOffset (uint8_t axis, int16_t offset)
 Sets the magnetometer offset. More...
 
float calcGyro (int16_t gyro)
 Convert from RAW signed 16-bit value to degrees per second This function reads in a signed 16-bit value and returns the scaled DPS. More...
 
float calcAccel (int16_t accel)
 Convert from RAW signed 16-bit value to gravity (g's). More...
 
float calcMag (int16_t mag)
 Convert from RAW signed 16-bit value to Gauss (Gs) This function reads in a signed 16-bit value and returns the scaled Gs. More...
 
void setGyroScale (GyroSettings::Scale gScl)
 Set the full-scale range of the gyroscope. More...
 
void setAccelScale (AccelSettings::Scale aScl)
 Set the full-scale range of the accelerometer. More...
 
void setMagScale (MagSettings::Scale mScl)
 Set the full-scale range of the magnetometer. More...
 
uint8_t getGyroIntSrc ()
 Get contents of Gyroscope interrupt source register.
 
uint8_t getAccelIntSrc ()
 Get contents of accelerometer interrupt source register.
 
uint8_t getMagIntSrc ()
 Get contents of magnetometer interrupt source register.
 
uint8_t getInactivity ()
 Get status of inactivity interrupt.
 
uint8_t getFIFOSamples ()
 Get number of FIFO samples.
 

Detailed Description

Main class for the LSM9DS1 acceleromter which manages the data acquisition via pigpio and calls the main program via a callback handler.

The constructor and the begin() function have default settings so that in the simplest case just a callback needs to be registered and then begin be called. To stop the data acquistion call end().

Constructor & Destructor Documentation

◆ LSM9DS1()

LSM9DS1::LSM9DS1 ( DeviceSettings  deviceSettings = DeviceSettings())

LSM9DS1 class constructor.

Parameters
deviceSettingsis defined in DeviceSettings The deviceSettings has default values for standard wiring.

Member Function Documentation

◆ accelAvailable()

bool LSM9DS1::accelAvailable ( )

Polls the accelerometer status register to check if new data is available.

Returns
true if data is available.

◆ begin()

void LSM9DS1::begin ( GyroSettings  gyroSettings = GyroSettings(),
AccelSettings  accelSettings = AccelSettings(),
MagSettings  magSettings = MagSettings(),
TemperatureSettings  temperatureSettings = TemperatureSettings() 
)

Initializes the gyro, accelerometer, magnetometer and starts the acquistion.

This will set up the scale and output rate of each sensor.

Parameters
accelSettingsAccelerometer settings with default settings.
gyroSettingsGyroscope settings with default settings.
magSettingsMagnetometer settings with default settings.
temperatureSettingsTemperature sensor settings with default settings.

◆ calcAccel()

float LSM9DS1::calcAccel ( int16_t  accel)

Convert from RAW signed 16-bit value to gravity (g's).

This function reads in a signed 16-bit value and returns the scaled g's. This function relies on aScale and aRes being correct.

Parameters
accelA signed 16-bit raw reading from the accelerometer.
Returns
Acceleration in m/s^2.

◆ calcGyro()

float LSM9DS1::calcGyro ( int16_t  gyro)

Convert from RAW signed 16-bit value to degrees per second This function reads in a signed 16-bit value and returns the scaled DPS.

This function relies on gScale and gRes being correct.

Parameters
gyroA signed 16-bit raw reading from the gyroscope.
Returns
Rotation in deg/s.

◆ calcMag()

float LSM9DS1::calcMag ( int16_t  mag)

Convert from RAW signed 16-bit value to Gauss (Gs) This function reads in a signed 16-bit value and returns the scaled Gs.

This function relies on mScale and mRes being correct.

Parameters
magA signed 16-bit raw reading from the magnetometer.
Returns
Magnetic field strength in Gauss.

◆ gyroAvailable()

bool LSM9DS1::gyroAvailable ( )

Polls the gyroscope status register to check if new data is available.

Returns
true if data is available.

◆ magAvailable()

bool LSM9DS1::magAvailable ( lsm9ds1_axis  axis = ALL_AXIS)

Polls the magnetometer status register to check if new data is available.

Parameters
axiscan be either X_AXIS, Y_AXIS, Z_AXIS, to check for new data on one specific axis. Or ALL_AXIS (default) to check for new data on all axes.
Returns
true if data is available.

◆ magOffset()

void LSM9DS1::magOffset ( uint8_t  axis,
int16_t  offset 
)

Sets the magnetometer offset.

Parameters
axiscan be any of X_AXIS, Y_AXIS, or Z_AXIS.
offsetin raw units

◆ readAccel()

int16_t LSM9DS1::readAccel ( lsm9ds1_axis  axis)

Read a specific axis of the accelerometer.

Parameters
axiscan be any of X_AXIS, Y_AXIS, or Z_AXIS.
Returns
A 16-bit signed integer with sensor data on requested axis.

◆ readGyro()

int16_t LSM9DS1::readGyro ( lsm9ds1_axis  axis)

Read a specific axis of the gyroscope.

Parameters
axiscan be any of X_AXIS, Y_AXIS, or Z_AXIS.
Returns
A 16-bit signed integer with sensor data on requested axis.

◆ readMag()

int16_t LSM9DS1::readMag ( lsm9ds1_axis  axis)

Read a specific axis of the magnetometer.

Parameters
axiscan be any of X_AXIS, Y_AXIS, or Z_AXIS.
Returns
A 16-bit signed integer with sensor data on requested axis.

◆ setAccelScale()

void LSM9DS1::setAccelScale ( AccelSettings::Scale  aScl)

Set the full-scale range of the accelerometer.

Parameters
Thedesired accelerometer scale.

◆ setCallback()

void LSM9DS1::setCallback ( LSM9DS1callback cb)
inline

Sets the callback which receives the samples at the sampling rate.

Parameters
cbCallback interface.

◆ setGyroScale()

void LSM9DS1::setGyroScale ( GyroSettings::Scale  gScl)

Set the full-scale range of the gyroscope.

This function can be called to set the scale of the gyroscope to 245, 500, or 200 degrees per second.

Parameters
gSclThe desired gyroscope scale.

◆ setMagScale()

void LSM9DS1::setMagScale ( MagSettings::Scale  mScl)

Set the full-scale range of the magnetometer.

The desired magnetometer scale.

◆ tempAvailable()

bool LSM9DS1::tempAvailable ( )

Polls the temperature status register to check if new data is available.

Returns
true if data is available.

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