I2C LSM9DS1 RaspberryPI C++ Library
|
30 #include "LSM9DS1_Registers.h"
31 #include "LSM9DS1_Types.h"
34 static const char could_not_open_i2c[] =
"Could not open I2C.\n";
36 #define ISR_TIMEOUT 1000
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
61 unsigned i2c_bus = LSM9DS1_DEFAULT_I2C_BUS;
118 uint8_t highResEnable =
false;
119 uint8_t highResBandwidth = 0;
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;
180 uint8_t enabled =
true;
215 uint8_t tempCompensationEnable =
false;
223 uint8_t ZPerformance = 3;
224 uint8_t lowPowerEnable =
false;
232 uint8_t enabled =
true;
354 lsm9ds1Callback = cb;
393 int16_t readGyro(lsm9ds1_axis axis);
400 int16_t readAccel(lsm9ds1_axis axis);
407 int16_t readMag(lsm9ds1_axis axis);
414 void magOffset(uint8_t axis, int16_t offset);
493 float gRes, aRes, mRes;
559 uint8_t mReadByte(uint8_t subAddress);
570 void mReadBytes(uint8_t subAddress, uint8_t * dest, uint8_t count);
576 void mWriteByte(uint8_t subAddress, uint8_t data);
583 uint8_t xgReadByte(uint8_t subAddress);
594 void xgReadBytes(uint8_t subAddress, uint8_t * dest, uint8_t count);
600 void xgWriteByte(uint8_t subAddress, uint8_t data);
622 void I2CwriteByte(uint8_t address, uint8_t subAddress, uint8_t data);
630 uint8_t I2CreadByte(uint8_t address, uint8_t subAddress);
640 uint8_t I2CreadBytes(uint8_t address, uint8_t subAddress, uint8_t * dest, uint8_t count);
651 static void gpioISR(
int gpio,
int level, uint32_t tick,
void* userdata)
654 ((
LSM9DS1*)userdata)->dataReady();
666 void setAccelODR(uint8_t aRate);
680 void configInactivity(uint8_t duration, uint8_t threshold,
bool sleepOn);
689 void configAccelInt(uint8_t generator,
bool andInterrupts =
false);
700 void configAccelThs(uint8_t threshold, lsm9ds1_axis axis, uint8_t duration = 0,
bool wait = 0);
710 void configGyroInt(uint8_t generator,
bool aoi,
bool latch);
721 void configGyroThs(int16_t threshold, lsm9ds1_axis axis, uint8_t duration,
bool wait);
734 void configInt(interrupt_select interupt, uint8_t generator,
735 h_lactive activeLow = INT_ACTIVE_LOW, pp_od pushPull = INT_PUSH_PULL);
744 void configMagInt(uint8_t generator, h_lactive activeLow,
bool latch =
true);
750 void configMagThs(uint16_t threshold);
755 void sleepGyro(
bool enable =
true);
760 void enableFIFO(
bool enable =
true);
768 void setFIFO(fifoMode_type fifoMode, uint8_t fifoThs);
781 int16_t gx = 0, gy = 0, gz = 0;
782 int16_t ax = 0, ay = 0, az = 0;
783 int16_t mx = 0, my = 0, mz = 0;
784 int16_t temperature = 0;
788 #endif // SFE_LSM9DS1_H //
Scale scale
accel scale (in g) can be 2, 4, 8, or 16
Definition: LSM9DS1.h:95
unsigned drdy_gpio
Data ready pin (INT2) of the accelerometer.
Definition: LSM9DS1.h:66
virtual void hasSample(LSM9DS1Sample sample)=0
Called after a sample has arrived.
bool gyroAvailable()
Polls the gyroscope status register to check if new data is available.
uint8_t getMagIntSrc()
Get contents of magnetometer interrupt source register.
float calcAccel(int16_t accel)
Convert from RAW signed 16-bit value to gravity (g's).
float ay
Y Acceleration in m/s^2.
Definition: LSM9DS1.h:254
@ G_ODR_119
119 Hz (3)
Definition: LSM9DS1.h:149
bool tempAvailable()
Polls the temperature status register to check if new data is available.
void magOffset(uint8_t axis, int16_t offset)
Sets the magnetometer offset.
uint8_t enableX
Enables accelerometer's X axis.
Definition: LSM9DS1.h:97
Magnetometer settings with default values.
Definition: LSM9DS1.h:178
void setGyroScale(GyroSettings::Scale gScl)
Set the full-scale range of the gyroscope.
float gz
Z Rotation in deg/s.
Definition: LSM9DS1.h:274
float gy
Y Rotation in deg/s.
Definition: LSM9DS1.h:269
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...
uint8_t mAddress
I2C magnetometer address.
Definition: LSM9DS1.h:56
float mz
Z Magnetic field in Gauss.
Definition: LSM9DS1.h:289
@ G_ODR_14_9
14.9 Hz (1)
Definition: LSM9DS1.h:147
bool magAvailable(lsm9ds1_axis axis=ALL_AXIS)
Polls the magnetometer status register to check if new data is available.
SampleRate
Defines all possible output data rates of the magnetometer.
Definition: LSM9DS1.h:198
uint8_t enableZ
Z axis enabled.
Definition: LSM9DS1.h:162
uint8_t enableX
X axis enabled.
Definition: LSM9DS1.h:160
@ G_SCALE_2000DPS
2000 dps
Definition: LSM9DS1.h:134
Scale
defines all possible FSR's of the accelerometer
Definition: LSM9DS1.h:84
@ A_ABW_OFF
no cutoff
Definition: LSM9DS1.h:110
void setCallback(LSM9DS1callback *cb)
Sets the callback which receives the samples at the sampling rate.
Definition: LSM9DS1.h:353
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...
@ G_ODR_476
476 Hz (5)
Definition: LSM9DS1.h:151
@ A_ABW_408
408 Hz (0x0)
Definition: LSM9DS1.h:106
SampleRate sampleRate
Output data rate of the magnetometer.
Definition: LSM9DS1.h:213
bool accelAvailable()
Polls the accelerometer status register to check if new data is available.
@ G_SCALE_500DPS
500 dps
Definition: LSM9DS1.h:133
@ M_SCALE_16GS
16Gs
Definition: LSM9DS1.h:190
Scale
Defines all possible FSR's of the magnetometer.
Definition: LSM9DS1.h:185
void end()
Ends the data acquisition and closes all IO.
Accelerometer settings with default values.
Definition: LSM9DS1.h:79
Hardware related settings.
Definition: LSM9DS1.h:46
SampleRate
Gyro & Acc sampling rates.
Definition: LSM9DS1.h:145
Abw
Defines all possible anti-aliasing filter rates of the accelerometer.
Definition: LSM9DS1.h:104
Abw bandwidth
Accel cutoff freqeuncy.
Definition: LSM9DS1.h:116
SampleRate sampleRate
Gyro & Accelerometer sample rate.
Definition: LSM9DS1.h:158
@ G_ODR_952
952 Hz (6)
Definition: LSM9DS1.h:152
Scale scale
gyro scale can be 245, 500, or 2000
Definition: LSM9DS1.h:140
uint8_t getAccelIntSrc()
Get contents of accelerometer interrupt source register.
void setAccelScale(AccelSettings::Scale aScl)
Set the full-scale range of the accelerometer.
uint8_t enableY
Enables accelerometer's Y axis.
Definition: LSM9DS1.h:98
unsigned i2c_bus
Default I2C bus number (most likely 1)
Definition: LSM9DS1.h:61
@ G_ODR_238
238 Hz (4)
Definition: LSM9DS1.h:150
uint8_t enableZ
Enables accelerometer's Z axis.
Definition: LSM9DS1.h:99
float az
Z Acceleration in m/s^2.
Definition: LSM9DS1.h:259
float gx
X Rotation in deg/s.
Definition: LSM9DS1.h:264
Scale
Gyro_scale defines the possible full-scale ranges of the gyroscope.
Definition: LSM9DS1.h:130
LSM9DS1(DeviceSettings deviceSettings=DeviceSettings())
LSM9DS1 class constructor.
@ A_ABW_211
211 Hz (0x1)
Definition: LSM9DS1.h:107
uint8_t enableY
Y axis enabled.
Definition: LSM9DS1.h:161
float my
Y Magnetic field in Gauss.
Definition: LSM9DS1.h:284
@ A_ABW_50
50 Hz (0x3)
Definition: LSM9DS1.h:109
void setMagScale(MagSettings::Scale mScl)
Set the full-scale range of the magnetometer.
@ G_ODR_59_5
59.5 Hz (2)
Definition: LSM9DS1.h:148
uint8_t getInactivity()
Get status of inactivity interrupt.
uint8_t getGyroIntSrc()
Get contents of Gyroscope interrupt source register.
float temperature
Chip temperature.
Definition: LSM9DS1.h:294
Main class for the LSM9DS1 acceleromter which manages the data acquisition via pigpio and calls the m...
Definition: LSM9DS1.h:316
Callback interface where the callback needs to be implemented by the host application.
Definition: LSM9DS1.h:301
@ A_ABW_105
105 Hz (0x2)
Definition: LSM9DS1.h:108
Temperature sensor settings.
Definition: LSM9DS1.h:230
@ M_SCALE_8GS
8Gs
Definition: LSM9DS1.h:188
Sample from the LSM9DS1.
Definition: LSM9DS1.h:245
float mx
X Magnetic field in Gauss.
Definition: LSM9DS1.h:279
@ M_SCALE_4GS
4Gs
Definition: LSM9DS1.h:187
Gyroscope settings with default values.
Definition: LSM9DS1.h:125
void begin(GyroSettings gyroSettings=GyroSettings(), AccelSettings accelSettings=AccelSettings(), MagSettings magSettings=MagSettings(), TemperatureSettings temperatureSettings=TemperatureSettings())
Initializes the gyro, accelerometer, magnetometer and starts the acquistion.
uint8_t agAddress
I2C acceleromter address.
Definition: LSM9DS1.h:51
@ G_SCALE_245DPS
245 degrees per second
Definition: LSM9DS1.h:132
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
float ax
X Acceleration in m/s^2.
Definition: LSM9DS1.h:249
uint8_t getFIFOSamples()
Get number of FIFO samples.
bool initPIGPIO
If set to true the pigpio library is initialised with signals disabled.
Definition: LSM9DS1.h:73
@ M_SCALE_12GS
12Gs
Definition: LSM9DS1.h:189