awesome library  0.5
Library for tutorial guiding through the library creation process
lsm9ds1.h
Go to the documentation of this file.
1 
16 #ifndef __LSM9DS1_IMU_SENSOR_H__ // Prevents duplicate
17 #define __LSM9DS1_IMU_SENSOR_H__ // declarations
18 
19 #if defined(__cplusplus) // If compiling for C++
20 extern "C" { // Compile for C
21 #endif
22 
23 
24 
25 // LSM9DS1 Accel/Gyro (XL/G) Registers
26 #define ACT_THS 0x04
27 #define ACT_DUR 0x05
28 #define INT_GEN_CFG_XL 0x06
29 #define INT_GEN_THS_X_XL 0x07
30 #define INT_GEN_THS_Y_XL 0x08
31 #define INT_GEN_THS_Z_XL 0x09
32 #define INT_GEN_DUR_XL 0x0A
33 #define REFERENCE_G 0x0B
34 #define INT1_CTRL 0x0C
35 #define INT2_CTRL 0x0D
36 #define WHO_AM_I_XG 0x0F
37 #define CTRL_REG1_G 0x10
38 #define CTRL_REG2_G 0x11
39 #define CTRL_REG3_G 0x12
40 #define ORIENT_CFG_G 0x13
41 #define INT_GEN_SRC_G 0x14
42 #define OUT_TEMP_L 0x15
43 #define OUT_TEMP_H 0x16
44 #define STATUS_REG_0 0x17
45 #define OUT_X_L_G 0x18
46 #define OUT_X_H_G 0x19
47 #define OUT_Y_L_G 0x1A
48 #define OUT_Y_H_G 0x1B
49 #define OUT_Z_L_G 0x1C
50 #define OUT_Z_H_G 0x1D
51 #define CTRL_REG4 0x1E
52 #define CTRL_REG5_XL 0x1F
53 #define CTRL_REG6_XL 0x20
54 #define CTRL_REG7_XL 0x21
55 #define CTRL_REG8 0x22
56 #define CTRL_REG9 0x23
57 #define CTRL_REG10 0x24
58 #define INT_GEN_SRC_XL 0x26
59 #define STATUS_REG_1 0x27
60 #define OUT_X_L_XL 0x28
61 #define OUT_X_H_XL 0x29
62 #define OUT_Y_L_XL 0x2A
63 #define OUT_Y_H_XL 0x2B
64 #define OUT_Z_L_XL 0x2C
65 #define OUT_Z_H_XL 0x2D
66 #define FIFO_CTRL 0x2E
67 #define FIFO_SRC 0x2F
68 #define INT_GEN_CFG_G 0x30
69 #define INT_GEN_THS_XH_G 0x31
70 #define INT_GEN_THS_XL_G 0x32
71 #define INT_GEN_THS_YH_G 0x33
72 #define INT_GEN_THS_YL_G 0x34
73 #define INT_GEN_THS_ZH_G 0x35
74 #define INT_GEN_THS_ZL_G 0x36
75 #define INT_GEN_DUR_G 0x37
76 
77 // LSM9DS1 Magneto Registers
78 #define OFFSET_X_REG_L_M 0x05
79 #define OFFSET_X_REG_H_M 0x06
80 #define OFFSET_Y_REG_L_M 0x07
81 #define OFFSET_Y_REG_H_M 0x08
82 #define OFFSET_Z_REG_L_M 0x09
83 #define OFFSET_Z_REG_H_M 0x0A
84 #define WHO_AM_I_M 0x0F
85 #define CTRL_REG1_M 0x20
86 #define CTRL_REG2_M 0x21
87 #define CTRL_REG3_M 0x22
88 #define CTRL_REG4_M 0x23
89 #define CTRL_REG5_M 0x24
90 #define STATUS_REG_M 0x27
91 #define OUT_X_L_M 0x28
92 #define OUT_X_H_M 0x29
93 #define OUT_Y_L_M 0x2A
94 #define OUT_Y_H_M 0x2B
95 #define OUT_Z_L_M 0x2C
96 #define OUT_Z_H_M 0x2D
97 #define INT_CFG_M 0x30
98 #define INT_SRC_M 0x30
99 #define INT_THS_L_M 0x32
100 #define INT_THS_H_M 0x33
101 
102 // LSM9DS1 WHO_AM_I Responses
103 #define WHO_AM_I_AG_RSP 0x68
104 #define WHO_AM_I_M_RSP 0x3D
105 
106 
107 // fifoMode_type
108 #define FIFO_OFF 0
109 #define FIFO_THS 1
110 #define FIFO_CONT_TRIGGER 3
111 #define FIFO_OFF_TRIGGER 4
112 #define FIFO_CONT 5
113 
114 // lsm9ds1_axis
115 #define X_AXIS 0
116 #define Y_AXIS 1
117 #define Z_AXIS 2
118 #define ALL_AXIS 3
119 
120 // temperature units
121 #define CELSIUS 0
122 #define FAHRENHEIT 1
123 #define KELVIN 2
124 
125 
147 int imu_init(int pinSCL, int pinSDIO, int pinAG, int pinM);
148 
149 
161 void imu_calibrateAG();
162 
163 
175 void imu_calibrateMag();
176 
177 
194 void imu_getMagCalibration(int *mxBias, int *myBias, int *mzBias);
195 
196 
213 void imu_getAccelCalibration(int *axBias, int *ayBias, int *azBias);
214 
215 
232 void imu_getGyroCalibration(int *gxBias, int *gyBias, int *gzBias);
233 
234 
250 void imu_setMagCalibration(int mxBias, int myBias, int mzBias);
251 
252 
268 void imu_setAccelCalibration(int axBias, int ayBias, int azBias);
269 
270 
286 void imu_setGyroCalibration(int gxBias, int gyBias, int gzBias);
287 
288 
295 unsigned char imu_accelAvailable();
296 
297 
304 unsigned char imu_gyroAvailable();
305 
306 
313 unsigned char imu_tempAvailable();
314 
315 
322 unsigned char imu_magAvailable();
323 
324 
337 void imu_readGyro(int *gx, int *gy, int *gz);
338 
339 
352 void imu_readAccel(int *ax, int *ay, int *az);
353 
354 
367 void imu_readMag(int *mx, int *my, int *mz);
368 
369 
378 void imu_readTemp(int *temperature);
379 
380 
394 void imu_readGyroCalculated(float *gx, float *gy, float *gz);
395 
396 
410 void imu_readAccelCalculated(float *ax, float *ay, float *az);
411 
412 
426 void imu_readMagCalculated(float *mx, float *my, float *mz);
427 
428 
441 void imu_readTempCalculated(float *temperature, char tempUnit);
442 
451 void imu_setGyroScale(unsigned int gScl);
452 
453 
462 void imu_setAccelScale(unsigned char aScl);
463 
464 
473 void imu_setMagScale(unsigned char mScl);
474 
475 
483 int imu_getGyroScale();
484 
485 
493 int imu_getAccelScale();
494 
495 
503 int imu_getMagScale();
504 
505 
513 
514 
522 
523 
530 void imu_clearMagInterrupt();
531 
532 
556 void imu_setAccelInterrupt(char axis, float threshold, char duration, char overUnder, char andOr);
557 
558 
581 void imu_setGyroInterrupt(char axis, float threshold, char duration, char overUnder, char andOr);
582 
583 
605 void imu_setMagInterrupt(char axis, float threshold, char overPos, char underNeg, char lowHigh);
606 
607 
608 
612 void imu_SPIwriteByte(unsigned char csPin, unsigned char subAddress, unsigned char data);
613 
614 
618 void imu_SPIreadBytes(unsigned char csPin, unsigned char subAddress, unsigned char *dest, unsigned char count);
619 
620 
621 
622 #if defined(__cplusplus)
623 } // End compile for C block
624 #endif
625 /* __cplusplus */
626 
627 #endif // End prevent duplicate forward
628 /* __LSM9DS1_IMU_SENSOR_H__ */ // declarations block
629 
630 
631 /*
632  * Based on the Arduino Library for the LSM9SD1 by Jim Lindblom of Sparkfun Electronics
633  */
634 
unsigned char imu_gyroAvailable()
Polls the Gyroscope status register to check if new data is available.
Definition: imu_gryoAvailable.c:22
void imu_setAccelInterrupt(char axis, float threshold, char duration, char overUnder, char andOr)
Configures the Accelerometer interrupt output to the INT_A/G pin.
Definition: imu_setAccelInterrupt.c:7
void imu_clearMagInterrupt()
Clears out any interrupts set up on the Magnetometer and resets all Magnetometer interrupt registers ...
Definition: imu_clearInterrupt.c:38
void imu_getAccelCalibration(int *axBias, int *ayBias, int *azBias)
Retrieves the Accelreometer's calibration biases.
Definition: imu_getCalibration.c:30
void imu_calibrateAG()
Calibrates the Accelerometer and Gyroscope on the LSM9DS1 IMU module.
Definition: imu_calibrateAG.c:30
unsigned char imu_magAvailable()
Polls the Magnetometer status register to check if new data is available.
Definition: imu_magAvailable.c:23
int imu_getGyroScale()
Retrieves the full-scale range of the Gyroscope.
Definition: imu_getScale.c:24
void imu_calibrateMag()
Calibrates the Magnetometer on the LSM9DS1 IMU module.
Definition: imu_calibrateMag.c:25
void imu_setAccelScale(unsigned char aScl)
Sets the full-scale range of the Accelerometer.
Definition: imu_setAccelScale.c:26
void imu_readMagCalculated(float *mx, float *my, float *mz)
Reads the Magnetometer output registers and scales the outputs to gauss'.
Definition: imu_readMag.c:40
void imu_readTempCalculated(float *temperature, char tempUnit)
Reads the Thermometer output registers and scales the outputs to degrees Celsius, Fahrenheit...
void imu_setAccelCalibration(int axBias, int ayBias, int azBias)
Sets the Accelerometer's calibration biases.
Definition: imu_setCalibration.c:40
void imu_SPIreadBytes(unsigned char csPin, unsigned char subAddress, unsigned char *dest, unsigned char count)
Reads a specified number of bytes from the specified LSM9DS1 register.
Definition: imu_SPIread.c:22
void imu_setGyroInterrupt(char axis, float threshold, char duration, char overUnder, char andOr)
Configures the Gyroscope interrupt output to the INT_A/G pin.
Definition: imu_setGyroInterrupt.c:7
void imu_setGyroScale(unsigned int gScl)
Sets the full-scale range of the Gyroscope.
Definition: imu_setGyroScale.c:26
void imu_readMag(int *mx, int *my, int *mz)
Reads the Magnetometer output registers.
Definition: imu_readMag.c:24
void imu_readTemp(int *temperature)
Reads the Temperature output registers.
Definition: imu_readTemp.c:21
void imu_readGyroCalculated(float *gx, float *gy, float *gz)
Reads the Gyroscope output registers and scales the outputs to degrees of rotation per second (DPS)...
Definition: imu_readGyro.c:49
void imu_getMagCalibration(int *mxBias, int *myBias, int *mzBias)
Retrieves the Magnetometer's calibration biases.
Definition: imu_getCalibration.c:23
unsigned char imu_accelAvailable()
Polls the Accelerometer status register to check if new data is available.
Definition: imu_accelAvailable.c:21
int imu_init(int pinSCL, int pinSDIO, int pinAG, int pinM)
Initializes the LSM9DS1 IMU module.
Definition: imu_init.c:23
void imu_getGyroCalibration(int *gxBias, int *gyBias, int *gzBias)
Retrieves the Gyroscope's calibration biases.
Definition: imu_getCalibration.c:37
void imu_SPIwriteByte(unsigned char csPin, unsigned char subAddress, unsigned char data)
Writes a byte to the specified LSM9DS1 register.
Definition: imu_SPIwrite.c:23
void imu_clearAccelInterrupt()
Clears out any interrupts set up on the Accelerometer and resets all Accelerometer interrupt register...
Definition: imu_clearInterrupt.c:5
void imu_readAccelCalculated(float *ax, float *ay, float *az)
Reads the Accelerometer output registers and scales the outputs to g's (1 g = 9.8 m/s/s)...
Definition: imu_readAccel.c:50
int imu_getMagScale()
Retrieves the full-scale range of the Magnetometer.
Definition: imu_getScale.c:34
void imu_clearGyroInterrupt()
Clears out any interrupts set up on the Gyroscope and resets all Gyroscope interrupt registers to the...
Definition: imu_clearInterrupt.c:20
int imu_getAccelScale()
Retrieves the full-scale range of the Accelerometer.
Definition: imu_getScale.c:29
void imu_readGyro(int *gx, int *gy, int *gz)
Reads the Gyroscope output registers.
Definition: imu_readGyro.c:27
void imu_readAccel(int *ax, int *ay, int *az)
Reads the Accelerometer output registers.
Definition: imu_readAccel.c:28
void imu_setGyroCalibration(int gxBias, int gyBias, int gzBias)
Sets the Gyroscope's calibration biases.
Definition: imu_setCalibration.c:47
void imu_setMagScale(unsigned char mScl)
Sets the full-scale range of the Magnetometer.
Definition: imu_setMagScale.c:25
unsigned char imu_tempAvailable()
Polls the Thermometer status register to check if new data is available.
Definition: imu_tempAvailable.c:22
void imu_setMagCalibration(int mxBias, int myBias, int mzBias)
Sets the Magnetometer's calibration biases.
Definition: imu_setCalibration.c:24
void imu_setMagInterrupt(char axis, float threshold, char overPos, char underNeg, char lowHigh)
Configures the Magnetometer interrupt output to the INT_M pin.
Definition: imu_setMagInterrupt.c:8