Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: 4180_LSM9DS0_lab HW2_P2 HW2_P3 HW2_P4 ... more
LSM9DS0 Class Reference
LSM9DS0 Class - driver for the 9 DoF IMU. More...
#include <LSM9DS0.h>
Public Types | |
| enum | gyro_scale |
gyro_scale defines the possible full-scale ranges of the gyroscope: More... | |
| enum | accel_scale |
accel_scale defines all possible FSR's of the accelerometer: More... | |
| enum | mag_scale |
mag_scale defines all possible FSR's of the magnetometer: More... | |
| enum | gyro_odr |
gyro_odr defines all possible data rate/bandwidth combos of the gyro: More... | |
| enum | accel_odr |
accel_oder defines all possible output data rates of the accelerometer: More... | |
| enum | mag_odr |
accel_oder defines all possible output data rates of the magnetometer: More... | |
Public Member Functions | |
| LSM9DS0 (PinName sda, PinName scl, uint8_t gAddr, uint8_t xmAddr) | |
| LSM9DS0 -- LSM9DS0 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_2GS, gyro_odr gODR=G_ODR_95_BW_125, accel_odr aODR=A_ODR_50, mag_odr mODR=M_ODR_50) |
| 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:
| |
| void | setAccelODR (accel_odr aRate) |
setAccelODR() -- Set the output data rate of the accelerometer Input:
| |
| void | setMagODR (mag_odr mRate) |
setMagODR() -- Set the output data rate of the magnetometer Input:
| |
| void | configGyroInt (uint8_t int1Cfg, uint16_t int1ThsX=0, uint16_t int1ThsY=0, uint16_t int1ThsZ=0, uint8_t duration=0) |
| configGyroInt() -- Configure the gyro interrupt output. | |
| float | calcHeading () |
| return a comass heading (in degrees) using X/Y magnetometer data | |
Detailed Description
LSM9DS0 Class - driver for the 9 DoF IMU.
Definition at line 100 of file LSM9DS0.h.
Member Enumeration Documentation
| enum accel_odr |
| enum accel_scale |
| enum gyro_odr |
| enum gyro_scale |
| enum mag_odr |
| enum mag_scale |
Constructor & Destructor Documentation
| LSM9DS0 | ( | PinName | sda, |
| PinName | scl, | ||
| uint8_t | gAddr, | ||
| uint8_t | xmAddr | ||
| ) |
LSM9DS0 -- LSM9DS0 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.
- gAddr = If MODE_I2C, this is the I2C address of the gyroscope. If MODE_SPI, this is the chip select pin of the gyro (CSG)
- xmAddr = If MODE_I2C, this is the I2C address of the accel/mag. If MODE_SPI, this is the cs pin of the accel/mag (CSXM)
Definition at line 4 of file LSM9DS0.cpp.
Member Function Documentation
| uint16_t begin | ( | gyro_scale | gScl = G_SCALE_245DPS, |
| accel_scale | aScl = A_SCALE_2G, |
||
| mag_scale | mScl = M_SCALE_2GS, |
||
| gyro_odr | gODR = G_ODR_95_BW_125, |
||
| accel_odr | aODR = A_ODR_50, |
||
| mag_odr | mODR = M_ODR_50 |
||
| ) |
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. The least significant two bytes are the WHO_AM_I reading of the gyro. All parameters have a defaulted value, so you can call just "begin()". Default values are FSR's of: +/- 245DPS, 2g, 2Gs; ODRs of 95 Hz for gyro, 100 Hz for accelerometer, 100 Hz for magnetometer. Use the return value of this function to verify communication.
Definition at line 11 of file LSM9DS0.cpp.
| float calcHeading | ( | ) |
return a comass heading (in degrees) using X/Y magnetometer data
Definition at line 317 of file LSM9DS0.cpp.
| void configGyroInt | ( | uint8_t | int1Cfg, |
| uint16_t | int1ThsX = 0, |
||
| uint16_t | int1ThsY = 0, |
||
| uint16_t | int1ThsZ = 0, |
||
| uint8_t | duration = 0 |
||
| ) |
configGyroInt() -- Configure the gyro interrupt output.
Triggers can be set to either rising above or falling below a specified threshold. This function helps setup the interrupt configuration and threshold values for all axes. Input:
- int1Cfg = A 8-bit value that is sent directly to the INT1_CFG_G register. This sets AND/OR and high/low interrupt gen for each axis
- int1ThsX = 16-bit interrupt threshold value for x-axis
- int1ThsY = 16-bit interrupt threshold value for y-axis
- int1ThsZ = 16-bit interrupt threshold value for z-axis
- duration = Duration an interrupt holds after triggered. This value is copied directly into the INT1_DURATION_G register. Before using this function, read about the INT1_CFG_G register and the related INT1* registers in the LMS9DS0 datasheet.
Definition at line 263 of file LSM9DS0.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 80 of file LSM9DS0.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 149 of file LSM9DS0.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 108 of file LSM9DS0.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 134 of file LSM9DS0.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, there're 11).
Definition at line 240 of file LSM9DS0.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, 6, 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 193 of file LSM9DS0.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, there're 14).
Definition at line 229 of file LSM9DS0.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 200 degrees per second. Input:
- gScl = The desired gyroscope scale. Must be one of three possible values from the gyro_scale enum.
Definition at line 175 of file LSM9DS0.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, there're 6).
Definition at line 251 of file LSM9DS0.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 2, 4, 8, or 12 Gs. Input:
- mScl = The desired magnetometer scale. Must be one of four possible values from the mag_scale enum.
Definition at line 211 of file LSM9DS0.cpp.
Generated on Mon Jul 18 2022 07:18:37 by
1.7.2