LSM9DS1 IMU sensor driver i2c

Dependents:   read_Pmod optWingforHAPS_Eigen hexaTest_Eigen

Embed: (wiki syntax)

« Back to documentation index

LSM9DS1 Class Reference

LSM9DS1 Class Reference

LSM9DS1 Class - driver for the 9 DoF IMU. More...

#include <LSM9DS1.h>

Public Types

enum  gyro_scale
 

gyro_scale defines the possible full-scale ranges of the gyroscope:

More...
enum  gyro_odr
 

gyro_odr defines all possible data rate/bandwidth combos of the gyro:

More...
enum  accel_scale
 

accel_scale defines all possible FSR's of the accelerometer:

More...
enum  accel_odr
 

accel_oder defines all possible output data rates of the accelerometer:

More...
enum  mag_scale
 

mag_scale defines all possible FSR's of the magnetometer:

More...
enum  mag_odr
 

mag_odr defines all possible output data rates of the magnetometer:

More...

Public Member Functions

 LSM9DS1 (I2C &p_i2c, uint8_t xgAddr=LSM9DS1_AG_I2C_ADDR(1), uint8_t mAddr=LSM9DS1_M_I2C_ADDR(1))
 LSM9DS1 -- LSM9DS1 class constructor The constructor will set up a handful of private variables, and set the communication mode as well.
uint16_t begin (gyro_scale gScl=G_SCALE_245DPS, accel_scale aScl=A_SCALE_2G, mag_scale mScl=M_SCALE_4GS, gyro_odr gODR=G_ODR_119_BW_14, accel_odr aODR=A_ODR_119, mag_odr mODR=M_ODR_80)
 begin() -- Initialize the gyro, accelerometer, and magnetometer.
void readGyro ()
 readGyro() -- Read the gyroscope output registers.
void readAccel ()
 readAccel() -- Read the accelerometer output registers.
void readMag ()
 readMag() -- Read the magnetometer output registers.
void readTemp ()
 readTemp() -- Read the temperature output register.
void setGyroScale (gyro_scale gScl)
 setGyroScale() -- Set the full-scale range of the gyroscope.
void setAccelScale (accel_scale aScl)
 setAccelScale() -- Set the full-scale range of the accelerometer.
void setMagScale (mag_scale mScl)
 setMagScale() -- Set the full-scale range of the magnetometer.
void setGyroODR (gyro_odr gRate)
 setGyroODR() -- Set the output data rate and bandwidth of the gyroscope Input:

  • gRate = The desired output rate and cutoff frequency of the gyro.

void setAccelODR (accel_odr aRate)
 setAccelODR() -- Set the output data rate of the accelerometer Input:

  • aRate = The desired output rate of the accel.

void setMagODR (mag_odr mRate)
 setMagODR() -- Set the output data rate of the magnetometer Input:

  • mRate = The desired output rate of the mag.


Detailed Description

LSM9DS1 Class - driver for the 9 DoF IMU.

Definition at line 102 of file LSM9DS1.h.


Member Enumeration Documentation

enum accel_odr

accel_oder defines all possible output data rates of the accelerometer:

Definition at line 146 of file LSM9DS1.h.

accel_scale defines all possible FSR's of the accelerometer:

Definition at line 137 of file LSM9DS1.h.

enum gyro_odr

gyro_odr defines all possible data rate/bandwidth combos of the gyro:

Definition at line 115 of file LSM9DS1.h.

enum gyro_scale

gyro_scale defines the possible full-scale ranges of the gyroscope:

Definition at line 107 of file LSM9DS1.h.

enum mag_odr

mag_odr defines all possible output data rates of the magnetometer:

Definition at line 177 of file LSM9DS1.h.

enum mag_scale

mag_scale defines all possible FSR's of the magnetometer:

Definition at line 168 of file LSM9DS1.h.


Constructor & Destructor Documentation

LSM9DS1 ( I2C &  p_i2c,
uint8_t  xgAddr = LSM9DS1_AG_I2C_ADDR(1),
uint8_t  mAddr = LSM9DS1_M_I2C_ADDR(1) 
)

LSM9DS1 -- LSM9DS1 class constructor The constructor will set up a handful of private variables, and set the communication mode as well.

Input:

  • interface = Either MODE_SPI or MODE_I2C, whichever you're using to talk to the IC.
  • xgAddr = If MODE_I2C, this is the I2C address of the accel/gyro. If MODE_SPI, this is the chip select pin of the accel/gyro (CS_A/G)
  • mAddr = If MODE_I2C, this is the I2C address of the mag. If MODE_SPI, this is the cs pin of the mag (CS_M)

Definition at line 3 of file LSM9DS1.cpp.


Member Function Documentation

uint16_t begin ( gyro_scale  gScl = G_SCALE_245DPS,
accel_scale  aScl = A_SCALE_2G,
mag_scale  mScl = M_SCALE_4GS,
gyro_odr  gODR = G_ODR_119_BW_14,
accel_odr  aODR = A_ODR_119,
mag_odr  mODR = M_ODR_80 
)

begin() -- Initialize the gyro, accelerometer, and magnetometer.

This will set up the scale and output rate of each sensor. It'll also "turn on" every sensor and every axis of every sensor. Input:

  • gScl = The scale of the gyroscope. This should be a gyro_scale value.
  • aScl = The scale of the accelerometer. Should be a accel_scale value.
  • mScl = The scale of the magnetometer. Should be a mag_scale value.
  • gODR = Output data rate of the gyroscope. gyro_odr value.
  • aODR = Output data rate of the accelerometer. accel_odr value.
  • mODR = Output data rate of the magnetometer. mag_odr value. Output: The function will return an unsigned 16-bit value. The most-sig bytes of the output are the WHO_AM_I reading of the accel/gyro. The least significant two bytes are the WHO_AM_I reading of the mag. All parameters have a defaulted value, so you can call just "begin()". Default values are FSR's of: +/- 245DPS, 4g, 2Gs; ODRs of 119 Hz for gyro, 119 Hz for accelerometer, 80 Hz for magnetometer. Use the return value of this function to verify communication.

Definition at line 10 of file LSM9DS1.cpp.

void readAccel (  )

readAccel() -- Read the accelerometer output registers.

This function will read all six accelerometer output registers. The readings are stored in the class' ax_raw, ay_raw, and az_raw variables. Read those _after_ calling readAccel().

Definition at line 106 of file LSM9DS1.cpp.

void readGyro (  )

readGyro() -- Read the gyroscope output registers.

This function will read all six gyroscope output registers. The readings are stored in the class' gx_raw, gy_raw, and gz_raw variables. Read those _after_ calling readGyro().

Definition at line 171 of file LSM9DS1.cpp.

void readMag (  )

readMag() -- Read the magnetometer output registers.

This function will read all six magnetometer output registers. The readings are stored in the class' mx_raw, my_raw, and mz_raw variables. Read those _after_ calling readMag().

Definition at line 128 of file LSM9DS1.cpp.

void readTemp (  )

readTemp() -- Read the temperature output register.

This function will read two temperature output registers. The combined readings are stored in the class' temperature variables. Read those _after_ calling readTemp().

Definition at line 150 of file LSM9DS1.cpp.

void setAccelODR ( accel_odr  aRate )

setAccelODR() -- Set the output data rate of the accelerometer Input:

  • aRate = The desired output rate of the accel.

Must be a value from the accel_odr enum (check above).

Definition at line 299 of file LSM9DS1.cpp.

void setAccelScale ( accel_scale  aScl )

setAccelScale() -- Set the full-scale range of the accelerometer.

This function can be called to set the scale of the accelerometer to 2, 4, 8, or 16 g's. Input:

  • aScl = The desired accelerometer scale. Must be one of five possible values from the accel_scale enum.

Definition at line 221 of file LSM9DS1.cpp.

void setGyroODR ( gyro_odr  gRate )

setGyroODR() -- Set the output data rate and bandwidth of the gyroscope Input:

  • gRate = The desired output rate and cutoff frequency of the gyro.

Must be a value from the gyro_odr enum (check above).

Definition at line 277 of file LSM9DS1.cpp.

void setGyroScale ( gyro_scale  gScl )

setGyroScale() -- Set the full-scale range of the gyroscope.

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

  • gScl = The desired gyroscope scale. Must be one of three possible values from the gyro_scale enum.

Definition at line 193 of file LSM9DS1.cpp.

void setMagODR ( mag_odr  mRate )

setMagODR() -- Set the output data rate of the magnetometer Input:

  • mRate = The desired output rate of the mag.

Must be a value from the mag_odr enum (check above).

Definition at line 321 of file LSM9DS1.cpp.

void setMagScale ( mag_scale  mScl )

setMagScale() -- Set the full-scale range of the magnetometer.

This function can be called to set the scale of the magnetometer to 4, 8, 12, or 16 Gs. Input:

  • mScl = The desired magnetometer scale. Must be one of four possible values from the mag_scale enum.

Definition at line 249 of file LSM9DS1.cpp.