19 #include <Adafruit_I2CDevice.h> 20 #include <Adafruit_LIS3MDL.h> 21 #include <Adafruit_SPIDevice.h> 22 #include <Adafruit_Sensor.h> 24 #define LSM9DS1_ADDRESS_ACCELGYRO (0x6B) 25 #define LSM9DS1_ADDRESS_MAG (0x1E) 26 #define LSM9DS1_XG_ID (0b01101000) 29 #define LSM9DS1_ACCEL_MG_LSB_2G (0.061F) 30 #define LSM9DS1_ACCEL_MG_LSB_4G (0.122F) 31 #define LSM9DS1_ACCEL_MG_LSB_8G (0.244F) 32 #define LSM9DS1_ACCEL_MG_LSB_16G (0.732F) 35 #define LSM9DS1_MAG_MGAUSS_4GAUSS (0.14F) 36 #define LSM9DS1_MAG_MGAUSS_8GAUSS (0.29F) 37 #define LSM9DS1_MAG_MGAUSS_12GAUSS (0.43F) 38 #define LSM9DS1_MAG_MGAUSS_16GAUSS (0.58F) 41 #define LSM9DS1_GYRO_DPS_DIGIT_245DPS (0.00875F) 42 #define LSM9DS1_GYRO_DPS_DIGIT_500DPS (0.01750F) 43 #define LSM9DS1_GYRO_DPS_DIGIT_2000DPS (0.07000F) 46 #define LSM9DS1_TEMP_LSB_DEGREE_CELSIUS (8) // 1°C = 8, 25° = 200, etc. 48 #define MAGTYPE (true) 49 #define XGTYPE (false) 70 int8_t gcs, int32_t sensorID = 0);
74 LSM9DS1_REGISTER_WHO_AM_I_XG = 0x0F,
75 LSM9DS1_REGISTER_CTRL_REG1_G = 0x10,
76 LSM9DS1_REGISTER_CTRL_REG2_G = 0x11,
77 LSM9DS1_REGISTER_CTRL_REG3_G = 0x12,
78 LSM9DS1_REGISTER_TEMP_OUT_L = 0x15,
79 LSM9DS1_REGISTER_TEMP_OUT_H = 0x16,
80 LSM9DS1_REGISTER_STATUS_REG = 0x17,
81 LSM9DS1_REGISTER_OUT_X_L_G = 0x18,
82 LSM9DS1_REGISTER_OUT_X_H_G = 0x19,
83 LSM9DS1_REGISTER_OUT_Y_L_G = 0x1A,
84 LSM9DS1_REGISTER_OUT_Y_H_G = 0x1B,
85 LSM9DS1_REGISTER_OUT_Z_L_G = 0x1C,
86 LSM9DS1_REGISTER_OUT_Z_H_G = 0x1D,
87 LSM9DS1_REGISTER_CTRL_REG4 = 0x1E,
88 LSM9DS1_REGISTER_CTRL_REG5_XL = 0x1F,
89 LSM9DS1_REGISTER_CTRL_REG6_XL = 0x20,
90 LSM9DS1_REGISTER_CTRL_REG7_XL = 0x21,
91 LSM9DS1_REGISTER_CTRL_REG8 = 0x22,
92 LSM9DS1_REGISTER_CTRL_REG9 = 0x23,
93 LSM9DS1_REGISTER_CTRL_REG10 = 0x24,
95 LSM9DS1_REGISTER_OUT_X_L_XL = 0x28,
96 LSM9DS1_REGISTER_OUT_X_H_XL = 0x29,
97 LSM9DS1_REGISTER_OUT_Y_L_XL = 0x2A,
98 LSM9DS1_REGISTER_OUT_Y_H_XL = 0x2B,
99 LSM9DS1_REGISTER_OUT_Z_L_XL = 0x2C,
100 LSM9DS1_REGISTER_OUT_Z_H_XL = 0x2D,
105 LSM9DS1_ACCELRANGE_2G = (0b00 << 3),
106 LSM9DS1_ACCELRANGE_16G = (0b01 << 3),
107 LSM9DS1_ACCELRANGE_4G = (0b10 << 3),
108 LSM9DS1_ACCELRANGE_8G = (0b11 << 3),
113 LSM9DS1_ACCELDATARATE_POWERDOWN = (0b0000 << 4),
115 LSM9DS1_ACCELDATARATE_10HZ = (0b001 << 5),
116 LSM9DS1_ACCELDATARATE_50HZ = (0b010 << 5),
117 LSM9DS1_ACCELDATARATE_119HZ = (0b011 << 5),
118 LSM9DS1_ACCELDATARATE_238HZ = (0b100 << 5),
119 LSM9DS1_ACCELDATARATE_476HZ = (0b101 << 5),
120 LSM9DS1_ACCELDATARATE_952HZ = (0b110 << 5),
125 LSM9DS1_MAGGAIN_4GAUSS = (0b00 << 5),
126 LSM9DS1_MAGGAIN_8GAUSS = (0b01 << 5),
127 LSM9DS1_MAGGAIN_12GAUSS = (0b10 << 5),
128 LSM9DS1_MAGGAIN_16GAUSS = (0b11 << 5)
133 LSM9DS1_GYROSCALE_245DPS =
135 LSM9DS1_GYROSCALE_500DPS =
137 LSM9DS1_GYROSCALE_2000DPS =
171 bool getEvent(sensors_event_t *accel, sensors_event_t *mag,
172 sensors_event_t *gyro, sensors_event_t *temp);
173 void getSensor(sensor_t *accel, sensor_t *mag, sensor_t *gyro,
186 : _parent(copy._parent), _readFunc(copy._readFunc),
187 _eventFunc(copy._eventFunc), _sensorFunc(copy._sensorFunc) {}
196 lsm9ds1_get_event_func eventFunc, lsm9ds1_get_sensor_func sensorFunc)
197 : _parent(parent), _readFunc(readFunc), _eventFunc(eventFunc),
198 _sensorFunc(sensorFunc) {}
204 (_parent->*_readFunc)();
205 (_parent->*_eventFunc)(event, millis());
212 (_parent->*_sensorFunc)(sensor);
217 lsm9ds1_read_func _readFunc;
218 lsm9ds1_get_event_func _eventFunc;
219 lsm9ds1_get_sensor_func _sensorFunc;
233 Adafruit_Sensor &
getMag(
void) {
return _magSensor; }
236 Adafruit_I2CDevice *i2c_dev = NULL;
237 Adafruit_SPIDevice *spi_dev = NULL;
238 void write8(
boolean type, byte reg, byte value);
239 byte read8(
boolean type, byte reg);
240 byte readBuffer(
boolean type, byte reg, byte len, uint8_t *buffer);
241 void initSensor(int32_t sensorID);
243 TwoWire *_wire = NULL;
244 int8_t _csm, _csxg, _mosi, _miso, _clk;
246 float _gyro_dps_digit;
247 int32_t _lsm9dso_sensorid_accel;
248 int32_t _lsm9dso_sensorid_gyro;
249 int32_t _lsm9dso_sensorid_temp;
251 Adafruit_LIS3MDL _magSensor;
260 void getAccelEvent(sensors_event_t *event, uint32_t timestamp);
261 void getMagEvent(sensors_event_t *event, uint32_t timestamp);
262 void getGyroEvent(sensors_event_t *event, uint32_t timestamp);
263 void getTempEvent(sensors_event_t *event, uint32_t timestamp);
264 void getAccelSensor(sensor_t *sensor);
265 void getMagSensor(sensor_t *sensor);
266 void getGyroSensor(sensor_t *sensor);
267 void getTempSensor(sensor_t *sensor);
Definition: Adafruit_LSM9DS1.h:64
void readGyro(void)
Read the sensor gyroscope sensor component.
Definition: Adafruit_LSM9DS1.cpp:208
-
void setupAccel(lsm9ds1AccelRange_t range)
Configure the accelerometer ranging.
Definition: Adafruit_LSM9DS1.cpp:259
-
Sensor(const Sensor ©)
Instantiate based on existing sensor.
Definition: Adafruit_LSM9DS1.h:188
-
lsm9ds1GyroScale_t
Definition: Adafruit_LSM9DS1.h:135
-
virtual void getSensor(sensor_t *sensor)
Get sensor metadata - type and range information.
Definition: Adafruit_LSM9DS1.h:214
-
Sensor(Adafruit_LSM9DS1 *parent, lsm9ds1_read_func readFunc, lsm9ds1_get_event_func eventFunc, lsm9ds1_get_sensor_func sensorFunc)
Instantiate based on existing sensor.
Definition: Adafruit_LSM9DS1.h:198
-
bool getEvent(sensors_event_t *accel, sensors_event_t *mag, sensors_event_t *gyro, sensors_event_t *temp)
Gets the most recent accel sensor events for all 4 sensors.
Definition: Adafruit_LSM9DS1.cpp:349
+
Sensor(const Sensor ©)
Instantiate based on existing sensor.
Definition: Adafruit_LSM9DS1.h:185
+
lsm9ds1GyroScale_t
Definition: Adafruit_LSM9DS1.h:132
+
virtual void getSensor(sensor_t *sensor)
Get sensor metadata - type and range information.
Definition: Adafruit_LSM9DS1.h:211
+
Sensor(Adafruit_LSM9DS1 *parent, lsm9ds1_read_func readFunc, lsm9ds1_get_event_func eventFunc, lsm9ds1_get_sensor_func sensorFunc)
Instantiate based on existing sensor.
Definition: Adafruit_LSM9DS1.h:195
+
bool getEvent(sensors_event_t *accel, sensors_event_t *mag, sensors_event_t *gyro, sensors_event_t *temp)
Gets the most recent accel sensor events for all 4 sensors.
Definition: Adafruit_LSM9DS1.cpp:353
void readTemp(void)
Read the sensor temperature sensor component.
Definition: Adafruit_LSM9DS1.cpp:238
-
float x
X component.
Definition: Adafruit_LSM9DS1.h:146
-
lsm9ds1Vector_t magData
Last read magnetometer data will be available here.
Definition: Adafruit_LSM9DS1.h:155
+
float x
X component.
Definition: Adafruit_LSM9DS1.h:143
+
lsm9ds1Vector_t magData
Last read magnetometer data will be available here.
Definition: Adafruit_LSM9DS1.h:152
bool begin(void)
Initialize I2C or SPI and detect/initialize subsensors.
Definition: Adafruit_LSM9DS1.cpp:88
void readMag(void)
Read the sensor magnetometer sensor component.
Definition: Adafruit_LSM9DS1.cpp:167
-
lm9ds1AccelDataRate_t
Definition: Adafruit_LSM9DS1.h:112
-
Sensor & getTemp(void)
Return Adafruit_Sensor compatible interface for temperature.
Definition: Adafruit_LSM9DS1.h:233
+
Sensor & getTemp(void)
Return Adafruit_Sensor compatible interface for temperature.
Definition: Adafruit_LSM9DS1.h:230
Adafruit_LSM9DS1(int32_t sensorID=0)
Instantiate with default hardware I2C interface.
Definition: Adafruit_LSM9DS1.cpp:39
void readAccel(void)
Read the sensor accelerometer sensor component.
Definition: Adafruit_LSM9DS1.cpp:179
void read(void)
Read all four sensor subcomponents.
Definition: Adafruit_LSM9DS1.cpp:154
-
Definition: Adafruit_LSM9DS1.h:145
+
Definition: Adafruit_LSM9DS1.h:142
lsm9ds1AccGyroRegisters_t
Definition: Adafruit_LSM9DS1.h:73
-
void getSensor(sensor_t *accel, sensor_t *mag, sensor_t *gyro, sensor_t *temp)
Gets the sensor_t data for all 4 sub-sensors at once call.
Definition: Adafruit_LSM9DS1.cpp:380
-
lsm9ds1Vector_t accelData
Last read accelerometer data will be available here.
Definition: Adafruit_LSM9DS1.h:152
-
lsm9ds1Vector_t gyroData
Last read gyroscope data will be available here.
Definition: Adafruit_LSM9DS1.h:153
+
void getSensor(sensor_t *accel, sensor_t *mag, sensor_t *gyro, sensor_t *temp)
Gets the sensor_t data for all 4 sub-sensors at once call.
Definition: Adafruit_LSM9DS1.cpp:384
+
lsm9ds1Vector_t accelData
Last read accelerometer data will be available here.
Definition: Adafruit_LSM9DS1.h:149
+
lsm9ds1Vector_t gyroData
Last read gyroscope data will be available here.
Definition: Adafruit_LSM9DS1.h:150
struct Adafruit_LSM9DS1::vector_s lsm9ds1Vector_t
lsm9ds1AccelRange_t
Definition: Adafruit_LSM9DS1.h:104
-
Definition: Adafruit_LSM9DS1.h:181
-
Sensor()
Basic instatiator.
Definition: Adafruit_LSM9DS1.h:184
-
void setupMag(lsm9ds1MagGain_t gain)
Configure the magnetometer gain.
Definition: Adafruit_LSM9DS1.cpp:289
-
Sensor & getGyro(void)
Return Adafruit_Sensor compatible interface for gyroscope.
Definition: Adafruit_LSM9DS1.h:230
-
void setupGyro(lsm9ds1GyroScale_t scale)
Configure the gyroscope scaling.
Definition: Adafruit_LSM9DS1.cpp:313
-
virtual bool getEvent(sensors_event_t *event)
Get sensor event data.
Definition: Adafruit_LSM9DS1.h:206
-
float z
Z component.
Definition: Adafruit_LSM9DS1.h:148
-
float y
Y component.
Definition: Adafruit_LSM9DS1.h:147
-
Sensor & getAccel(void)
Return Adafruit_Sensor compatible interface for accelerometer.
Definition: Adafruit_LSM9DS1.h:227
-
lsm9ds1MagGain_t
Definition: Adafruit_LSM9DS1.h:127
-
Adafruit_Sensor & getMag(void)
Return Adafruit_Sensor compatible interface for magnetometer.
Definition: Adafruit_LSM9DS1.h:236
-
int16_t temperature
Last read temperzture data will be available here.
Definition: Adafruit_LSM9DS1.h:156
+
Definition: Adafruit_LSM9DS1.h:178
+
Sensor()
Basic instatiator.
Definition: Adafruit_LSM9DS1.h:181
+
void setupMag(lsm9ds1MagGain_t gain)
Configure the magnetometer gain.
Definition: Adafruit_LSM9DS1.cpp:293
+
Sensor & getGyro(void)
Return Adafruit_Sensor compatible interface for gyroscope.
Definition: Adafruit_LSM9DS1.h:227
+
void setupGyro(lsm9ds1GyroScale_t scale)
Configure the gyroscope scaling.
Definition: Adafruit_LSM9DS1.cpp:317
+
virtual bool getEvent(sensors_event_t *event)
Get sensor event data.
Definition: Adafruit_LSM9DS1.h:203
+
lsm9ds1AccelDataRate_t
Definition: Adafruit_LSM9DS1.h:112
+
float z
Z component.
Definition: Adafruit_LSM9DS1.h:145
+
float y
Y component.
Definition: Adafruit_LSM9DS1.h:144
+
Sensor & getAccel(void)
Return Adafruit_Sensor compatible interface for accelerometer.
Definition: Adafruit_LSM9DS1.h:224
+
lsm9ds1MagGain_t
Definition: Adafruit_LSM9DS1.h:124
+
Adafruit_Sensor & getMag(void)
Return Adafruit_Sensor compatible interface for magnetometer.
Definition: Adafruit_LSM9DS1.h:233
+
void setupAccel(lsm9ds1AccelRange_t range, lsm9ds1AccelDataRate_t rate)
Configure the accelerometer ranging.
Definition: Adafruit_LSM9DS1.cpp:262
+
int16_t temperature
Last read temperzture data will be available here.
Definition: Adafruit_LSM9DS1.h:153