I2C LSM9DS1 RaspberryPI C++ Library
LSM9DS1.h
1 /******************************************************************************
2 SFE_LSM9DS1.h
3 SFE_LSM9DS1 Library Header File
4 Jim Lindblom @ SparkFun Electronics
5 Original Creation Date: February 27, 2015
6 https://github.com/sparkfun/LSM9DS1_Breakout
7 
8 2020-2022, Bernd Porr, mail@berndporr.me.uk
9 
10 This file prototypes the LSM9DS1 class, implemented in SFE_LSM9DS1.cpp. In
11 addition, it defines every register in the LSM9DS1 (both the Gyro and Accel/
12 Magnetometer registers).
13 
14 Development environment specifics:
15  Hardware Platform: Raspberry PI
16  LSM9DS1
17 
18 This code is beerware; if you see me (or any other SparkFun employee) at the
19 local, and you've found our code helpful, please buy us a round!
20 
21 Distributed as-is; no warranty is given.
22 ******************************************************************************/
23 #ifndef __LSM9DS1_H__
24 #define __LSM9DS1_H__
25 
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <stdint.h>
29 #include <thread>
30 #include "LSM9DS1_Registers.h"
31 #include "LSM9DS1_Types.h"
32 #include <pigpio.h>
33 
34 static const char could_not_open_i2c[] = "Could not open I2C.\n";
35 
36 #define ISR_TIMEOUT 1000
37 
38 #define LSM9DS1_AG_ADDR 0x6B
39 #define LSM9DS1_M_ADDR 0x1E
40 #define LSM9DS1_DEFAULT_I2C_BUS 1
41 #define LSM9DS1_DRDY_GPIO 22
42 
47 {
51  uint8_t agAddress = LSM9DS1_AG_ADDR;
52 
56  uint8_t mAddress = LSM9DS1_M_ADDR;
57 
61  unsigned i2c_bus = LSM9DS1_DEFAULT_I2C_BUS;
62 
66  unsigned drdy_gpio = LSM9DS1_DRDY_GPIO;
67 
73  bool initPIGPIO = true; // inits pigpio
74 };
75 
80 {
84  enum Scale
85  {
86  A_SCALE_2G = 2,
87  A_SCALE_16G = 16,
88  A_SCALE_4G = 4,
89  A_SCALE_8G = 8
90  };
91 
95  Scale scale = A_SCALE_16G;
96 
97  uint8_t enableX = true;
98  uint8_t enableY = true;
99  uint8_t enableZ = true;
100 
104  enum Abw
105  {
106  A_ABW_408 = 0,
107  A_ABW_211 = 1,
108  A_ABW_105 = 2,
109  A_ABW_50 = 3,
110  A_ABW_OFF = -1
111  };
112 
117 
118  uint8_t highResEnable = false;
119  uint8_t highResBandwidth = 0;
120 };
121 
126 {
130  enum Scale
131  {
135  };
136 
141 
146  {
149  G_ODR_119 = 3,
150  G_ODR_238 = 4,
151  G_ODR_476 = 5,
153  };
154 
159 
160  uint8_t enableX = true;
161  uint8_t enableY = true;
162  uint8_t enableZ = true;
163 
164  uint8_t bandwidth = 0;
165  uint8_t lowPowerEnable = false;
166  uint8_t HPFEnable = false;
167  uint8_t HPFCutoff = 0;
168  uint8_t flipX = false;
169  uint8_t flipY = false;
170  uint8_t flipZ = false;
171  uint8_t orientation = 0;
172  uint8_t latchInterrupt = true;
173 };
174 
179 {
180  uint8_t enabled = true;
181 
185  enum Scale
186  {
191  };
192 
193  Scale scale = M_SCALE_16GS;
194 
199  {
200  M_ODR_0625, // 0.625 Hz (0)
201  M_ODR_125, // 1.25 Hz (1)
202  M_ODR_250, // 2.5 Hz (2)
203  M_ODR_5, // 5 Hz (3)
204  M_ODR_10, // 10 Hz (4)
205  M_ODR_20, // 20 Hz (5)
206  M_ODR_40, // 40 Hz (6)
207  M_ODR_80 // 80 Hz (7)
208  };
209 
213  SampleRate sampleRate = M_ODR_80;
214 
215  uint8_t tempCompensationEnable = false;
216 
222  uint8_t XYPerformance = 3;
223  uint8_t ZPerformance = 3;
224  uint8_t lowPowerEnable = false;
225 };
226 
231 {
232  uint8_t enabled = true;
233 };
234 
235 enum lsm9ds1_axis {
236  X_AXIS,
237  Y_AXIS,
238  Z_AXIS,
239  ALL_AXIS
240 };
241 
249  float ax = 0;
250 
254  float ay = 0;
255 
259  float az = 0;
260 
264  float gx = 0;
265 
269  float gy = 0;
270 
274  float gz = 0;
275 
279  float mx = 0;
280 
284  float my = 0;
285 
289  float mz = 0;
290 
294  float temperature = 0;
295 };
296 
302 public:
306  virtual void hasSample(LSM9DS1Sample sample) = 0;
307 };
308 
316 class LSM9DS1
317 {
318 public:
324  LSM9DS1(DeviceSettings deviceSettings = DeviceSettings());
325 
334  void begin(GyroSettings gyroSettings = GyroSettings(),
335  AccelSettings accelSettings = AccelSettings(),
336  MagSettings magSettings = MagSettings(),
337  TemperatureSettings temperatureSettings = TemperatureSettings()
338  );
339 
343  void end();
344 
345  ~LSM9DS1() {
346  end();
347  }
348 
354  lsm9ds1Callback = cb;
355  }
356 
362  bool accelAvailable();
363 
369  bool gyroAvailable();
370 
376  bool tempAvailable();
377 
386  bool magAvailable(lsm9ds1_axis axis = ALL_AXIS);
387 
393  int16_t readGyro(lsm9ds1_axis axis);
394 
400  int16_t readAccel(lsm9ds1_axis axis);
401 
407  int16_t readMag(lsm9ds1_axis axis);
408 
414  void magOffset(uint8_t axis, int16_t offset);
415 
423  float calcGyro(int16_t gyro);
424 
432  float calcAccel(int16_t accel);
433 
441  float calcMag(int16_t mag);
442 
450 
456 
461  void setMagScale(MagSettings::Scale mScl);
462 
466  uint8_t getGyroIntSrc();
467 
471  uint8_t getAccelIntSrc();
472 
476  uint8_t getMagIntSrc();
477 
481  uint8_t getInactivity();
482 
486  uint8_t getFIFOSamples();
487 
488 
489 private:
490  // gRes, aRes, and mRes store the current resolution for each sensor.
491  // Units of these values would be DPS (or g's or Gs's) per ADC tick.
492  // This value is calculated as (sensor scale) / (2^15).
493  float gRes, aRes, mRes;
494 
495  // initGyro() -- Sets up the gyroscope to begin reading.
496  // This function steps through all five gyroscope control registers.
497  // Upon exit, the following parameters will be set:
498  // - CTRL_REG1_G = 0x0F: Normal operation mode, all axes enabled.
499  // 95 Hz ODR, 12.5 Hz cutoff frequency.
500  // - CTRL_REG2_G = 0x00: HPF set to normal mode, cutoff frequency
501  // set to 7.2 Hz (depends on ODR).
502  // - CTRL_REG3_G = 0x88: Interrupt enabled on INT_G (set to push-pull and
503  // active high). Data-ready output enabled on DRDY_G.
504  // - CTRL_REG4_G = 0x00: Continuous update mode. Data LSB stored in lower
505  // address. Scale set to 245 DPS.
506  // - CTRL_REG5_G = 0x00: FIFO disabled. HPF disabled.
507  void initGyro();
508 
509  // readGyro() -- Read the gyroscope output registers.
510  // This function will read all six gyroscope output registers.
511  // The readings are stored in the class' gx, gy, and gz variables. Read
512  // those _after_ calling readGyro().
513  void readGyro();
514 
515  // initAccel() -- Sets up the accelerometer to begin reading.
516  // This function steps through all accelerometer related control registers.
517  // Upon exit these registers will be set as:
518  // - CTRL_REG0_XM = 0x00: FIFO disabled. HPF bypassed. Normal mode.
519  // - CTRL_REG1_XM = 0x57: 100 Hz data rate. Continuous update.
520  // all axes enabled.
521  // - CTRL_REG2_XM = 0x00: 2g scale. 773 Hz anti-alias filter BW.
522  // - CTRL_REG3_XM = 0x04: Accel data ready signal on INT1_XM pin.
523  void initAccel();
524 
525  // readAccel() -- Read the accelerometer output registers.
526  // This function will read all six accelerometer output registers.
527  // The readings are stored in the class' ax, ay, and az variables. Read
528  // those _after_ calling readAccel().
529  void readAccel();
530 
531  // initMag() -- Sets up the magnetometer to begin reading.
532  // This function steps through all magnetometer-related control registers.
533  // Upon exit these registers will be set as:
534  // - CTRL_REG4_XM = 0x04: Mag data ready signal on INT2_XM pin.
535  // - CTRL_REG5_XM = 0x14: 100 Hz update rate. Low resolution. Interrupt
536  // requests don't latch. Temperature sensor disabled.
537  // - CTRL_REG6_XM = 0x00: 2 Gs scale.
538  // - CTRL_REG7_XM = 0x00: Continuous conversion mode. Normal HPF mode.
539  // - INT_CTRL_REG_M = 0x09: Interrupt active-high. Enable interrupts.
540  void initMag();
541 
542  // readMag() -- Read the magnetometer output registers.
543  // This function will read all six magnetometer output registers.
544  // The readings are stored in the class' mx, my, and mz variables. Read
545  // those _after_ calling readMag().
546  void readMag();
547 
548  // readTemp() -- Read the temperature output register.
549  // This function will read two temperature output registers.
550  // The combined readings are stored in the class' temperature variables. Read
551  // those _after_ calling readTemp().
552  void readTemp();
553 
554  // gReadByte() -- Reads a byte from a specified gyroscope register.
555  // Input:
556  // - subAddress = Register to be read from.
557  // Output:
558  // - An 8-bit value read from the requested address.
559  uint8_t mReadByte(uint8_t subAddress);
560 
561  // gReadBytes() -- Reads a number of bytes -- beginning at an address
562  // and incrementing from there -- from the gyroscope.
563  // Input:
564  // - subAddress = Register to be read from.
565  // - * dest = A pointer to an array of uint8_t's. Values read will be
566  // stored in here on return.
567  // - count = The number of bytes to be read.
568  // Output: No value is returned, but the `dest` array will store
569  // the data read upon exit.
570  void mReadBytes(uint8_t subAddress, uint8_t * dest, uint8_t count);
571 
572  // gWriteByte() -- Write a byte to a register in the gyroscope.
573  // Input:
574  // - subAddress = Register to be written to.
575  // - data = data to be written to the register.
576  void mWriteByte(uint8_t subAddress, uint8_t data);
577 
578  // xmReadByte() -- Read a byte from a register in the accel/mag sensor
579  // Input:
580  // - subAddress = Register to be read from.
581  // Output:
582  // - An 8-bit value read from the requested register.
583  uint8_t xgReadByte(uint8_t subAddress);
584 
585  // xmReadBytes() -- Reads a number of bytes -- beginning at an address
586  // and incrementing from there -- from the accelerometer/magnetometer.
587  // Input:
588  // - subAddress = Register to be read from.
589  // - * dest = A pointer to an array of uint8_t's. Values read will be
590  // stored in here on return.
591  // - count = The number of bytes to be read.
592  // Output: No value is returned, but the `dest` array will store
593  // the data read upon exit.
594  void xgReadBytes(uint8_t subAddress, uint8_t * dest, uint8_t count);
595 
596  // xmWriteByte() -- Write a byte to a register in the accel/mag sensor.
597  // Input:
598  // - subAddress = Register to be written to.
599  // - data = data to be written to the register.
600  void xgWriteByte(uint8_t subAddress, uint8_t data);
601 
602  // calcgRes() -- Calculate the resolution of the gyroscope.
603  // This function will set the value of the gRes variable. gScale must
604  // be set prior to calling this function.
605  void calcgRes();
606 
607  // calcmRes() -- Calculate the resolution of the magnetometer.
608  // This function will set the value of the mRes variable. mScale must
609  // be set prior to calling this function.
610  void calcmRes();
611 
612  // calcaRes() -- Calculate the resolution of the accelerometer.
613  // This function will set the value of the aRes variable. aScale must
614  // be set prior to calling this function.
615  void calcaRes();
616 
617  // I2CwriteByte() -- Write a byte out of I2C to a register in the device
618  // Input:
619  // - address = The 7-bit I2C address of the slave device.
620  // - subAddress = The register to be written to.
621  // - data = Byte to be written to the register.
622  void I2CwriteByte(uint8_t address, uint8_t subAddress, uint8_t data);
623 
624  // I2CreadByte() -- Read a single byte from a register over I2C.
625  // Input:
626  // - address = The 7-bit I2C address of the slave device.
627  // - subAddress = The register to be read from.
628  // Output:
629  // - The byte read from the requested address.
630  uint8_t I2CreadByte(uint8_t address, uint8_t subAddress);
631 
632  // I2CreadBytes() -- Read a series of bytes, starting at a register via SPI
633  // Input:
634  // - address = The 7-bit I2C address of the slave device.
635  // - subAddress = The register to begin reading.
636  // - * dest = Pointer to an array where we'll store the readings.
637  // - count = Number of registers to be read.
638  // Output: No value is returned by the function, but the registers read are
639  // all stored in the *dest array given.
640  uint8_t I2CreadBytes(uint8_t address, uint8_t subAddress, uint8_t * dest, uint8_t count);
641 
642  // Callback interface which is registered with the main program.
643  LSM9DS1callback* lsm9ds1Callback = nullptr;
644 
645  // Callback function in this class context which is called by the
646  // static low level interrupt handler gpioISR.
647  void dataReady();
648 
649  // Static low level callback handler registered with from pigpio
650  // The userdata contains a pointer to this class instance.
651  static void gpioISR(int gpio, int level, uint32_t tick, void* userdata)
652  {
653  if (level) {
654  ((LSM9DS1*)userdata)->dataReady();
655  }
656  }
657 
658  // setGyroODR() -- Set the output data rate and bandwidth of the gyroscope
659  // Input:
660  // - gRate = The desired output rate and cutoff frequency of the gyro.
661  void setGyroODR(GyroSettings::SampleRate gRate);
662 
663  // setAccelODR() -- Set the output data rate of the accelerometer
664  // Input:
665  // - aRate = The desired output rate of the accel.
666  void setAccelODR(uint8_t aRate);
667 
668  // setMagODR() -- Set the output data rate of the magnetometer
669  // Input:
670  // - mRate = The desired output rate of the mag.
671  void setMagODR(MagSettings::SampleRate mRate);
672 
673  // configInactivity() -- Configure inactivity interrupt parameters
674  // Input:
675  // - duration = Inactivity duration - actual value depends on gyro ODR
676  // - threshold = Activity Threshold
677  // - sleepOn = Gyroscope operating mode during inactivity.
678  // true: gyroscope in sleep mode
679  // false: gyroscope in power-down
680  void configInactivity(uint8_t duration, uint8_t threshold, bool sleepOn);
681 
682  // configAccelInt() -- Configure Accelerometer Interrupt Generator
683  // Input:
684  // - generator = Interrupt axis/high-low events
685  // Any OR'd combination of ZHIE_XL, ZLIE_XL, YHIE_XL, YLIE_XL, XHIE_XL, XLIE_XL
686  // - andInterrupts = AND/OR combination of interrupt events
687  // true: AND combination
688  // false: OR combination
689  void configAccelInt(uint8_t generator, bool andInterrupts = false);
690 
691  // configAccelThs() -- Configure the threshold of an accelereomter axis
692  // Input:
693  // - threshold = Interrupt threshold. Possible values: 0-255.
694  // Multiply by 128 to get the actual raw accel value.
695  // - axis = Axis to be configured. Either X_AXIS, Y_AXIS, or Z_AXIS
696  // - duration = Duration value must be above or below threshold to trigger interrupt
697  // - wait = Wait function on duration counter
698  // true: Wait for duration samples before exiting interrupt
699  // false: Wait function off
700  void configAccelThs(uint8_t threshold, lsm9ds1_axis axis, uint8_t duration = 0, bool wait = 0);
701 
702  // configGyroInt() -- Configure Gyroscope Interrupt Generator
703  // Input:
704  // - generator = Interrupt axis/high-low events
705  // Any OR'd combination of ZHIE_G, ZLIE_G, YHIE_G, YLIE_G, XHIE_G, XLIE_G
706  // - aoi = AND/OR combination of interrupt events
707  // true: AND combination
708  // false: OR combination
709  // - latch: latch gyroscope interrupt request.
710  void configGyroInt(uint8_t generator, bool aoi, bool latch);
711 
712  // configGyroThs() -- Configure the threshold of a gyroscope axis
713  // Input:
714  // - threshold = Interrupt threshold. Possible values: 0-0x7FF.
715  // Value is equivalent to raw gyroscope value.
716  // - axis = Axis to be configured. Either X_AXIS, Y_AXIS, or Z_AXIS
717  // - duration = Duration value must be above or below threshold to trigger interrupt
718  // - wait = Wait function on duration counter
719  // true: Wait for duration samples before exiting interrupt
720  // false: Wait function off
721  void configGyroThs(int16_t threshold, lsm9ds1_axis axis, uint8_t duration, bool wait);
722 
723  // configInt() -- Configure INT1 or INT2 (Gyro and Accel Interrupts only)
724  // Input:
725  // - interrupt = Select INT1 or INT2
726  // Possible values: XG_INT1 or XG_INT2
727  // - generator = Or'd combination of interrupt generators.
728  // Possible values: INT_DRDY_XL, INT_DRDY_G, INT1_BOOT (INT1 only), INT2_DRDY_TEMP (INT2 only)
729  // INT_FTH, INT_OVR, INT_FSS5, INT_IG_XL (INT1 only), INT1_IG_G (INT1 only), INT2_INACT (INT2 only)
730  // - activeLow = Interrupt active configuration
731  // Can be either INT_ACTIVE_HIGH or INT_ACTIVE_LOW
732  // - pushPull = Push-pull or open drain interrupt configuration
733  // Can be either INT_PUSH_PULL or INT_OPEN_DRAIN
734  void configInt(interrupt_select interupt, uint8_t generator,
735  h_lactive activeLow = INT_ACTIVE_LOW, pp_od pushPull = INT_PUSH_PULL);
736 
737  // configMagInt() -- Configure Magnetometer Interrupt Generator
738  // Input:
739  // - generator = Interrupt axis/high-low events
740  // Any OR'd combination of ZIEN, YIEN, XIEN
741  // - activeLow = Interrupt active configuration
742  // Can be either INT_ACTIVE_HIGH or INT_ACTIVE_LOW
743  // - latch: latch gyroscope interrupt request.
744  void configMagInt(uint8_t generator, h_lactive activeLow, bool latch = true);
745 
746  // configMagThs() -- Configure the threshold of a gyroscope axis
747  // Input:
748  // - threshold = Interrupt threshold. Possible values: 0-0x7FF.
749  // Value is equivalent to raw magnetometer value.
750  void configMagThs(uint16_t threshold);
751 
752  // sleepGyro() -- Sleep or wake the gyroscope
753  // Input:
754  // - enable: True = sleep gyro. False = wake gyro.
755  void sleepGyro(bool enable = true);
756 
757  // enableFIFO() - Enable or disable the FIFO
758  // Input:
759  // - enable: true = enable, false = disable.
760  void enableFIFO(bool enable = true);
761 
762  // setFIFO() - Configure FIFO mode and Threshold
763  // Input:
764  // - fifoMode: Set FIFO mode to off, FIFO (stop when full), continuous, bypass
765  // Possible inputs: FIFO_OFF, FIFO_THS, FIFO_CONT_TRIGGER, FIFO_OFF_TRIGGER, FIFO_CONT
766  // - fifoThs: FIFO threshold level setting
767  // Any value from 0-0x1F is acceptable.
768  void setFIFO(fifoMode_type fifoMode, uint8_t fifoThs);
769 
770  DeviceSettings device;
771  MagSettings mag;
772  GyroSettings gyro;
773  AccelSettings accel;
774  TemperatureSettings temp;
775 
776  // We'll store the gyro, accel, and magnetometer readings in a series of
777  // public class variables. Each sensor gets three variables -- one for each
778  // axis. Call readGyro(), readAccel(), and readMag() first, before using
779  // these variables!
780  // These values are the RAW signed 16-bit readings from the sensors.
781  int16_t gx = 0, gy = 0, gz = 0; // x, y, and z axis readings of the gyroscope
782  int16_t ax = 0, ay = 0, az = 0; // x, y, and z axis readings of the accelerometer
783  int16_t mx = 0, my = 0, mz = 0; // x, y, and z axis readings of the magnetometer
784  int16_t temperature = 0; // Chip temperature
785 
786 };
787 
788 #endif // SFE_LSM9DS1_H //
AccelSettings::scale
Scale scale
accel scale (in g) can be 2, 4, 8, or 16
Definition: LSM9DS1.h:95
DeviceSettings::drdy_gpio
unsigned drdy_gpio
Data ready pin (INT2) of the accelerometer.
Definition: LSM9DS1.h:66
LSM9DS1callback::hasSample
virtual void hasSample(LSM9DS1Sample sample)=0
Called after a sample has arrived.
LSM9DS1::gyroAvailable
bool gyroAvailable()
Polls the gyroscope status register to check if new data is available.
LSM9DS1::getMagIntSrc
uint8_t getMagIntSrc()
Get contents of magnetometer interrupt source register.
LSM9DS1::calcAccel
float calcAccel(int16_t accel)
Convert from RAW signed 16-bit value to gravity (g's).
LSM9DS1Sample::ay
float ay
Y Acceleration in m/s^2.
Definition: LSM9DS1.h:254
GyroSettings::G_ODR_119
@ G_ODR_119
119 Hz (3)
Definition: LSM9DS1.h:149
LSM9DS1::tempAvailable
bool tempAvailable()
Polls the temperature status register to check if new data is available.
LSM9DS1::magOffset
void magOffset(uint8_t axis, int16_t offset)
Sets the magnetometer offset.
AccelSettings::enableX
uint8_t enableX
Enables accelerometer's X axis.
Definition: LSM9DS1.h:97
MagSettings
Magnetometer settings with default values.
Definition: LSM9DS1.h:178
LSM9DS1::setGyroScale
void setGyroScale(GyroSettings::Scale gScl)
Set the full-scale range of the gyroscope.
LSM9DS1Sample::gz
float gz
Z Rotation in deg/s.
Definition: LSM9DS1.h:274
LSM9DS1Sample::gy
float gy
Y Rotation in deg/s.
Definition: LSM9DS1.h:269
LSM9DS1::calcGyro
float calcGyro(int16_t gyro)
Convert from RAW signed 16-bit value to degrees per second This function reads in a signed 16-bit val...
DeviceSettings::mAddress
uint8_t mAddress
I2C magnetometer address.
Definition: LSM9DS1.h:56
LSM9DS1Sample::mz
float mz
Z Magnetic field in Gauss.
Definition: LSM9DS1.h:289
GyroSettings::G_ODR_14_9
@ G_ODR_14_9
14.9 Hz (1)
Definition: LSM9DS1.h:147
LSM9DS1::magAvailable
bool magAvailable(lsm9ds1_axis axis=ALL_AXIS)
Polls the magnetometer status register to check if new data is available.
MagSettings::SampleRate
SampleRate
Defines all possible output data rates of the magnetometer.
Definition: LSM9DS1.h:198
GyroSettings::enableZ
uint8_t enableZ
Z axis enabled.
Definition: LSM9DS1.h:162
GyroSettings::enableX
uint8_t enableX
X axis enabled.
Definition: LSM9DS1.h:160
GyroSettings::G_SCALE_2000DPS
@ G_SCALE_2000DPS
2000 dps
Definition: LSM9DS1.h:134
AccelSettings::Scale
Scale
defines all possible FSR's of the accelerometer
Definition: LSM9DS1.h:84
AccelSettings::A_ABW_OFF
@ A_ABW_OFF
no cutoff
Definition: LSM9DS1.h:110
LSM9DS1::setCallback
void setCallback(LSM9DS1callback *cb)
Sets the callback which receives the samples at the sampling rate.
Definition: LSM9DS1.h:353
LSM9DS1::calcMag
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 r...
GyroSettings::G_ODR_476
@ G_ODR_476
476 Hz (5)
Definition: LSM9DS1.h:151
AccelSettings::A_ABW_408
@ A_ABW_408
408 Hz (0x0)
Definition: LSM9DS1.h:106
MagSettings::sampleRate
SampleRate sampleRate
Output data rate of the magnetometer.
Definition: LSM9DS1.h:213
LSM9DS1::accelAvailable
bool accelAvailable()
Polls the accelerometer status register to check if new data is available.
GyroSettings::G_SCALE_500DPS
@ G_SCALE_500DPS
500 dps
Definition: LSM9DS1.h:133
MagSettings::M_SCALE_16GS
@ M_SCALE_16GS
16Gs
Definition: LSM9DS1.h:190
MagSettings::Scale
Scale
Defines all possible FSR's of the magnetometer.
Definition: LSM9DS1.h:185
LSM9DS1::end
void end()
Ends the data acquisition and closes all IO.
AccelSettings
Accelerometer settings with default values.
Definition: LSM9DS1.h:79
DeviceSettings
Hardware related settings.
Definition: LSM9DS1.h:46
GyroSettings::SampleRate
SampleRate
Gyro & Acc sampling rates.
Definition: LSM9DS1.h:145
AccelSettings::Abw
Abw
Defines all possible anti-aliasing filter rates of the accelerometer.
Definition: LSM9DS1.h:104
AccelSettings::bandwidth
Abw bandwidth
Accel cutoff freqeuncy.
Definition: LSM9DS1.h:116
GyroSettings::sampleRate
SampleRate sampleRate
Gyro & Accelerometer sample rate.
Definition: LSM9DS1.h:158
GyroSettings::G_ODR_952
@ G_ODR_952
952 Hz (6)
Definition: LSM9DS1.h:152
GyroSettings::scale
Scale scale
gyro scale can be 245, 500, or 2000
Definition: LSM9DS1.h:140
LSM9DS1::getAccelIntSrc
uint8_t getAccelIntSrc()
Get contents of accelerometer interrupt source register.
LSM9DS1::setAccelScale
void setAccelScale(AccelSettings::Scale aScl)
Set the full-scale range of the accelerometer.
AccelSettings::enableY
uint8_t enableY
Enables accelerometer's Y axis.
Definition: LSM9DS1.h:98
DeviceSettings::i2c_bus
unsigned i2c_bus
Default I2C bus number (most likely 1)
Definition: LSM9DS1.h:61
GyroSettings::G_ODR_238
@ G_ODR_238
238 Hz (4)
Definition: LSM9DS1.h:150
AccelSettings::enableZ
uint8_t enableZ
Enables accelerometer's Z axis.
Definition: LSM9DS1.h:99
LSM9DS1Sample::az
float az
Z Acceleration in m/s^2.
Definition: LSM9DS1.h:259
LSM9DS1Sample::gx
float gx
X Rotation in deg/s.
Definition: LSM9DS1.h:264
GyroSettings::Scale
Scale
Gyro_scale defines the possible full-scale ranges of the gyroscope.
Definition: LSM9DS1.h:130
LSM9DS1::LSM9DS1
LSM9DS1(DeviceSettings deviceSettings=DeviceSettings())
LSM9DS1 class constructor.
AccelSettings::A_ABW_211
@ A_ABW_211
211 Hz (0x1)
Definition: LSM9DS1.h:107
GyroSettings::enableY
uint8_t enableY
Y axis enabled.
Definition: LSM9DS1.h:161
LSM9DS1Sample::my
float my
Y Magnetic field in Gauss.
Definition: LSM9DS1.h:284
AccelSettings::A_ABW_50
@ A_ABW_50
50 Hz (0x3)
Definition: LSM9DS1.h:109
LSM9DS1::setMagScale
void setMagScale(MagSettings::Scale mScl)
Set the full-scale range of the magnetometer.
GyroSettings::G_ODR_59_5
@ G_ODR_59_5
59.5 Hz (2)
Definition: LSM9DS1.h:148
LSM9DS1::getInactivity
uint8_t getInactivity()
Get status of inactivity interrupt.
LSM9DS1::getGyroIntSrc
uint8_t getGyroIntSrc()
Get contents of Gyroscope interrupt source register.
LSM9DS1Sample::temperature
float temperature
Chip temperature.
Definition: LSM9DS1.h:294
LSM9DS1
Main class for the LSM9DS1 acceleromter which manages the data acquisition via pigpio and calls the m...
Definition: LSM9DS1.h:316
LSM9DS1callback
Callback interface where the callback needs to be implemented by the host application.
Definition: LSM9DS1.h:301
AccelSettings::A_ABW_105
@ A_ABW_105
105 Hz (0x2)
Definition: LSM9DS1.h:108
TemperatureSettings
Temperature sensor settings.
Definition: LSM9DS1.h:230
MagSettings::M_SCALE_8GS
@ M_SCALE_8GS
8Gs
Definition: LSM9DS1.h:188
LSM9DS1Sample
Sample from the LSM9DS1.
Definition: LSM9DS1.h:245
LSM9DS1Sample::mx
float mx
X Magnetic field in Gauss.
Definition: LSM9DS1.h:279
MagSettings::M_SCALE_4GS
@ M_SCALE_4GS
4Gs
Definition: LSM9DS1.h:187
GyroSettings
Gyroscope settings with default values.
Definition: LSM9DS1.h:125
LSM9DS1::begin
void begin(GyroSettings gyroSettings=GyroSettings(), AccelSettings accelSettings=AccelSettings(), MagSettings magSettings=MagSettings(), TemperatureSettings temperatureSettings=TemperatureSettings())
Initializes the gyro, accelerometer, magnetometer and starts the acquistion.
DeviceSettings::agAddress
uint8_t agAddress
I2C acceleromter address.
Definition: LSM9DS1.h:51
GyroSettings::G_SCALE_245DPS
@ G_SCALE_245DPS
245 degrees per second
Definition: LSM9DS1.h:132
MagSettings::XYPerformance
uint8_t XYPerformance
magPerformance can be any value between 0-3 0 = Low power mode 2 = high performance 1 = medium perfor...
Definition: LSM9DS1.h:222
LSM9DS1Sample::ax
float ax
X Acceleration in m/s^2.
Definition: LSM9DS1.h:249
LSM9DS1::getFIFOSamples
uint8_t getFIFOSamples()
Get number of FIFO samples.
DeviceSettings::initPIGPIO
bool initPIGPIO
If set to true the pigpio library is initialised with signals disabled.
Definition: LSM9DS1.h:73
MagSettings::M_SCALE_12GS
@ M_SCALE_12GS
12Gs
Definition: LSM9DS1.h:189