├── .github ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── githubci.yml ├── .gitignore ├── Adafruit_ISM330DHCX.cpp ├── Adafruit_ISM330DHCX.h ├── Adafruit_LSM6DS.cpp ├── Adafruit_LSM6DS.h ├── Adafruit_LSM6DS3.cpp ├── Adafruit_LSM6DS3.h ├── Adafruit_LSM6DS33.cpp ├── Adafruit_LSM6DS33.h ├── Adafruit_LSM6DS3TRC.cpp ├── Adafruit_LSM6DS3TRC.h ├── Adafruit_LSM6DSL.cpp ├── Adafruit_LSM6DSL.h ├── Adafruit_LSM6DSO32.cpp ├── Adafruit_LSM6DSO32.h ├── Adafruit_LSM6DSOX.cpp ├── Adafruit_LSM6DSOX.h ├── README.md ├── assets ├── board.jpg └── board.png ├── code-of-conduct.md ├── examples ├── adafruit_ism330dhcx_test │ └── adafruit_ism330dhcx_test.ino ├── adafruit_lsm6ds33_test │ └── adafruit_lsm6ds33_test.ino ├── adafruit_lsm6ds3trc_test │ └── adafruit_lsm6ds3trc_test.ino ├── adafruit_lsm6ds_pedometer │ └── adafruit_lsm6ds_pedometer.ino ├── adafruit_lsm6ds_shake │ └── adafruit_lsm6ds_shake.ino ├── adafruit_lsm6ds_unifiedsensors │ └── adafruit_lsm6ds_unifiedsensors.ino ├── adafruit_lsm6dso32_test │ └── adafruit_lsm6dso32_test.ino └── adafruit_lsm6dsox_test │ └── adafruit_lsm6dsox_test.ino ├── library.properties └── license.txt /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for opening an issue on an Adafruit Arduino library repository. To 2 | improve the speed of resolution please review the following guidelines and 3 | common troubleshooting steps below before creating the issue: 4 | 5 | - **Do not use GitHub issues for troubleshooting projects and issues.** Instead use 6 | the forums at http://forums.adafruit.com to ask questions and troubleshoot why 7 | something isn't working as expected. In many cases the problem is a common issue 8 | that you will more quickly receive help from the forum community. GitHub issues 9 | are meant for known defects in the code. If you don't know if there is a defect 10 | in the code then start with troubleshooting on the forum first. 11 | 12 | - **If following a tutorial or guide be sure you didn't miss a step.** Carefully 13 | check all of the steps and commands to run have been followed. Consult the 14 | forum if you're unsure or have questions about steps in a guide/tutorial. 15 | 16 | - **For Arduino projects check these very common issues to ensure they don't apply**: 17 | 18 | - For uploading sketches or communicating with the board make sure you're using 19 | a **USB data cable** and **not** a **USB charge-only cable**. It is sometimes 20 | very hard to tell the difference between a data and charge cable! Try using the 21 | cable with other devices or swapping to another cable to confirm it is not 22 | the problem. 23 | 24 | - **Be sure you are supplying adequate power to the board.** Check the specs of 25 | your board and plug in an external power supply. In many cases just 26 | plugging a board into your computer is not enough to power it and other 27 | peripherals. 28 | 29 | - **Double check all soldering joints and connections.** Flakey connections 30 | cause many mysterious problems. See the [guide to excellent soldering](https://learn.adafruit.com/adafruit-guide-excellent-soldering/tools) for examples of good solder joints. 31 | 32 | - **Ensure you are using an official Arduino or Adafruit board.** We can't 33 | guarantee a clone board will have the same functionality and work as expected 34 | with this code and don't support them. 35 | 36 | If you're sure this issue is a defect in the code and checked the steps above 37 | please fill in the following fields to provide enough troubleshooting information. 38 | You may delete the guideline and text above to just leave the following details: 39 | 40 | - Arduino board: **INSERT ARDUINO BOARD NAME/TYPE HERE** 41 | 42 | - Arduino IDE version (found in Arduino -> About Arduino menu): **INSERT ARDUINO 43 | VERSION HERE** 44 | 45 | - List the steps to reproduce the problem below (if possible attach a sketch or 46 | copy the sketch code in too): **LIST REPRO STEPS BELOW** 47 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for creating a pull request to contribute to Adafruit's GitHub code! 2 | Before you open the request please review the following guidelines and tips to 3 | help it be more easily integrated: 4 | 5 | - **Describe the scope of your change--i.e. what the change does and what parts 6 | of the code were modified.** This will help us understand any risks of integrating 7 | the code. 8 | 9 | - **Describe any known limitations with your change.** For example if the change 10 | doesn't apply to a supported platform of the library please mention it. 11 | 12 | - **Please run any tests or examples that can exercise your modified code.** We 13 | strive to not break users of the code and running tests/examples helps with this 14 | process. 15 | 16 | Thank you again for contributing! We will try to test and integrate the change 17 | as soon as we can, but be aware we have many GitHub repositories to manage and 18 | can't immediately respond to every request. There is no need to bump or check in 19 | on a pull request (it will clutter the discussion of the request). 20 | 21 | Also don't be worried if the request is closed or not integrated--sometimes the 22 | priorities of Adafruit's GitHub code (education, ease of use) might not match the 23 | priorities of the pull request. Don't fret, the open source community thrives on 24 | forks and GitHub makes it easy to keep your changes in a forked repo. 25 | 26 | After reviewing the guidelines above you can delete this text from the pull request. 27 | -------------------------------------------------------------------------------- /.github/workflows/githubci.yml: -------------------------------------------------------------------------------- 1 | name: Arduino Library CI 2 | 3 | on: [pull_request, push, repository_dispatch] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | 9 | steps: 10 | - uses: actions/setup-python@v4 11 | with: 12 | python-version: '3.x' 13 | - uses: actions/checkout@v3 14 | - uses: actions/checkout@v3 15 | with: 16 | repository: adafruit/ci-arduino 17 | path: ci 18 | 19 | - name: Install the prerequisites 20 | run: bash ci/actions_install.sh 21 | 22 | - name: Check for correct code formatting with clang-format 23 | run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r . 24 | 25 | - name: Check for correct documentation with doxygen 26 | env: 27 | GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }} 28 | PRETTYNAME : "Adafruit LSM6DS Sensors Library" 29 | run: bash ci/doxy_gen_and_deploy.sh 30 | 31 | - name: Test the code on supported platforms 32 | run: python3 ci/build_platform.py main_platforms 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.elf 2 | *.hex 3 | html/ 4 | Doxyfile 5 | .vscode/ 6 | -------------------------------------------------------------------------------- /Adafruit_ISM330DHCX.cpp: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * @file Adafruit_ISM330DHCX.cpp Adafruit ISM330DHCX 6-DoF Accelerometer 4 | * and Gyroscope library 5 | * 6 | * Bryan Siepert for Adafruit Industries 7 | * BSD (see license.txt) 8 | */ 9 | 10 | #include "Arduino.h" 11 | #include 12 | 13 | #include "Adafruit_ISM330DHCX.h" 14 | 15 | /*! 16 | * @brief Instantiates a new ISM330DHCX class 17 | */ 18 | Adafruit_ISM330DHCX::Adafruit_ISM330DHCX(void) {} 19 | 20 | bool Adafruit_ISM330DHCX::_init(int32_t sensor_id) { 21 | // make sure we're talking to the right chip 22 | if (chipID() != ISM330DHCX_CHIP_ID) { 23 | return false; 24 | } 25 | _sensorid_accel = sensor_id; 26 | _sensorid_gyro = sensor_id + 1; 27 | _sensorid_temp = sensor_id + 2; 28 | 29 | reset(); 30 | 31 | // call base class _init() 32 | Adafruit_LSM6DS::_init(sensor_id); 33 | 34 | // set the Block Data Update bit 35 | // this prevents MSB/LSB data registers from being updated until both are read 36 | Adafruit_BusIO_Register ctrl3 = Adafruit_BusIO_Register( 37 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_CTRL3_C); 38 | Adafruit_BusIO_RegisterBits bdu = Adafruit_BusIO_RegisterBits(&ctrl3, 1, 6); 39 | bdu.write(1); 40 | 41 | return true; 42 | } 43 | -------------------------------------------------------------------------------- /Adafruit_ISM330DHCX.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file Adafruit_ISM330DHCX.h 3 | * 4 | * I2C Driver for the Adafruit ISM330DHCX 6-DoF Accelerometer and Gyroscope 5 | *library 6 | * 7 | * This is a library for the Adafruit ISM330DHCX breakout: 8 | * https://www.adafruit.com/products/4480 9 | * 10 | * Adafruit invests time and resources providing this open source code, 11 | * please support Adafruit and open-source hardware by purchasing products from 12 | * Adafruit! 13 | * 14 | * 15 | * BSD license (see license.txt) 16 | */ 17 | 18 | #ifndef _ADAFRUIT_ISM330DHCX_H 19 | #define _ADAFRUIT_ISM330DHCX_H 20 | 21 | #include "Adafruit_LSM6DSOX.h" 22 | 23 | #define ISM330DHCX_CHIP_ID 0x6B ///< ISM330DHCX default device id from WHOAMI 24 | 25 | /*! 26 | * @brief Class that stores state and functions for interacting with 27 | * the ISM330DHCX I2C Digital Potentiometer 28 | */ 29 | class Adafruit_ISM330DHCX : public Adafruit_LSM6DSOX { 30 | public: 31 | Adafruit_ISM330DHCX(); 32 | ~Adafruit_ISM330DHCX(){}; 33 | 34 | private: 35 | bool _init(int32_t sensor_id); 36 | }; 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /Adafruit_LSM6DS.cpp: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * @file Adafruit_LSM6DS.cpp Adafruit LSM6DS 6-DoF Accelerometer 4 | * and Gyroscope library 5 | * 6 | * @section intro_sec Introduction 7 | * 8 | * I2C Driver base for Adafruit LSM6DS 6-DoF Accelerometer 9 | * and Gyroscope libraries 10 | * 11 | * Adafruit invests time and resources providing this open source code, 12 | * please support Adafruit and open-source hardware by purchasing products from 13 | * Adafruit! 14 | * 15 | * @section dependencies Dependencies 16 | * This library depends on the Adafruit BusIO library 17 | * 18 | * This library depends on the Adafruit Unified Sensor library 19 | 20 | * @section author Author 21 | * 22 | * Bryan Siepert for Adafruit Industries 23 | * 24 | * @section license License 25 | * 26 | * BSD (see license.txt) 27 | * 28 | * @section HISTORY 29 | * 30 | * v1.0 - First release 31 | */ 32 | 33 | #include "Arduino.h" 34 | #include 35 | 36 | #include "Adafruit_LSM6DS.h" 37 | 38 | static const float _data_rate_arr[] = { 39 | [LSM6DS_RATE_SHUTDOWN] = 0.0f, [LSM6DS_RATE_12_5_HZ] = 12.5f, 40 | [LSM6DS_RATE_26_HZ] = 26.0f, [LSM6DS_RATE_52_HZ] = 52.0f, 41 | [LSM6DS_RATE_104_HZ] = 104.0f, [LSM6DS_RATE_208_HZ] = 208.0f, 42 | [LSM6DS_RATE_416_HZ] = 416.0f, [LSM6DS_RATE_833_HZ] = 833.0f, 43 | [LSM6DS_RATE_1_66K_HZ] = 1660.0f, [LSM6DS_RATE_3_33K_HZ] = 3330.0f, 44 | [LSM6DS_RATE_6_66K_HZ] = 6660.0f, 45 | }; 46 | 47 | /*! 48 | * @brief Instantiates a new LSM6DS class 49 | */ 50 | Adafruit_LSM6DS::Adafruit_LSM6DS(void) {} 51 | 52 | /*! 53 | * @brief Cleans up the LSM6DS 54 | */ 55 | Adafruit_LSM6DS::~Adafruit_LSM6DS(void) { delete temp_sensor; } 56 | 57 | /*! @brief Unique subclass initializer post i2c/spi init 58 | * @param sensor_id Optional unique ID for the sensor set 59 | * @returns True if chip identified and initialized 60 | */ 61 | bool Adafruit_LSM6DS::_init(int32_t sensor_id) { 62 | (void)sensor_id; 63 | 64 | // Enable accelerometer with 104 Hz data rate, 4G 65 | setAccelDataRate(LSM6DS_RATE_104_HZ); 66 | setAccelRange(LSM6DS_ACCEL_RANGE_4_G); 67 | 68 | // Enable gyro with 104 Hz data rate, 2000 dps 69 | setGyroDataRate(LSM6DS_RATE_104_HZ); 70 | setGyroRange(LSM6DS_GYRO_RANGE_2000_DPS); 71 | 72 | delay(10); 73 | 74 | // delete objects if sensor is reinitialized 75 | delete temp_sensor; 76 | delete accel_sensor; 77 | delete gyro_sensor; 78 | 79 | temp_sensor = new Adafruit_LSM6DS_Temp(this); 80 | accel_sensor = new Adafruit_LSM6DS_Accelerometer(this); 81 | gyro_sensor = new Adafruit_LSM6DS_Gyro(this); 82 | 83 | return false; 84 | }; 85 | 86 | /*! 87 | * @brief Read chip identification register 88 | * @returns 8 Bit value from WHOAMI register 89 | */ 90 | uint8_t Adafruit_LSM6DS::chipID(void) { 91 | Adafruit_BusIO_Register chip_id = Adafruit_BusIO_Register( 92 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_WHOAMI); 93 | // Serial.print("Read ID 0x"); Serial.println(chip_id.read(), HEX); 94 | 95 | // make sure we're talking to the right chip 96 | return chip_id.read(); 97 | } 98 | 99 | /*! 100 | * @brief Read Status register 101 | * @returns 8 Bit value from Status register 102 | */ 103 | uint8_t Adafruit_LSM6DS::status(void) { 104 | Adafruit_BusIO_Register status_reg = Adafruit_BusIO_Register( 105 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_STATUS_REG); 106 | return status_reg.read(); 107 | } 108 | 109 | /*! 110 | * @brief Sets up the hardware and initializes I2C 111 | * @param i2c_address 112 | * The I2C address to be used. 113 | * @param wire 114 | * The Wire object to be used for I2C connections. 115 | * @param sensor_id 116 | * The user-defined ID to differentiate different sensors 117 | * @return True if initialization was successful, otherwise false. 118 | */ 119 | boolean Adafruit_LSM6DS::begin_I2C(uint8_t i2c_address, TwoWire *wire, 120 | int32_t sensor_id) { 121 | delete i2c_dev; // remove old interface 122 | 123 | i2c_dev = new Adafruit_I2CDevice(i2c_address, wire); 124 | 125 | if (!i2c_dev->begin()) { 126 | return false; 127 | } 128 | 129 | return _init(sensor_id); 130 | } 131 | 132 | /*! 133 | * @brief Sets up the hardware and initializes hardware SPI 134 | * @param cs_pin The arduino pin # connected to chip select 135 | * @param theSPI The SPI object to be used for SPI connections. 136 | * @param frequency The SPI bus frequency 137 | * @param sensor_id 138 | * The user-defined ID to differentiate different sensors 139 | * @return True if initialization was successful, otherwise false. 140 | */ 141 | bool Adafruit_LSM6DS::begin_SPI(uint8_t cs_pin, SPIClass *theSPI, 142 | int32_t sensor_id, uint32_t frequency) { 143 | i2c_dev = NULL; 144 | 145 | delete spi_dev; // remove old interface 146 | 147 | spi_dev = new Adafruit_SPIDevice(cs_pin, 148 | frequency, // frequency 149 | SPI_BITORDER_MSBFIRST, // bit order 150 | SPI_MODE0, // data mode 151 | theSPI); 152 | if (!spi_dev->begin()) { 153 | return false; 154 | } 155 | 156 | return _init(sensor_id); 157 | } 158 | 159 | /*! 160 | * @brief Sets up the hardware and initializes software SPI 161 | * @param cs_pin The arduino pin # connected to chip select 162 | * @param sck_pin The arduino pin # connected to SPI clock 163 | * @param miso_pin The arduino pin # connected to SPI MISO 164 | * @param mosi_pin The arduino pin # connected to SPI MOSI 165 | * @param frequency The SPI bus frequency 166 | * @param sensor_id 167 | * The user-defined ID to differentiate different sensors 168 | * @return True if initialization was successful, otherwise false. 169 | */ 170 | bool Adafruit_LSM6DS::begin_SPI(int8_t cs_pin, int8_t sck_pin, int8_t miso_pin, 171 | int8_t mosi_pin, int32_t sensor_id, 172 | uint32_t frequency) { 173 | i2c_dev = NULL; 174 | 175 | delete spi_dev; // remove old interface 176 | 177 | spi_dev = new Adafruit_SPIDevice(cs_pin, sck_pin, miso_pin, mosi_pin, 178 | frequency, // frequency 179 | SPI_BITORDER_MSBFIRST, // bit order 180 | SPI_MODE0); // data mode 181 | if (!spi_dev->begin()) { 182 | return false; 183 | } 184 | 185 | return _init(sensor_id); 186 | } 187 | 188 | /**************************************************************************/ 189 | /*! 190 | @brief Resets the sensor to its power-on state, clearing all registers and 191 | memory 192 | */ 193 | void Adafruit_LSM6DS::reset(void) { 194 | 195 | Adafruit_BusIO_Register ctrl3 = Adafruit_BusIO_Register( 196 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_CTRL3_C); 197 | 198 | Adafruit_BusIO_RegisterBits sw_reset = 199 | Adafruit_BusIO_RegisterBits(&ctrl3, 1, 0); 200 | 201 | // Adafruit_BusIO_RegisterBits boot = Adafruit_BusIO_RegisterBits(&ctrl3, 1, 202 | // 7); 203 | 204 | sw_reset.write(true); 205 | 206 | while (sw_reset.read()) { 207 | delay(1); 208 | } 209 | } 210 | 211 | /*! 212 | @brief Gets an Adafruit Unified Sensor object for the temp sensor component 213 | @return Adafruit_Sensor pointer to temperature sensor 214 | */ 215 | Adafruit_Sensor *Adafruit_LSM6DS::getTemperatureSensor(void) { 216 | return temp_sensor; 217 | } 218 | 219 | /*! 220 | @brief Gets an Adafruit Unified Sensor object for the accelerometer 221 | sensor component 222 | @return Adafruit_Sensor pointer to accelerometer sensor 223 | */ 224 | Adafruit_Sensor *Adafruit_LSM6DS::getAccelerometerSensor(void) { 225 | return accel_sensor; 226 | } 227 | 228 | /*! 229 | @brief Gets an Adafruit Unified Sensor object for the gyro sensor component 230 | @return Adafruit_Sensor pointer to gyro sensor 231 | */ 232 | Adafruit_Sensor *Adafruit_LSM6DS::getGyroSensor(void) { return gyro_sensor; } 233 | 234 | /**************************************************************************/ 235 | /*! 236 | @brief Gets the most recent sensor event, Adafruit Unified Sensor format 237 | @param accel 238 | Pointer to an Adafruit Unified sensor_event_t object to be filled 239 | with acceleration event data. 240 | 241 | @param gyro 242 | Pointer to an Adafruit Unified sensor_event_t object to be filled 243 | with gyro event data. 244 | 245 | @param temp 246 | Pointer to an Adafruit Unified sensor_event_t object to be filled 247 | with temperature event data. 248 | 249 | @return True on successful read 250 | */ 251 | /**************************************************************************/ 252 | bool Adafruit_LSM6DS::getEvent(sensors_event_t *accel, sensors_event_t *gyro, 253 | sensors_event_t *temp) { 254 | uint32_t t = millis(); 255 | _read(); 256 | 257 | // use helpers to fill in the events 258 | fillAccelEvent(accel, t); 259 | fillGyroEvent(gyro, t); 260 | fillTempEvent(temp, t); 261 | return true; 262 | } 263 | 264 | void Adafruit_LSM6DS::fillTempEvent(sensors_event_t *temp, uint32_t timestamp) { 265 | memset(temp, 0, sizeof(sensors_event_t)); 266 | temp->version = sizeof(sensors_event_t); 267 | temp->sensor_id = _sensorid_temp; 268 | temp->type = SENSOR_TYPE_AMBIENT_TEMPERATURE; 269 | temp->timestamp = timestamp; 270 | temp->temperature = temperature; 271 | } 272 | 273 | void Adafruit_LSM6DS::fillGyroEvent(sensors_event_t *gyro, uint32_t timestamp) { 274 | memset(gyro, 0, sizeof(sensors_event_t)); 275 | gyro->version = 1; 276 | gyro->sensor_id = _sensorid_gyro; 277 | gyro->type = SENSOR_TYPE_GYROSCOPE; 278 | gyro->timestamp = timestamp; 279 | gyro->gyro.x = gyroX; 280 | gyro->gyro.y = gyroY; 281 | gyro->gyro.z = gyroZ; 282 | } 283 | 284 | void Adafruit_LSM6DS::fillAccelEvent(sensors_event_t *accel, 285 | uint32_t timestamp) { 286 | memset(accel, 0, sizeof(sensors_event_t)); 287 | accel->version = 1; 288 | accel->sensor_id = _sensorid_accel; 289 | accel->type = SENSOR_TYPE_ACCELEROMETER; 290 | accel->timestamp = timestamp; 291 | accel->acceleration.x = accX; 292 | accel->acceleration.y = accY; 293 | accel->acceleration.z = accZ; 294 | } 295 | 296 | /**************************************************************************/ 297 | /*! 298 | @brief Gets the accelerometer data rate. 299 | @returns The the accelerometer data rate. 300 | */ 301 | lsm6ds_data_rate_t Adafruit_LSM6DS::getAccelDataRate(void) { 302 | 303 | Adafruit_BusIO_Register ctrl1 = Adafruit_BusIO_Register( 304 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_CTRL1_XL); 305 | 306 | Adafruit_BusIO_RegisterBits accel_data_rate = 307 | Adafruit_BusIO_RegisterBits(&ctrl1, 4, 4); 308 | 309 | return (lsm6ds_data_rate_t)accel_data_rate.read(); 310 | } 311 | 312 | /**************************************************************************/ 313 | /*! 314 | @brief Sets the accelerometer data rate. 315 | @param data_rate 316 | The the accelerometer data rate. Must be a `lsm6ds_data_rate_t`. 317 | */ 318 | void Adafruit_LSM6DS::setAccelDataRate(lsm6ds_data_rate_t data_rate) { 319 | 320 | Adafruit_BusIO_Register ctrl1 = Adafruit_BusIO_Register( 321 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_CTRL1_XL); 322 | 323 | Adafruit_BusIO_RegisterBits accel_data_rate = 324 | Adafruit_BusIO_RegisterBits(&ctrl1, 4, 4); 325 | 326 | accel_data_rate.write(data_rate); 327 | } 328 | 329 | /**************************************************************************/ 330 | /*! 331 | @brief Gets the accelerometer measurement range. 332 | @returns The the accelerometer measurement range. 333 | */ 334 | lsm6ds_accel_range_t Adafruit_LSM6DS::getAccelRange(void) { 335 | 336 | Adafruit_BusIO_Register ctrl1 = Adafruit_BusIO_Register( 337 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_CTRL1_XL); 338 | 339 | Adafruit_BusIO_RegisterBits accel_range = 340 | Adafruit_BusIO_RegisterBits(&ctrl1, 2, 2); 341 | 342 | accelRangeBuffered = (lsm6ds_accel_range_t)accel_range.read(); 343 | 344 | return accelRangeBuffered; 345 | } 346 | /**************************************************************************/ 347 | /*! 348 | @brief Sets the accelerometer measurement range. 349 | @param new_range The `lsm6ds_accel_range_t` range to set. 350 | */ 351 | void Adafruit_LSM6DS::setAccelRange(lsm6ds_accel_range_t new_range) { 352 | 353 | Adafruit_BusIO_Register ctrl1 = Adafruit_BusIO_Register( 354 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_CTRL1_XL); 355 | 356 | Adafruit_BusIO_RegisterBits accel_range = 357 | Adafruit_BusIO_RegisterBits(&ctrl1, 2, 2); 358 | 359 | accel_range.write(new_range); 360 | 361 | accelRangeBuffered = new_range; 362 | } 363 | 364 | /**************************************************************************/ 365 | /*! 366 | @brief Gets the gyro data rate. 367 | @returns The the gyro data rate. 368 | */ 369 | lsm6ds_data_rate_t Adafruit_LSM6DS::getGyroDataRate(void) { 370 | 371 | Adafruit_BusIO_Register ctrl2 = Adafruit_BusIO_Register( 372 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_CTRL2_G); 373 | 374 | Adafruit_BusIO_RegisterBits gyro_data_rate = 375 | Adafruit_BusIO_RegisterBits(&ctrl2, 4, 4); 376 | 377 | return (lsm6ds_data_rate_t)gyro_data_rate.read(); 378 | } 379 | 380 | /**************************************************************************/ 381 | /*! 382 | @brief Sets the gyro data rate. 383 | @param data_rate 384 | The the gyro data rate. Must be a `lsm6ds_data_rate_t`. 385 | */ 386 | void Adafruit_LSM6DS::setGyroDataRate(lsm6ds_data_rate_t data_rate) { 387 | 388 | Adafruit_BusIO_Register ctrl2 = Adafruit_BusIO_Register( 389 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_CTRL2_G); 390 | 391 | Adafruit_BusIO_RegisterBits gyro_data_rate = 392 | Adafruit_BusIO_RegisterBits(&ctrl2, 4, 4); 393 | 394 | gyro_data_rate.write(data_rate); 395 | } 396 | 397 | /**************************************************************************/ 398 | /*! 399 | @brief Gets the gyro range. 400 | @returns The the gyro range. 401 | */ 402 | lsm6ds_gyro_range_t Adafruit_LSM6DS::getGyroRange(void) { 403 | 404 | Adafruit_BusIO_Register ctrl2 = Adafruit_BusIO_Register( 405 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_CTRL2_G); 406 | 407 | Adafruit_BusIO_RegisterBits gyro_range = 408 | Adafruit_BusIO_RegisterBits(&ctrl2, 4, 0); 409 | 410 | gyroRangeBuffered = (lsm6ds_gyro_range_t)gyro_range.read(); 411 | 412 | return gyroRangeBuffered; 413 | } 414 | 415 | /**************************************************************************/ 416 | /*! 417 | @brief Sets the gyro range. 418 | @param new_range The `lsm6ds_gyro_range_t` to set. 419 | */ 420 | void Adafruit_LSM6DS::setGyroRange(lsm6ds_gyro_range_t new_range) { 421 | 422 | Adafruit_BusIO_Register ctrl2 = Adafruit_BusIO_Register( 423 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_CTRL2_G); 424 | 425 | Adafruit_BusIO_RegisterBits gyro_range = 426 | Adafruit_BusIO_RegisterBits(&ctrl2, 4, 0); 427 | 428 | gyro_range.write(new_range); 429 | 430 | gyroRangeBuffered = new_range; 431 | } 432 | 433 | /**************************************************************************/ 434 | /*! 435 | @brief Enables the high pass filter and/or slope filter 436 | @param filter_enabled Whether to enable the slope filter (see datasheet) 437 | @param filter The lsm6ds_hp_filter_t that sets the data rate divisor 438 | */ 439 | /**************************************************************************/ 440 | void Adafruit_LSM6DS::highPassFilter(bool filter_enabled, 441 | lsm6ds_hp_filter_t filter) { 442 | Adafruit_BusIO_Register ctrl8 = Adafruit_BusIO_Register( 443 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_CTRL8_XL); 444 | Adafruit_BusIO_RegisterBits HPF_en = 445 | Adafruit_BusIO_RegisterBits(&ctrl8, 1, 2); 446 | Adafruit_BusIO_RegisterBits HPF_filter = 447 | Adafruit_BusIO_RegisterBits(&ctrl8, 2, 5); 448 | HPF_en.write(filter_enabled); 449 | HPF_filter.write(filter); 450 | } 451 | 452 | /******************* Adafruit_Sensor functions *****************/ 453 | /*! 454 | * @brief Updates the measurement data for all sensors simultaneously 455 | */ 456 | /**************************************************************************/ 457 | void Adafruit_LSM6DS::_read(void) { 458 | // get raw readings 459 | Adafruit_BusIO_Register data_reg = Adafruit_BusIO_Register( 460 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_OUT_TEMP_L, 14); 461 | 462 | uint8_t buffer[14]; 463 | data_reg.read(buffer, 14); 464 | 465 | rawTemp = buffer[1] << 8 | buffer[0]; 466 | temperature = (rawTemp / temperature_sensitivity) + 25.0; 467 | 468 | rawGyroX = buffer[3] << 8 | buffer[2]; 469 | rawGyroY = buffer[5] << 8 | buffer[4]; 470 | rawGyroZ = buffer[7] << 8 | buffer[6]; 471 | 472 | rawAccX = buffer[9] << 8 | buffer[8]; 473 | rawAccY = buffer[11] << 8 | buffer[10]; 474 | rawAccZ = buffer[13] << 8 | buffer[12]; 475 | 476 | float gyro_scale = 1; // range is in milli-dps per bit! 477 | switch (gyroRangeBuffered) { 478 | case ISM330DHCX_GYRO_RANGE_4000_DPS: 479 | gyro_scale = 140.0; 480 | break; 481 | case LSM6DS_GYRO_RANGE_2000_DPS: 482 | gyro_scale = 70.0; 483 | break; 484 | case LSM6DS_GYRO_RANGE_1000_DPS: 485 | gyro_scale = 35.0; 486 | break; 487 | case LSM6DS_GYRO_RANGE_500_DPS: 488 | gyro_scale = 17.50; 489 | break; 490 | case LSM6DS_GYRO_RANGE_250_DPS: 491 | gyro_scale = 8.75; 492 | break; 493 | case LSM6DS_GYRO_RANGE_125_DPS: 494 | gyro_scale = 4.375; 495 | break; 496 | } 497 | 498 | gyroX = rawGyroX * gyro_scale * SENSORS_DPS_TO_RADS / 1000.0; 499 | gyroY = rawGyroY * gyro_scale * SENSORS_DPS_TO_RADS / 1000.0; 500 | gyroZ = rawGyroZ * gyro_scale * SENSORS_DPS_TO_RADS / 1000.0; 501 | 502 | float accel_scale = 1; // range is in milli-g per bit! 503 | switch (accelRangeBuffered) { 504 | case LSM6DS_ACCEL_RANGE_16_G: 505 | accel_scale = 0.488; 506 | break; 507 | case LSM6DS_ACCEL_RANGE_8_G: 508 | accel_scale = 0.244; 509 | break; 510 | case LSM6DS_ACCEL_RANGE_4_G: 511 | accel_scale = 0.122; 512 | break; 513 | case LSM6DS_ACCEL_RANGE_2_G: 514 | accel_scale = 0.061; 515 | break; 516 | } 517 | 518 | accX = rawAccX * accel_scale * SENSORS_GRAVITY_STANDARD / 1000; 519 | accY = rawAccY * accel_scale * SENSORS_GRAVITY_STANDARD / 1000; 520 | accZ = rawAccZ * accel_scale * SENSORS_GRAVITY_STANDARD / 1000; 521 | } 522 | 523 | /**************************************************************************/ 524 | /*! 525 | @brief Sets the INT1 and INT2 pin activation mode 526 | @param active_low true to set the pins as active high, false to set the 527 | mode to active low 528 | @param open_drain true to set the pin mode as open-drain, false to set the 529 | mode to push-pull 530 | */ 531 | void Adafruit_LSM6DS::configIntOutputs(bool active_low, bool open_drain) { 532 | 533 | Adafruit_BusIO_Register ctrl3 = Adafruit_BusIO_Register( 534 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_CTRL3_C); 535 | Adafruit_BusIO_RegisterBits ppod_bits = 536 | Adafruit_BusIO_RegisterBits(&ctrl3, 2, 4); 537 | 538 | ppod_bits.write((active_low << 1) | open_drain); 539 | } 540 | 541 | /**************************************************************************/ 542 | /*! 543 | @brief Enables and disables the data ready interrupt on INT 1. 544 | @param drdy_temp true to output the data ready temperature interrupt 545 | @param drdy_g true to output the data ready gyro interrupt 546 | @param drdy_xl true to output the data ready accelerometer interrupt 547 | @param step_detect true to output the step detection interrupt (default off) 548 | @param wakeup true to output the wake up interrupt (default off) 549 | */ 550 | void Adafruit_LSM6DS::configInt1(bool drdy_temp, bool drdy_g, bool drdy_xl, 551 | bool step_detect, bool wakeup) { 552 | 553 | Adafruit_BusIO_Register int1_ctrl = Adafruit_BusIO_Register( 554 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_INT1_CTRL); 555 | 556 | int1_ctrl.write((step_detect << 7) | (drdy_temp << 2) | (drdy_g << 1) | 557 | drdy_xl); 558 | 559 | Adafruit_BusIO_Register md1cfg = Adafruit_BusIO_Register( 560 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_MD1_CFG); 561 | 562 | Adafruit_BusIO_RegisterBits wu = Adafruit_BusIO_RegisterBits(&md1cfg, 1, 5); 563 | wu.write(wakeup); 564 | } 565 | 566 | /**************************************************************************/ 567 | /*! 568 | @brief Enables and disables the data ready interrupt on INT 2. 569 | @param drdy_temp true to output the data ready temperature interrupt 570 | @param drdy_g true to output the data ready gyro interrupt 571 | @param drdy_xl true to output the data ready accelerometer interrupt 572 | */ 573 | void Adafruit_LSM6DS::configInt2(bool drdy_temp, bool drdy_g, bool drdy_xl) { 574 | 575 | Adafruit_BusIO_Register int2_ctrl = Adafruit_BusIO_Register( 576 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_INT2_CTRL); 577 | 578 | Adafruit_BusIO_RegisterBits int2_drdy_bits = 579 | Adafruit_BusIO_RegisterBits(&int2_ctrl, 3, 0); 580 | 581 | int2_drdy_bits.write((drdy_temp << 2) | (drdy_g << 1) | drdy_xl); 582 | } 583 | 584 | /**************************************************************************/ 585 | /*! 586 | @brief Gets the sensor_t data for the LSM6DS's gyroscope sensor 587 | */ 588 | /**************************************************************************/ 589 | void Adafruit_LSM6DS_Gyro::getSensor(sensor_t *sensor) { 590 | /* Clear the sensor_t object */ 591 | memset(sensor, 0, sizeof(sensor_t)); 592 | 593 | /* Insert the sensor name in the fixed length char array */ 594 | strncpy(sensor->name, "LSM6DS_G", sizeof(sensor->name) - 1); 595 | sensor->name[sizeof(sensor->name) - 1] = 0; 596 | sensor->version = 1; 597 | sensor->sensor_id = _sensorID; 598 | sensor->type = SENSOR_TYPE_GYROSCOPE; 599 | sensor->min_delay = 0; 600 | sensor->min_value = -34.91; /* -2000 dps -> rad/s (radians per second) */ 601 | sensor->max_value = +34.91; 602 | sensor->resolution = 7.6358e-5; /* 4.375 mdps -> rad/s */ 603 | } 604 | 605 | /**************************************************************************/ 606 | /*! 607 | @brief Gets the gyroscope as a standard sensor event 608 | @param event Sensor event object that will be populated 609 | @returns True 610 | */ 611 | /**************************************************************************/ 612 | bool Adafruit_LSM6DS_Gyro::getEvent(sensors_event_t *event) { 613 | _theLSM6DS->_read(); 614 | _theLSM6DS->fillGyroEvent(event, millis()); 615 | 616 | return true; 617 | } 618 | 619 | /**************************************************************************/ 620 | /*! 621 | @brief Gets the sensor_t data for the LSM6DS's accelerometer 622 | */ 623 | /**************************************************************************/ 624 | void Adafruit_LSM6DS_Accelerometer::getSensor(sensor_t *sensor) { 625 | /* Clear the sensor_t object */ 626 | memset(sensor, 0, sizeof(sensor_t)); 627 | 628 | /* Insert the sensor name in the fixed length char array */ 629 | strncpy(sensor->name, "LSM6DS_A", sizeof(sensor->name) - 1); 630 | sensor->name[sizeof(sensor->name) - 1] = 0; 631 | sensor->version = 1; 632 | sensor->sensor_id = _sensorID; 633 | sensor->type = SENSOR_TYPE_ACCELEROMETER; 634 | sensor->min_delay = 0; 635 | sensor->min_value = -156.9064F; /* -16g = 156.9064 m/s^2 */ 636 | sensor->max_value = 156.9064F; /* 16g = 156.9064 m/s^2 */ 637 | sensor->resolution = 0.061; /* 0.061 mg/LSB at +-2g */ 638 | } 639 | 640 | /**************************************************************************/ 641 | /*! 642 | @brief Gets the accelerometer as a standard sensor event 643 | @param event Sensor event object that will be populated 644 | @returns True 645 | */ 646 | /**************************************************************************/ 647 | bool Adafruit_LSM6DS_Accelerometer::getEvent(sensors_event_t *event) { 648 | _theLSM6DS->_read(); 649 | _theLSM6DS->fillAccelEvent(event, millis()); 650 | 651 | return true; 652 | } 653 | 654 | /**************************************************************************/ 655 | /*! 656 | @brief Gets the sensor_t data for the LSM6DS's tenperature 657 | */ 658 | /**************************************************************************/ 659 | void Adafruit_LSM6DS_Temp::getSensor(sensor_t *sensor) { 660 | /* Clear the sensor_t object */ 661 | memset(sensor, 0, sizeof(sensor_t)); 662 | 663 | /* Insert the sensor name in the fixed length char array */ 664 | strncpy(sensor->name, "LSM6DS_T", sizeof(sensor->name) - 1); 665 | sensor->name[sizeof(sensor->name) - 1] = 0; 666 | sensor->version = 1; 667 | sensor->sensor_id = _sensorID; 668 | sensor->type = SENSOR_TYPE_AMBIENT_TEMPERATURE; 669 | sensor->min_delay = 0; 670 | sensor->min_value = -40; 671 | sensor->max_value = 85; 672 | sensor->resolution = 1; /* not a great sensor */ 673 | } 674 | 675 | /**************************************************************************/ 676 | /*! 677 | @brief Gets the temperature as a standard sensor event 678 | @param event Sensor event object that will be populated 679 | @returns True 680 | */ 681 | /**************************************************************************/ 682 | bool Adafruit_LSM6DS_Temp::getEvent(sensors_event_t *event) { 683 | _theLSM6DS->_read(); 684 | _theLSM6DS->fillTempEvent(event, millis()); 685 | 686 | return true; 687 | } 688 | 689 | /**************************************************************************/ 690 | /*! 691 | @brief Enables and disables the pedometer function 692 | @param enable True to turn on the pedometer function, false to turn off 693 | */ 694 | /**************************************************************************/ 695 | void Adafruit_LSM6DS::enablePedometer(bool enable) { 696 | // enable or disable step counter 697 | Adafruit_BusIO_Register tapcfg = Adafruit_BusIO_Register( 698 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_TAP_CFG); 699 | Adafruit_BusIO_RegisterBits pedo_en = 700 | Adafruit_BusIO_RegisterBits(&tapcfg, 1, 6); 701 | pedo_en.write(enable); 702 | 703 | // enable or disable functionality 704 | Adafruit_BusIO_Register ctrl10 = Adafruit_BusIO_Register( 705 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_CTRL10_C); 706 | Adafruit_BusIO_RegisterBits func_en = 707 | Adafruit_BusIO_RegisterBits(&ctrl10, 1, 2); 708 | func_en.write(enable); 709 | 710 | resetPedometer(); 711 | } 712 | 713 | /**************************************************************************/ 714 | /*! 715 | @brief Enables and disables the wakeup function 716 | @param enable True to turn on the wakeup function, false to turn off 717 | @param duration How many > threshold readings to generate a wakeup 718 | @param thresh The threshold (sensitivity) 719 | */ 720 | /**************************************************************************/ 721 | void Adafruit_LSM6DS::enableWakeup(bool enable, uint8_t duration, 722 | uint8_t thresh) { 723 | // enable or disable functionality 724 | Adafruit_BusIO_Register tapcfg = Adafruit_BusIO_Register( 725 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_TAP_CFG); 726 | Adafruit_BusIO_RegisterBits slope_en = 727 | Adafruit_BusIO_RegisterBits(&tapcfg, 1, 4); 728 | Adafruit_BusIO_RegisterBits timer_en = 729 | Adafruit_BusIO_RegisterBits(&tapcfg, 1, 7); 730 | slope_en.write(enable); 731 | timer_en.write(enable); 732 | if (enable) { 733 | Adafruit_BusIO_Register wake_dur = Adafruit_BusIO_Register( 734 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_WAKEUP_DUR); 735 | Adafruit_BusIO_RegisterBits durbits = 736 | Adafruit_BusIO_RegisterBits(&wake_dur, 2, 5); 737 | durbits.write(duration); 738 | 739 | Adafruit_BusIO_Register wake_ths = Adafruit_BusIO_Register( 740 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_WAKEUP_THS); 741 | Adafruit_BusIO_RegisterBits thsbits = 742 | Adafruit_BusIO_RegisterBits(&wake_ths, 6, 0); 743 | thsbits.write(thresh); 744 | } 745 | } 746 | 747 | /**************************************************************************/ 748 | /*! 749 | @brief Checks interrupt register to see if we have a wake signal 750 | @returns True if wake event bit is set in WAKEUP_SRC (cleared on read) 751 | */ 752 | /**************************************************************************/ 753 | bool Adafruit_LSM6DS::awake(void) { 754 | Adafruit_BusIO_Register wakesrc = Adafruit_BusIO_Register( 755 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_WAKEUP_SRC); 756 | Adafruit_BusIO_RegisterBits wake_evt = 757 | Adafruit_BusIO_RegisterBits(&wakesrc, 1, 3); 758 | return wake_evt.read(); 759 | } 760 | 761 | /**************************************************************************/ 762 | /*! 763 | @brief Simple shake detection. Must call enableWakeup() first. 764 | @returns True if shake (wake) detected, otherwise false. 765 | */ 766 | /**************************************************************************/ 767 | bool Adafruit_LSM6DS::shake(void) { 768 | Adafruit_BusIO_Register tapcfg = Adafruit_BusIO_Register( 769 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_TAP_CFG); 770 | Adafruit_BusIO_RegisterBits slope_en = 771 | Adafruit_BusIO_RegisterBits(&tapcfg, 1, 4); 772 | Adafruit_BusIO_RegisterBits timer_en = 773 | Adafruit_BusIO_RegisterBits(&tapcfg, 1, 7); 774 | // only check if enabled 775 | if (slope_en.read() && timer_en.read()) { 776 | return awake(); 777 | } 778 | return false; 779 | } 780 | 781 | /**************************************************************************/ 782 | /*! 783 | @brief Reset the pedometer count 784 | */ 785 | /**************************************************************************/ 786 | void Adafruit_LSM6DS::resetPedometer(void) { 787 | // reset bit to clear counter 788 | Adafruit_BusIO_Register ctrl10 = Adafruit_BusIO_Register( 789 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_CTRL10_C); 790 | Adafruit_BusIO_RegisterBits ped_rst = 791 | Adafruit_BusIO_RegisterBits(&ctrl10, 1, 1); 792 | ped_rst.write(true); 793 | } 794 | 795 | /**************************************************************************/ 796 | /*! 797 | @brief Read the 16-bit pedometer count 798 | @returns The value from the step counter 799 | */ 800 | /**************************************************************************/ 801 | uint16_t Adafruit_LSM6DS::readPedometer(void) { 802 | Adafruit_BusIO_Register steps_reg = Adafruit_BusIO_Register( 803 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_STEPCOUNTER, 2); 804 | return steps_reg.read(); 805 | } 806 | 807 | /**************************************************************************/ 808 | /*! 809 | @brief Gets the accelerometer data rate. 810 | @returns The data rate in float 811 | */ 812 | float Adafruit_LSM6DS::accelerationSampleRate(void) { 813 | return _data_rate_arr[this->getAccelDataRate()]; 814 | } 815 | 816 | /**************************************************************************/ 817 | /*! 818 | @brief Check for available data from accelerometer 819 | @returns 1 if available, 0 if not 820 | */ 821 | int Adafruit_LSM6DS::accelerationAvailable(void) { 822 | return (this->status() & 0x01) ? 1 : 0; 823 | } 824 | 825 | /**************************************************************************/ 826 | /*! 827 | @brief Read accelerometer data 828 | @param x reference to x axis 829 | @param y reference to y axis 830 | @param z reference to z axis 831 | @returns 1 if success, 0 if not 832 | */ 833 | int Adafruit_LSM6DS::readAcceleration(float &x, float &y, float &z) { 834 | int16_t data[3]; 835 | 836 | Adafruit_BusIO_Register accel_data = Adafruit_BusIO_Register( 837 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_OUTX_L_A, 6); 838 | 839 | if (!accel_data.read((uint8_t *)data, sizeof(data))) { 840 | x = y = z = NAN; 841 | return 0; 842 | } 843 | 844 | // scale to range of -4 – 4 845 | x = data[0] * 4.0 / 32768.0; 846 | y = data[1] * 4.0 / 32768.0; 847 | z = data[2] * 4.0 / 32768.0; 848 | 849 | return 1; 850 | } 851 | 852 | /**************************************************************************/ 853 | /*! 854 | @brief Get the gyroscope data rate. 855 | @returns The data rate in float 856 | */ 857 | float Adafruit_LSM6DS::gyroscopeSampleRate(void) { 858 | return _data_rate_arr[this->getGyroDataRate()]; 859 | } 860 | 861 | /**************************************************************************/ 862 | /*! 863 | @brief Check for available data from gyroscope 864 | @returns 1 if available, 0 if not 865 | */ 866 | int Adafruit_LSM6DS::gyroscopeAvailable(void) { 867 | return (this->status() & 0x02) ? 1 : 0; 868 | } 869 | 870 | /**************************************************************************/ 871 | /*! 872 | @brief Read gyroscope data 873 | @param x reference to x axis 874 | @param y reference to y axis 875 | @param z reference to z axis 876 | @returns 1 if success, 0 if not 877 | */ 878 | int Adafruit_LSM6DS::readGyroscope(float &x, float &y, float &z) { 879 | int16_t data[3]; 880 | 881 | Adafruit_BusIO_Register gyro_data = Adafruit_BusIO_Register( 882 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_OUTX_L_G, 6); 883 | 884 | if (!gyro_data.read((uint8_t *)data, sizeof(data))) { 885 | x = y = z = NAN; 886 | return 0; 887 | } 888 | 889 | // scale to range of -2000 – 2000 890 | x = data[0] * 2000.0 / 32768.0; 891 | y = data[1] * 2000.0 / 32768.0; 892 | z = data[2] * 2000.0 / 32768.0; 893 | 894 | return 1; 895 | } 896 | -------------------------------------------------------------------------------- /Adafruit_LSM6DS.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file Adafruit_LSM6DS.h 3 | * 4 | * I2C Driver base for Adafruit LSM6DSxx 6-DoF Accelerometer and Gyroscope 5 | * library 6 | * 7 | * Adafruit invests time and resources providing this open source code, 8 | * please support Adafruit and open-source hardware by purchasing products 9 | *from Adafruit! 10 | * 11 | * BSD license (see license.txt) 12 | */ 13 | 14 | #ifndef _ADAFRUIT_LSM6DS_H 15 | #define _ADAFRUIT_LSM6DS_H 16 | 17 | #include "Arduino.h" 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #define LSM6DS_I2CADDR_DEFAULT 0x6A ///< LSM6DS default i2c address 24 | 25 | #define LSM6DS_FUNC_CFG_ACCESS 0x1 ///< Enable embedded functions register 26 | #define LSM6DS_INT1_CTRL 0x0D ///< Interrupt control for INT 1 27 | #define LSM6DS_INT2_CTRL 0x0E ///< Interrupt control for INT 2 28 | #define LSM6DS_WHOAMI 0x0F ///< Chip ID register 29 | #define LSM6DS_CTRL1_XL 0x10 ///< Main accelerometer config register 30 | #define LSM6DS_CTRL2_G 0x11 ///< Main gyro config register 31 | #define LSM6DS_CTRL3_C 0x12 ///< Main configuration register 32 | #define LSM6DS_CTRL8_XL 0x17 ///< High and low pass for accel 33 | #define LSM6DS_CTRL10_C 0x19 ///< Main configuration register 34 | #define LSM6DS_WAKEUP_SRC 0x1B ///< Why we woke up 35 | #define LSM6DS_STATUS_REG 0X1E ///< Status register 36 | #define LSM6DS_OUT_TEMP_L 0x20 ///< First data register (temperature low) 37 | #define LSM6DS_OUTX_L_G 0x22 ///< First gyro data register 38 | #define LSM6DS_OUTX_L_A 0x28 ///< First accel data register 39 | #define LSM6DS_STEPCOUNTER 0x4B ///< 16-bit step counter 40 | #define LSM6DS_TAP_CFG 0x58 ///< Tap/pedometer configuration 41 | #define LSM6DS_WAKEUP_THS \ 42 | 0x5B ///< Single and double-tap function threshold register 43 | #define LSM6DS_WAKEUP_DUR \ 44 | 0x5C ///< Free-fall, wakeup, timestamp and sleep mode duration 45 | #define LSM6DS_MD1_CFG 0x5E ///< Functions routing on INT1 register 46 | 47 | /** The accelerometer data rate */ 48 | typedef enum data_rate { 49 | LSM6DS_RATE_SHUTDOWN, 50 | LSM6DS_RATE_12_5_HZ, 51 | LSM6DS_RATE_26_HZ, 52 | LSM6DS_RATE_52_HZ, 53 | LSM6DS_RATE_104_HZ, 54 | LSM6DS_RATE_208_HZ, 55 | LSM6DS_RATE_416_HZ, 56 | LSM6DS_RATE_833_HZ, 57 | LSM6DS_RATE_1_66K_HZ, 58 | LSM6DS_RATE_3_33K_HZ, 59 | LSM6DS_RATE_6_66K_HZ, 60 | } lsm6ds_data_rate_t; 61 | 62 | /** The accelerometer data range */ 63 | typedef enum accel_range { 64 | LSM6DS_ACCEL_RANGE_2_G, 65 | LSM6DS_ACCEL_RANGE_16_G, 66 | LSM6DS_ACCEL_RANGE_4_G, 67 | LSM6DS_ACCEL_RANGE_8_G 68 | } lsm6ds_accel_range_t; 69 | 70 | /** The gyro data range */ 71 | typedef enum gyro_range { 72 | LSM6DS_GYRO_RANGE_125_DPS = 0b0010, 73 | LSM6DS_GYRO_RANGE_250_DPS = 0b0000, 74 | LSM6DS_GYRO_RANGE_500_DPS = 0b0100, 75 | LSM6DS_GYRO_RANGE_1000_DPS = 0b1000, 76 | LSM6DS_GYRO_RANGE_2000_DPS = 0b1100, 77 | ISM330DHCX_GYRO_RANGE_4000_DPS = 0b0001 78 | } lsm6ds_gyro_range_t; 79 | 80 | /** The high pass filter bandwidth */ 81 | typedef enum hpf_range { 82 | LSM6DS_HPF_ODR_DIV_50 = 0, 83 | LSM6DS_HPF_ODR_DIV_100 = 1, 84 | LSM6DS_HPF_ODR_DIV_9 = 2, 85 | LSM6DS_HPF_ODR_DIV_400 = 3, 86 | } lsm6ds_hp_filter_t; 87 | 88 | class Adafruit_LSM6DS; 89 | 90 | /** Adafruit Unified Sensor interface for temperature component of LSM6DS */ 91 | class Adafruit_LSM6DS_Temp : public Adafruit_Sensor { 92 | public: 93 | /** @brief Create an Adafruit_Sensor compatible object for the temp sensor 94 | @param parent A pointer to the LSM6DS class */ 95 | Adafruit_LSM6DS_Temp(Adafruit_LSM6DS *parent) { _theLSM6DS = parent; } 96 | bool getEvent(sensors_event_t *); 97 | void getSensor(sensor_t *); 98 | 99 | private: 100 | int _sensorID = 0x6D0; 101 | Adafruit_LSM6DS *_theLSM6DS = NULL; 102 | }; 103 | 104 | /** Adafruit Unified Sensor interface for accelerometer component of LSM6DS */ 105 | class Adafruit_LSM6DS_Accelerometer : public Adafruit_Sensor { 106 | public: 107 | /** @brief Create an Adafruit_Sensor compatible object for the accelerometer 108 | sensor 109 | @param parent A pointer to the LSM6DS class */ 110 | Adafruit_LSM6DS_Accelerometer(Adafruit_LSM6DS *parent) { 111 | _theLSM6DS = parent; 112 | } 113 | bool getEvent(sensors_event_t *); 114 | void getSensor(sensor_t *); 115 | 116 | private: 117 | int _sensorID = 0x6D1; 118 | Adafruit_LSM6DS *_theLSM6DS = NULL; 119 | }; 120 | 121 | /** Adafruit Unified Sensor interface for gyro component of LSM6DS */ 122 | class Adafruit_LSM6DS_Gyro : public Adafruit_Sensor { 123 | public: 124 | /** @brief Create an Adafruit_Sensor compatible object for the gyro sensor 125 | @param parent A pointer to the LSM6DS class */ 126 | Adafruit_LSM6DS_Gyro(Adafruit_LSM6DS *parent) { _theLSM6DS = parent; } 127 | bool getEvent(sensors_event_t *); 128 | void getSensor(sensor_t *); 129 | 130 | private: 131 | int _sensorID = 0x6D2; 132 | Adafruit_LSM6DS *_theLSM6DS = NULL; 133 | }; 134 | 135 | /*! 136 | * @brief Base class for use with LSM6DS series acclerometer gyro sensors 137 | * from STMicroelectronics. DO NOT USE DIRECTLY. Specific sensor variants should 138 | * be subclassed as needed. 139 | */ 140 | class Adafruit_LSM6DS { 141 | public: 142 | Adafruit_LSM6DS(); 143 | virtual ~Adafruit_LSM6DS(); 144 | 145 | bool begin_I2C(uint8_t i2c_addr = LSM6DS_I2CADDR_DEFAULT, 146 | TwoWire *wire = &Wire, int32_t sensorID = 0); 147 | 148 | bool begin_SPI(uint8_t cs_pin, SPIClass *theSPI = &SPI, int32_t sensorID = 0, 149 | uint32_t frequency = 1000000); 150 | bool begin_SPI(int8_t cs_pin, int8_t sck_pin, int8_t miso_pin, 151 | int8_t mosi_pin, int32_t sensorID = 0, 152 | uint32_t frequency = 1000000); 153 | 154 | bool getEvent(sensors_event_t *accel, sensors_event_t *gyro, 155 | sensors_event_t *temp); 156 | 157 | lsm6ds_data_rate_t getAccelDataRate(void); 158 | void setAccelDataRate(lsm6ds_data_rate_t data_rate); 159 | 160 | lsm6ds_accel_range_t getAccelRange(void); 161 | void setAccelRange(lsm6ds_accel_range_t new_range); 162 | 163 | lsm6ds_data_rate_t getGyroDataRate(void); 164 | void setGyroDataRate(lsm6ds_data_rate_t data_rate); 165 | 166 | lsm6ds_gyro_range_t getGyroRange(void); 167 | void setGyroRange(lsm6ds_gyro_range_t new_range); 168 | 169 | void reset(void); 170 | void configIntOutputs(bool active_low, bool open_drain); 171 | void configInt1(bool drdy_temp, bool drdy_g, bool drdy_xl, 172 | bool step_detect = false, bool wakeup = false); 173 | void configInt2(bool drdy_temp, bool drdy_g, bool drdy_xl); 174 | void highPassFilter(bool enabled, lsm6ds_hp_filter_t filter); 175 | 176 | void enableWakeup(bool enable, uint8_t duration = 0, uint8_t thresh = 20); 177 | bool awake(void); 178 | bool shake(void); 179 | 180 | void enablePedometer(bool enable); 181 | void resetPedometer(void); 182 | uint16_t readPedometer(void); 183 | 184 | // Arduino compatible API 185 | int readAcceleration(float &x, float &y, float &z); 186 | float accelerationSampleRate(void); 187 | int accelerationAvailable(void); 188 | 189 | int readGyroscope(float &x, float &y, float &z); 190 | float gyroscopeSampleRate(void); 191 | int gyroscopeAvailable(void); 192 | 193 | int16_t rawAccX, ///< Last reading's raw accelerometer X axis 194 | rawAccY, ///< Last reading's raw accelerometer Y axis 195 | rawAccZ, ///< Last reading's raw accelerometer Z axis 196 | rawTemp, ///< Last reading's raw temperature reading 197 | rawGyroX, ///< Last reading's raw gyro X axis 198 | rawGyroY, ///< Last reading's raw gyro Y axis 199 | rawGyroZ; ///< Last reading's raw gyro Z axis 200 | 201 | float temperature, ///< Last reading's temperature (C) 202 | accX, ///< Last reading's accelerometer X axis m/s^2 203 | accY, ///< Last reading's accelerometer Y axis m/s^2 204 | accZ, ///< Last reading's accelerometer Z axis m/s^2 205 | gyroX, ///< Last reading's gyro X axis in rad/s 206 | gyroY, ///< Last reading's gyro Y axis in rad/s 207 | gyroZ; ///< Last reading's gyro Z axis in rad/s 208 | 209 | Adafruit_Sensor *getTemperatureSensor(void); 210 | Adafruit_Sensor *getAccelerometerSensor(void); 211 | Adafruit_Sensor *getGyroSensor(void); 212 | 213 | protected: 214 | uint8_t chipID(void); 215 | uint8_t status(void); 216 | virtual void _read(void); 217 | virtual bool _init(int32_t sensor_id); 218 | 219 | uint16_t _sensorid_accel, ///< ID number for accelerometer 220 | _sensorid_gyro, ///< ID number for gyro 221 | _sensorid_temp; ///< ID number for temperature 222 | 223 | Adafruit_I2CDevice *i2c_dev = NULL; ///< Pointer to I2C bus interface 224 | Adafruit_SPIDevice *spi_dev = NULL; ///< Pointer to SPI bus interface 225 | 226 | float temperature_sensitivity = 227 | 256.0; ///< Temp sensor sensitivity in LSB/degC 228 | Adafruit_LSM6DS_Temp *temp_sensor = NULL; ///< Temp sensor data object 229 | Adafruit_LSM6DS_Accelerometer *accel_sensor = 230 | NULL; ///< Accelerometer data object 231 | Adafruit_LSM6DS_Gyro *gyro_sensor = NULL; ///< Gyro data object 232 | 233 | //! buffer for the accelerometer range 234 | lsm6ds_accel_range_t accelRangeBuffered = LSM6DS_ACCEL_RANGE_2_G; 235 | //! buffer for the gyroscope range 236 | lsm6ds_gyro_range_t gyroRangeBuffered = LSM6DS_GYRO_RANGE_250_DPS; 237 | 238 | private: 239 | friend class Adafruit_LSM6DS_Temp; ///< Gives access to private members to 240 | ///< Temp data object 241 | friend class Adafruit_LSM6DS_Accelerometer; ///< Gives access to private 242 | ///< members to Accelerometer data 243 | ///< object 244 | friend class Adafruit_LSM6DS_Gyro; ///< Gives access to private members to 245 | ///< Gyro data object 246 | 247 | void fillTempEvent(sensors_event_t *temp, uint32_t timestamp); 248 | void fillAccelEvent(sensors_event_t *accel, uint32_t timestamp); 249 | void fillGyroEvent(sensors_event_t *gyro, uint32_t timestamp); 250 | }; 251 | 252 | #endif 253 | -------------------------------------------------------------------------------- /Adafruit_LSM6DS3.cpp: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * @file Adafruit_LSM6DS3.cpp Adafruit LSM6DS3 6-DoF Accelerometer 4 | * and Gyroscope library 5 | * 6 | * Bryan Siepert for Adafruit Industries 7 | * BSD (see license.txt) 8 | */ 9 | 10 | #include "Arduino.h" 11 | #include 12 | 13 | #include "Adafruit_LSM6DS3.h" 14 | 15 | /*! 16 | * @brief Instantiates a new LSM6DS3 class 17 | */ 18 | Adafruit_LSM6DS3::Adafruit_LSM6DS3(void) {} 19 | 20 | bool Adafruit_LSM6DS3::_init(int32_t sensor_id) { 21 | // make sure we're talking to the right chip 22 | if (chipID() != LSM6DS3_CHIP_ID) { 23 | return false; 24 | } 25 | _sensorid_accel = sensor_id; 26 | _sensorid_gyro = sensor_id + 1; 27 | _sensorid_temp = sensor_id + 2; 28 | 29 | temperature_sensitivity = 16.0; 30 | 31 | reset(); 32 | 33 | // call base class _init() 34 | Adafruit_LSM6DS::_init(sensor_id); 35 | 36 | return true; 37 | } 38 | 39 | /**************************************************************************/ 40 | /*! 41 | @brief Enables and disables the I2C master bus pulllups. 42 | @param enable_pullups true to enable the I2C pullups, false to disable. 43 | */ 44 | void Adafruit_LSM6DS3::enableI2CMasterPullups(bool enable_pullups) { 45 | Adafruit_BusIO_Register master_config = Adafruit_BusIO_Register( 46 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS3_MASTER_CONFIG); 47 | Adafruit_BusIO_RegisterBits i2c_master_pu_en = 48 | Adafruit_BusIO_RegisterBits(&master_config, 1, 3); 49 | 50 | i2c_master_pu_en.write(enable_pullups); 51 | } 52 | -------------------------------------------------------------------------------- /Adafruit_LSM6DS3.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file Adafruit_LSM6DS3.h 3 | * 4 | * I2C Driver for the Adafruit LSM6DS3 6-DoF Accelerometer and Gyroscope 5 | *library 6 | * 7 | * This is a library for the Adafruit LSM6DS3 breakout: 8 | * https://www.adafruit.com/ 9 | * 10 | * Adafruit invests time and resources providing this open source code, 11 | * please support Adafruit and open-source hardware by purchasing products from 12 | * Adafruit! 13 | * 14 | * 15 | * BSD license (see license.txt) 16 | */ 17 | 18 | #ifndef _ADAFRUIT_LSM6DS3_H 19 | #define _ADAFRUIT_LSM6DS3_H 20 | 21 | #include "Adafruit_LSM6DS.h" 22 | 23 | #define LSM6DS3_CHIP_ID 0x69 ///< LSM6DS3 default device id from WHOAMI 24 | 25 | #define LSM6DS3_MASTER_CONFIG 0x1A ///< I2C Master config 26 | 27 | /*! 28 | * @brief Class that stores state and functions for interacting with 29 | * the LSM6DS3 30 | */ 31 | class Adafruit_LSM6DS3 : public Adafruit_LSM6DS { 32 | public: 33 | Adafruit_LSM6DS3(); 34 | ~Adafruit_LSM6DS3(){}; 35 | 36 | void enableI2CMasterPullups(bool enable_pullups); 37 | 38 | private: 39 | bool _init(int32_t sensor_id); 40 | }; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /Adafruit_LSM6DS33.cpp: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * @file Adafruit_LSM6DS33.cpp Adafruit LSM6DS33 6-DoF Accelerometer 4 | * and Gyroscope library 5 | * 6 | * Bryan Siepert for Adafruit Industries 7 | * BSD (see license.txt) 8 | */ 9 | 10 | #include "Arduino.h" 11 | #include 12 | 13 | #include "Adafruit_LSM6DS33.h" 14 | 15 | /*! 16 | * @brief Instantiates a new LSM6DS33 class 17 | */ 18 | Adafruit_LSM6DS33::Adafruit_LSM6DS33(void) {} 19 | 20 | bool Adafruit_LSM6DS33::_init(int32_t sensor_id) { 21 | // make sure we're talking to the right chip 22 | if (chipID() != LSM6DS33_CHIP_ID) { 23 | return false; 24 | } 25 | _sensorid_accel = sensor_id; 26 | _sensorid_gyro = sensor_id + 1; 27 | _sensorid_temp = sensor_id + 2; 28 | 29 | temperature_sensitivity = 16.0; 30 | 31 | reset(); 32 | if (chipID() != LSM6DS33_CHIP_ID) { 33 | return false; 34 | } 35 | 36 | // call base class _init() 37 | Adafruit_LSM6DS::_init(sensor_id); 38 | 39 | return true; 40 | } 41 | -------------------------------------------------------------------------------- /Adafruit_LSM6DS33.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file Adafruit_LSM6DS33.h 3 | * 4 | * I2C Driver for the Adafruit LSM6DS33 6-DoF Accelerometer and Gyroscope 5 | *library 6 | * 7 | * This is a library for the Adafruit LSM6DS33 breakout: 8 | * https://www.adafruit.com/products/4480 9 | * 10 | * Adafruit invests time and resources providing this open source code, 11 | * please support Adafruit and open-source hardware by purchasing products from 12 | * Adafruit! 13 | * 14 | * 15 | * BSD license (see license.txt) 16 | */ 17 | 18 | #ifndef _ADAFRUIT_LSM6DS33_H 19 | #define _ADAFRUIT_LSM6DS33_H 20 | 21 | #include "Adafruit_LSM6DS.h" 22 | 23 | #define LSM6DS33_CHIP_ID 0x69 ///< LSM6DS33 default device id from WHOAMI 24 | 25 | /*! 26 | * @brief Class that stores state and functions for interacting with 27 | * the LSM6DS33 I2C Digital Potentiometer 28 | */ 29 | class Adafruit_LSM6DS33 : public Adafruit_LSM6DS { 30 | public: 31 | Adafruit_LSM6DS33(); 32 | ~Adafruit_LSM6DS33(){}; 33 | 34 | private: 35 | bool _init(int32_t sensor_id); 36 | }; 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /Adafruit_LSM6DS3TRC.cpp: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * @file Adafruit_LSM6DS3TRC.cpp Adafruit LSM6DS3TR-C 6-DoF Accelerometer 4 | * and Gyroscope library 5 | * 6 | * Written by ladyada for Adafruit Industries 7 | * BSD (see license.txt) 8 | */ 9 | 10 | #include "Arduino.h" 11 | #include 12 | 13 | #include "Adafruit_LSM6DS3TRC.h" 14 | 15 | /*! 16 | * @brief Instantiates a new LSM6DS3TRC class 17 | */ 18 | Adafruit_LSM6DS3TRC::Adafruit_LSM6DS3TRC(void) {} 19 | 20 | bool Adafruit_LSM6DS3TRC::_init(int32_t sensor_id) { 21 | // make sure we're talking to the right chip 22 | if (chipID() != LSM6DS3TRC_CHIP_ID) { 23 | return false; 24 | } 25 | _sensorid_accel = sensor_id; 26 | _sensorid_gyro = sensor_id + 1; 27 | _sensorid_temp = sensor_id + 2; 28 | 29 | reset(); 30 | 31 | // call base class _init() 32 | Adafruit_LSM6DS::_init(sensor_id); 33 | 34 | // set the Block Data Update bit 35 | // this prevents MSB/LSB data registers from being updated until both are read 36 | Adafruit_BusIO_Register ctrl3 = Adafruit_BusIO_Register( 37 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_CTRL3_C); 38 | Adafruit_BusIO_RegisterBits bdu = Adafruit_BusIO_RegisterBits(&ctrl3, 1, 6); 39 | bdu.write(1); 40 | 41 | return true; 42 | } 43 | 44 | /**************************************************************************/ 45 | /*! 46 | @brief Enables and disables the pedometer function 47 | @param enable True to turn on the pedometer function, false to turn off 48 | */ 49 | /**************************************************************************/ 50 | void Adafruit_LSM6DS3TRC::enablePedometer(bool enable) { 51 | // enable or disable functionality 52 | Adafruit_BusIO_Register ctrl10 = Adafruit_BusIO_Register( 53 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_CTRL10_C); 54 | 55 | Adafruit_BusIO_RegisterBits ped_en = 56 | Adafruit_BusIO_RegisterBits(&ctrl10, 1, 4); 57 | ped_en.write(enable); 58 | 59 | Adafruit_BusIO_RegisterBits func_en = 60 | Adafruit_BusIO_RegisterBits(&ctrl10, 1, 2); 61 | func_en.write(enable); 62 | 63 | resetPedometer(); 64 | } 65 | 66 | /**************************************************************************/ 67 | /*! 68 | @brief Enables and disables the I2C master bus pulllups. 69 | @param enable_pullups true to enable the I2C pullups, false to disable. 70 | */ 71 | void Adafruit_LSM6DS3TRC::enableI2CMasterPullups(bool enable_pullups) { 72 | Adafruit_BusIO_Register master_config = Adafruit_BusIO_Register( 73 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS3TRC_MASTER_CONFIG); 74 | Adafruit_BusIO_RegisterBits i2c_master_pu_en = 75 | Adafruit_BusIO_RegisterBits(&master_config, 1, 3); 76 | 77 | i2c_master_pu_en.write(enable_pullups); 78 | } 79 | -------------------------------------------------------------------------------- /Adafruit_LSM6DS3TRC.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file Adafruit_LSM6DSL.h 3 | * 4 | * I2C Driver for the Adafruit LSM6DSL 6-DoF Accelerometer and Gyroscope 5 | *library 6 | * 7 | * This is a library for the Adafruit LSM6DSL breakout: 8 | * https://www.adafruit.com/ 9 | * 10 | * Adafruit invests time and resources providing this open source code, 11 | * please support Adafruit and open-source hardware by purchasing products from 12 | * Adafruit! 13 | * 14 | * 15 | * BSD license (see license.txt) 16 | */ 17 | 18 | #ifndef _ADAFRUIT_LSM6DS3TRC_H 19 | #define _ADAFRUIT_LSM6DS3TRC_H 20 | 21 | #include "Adafruit_LSM6DS.h" 22 | 23 | #define LSM6DS3TRC_CHIP_ID 0x6A ///< LSM6DSL default device id from WHOAMI 24 | 25 | #define LSM6DS3TRC_MASTER_CONFIG 0x1A ///< I2C Master config 26 | 27 | /*! 28 | * @brief Class that stores state and functions for interacting with 29 | * the LSM6DS3TRC 30 | */ 31 | class Adafruit_LSM6DS3TRC : public Adafruit_LSM6DS { 32 | public: 33 | Adafruit_LSM6DS3TRC(); 34 | ~Adafruit_LSM6DS3TRC(){}; 35 | 36 | void enableI2CMasterPullups(bool enable_pullups); 37 | void enablePedometer(bool enable); 38 | 39 | private: 40 | bool _init(int32_t sensor_id); 41 | }; 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /Adafruit_LSM6DSL.cpp: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * @file Adafruit_LSM6DSL.cpp Adafruit LSM6DSL 6-DoF Accelerometer 4 | * and Gyroscope library 5 | * 6 | * Adapted by Eugene Anikin for Adafruit Industries 7 | * BSD (see license.txt) 8 | */ 9 | 10 | #include "Arduino.h" 11 | #include 12 | 13 | #include "Adafruit_LSM6DSL.h" 14 | 15 | /*! 16 | * @brief Instantiates a new LSM6DSL class 17 | */ 18 | Adafruit_LSM6DSL::Adafruit_LSM6DSL(void) {} 19 | 20 | bool Adafruit_LSM6DSL::_init(int32_t sensor_id) { 21 | // make sure we're talking to the right chip 22 | if (chipID() != LSM6DSL_CHIP_ID) { 23 | return false; 24 | } 25 | _sensorid_accel = sensor_id; 26 | _sensorid_gyro = sensor_id + 1; 27 | _sensorid_temp = sensor_id + 2; 28 | 29 | reset(); 30 | 31 | // call base class _init() 32 | Adafruit_LSM6DS::_init(sensor_id); 33 | 34 | return true; 35 | } 36 | 37 | /**************************************************************************/ 38 | /*! 39 | @brief Enables and disables the I2C master bus pulllups. 40 | @param enable_pullups true to enable the I2C pullups, false to disable. 41 | */ 42 | void Adafruit_LSM6DSL::enableI2CMasterPullups(bool enable_pullups) { 43 | Adafruit_BusIO_Register master_config = Adafruit_BusIO_Register( 44 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DSL_MASTER_CONFIG); 45 | Adafruit_BusIO_RegisterBits i2c_master_pu_en = 46 | Adafruit_BusIO_RegisterBits(&master_config, 1, 3); 47 | 48 | i2c_master_pu_en.write(enable_pullups); 49 | } 50 | -------------------------------------------------------------------------------- /Adafruit_LSM6DSL.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file Adafruit_LSM6DSL.h 3 | * 4 | * I2C Driver for the Adafruit LSM6DSL 6-DoF Accelerometer and Gyroscope 5 | *library 6 | * 7 | * This is a library for the Adafruit LSM6DSL breakout: 8 | * https://www.adafruit.com/ 9 | * 10 | * Adafruit invests time and resources providing this open source code, 11 | * please support Adafruit and open-source hardware by purchasing products from 12 | * Adafruit! 13 | * 14 | * 15 | * BSD license (see license.txt) 16 | */ 17 | 18 | #ifndef _ADAFRUIT_LSM6DSL_H 19 | #define _ADAFRUIT_LSM6DSL_H 20 | 21 | #include "Adafruit_LSM6DS.h" 22 | 23 | #define LSM6DSL_CHIP_ID 0x6A ///< LSM6DSL default device id from WHOAMI 24 | 25 | #define LSM6DSL_MASTER_CONFIG 0x1A ///< I2C Master config 26 | 27 | /*! 28 | * @brief Class that stores state and functions for interacting with 29 | * the LSM6DSL 30 | */ 31 | class Adafruit_LSM6DSL : public Adafruit_LSM6DS { 32 | public: 33 | Adafruit_LSM6DSL(); 34 | ~Adafruit_LSM6DSL(){}; 35 | 36 | void enableI2CMasterPullups(bool enable_pullups); 37 | 38 | private: 39 | bool _init(int32_t sensor_id); 40 | }; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /Adafruit_LSM6DSO32.cpp: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * @file Adafruit_LSM6DSO32.cpp 4 | * Adafruit LSM6DSO32 6-DoF Accelerometer and Gyroscope library 5 | * 6 | * Bryan Siepert for Adafruit Industries 7 | * BSD (see license.txt) 8 | */ 9 | 10 | #include "Arduino.h" 11 | #include 12 | 13 | #include "Adafruit_LSM6DSO32.h" 14 | #include "Adafruit_LSM6DSOX.h" 15 | 16 | /*! 17 | * @brief Instantiates a new LSM6DSO32 class 18 | */ 19 | Adafruit_LSM6DSO32::Adafruit_LSM6DSO32(void) {} 20 | 21 | bool Adafruit_LSM6DSO32::_init(int32_t sensor_id) { 22 | Adafruit_BusIO_Register chip_id = Adafruit_BusIO_Register( 23 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_WHOAMI); 24 | 25 | // make sure we're talking to the right chip 26 | if (chip_id.read() != LSM6DSO32_CHIP_ID) { 27 | return false; 28 | } 29 | _sensorid_accel = sensor_id; 30 | _sensorid_gyro = sensor_id + 1; 31 | _sensorid_temp = sensor_id + 2; 32 | 33 | reset(); 34 | 35 | // set the Block Data Update bit 36 | // this prevents MSB/LSB data registers from being updated until both are read 37 | Adafruit_BusIO_Register ctrl3 = Adafruit_BusIO_Register( 38 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DSOX_CTRL3_C); 39 | Adafruit_BusIO_RegisterBits bdu = Adafruit_BusIO_RegisterBits(&ctrl3, 1, 6); 40 | bdu.write(true); 41 | 42 | // Disable I3C 43 | Adafruit_BusIO_Register ctrl_9 = Adafruit_BusIO_Register( 44 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DSOX_CTRL9_XL); 45 | Adafruit_BusIO_RegisterBits i3c_disable_bit = 46 | Adafruit_BusIO_RegisterBits(&ctrl_9, 1, 1); 47 | 48 | i3c_disable_bit.write(true); 49 | 50 | // call base class _init() 51 | Adafruit_LSM6DS::_init(sensor_id); 52 | 53 | return true; 54 | } 55 | 56 | /******************* Adafruit_Sensor functions *****************/ 57 | /*! 58 | * @brief Updates the measurement data for all sensors simultaneously 59 | */ 60 | /**************************************************************************/ 61 | // works for now, should refactor 62 | void Adafruit_LSM6DSO32::_read(void) { 63 | // get raw readings 64 | Adafruit_BusIO_Register data_reg = Adafruit_BusIO_Register( 65 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_OUT_TEMP_L, 14); 66 | 67 | uint8_t buffer[14]; 68 | data_reg.read(buffer, 14); 69 | 70 | rawTemp = buffer[1] << 8 | buffer[0]; 71 | temperature = (rawTemp / 256.0) + 25.0; 72 | 73 | rawGyroX = buffer[3] << 8 | buffer[2]; 74 | rawGyroY = buffer[5] << 8 | buffer[4]; 75 | rawGyroZ = buffer[7] << 8 | buffer[6]; 76 | 77 | rawAccX = buffer[9] << 8 | buffer[8]; 78 | rawAccY = buffer[11] << 8 | buffer[10]; 79 | rawAccZ = buffer[13] << 8 | buffer[12]; 80 | 81 | lsm6ds_gyro_range_t gyro_range = getGyroRange(); 82 | float gyro_scale = 1; // range is in milli-dps per bit! 83 | if (gyro_range == ISM330DHCX_GYRO_RANGE_4000_DPS) 84 | gyro_scale = 140.0; 85 | if (gyro_range == LSM6DS_GYRO_RANGE_2000_DPS) 86 | gyro_scale = 70.0; 87 | if (gyro_range == LSM6DS_GYRO_RANGE_1000_DPS) 88 | gyro_scale = 35.0; 89 | if (gyro_range == LSM6DS_GYRO_RANGE_500_DPS) 90 | gyro_scale = 17.50; 91 | if (gyro_range == LSM6DS_GYRO_RANGE_250_DPS) 92 | gyro_scale = 8.75; 93 | if (gyro_range == LSM6DS_GYRO_RANGE_125_DPS) 94 | gyro_scale = 4.375; 95 | 96 | gyroX = rawGyroX * gyro_scale * SENSORS_DPS_TO_RADS / 1000.0; 97 | gyroY = rawGyroY * gyro_scale * SENSORS_DPS_TO_RADS / 1000.0; 98 | gyroZ = rawGyroZ * gyro_scale * SENSORS_DPS_TO_RADS / 1000.0; 99 | 100 | lsm6dso32_accel_range_t accel_range = getAccelRange(); 101 | float accel_scale = 1; // range is in milli-g per bit! 102 | if (accel_range == LSM6DSO32_ACCEL_RANGE_32_G) 103 | accel_scale = 0.976; 104 | if (accel_range == LSM6DSO32_ACCEL_RANGE_16_G) 105 | accel_scale = 0.488; 106 | if (accel_range == LSM6DSO32_ACCEL_RANGE_8_G) 107 | accel_scale = 0.244; 108 | if (accel_range == LSM6DSO32_ACCEL_RANGE_4_G) 109 | accel_scale = 0.122; 110 | accX = rawAccX * accel_scale * SENSORS_GRAVITY_STANDARD / 1000; 111 | accY = rawAccY * accel_scale * SENSORS_GRAVITY_STANDARD / 1000; 112 | accZ = rawAccZ * accel_scale * SENSORS_GRAVITY_STANDARD / 1000; 113 | } 114 | 115 | /**************************************************************************/ 116 | /*! 117 | @brief Gets the accelerometer measurement range. 118 | @returns The the accelerometer measurement range. 119 | */ 120 | lsm6dso32_accel_range_t Adafruit_LSM6DSO32::getAccelRange(void) { 121 | 122 | Adafruit_BusIO_Register ctrl1 = Adafruit_BusIO_Register( 123 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_CTRL1_XL); 124 | 125 | Adafruit_BusIO_RegisterBits accel_range = 126 | Adafruit_BusIO_RegisterBits(&ctrl1, 2, 2); 127 | 128 | return (lsm6dso32_accel_range_t)accel_range.read(); 129 | } 130 | /**************************************************************************/ 131 | /*! 132 | @brief Sets the accelerometer measurement range. 133 | @param new_range The `lsm6dso32_accel_range_t` range to set. 134 | */ 135 | void Adafruit_LSM6DSO32::setAccelRange(lsm6dso32_accel_range_t new_range) { 136 | 137 | Adafruit_BusIO_Register ctrl1 = Adafruit_BusIO_Register( 138 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_CTRL1_XL); 139 | 140 | Adafruit_BusIO_RegisterBits accel_range = 141 | Adafruit_BusIO_RegisterBits(&ctrl1, 2, 2); 142 | 143 | accel_range.write(new_range); 144 | delay(20); 145 | } 146 | -------------------------------------------------------------------------------- /Adafruit_LSM6DSO32.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file Adafruit_LSM6DSO32.h 3 | * 4 | * I2C Driver for the Adafruit LSM6DSO32 6-DoF Accelerometer and Gyroscope 5 | *library 6 | * 7 | * This is a library for the Adafruit LSM6DSO32 breakout: 8 | * https://www.adafruit.com/products/PID_HERE 9 | * 10 | * Adafruit invests time and resources providing this open source code, 11 | * please support Adafruit and open-source hardware by purchasing products from 12 | * Adafruit! 13 | * 14 | * 15 | * BSD license (see license.txt) 16 | */ 17 | 18 | #ifndef _ADAFRUIT_LSM6DSO32_H 19 | #define _ADAFRUIT_LSM6DSO32_H 20 | 21 | #include "Adafruit_LSM6DS.h" 22 | #include "Adafruit_LSM6DSOX.h" 23 | #define LSM6DSO32_CHIP_ID 0x6C ///< LSM6DSO32 default device id from WHOAMI 24 | 25 | /** The accelerometer data range */ 26 | typedef enum dso32_accel_range { 27 | LSM6DSO32_ACCEL_RANGE_4_G, 28 | LSM6DSO32_ACCEL_RANGE_32_G, 29 | LSM6DSO32_ACCEL_RANGE_8_G, 30 | LSM6DSO32_ACCEL_RANGE_16_G 31 | } lsm6dso32_accel_range_t; 32 | 33 | /*! 34 | * @brief Class that stores state and functions for interacting with 35 | * the LSM6DSO32 I2C Digital Potentiometer 36 | */ 37 | class Adafruit_LSM6DSO32 : public Adafruit_LSM6DSOX { 38 | public: 39 | Adafruit_LSM6DSO32(); 40 | 41 | lsm6dso32_accel_range_t getAccelRange(void); 42 | void setAccelRange(lsm6dso32_accel_range_t new_range); 43 | void _read(void); 44 | 45 | private: 46 | bool _init(int32_t sensor_id); 47 | }; 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /Adafruit_LSM6DSOX.cpp: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * @file Adafruit_LSM6DSOX.cpp 4 | * Adafruit LSM6DSOX 6-DoF Accelerometer and Gyroscope library 5 | * 6 | * Bryan Siepert for Adafruit Industries 7 | * BSD (see license.txt) 8 | */ 9 | 10 | #include "Arduino.h" 11 | #include 12 | 13 | #include "Adafruit_LSM6DSOX.h" 14 | 15 | /*! 16 | * @brief Instantiates a new LSM6DSOX class 17 | */ 18 | Adafruit_LSM6DSOX::Adafruit_LSM6DSOX(void) {} 19 | 20 | bool Adafruit_LSM6DSOX::_init(int32_t sensor_id) { 21 | Adafruit_BusIO_Register chip_id = Adafruit_BusIO_Register( 22 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_WHOAMI); 23 | 24 | // make sure we're talking to the right chip 25 | if (chip_id.read() != LSM6DSOX_CHIP_ID) { 26 | return false; 27 | } 28 | _sensorid_accel = sensor_id; 29 | _sensorid_gyro = sensor_id + 1; 30 | _sensorid_temp = sensor_id + 2; 31 | 32 | reset(); 33 | 34 | // Block Data Update 35 | // this prevents MSB/LSB data registers from being updated until both are read 36 | Adafruit_BusIO_Register ctrl3 = Adafruit_BusIO_Register( 37 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DSOX_CTRL3_C); 38 | Adafruit_BusIO_RegisterBits bdu = Adafruit_BusIO_RegisterBits(&ctrl3, 1, 6); 39 | bdu.write(true); 40 | 41 | // Disable I3C 42 | Adafruit_BusIO_Register ctrl_9 = Adafruit_BusIO_Register( 43 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DSOX_CTRL9_XL); 44 | Adafruit_BusIO_RegisterBits i3c_disable_bit = 45 | Adafruit_BusIO_RegisterBits(&ctrl_9, 1, 1); 46 | 47 | i3c_disable_bit.write(true); 48 | 49 | // call base class _init() 50 | Adafruit_LSM6DS::_init(sensor_id); 51 | 52 | return true; 53 | } 54 | 55 | /**************************************************************************/ 56 | /*! 57 | @brief Disables and enables the SPI master bus pulllups. 58 | @param disable_pullups true to **disable** the I2C pullups, false to enable. 59 | */ 60 | void Adafruit_LSM6DSOX::disableSPIMasterPullups(bool disable_pullups) { 61 | 62 | Adafruit_BusIO_Register pin_config = Adafruit_BusIO_Register( 63 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DSOX_PIN_CTRL); 64 | 65 | Adafruit_BusIO_RegisterBits disable_ois_pu = 66 | Adafruit_BusIO_RegisterBits(&pin_config, 1, 7); 67 | 68 | disable_ois_pu.write(disable_pullups); 69 | } 70 | 71 | /**************************************************************************/ 72 | /*! 73 | @brief Enables and disables the I2C master bus pulllups. 74 | @param enable_pullups true to enable the I2C pullups, false to disable. 75 | */ 76 | void Adafruit_LSM6DSOX::enableI2CMasterPullups(bool enable_pullups) { 77 | 78 | Adafruit_BusIO_Register func_cfg_access = Adafruit_BusIO_Register( 79 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DSOX_FUNC_CFG_ACCESS); 80 | Adafruit_BusIO_RegisterBits master_cfg_enable_bit = 81 | Adafruit_BusIO_RegisterBits(&func_cfg_access, 1, 6); 82 | 83 | Adafruit_BusIO_Register master_config = Adafruit_BusIO_Register( 84 | i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DSOX_MASTER_CONFIG); 85 | Adafruit_BusIO_RegisterBits i2c_master_pu_en = 86 | Adafruit_BusIO_RegisterBits(&master_config, 1, 3); 87 | 88 | master_cfg_enable_bit.write(true); 89 | i2c_master_pu_en.write(enable_pullups); 90 | master_cfg_enable_bit.write(false); 91 | } 92 | -------------------------------------------------------------------------------- /Adafruit_LSM6DSOX.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file Adafruit_LSM6DSOX.h 3 | * 4 | * I2C Driver for the Adafruit LSM6DSOX 6-DoF Accelerometer and Gyroscope 5 | *library 6 | * 7 | * This is a library for the Adafruit LSM6DSOX breakout: 8 | * https://www.adafruit.com/products/PID_HERE 9 | * 10 | * Adafruit invests time and resources providing this open source code, 11 | * please support Adafruit and open-source hardware by purchasing products from 12 | * Adafruit! 13 | * 14 | * 15 | * BSD license (see license.txt) 16 | */ 17 | 18 | #ifndef _ADAFRUIT_LSM6DSOX_H 19 | #define _ADAFRUIT_LSM6DSOX_H 20 | 21 | #include "Adafruit_LSM6DS.h" 22 | 23 | #define LSM6DSOX_CHIP_ID 0x6C ///< LSM6DSOX default device id from WHOAMI 24 | 25 | #define LSM6DSOX_FUNC_CFG_ACCESS 0x1 ///< Enable embedded functions register 26 | #define LSM6DSOX_PIN_CTRL 0x2 ///< Pin control register 27 | 28 | #define LSM6DSOX_INT1_CTRL 0x0D ///< Interrupt enable for data ready 29 | #define LSM6DSOX_CTRL1_XL 0x10 ///< Main accelerometer config register 30 | #define LSM6DSOX_CTRL2_G 0x11 ///< Main gyro config register 31 | #define LSM6DSOX_CTRL3_C 0x12 ///< Main configuration register 32 | #define LSM6DSOX_CTRL9_XL 0x18 ///< Includes i3c disable bit 33 | 34 | #define LSM6DSOX_MASTER_CONFIG 0x14 35 | ///< I2C Master config; access must be enabled with bit SHUB_REG_ACCESS 36 | ///< is set to '1' in FUNC_CFG_ACCESS (01h). 37 | 38 | /*! 39 | * @brief Class that stores state and functions for interacting with 40 | * the LSM6DSOX I2C Digital Potentiometer 41 | */ 42 | class Adafruit_LSM6DSOX : public Adafruit_LSM6DS { 43 | public: 44 | Adafruit_LSM6DSOX(); 45 | 46 | void enableI2CMasterPullups(bool enable_pullups); 47 | void disableSPIMasterPullups(bool disable_pullups); 48 | 49 | private: 50 | bool _init(int32_t sensor_id); 51 | }; 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Adafruit LSM6DS ![Build Status](https://github.com/adafruit/Adafruit_LSM6DS/workflows/Arduino%20Library%20CI/badge.svg) 2 | 3 | This is the Adafruit LSM6DS 6-DoF Accelerometer and Gyroscope Sensor Library for Arduino 4 | 5 | Tested and works great with the Adafruit LSM6DSOX Breakout Board 6 | [](https://www.adafruit.com/products/4438) 7 | 8 | 9 | This chip uses I2C to communicate, 2 pins are required to interface 10 | 11 | Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! 12 | 13 | # Dependencies 14 | * [Adafruit_BusIO](https://github.com/adafruit/Adafruit_BusIO) 15 | * [Adafruit_Sensor](https://github.com/adafruit/Adafruit_Sensor) 16 | 17 | # Contributing 18 | 19 | Contributions are welcome! Please read our [Code of Conduct](https://github.com/adafruit/Adafruit_LSM6DSOX/blob/master/CODE_OF_CONDUCT.md>) 20 | before contributing to help this project stay welcoming. 21 | 22 | ## Documentation and doxygen 23 | Documentation is produced by doxygen. Contributions should include documentation for any new code added. 24 | 25 | Some examples of how to use doxygen can be found in these guide pages: 26 | 27 | https://learn.adafruit.com/the-well-automated-arduino-library/doxygen 28 | 29 | https://learn.adafruit.com/the-well-automated-arduino-library/doxygen-tips 30 | 31 | Written by Bryan Siepert for Adafruit Industries. 32 | BSD license, check license.txt for more information 33 | All text above must be included in any redistribution 34 | 35 | To install, use the Arduino Library Manager and search for "Adafruit LSM6DS" and install the library. 36 | -------------------------------------------------------------------------------- /assets/board.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/Adafruit_LSM6DS/379a5204c0bad71264c3d635de84d0f9679ab784/assets/board.jpg -------------------------------------------------------------------------------- /assets/board.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/Adafruit_LSM6DS/379a5204c0bad71264c3d635de84d0f9679ab784/assets/board.png -------------------------------------------------------------------------------- /code-of-conduct.md: -------------------------------------------------------------------------------- 1 | # Adafruit Community Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and leaders pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level or type of 9 | experience, education, socio-economic status, nationality, personal appearance, 10 | race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | We are committed to providing a friendly, safe and welcoming environment for 15 | all. 16 | 17 | Examples of behavior that contributes to creating a positive environment 18 | include: 19 | 20 | * Be kind and courteous to others 21 | * Using welcoming and inclusive language 22 | * Being respectful of differing viewpoints and experiences 23 | * Collaborating with other community members 24 | * Gracefully accepting constructive criticism 25 | * Focusing on what is best for the community 26 | * Showing empathy towards other community members 27 | 28 | Examples of unacceptable behavior by participants include: 29 | 30 | * The use of sexualized language or imagery and sexual attention or advances 31 | * The use of inappropriate images, including in a community member's avatar 32 | * The use of inappropriate language, including in a community member's nickname 33 | * Any spamming, flaming, baiting or other attention-stealing behavior 34 | * Excessive or unwelcome helping; answering outside the scope of the question 35 | asked 36 | * Trolling, insulting/derogatory comments, and personal or political attacks 37 | * Public or private harassment 38 | * Publishing others' private information, such as a physical or electronic 39 | address, without explicit permission 40 | * Other conduct which could reasonably be considered inappropriate 41 | 42 | The goal of the standards and moderation guidelines outlined here is to build 43 | and maintain a respectful community. We ask that you don’t just aim to be 44 | "technically unimpeachable", but rather try to be your best self. 45 | 46 | We value many things beyond technical expertise, including collaboration and 47 | supporting others within our community. Providing a positive experience for 48 | other community members can have a much more significant impact than simply 49 | providing the correct answer. 50 | 51 | ## Our Responsibilities 52 | 53 | Project leaders are responsible for clarifying the standards of acceptable 54 | behavior and are expected to take appropriate and fair corrective action in 55 | response to any instances of unacceptable behavior. 56 | 57 | Project leaders have the right and responsibility to remove, edit, or 58 | reject messages, comments, commits, code, issues, and other contributions 59 | that are not aligned to this Code of Conduct, or to ban temporarily or 60 | permanently any community member for other behaviors that they deem 61 | inappropriate, threatening, offensive, or harmful. 62 | 63 | ## Moderation 64 | 65 | Instances of behaviors that violate the Adafruit Community Code of Conduct 66 | may be reported by any member of the community. Community members are 67 | encouraged to report these situations, including situations they witness 68 | involving other community members. 69 | 70 | You may report in the following ways: 71 | 72 | In any situation, you may send an email to . 73 | 74 | On the Adafruit Discord, you may send an open message from any channel 75 | to all Community Helpers by tagging @community helpers. You may also send an 76 | open message from any channel, or a direct message to @kattni#1507, 77 | @tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, or 78 | @Andon#8175. 79 | 80 | Email and direct message reports will be kept confidential. 81 | 82 | In situations on Discord where the issue is particularly egregious, possibly 83 | illegal, requires immediate action, or violates the Discord terms of service, 84 | you should also report the message directly to Discord. 85 | 86 | These are the steps for upholding our community’s standards of conduct. 87 | 88 | 1. Any member of the community may report any situation that violates the 89 | Adafruit Community Code of Conduct. All reports will be reviewed and 90 | investigated. 91 | 2. If the behavior is an egregious violation, the community member who 92 | committed the violation may be banned immediately, without warning. 93 | 3. Otherwise, moderators will first respond to such behavior with a warning. 94 | 4. Moderators follow a soft "three strikes" policy - the community member may 95 | be given another chance, if they are receptive to the warning and change their 96 | behavior. 97 | 5. If the community member is unreceptive or unreasonable when warned by a 98 | moderator, or the warning goes unheeded, they may be banned for a first or 99 | second offense. Repeated offenses will result in the community member being 100 | banned. 101 | 102 | ## Scope 103 | 104 | This Code of Conduct and the enforcement policies listed above apply to all 105 | Adafruit Community venues. This includes but is not limited to any community 106 | spaces (both public and private), the entire Adafruit Discord server, and 107 | Adafruit GitHub repositories. Examples of Adafruit Community spaces include 108 | but are not limited to meet-ups, audio chats on the Adafruit Discord, or 109 | interaction at a conference. 110 | 111 | This Code of Conduct applies both within project spaces and in public spaces 112 | when an individual is representing the project or its community. As a community 113 | member, you are representing our community, and are expected to behave 114 | accordingly. 115 | 116 | ## Attribution 117 | 118 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 119 | version 1.4, available at 120 | , 121 | and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html). 122 | 123 | For other projects adopting the Adafruit Community Code of 124 | Conduct, please contact the maintainers of those projects for enforcement. 125 | If you wish to use this code of conduct for your own project, consider 126 | explicitly mentioning your moderation policy or making a copy with your 127 | own moderation policy so as to avoid confusion. 128 | -------------------------------------------------------------------------------- /examples/adafruit_ism330dhcx_test/adafruit_ism330dhcx_test.ino: -------------------------------------------------------------------------------- 1 | // Basic demo for accelerometer/gyro readings from Adafruit ISM330DHCX 2 | 3 | #include 4 | 5 | // For SPI mode, we need a CS pin 6 | #define LSM_CS 10 7 | // For software-SPI mode we need SCK/MOSI/MISO pins 8 | #define LSM_SCK 13 9 | #define LSM_MISO 12 10 | #define LSM_MOSI 11 11 | 12 | Adafruit_ISM330DHCX ism330dhcx; 13 | void setup(void) { 14 | Serial.begin(115200); 15 | while (!Serial) 16 | delay(10); // will pause Zero, Leonardo, etc until serial console opens 17 | 18 | Serial.println("Adafruit ISM330DHCX test!"); 19 | 20 | if (!ism330dhcx.begin_I2C()) { 21 | // if (!ism330dhcx.begin_SPI(LSM_CS)) { 22 | // if (!ism330dhcx.begin_SPI(LSM_CS, LSM_SCK, LSM_MISO, LSM_MOSI)) { 23 | Serial.println("Failed to find ISM330DHCX chip"); 24 | while (1) { 25 | delay(10); 26 | } 27 | } 28 | 29 | Serial.println("ISM330DHCX Found!"); 30 | 31 | // ism330dhcx.setAccelRange(LSM6DS_ACCEL_RANGE_2_G); 32 | Serial.print("Accelerometer range set to: "); 33 | switch (ism330dhcx.getAccelRange()) { 34 | case LSM6DS_ACCEL_RANGE_2_G: 35 | Serial.println("+-2G"); 36 | break; 37 | case LSM6DS_ACCEL_RANGE_4_G: 38 | Serial.println("+-4G"); 39 | break; 40 | case LSM6DS_ACCEL_RANGE_8_G: 41 | Serial.println("+-8G"); 42 | break; 43 | case LSM6DS_ACCEL_RANGE_16_G: 44 | Serial.println("+-16G"); 45 | break; 46 | } 47 | 48 | // ism330dhcx.setGyroRange(LSM6DS_GYRO_RANGE_250_DPS); 49 | Serial.print("Gyro range set to: "); 50 | switch (ism330dhcx.getGyroRange()) { 51 | case LSM6DS_GYRO_RANGE_125_DPS: 52 | Serial.println("125 degrees/s"); 53 | break; 54 | case LSM6DS_GYRO_RANGE_250_DPS: 55 | Serial.println("250 degrees/s"); 56 | break; 57 | case LSM6DS_GYRO_RANGE_500_DPS: 58 | Serial.println("500 degrees/s"); 59 | break; 60 | case LSM6DS_GYRO_RANGE_1000_DPS: 61 | Serial.println("1000 degrees/s"); 62 | break; 63 | case LSM6DS_GYRO_RANGE_2000_DPS: 64 | Serial.println("2000 degrees/s"); 65 | break; 66 | case ISM330DHCX_GYRO_RANGE_4000_DPS: 67 | Serial.println("4000 degrees/s"); 68 | break; 69 | } 70 | 71 | // ism330dhcx.setAccelDataRate(LSM6DS_RATE_12_5_HZ); 72 | Serial.print("Accelerometer data rate set to: "); 73 | switch (ism330dhcx.getAccelDataRate()) { 74 | case LSM6DS_RATE_SHUTDOWN: 75 | Serial.println("0 Hz"); 76 | break; 77 | case LSM6DS_RATE_12_5_HZ: 78 | Serial.println("12.5 Hz"); 79 | break; 80 | case LSM6DS_RATE_26_HZ: 81 | Serial.println("26 Hz"); 82 | break; 83 | case LSM6DS_RATE_52_HZ: 84 | Serial.println("52 Hz"); 85 | break; 86 | case LSM6DS_RATE_104_HZ: 87 | Serial.println("104 Hz"); 88 | break; 89 | case LSM6DS_RATE_208_HZ: 90 | Serial.println("208 Hz"); 91 | break; 92 | case LSM6DS_RATE_416_HZ: 93 | Serial.println("416 Hz"); 94 | break; 95 | case LSM6DS_RATE_833_HZ: 96 | Serial.println("833 Hz"); 97 | break; 98 | case LSM6DS_RATE_1_66K_HZ: 99 | Serial.println("1.66 KHz"); 100 | break; 101 | case LSM6DS_RATE_3_33K_HZ: 102 | Serial.println("3.33 KHz"); 103 | break; 104 | case LSM6DS_RATE_6_66K_HZ: 105 | Serial.println("6.66 KHz"); 106 | break; 107 | } 108 | 109 | // ism330dhcx.setGyroDataRate(LSM6DS_RATE_12_5_HZ); 110 | Serial.print("Gyro data rate set to: "); 111 | switch (ism330dhcx.getGyroDataRate()) { 112 | case LSM6DS_RATE_SHUTDOWN: 113 | Serial.println("0 Hz"); 114 | break; 115 | case LSM6DS_RATE_12_5_HZ: 116 | Serial.println("12.5 Hz"); 117 | break; 118 | case LSM6DS_RATE_26_HZ: 119 | Serial.println("26 Hz"); 120 | break; 121 | case LSM6DS_RATE_52_HZ: 122 | Serial.println("52 Hz"); 123 | break; 124 | case LSM6DS_RATE_104_HZ: 125 | Serial.println("104 Hz"); 126 | break; 127 | case LSM6DS_RATE_208_HZ: 128 | Serial.println("208 Hz"); 129 | break; 130 | case LSM6DS_RATE_416_HZ: 131 | Serial.println("416 Hz"); 132 | break; 133 | case LSM6DS_RATE_833_HZ: 134 | Serial.println("833 Hz"); 135 | break; 136 | case LSM6DS_RATE_1_66K_HZ: 137 | Serial.println("1.66 KHz"); 138 | break; 139 | case LSM6DS_RATE_3_33K_HZ: 140 | Serial.println("3.33 KHz"); 141 | break; 142 | case LSM6DS_RATE_6_66K_HZ: 143 | Serial.println("6.66 KHz"); 144 | break; 145 | } 146 | 147 | ism330dhcx.configInt1(false, false, true); // accelerometer DRDY on INT1 148 | ism330dhcx.configInt2(false, true, false); // gyro DRDY on INT2 149 | } 150 | 151 | void loop() { 152 | // /* Get a new normalized sensor event */ 153 | sensors_event_t accel; 154 | sensors_event_t gyro; 155 | sensors_event_t temp; 156 | ism330dhcx.getEvent(&accel, &gyro, &temp); 157 | 158 | Serial.print("\t\tTemperature "); 159 | Serial.print(temp.temperature); 160 | Serial.println(" deg C"); 161 | 162 | /* Display the results (acceleration is measured in m/s^2) */ 163 | Serial.print("\t\tAccel X: "); 164 | Serial.print(accel.acceleration.x); 165 | Serial.print(" \tY: "); 166 | Serial.print(accel.acceleration.y); 167 | Serial.print(" \tZ: "); 168 | Serial.print(accel.acceleration.z); 169 | Serial.println(" m/s^2 "); 170 | 171 | /* Display the results (rotation is measured in rad/s) */ 172 | Serial.print("\t\tGyro X: "); 173 | Serial.print(gyro.gyro.x); 174 | Serial.print(" \tY: "); 175 | Serial.print(gyro.gyro.y); 176 | Serial.print(" \tZ: "); 177 | Serial.print(gyro.gyro.z); 178 | Serial.println(" radians/s "); 179 | Serial.println(); 180 | 181 | delay(100); 182 | 183 | // // serial plotter friendly format 184 | 185 | // Serial.print(temp.temperature); 186 | // Serial.print(","); 187 | 188 | // Serial.print(accel.acceleration.x); 189 | // Serial.print(","); Serial.print(accel.acceleration.y); 190 | // Serial.print(","); Serial.print(accel.acceleration.z); 191 | // Serial.print(","); 192 | 193 | // Serial.print(gyro.gyro.x); 194 | // Serial.print(","); Serial.print(gyro.gyro.y); 195 | // Serial.print(","); Serial.print(gyro.gyro.z); 196 | // Serial.println(); 197 | // delayMicroseconds(10000); 198 | } 199 | -------------------------------------------------------------------------------- /examples/adafruit_lsm6ds33_test/adafruit_lsm6ds33_test.ino: -------------------------------------------------------------------------------- 1 | // Basic demo for accelerometer/gyro readings from Adafruit LSM6DS33 2 | 3 | #include 4 | 5 | // For SPI mode, we need a CS pin 6 | #define LSM_CS 10 7 | // For software-SPI mode we need SCK/MOSI/MISO pins 8 | #define LSM_SCK 13 9 | #define LSM_MISO 12 10 | #define LSM_MOSI 11 11 | 12 | Adafruit_LSM6DS33 lsm6ds33; 13 | void setup(void) { 14 | Serial.begin(115200); 15 | while (!Serial) 16 | delay(10); // will pause Zero, Leonardo, etc until serial console opens 17 | 18 | Serial.println("Adafruit LSM6DS33 test!"); 19 | 20 | if (!lsm6ds33.begin_I2C()) { 21 | // if (!lsm6ds33.begin_SPI(LSM_CS)) { 22 | // if (!lsm6ds33.begin_SPI(LSM_CS, LSM_SCK, LSM_MISO, LSM_MOSI)) { 23 | Serial.println("Failed to find LSM6DS33 chip"); 24 | while (1) { 25 | delay(10); 26 | } 27 | } 28 | 29 | Serial.println("LSM6DS33 Found!"); 30 | 31 | // lsm6ds33.setAccelRange(LSM6DS_ACCEL_RANGE_2_G); 32 | Serial.print("Accelerometer range set to: "); 33 | switch (lsm6ds33.getAccelRange()) { 34 | case LSM6DS_ACCEL_RANGE_2_G: 35 | Serial.println("+-2G"); 36 | break; 37 | case LSM6DS_ACCEL_RANGE_4_G: 38 | Serial.println("+-4G"); 39 | break; 40 | case LSM6DS_ACCEL_RANGE_8_G: 41 | Serial.println("+-8G"); 42 | break; 43 | case LSM6DS_ACCEL_RANGE_16_G: 44 | Serial.println("+-16G"); 45 | break; 46 | } 47 | 48 | // lsm6ds33.setGyroRange(LSM6DS_GYRO_RANGE_250_DPS); 49 | Serial.print("Gyro range set to: "); 50 | switch (lsm6ds33.getGyroRange()) { 51 | case LSM6DS_GYRO_RANGE_125_DPS: 52 | Serial.println("125 degrees/s"); 53 | break; 54 | case LSM6DS_GYRO_RANGE_250_DPS: 55 | Serial.println("250 degrees/s"); 56 | break; 57 | case LSM6DS_GYRO_RANGE_500_DPS: 58 | Serial.println("500 degrees/s"); 59 | break; 60 | case LSM6DS_GYRO_RANGE_1000_DPS: 61 | Serial.println("1000 degrees/s"); 62 | break; 63 | case LSM6DS_GYRO_RANGE_2000_DPS: 64 | Serial.println("2000 degrees/s"); 65 | break; 66 | case ISM330DHCX_GYRO_RANGE_4000_DPS: 67 | break; // unsupported range for the DS33 68 | } 69 | 70 | // lsm6ds33.setAccelDataRate(LSM6DS_RATE_12_5_HZ); 71 | Serial.print("Accelerometer data rate set to: "); 72 | switch (lsm6ds33.getAccelDataRate()) { 73 | case LSM6DS_RATE_SHUTDOWN: 74 | Serial.println("0 Hz"); 75 | break; 76 | case LSM6DS_RATE_12_5_HZ: 77 | Serial.println("12.5 Hz"); 78 | break; 79 | case LSM6DS_RATE_26_HZ: 80 | Serial.println("26 Hz"); 81 | break; 82 | case LSM6DS_RATE_52_HZ: 83 | Serial.println("52 Hz"); 84 | break; 85 | case LSM6DS_RATE_104_HZ: 86 | Serial.println("104 Hz"); 87 | break; 88 | case LSM6DS_RATE_208_HZ: 89 | Serial.println("208 Hz"); 90 | break; 91 | case LSM6DS_RATE_416_HZ: 92 | Serial.println("416 Hz"); 93 | break; 94 | case LSM6DS_RATE_833_HZ: 95 | Serial.println("833 Hz"); 96 | break; 97 | case LSM6DS_RATE_1_66K_HZ: 98 | Serial.println("1.66 KHz"); 99 | break; 100 | case LSM6DS_RATE_3_33K_HZ: 101 | Serial.println("3.33 KHz"); 102 | break; 103 | case LSM6DS_RATE_6_66K_HZ: 104 | Serial.println("6.66 KHz"); 105 | break; 106 | } 107 | 108 | // lsm6ds33.setGyroDataRate(LSM6DS_RATE_12_5_HZ); 109 | Serial.print("Gyro data rate set to: "); 110 | switch (lsm6ds33.getGyroDataRate()) { 111 | case LSM6DS_RATE_SHUTDOWN: 112 | Serial.println("0 Hz"); 113 | break; 114 | case LSM6DS_RATE_12_5_HZ: 115 | Serial.println("12.5 Hz"); 116 | break; 117 | case LSM6DS_RATE_26_HZ: 118 | Serial.println("26 Hz"); 119 | break; 120 | case LSM6DS_RATE_52_HZ: 121 | Serial.println("52 Hz"); 122 | break; 123 | case LSM6DS_RATE_104_HZ: 124 | Serial.println("104 Hz"); 125 | break; 126 | case LSM6DS_RATE_208_HZ: 127 | Serial.println("208 Hz"); 128 | break; 129 | case LSM6DS_RATE_416_HZ: 130 | Serial.println("416 Hz"); 131 | break; 132 | case LSM6DS_RATE_833_HZ: 133 | Serial.println("833 Hz"); 134 | break; 135 | case LSM6DS_RATE_1_66K_HZ: 136 | Serial.println("1.66 KHz"); 137 | break; 138 | case LSM6DS_RATE_3_33K_HZ: 139 | Serial.println("3.33 KHz"); 140 | break; 141 | case LSM6DS_RATE_6_66K_HZ: 142 | Serial.println("6.66 KHz"); 143 | break; 144 | } 145 | 146 | lsm6ds33.configInt1(false, false, true); // accelerometer DRDY on INT1 147 | lsm6ds33.configInt2(false, true, false); // gyro DRDY on INT2 148 | } 149 | 150 | void loop() { 151 | // /* Get a new normalized sensor event */ 152 | sensors_event_t accel; 153 | sensors_event_t gyro; 154 | sensors_event_t temp; 155 | lsm6ds33.getEvent(&accel, &gyro, &temp); 156 | 157 | Serial.print("\t\tTemperature "); 158 | Serial.print(temp.temperature); 159 | Serial.println(" deg C"); 160 | 161 | /* Display the results (acceleration is measured in m/s^2) */ 162 | Serial.print("\t\tAccel X: "); 163 | Serial.print(accel.acceleration.x); 164 | Serial.print(" \tY: "); 165 | Serial.print(accel.acceleration.y); 166 | Serial.print(" \tZ: "); 167 | Serial.print(accel.acceleration.z); 168 | Serial.println(" m/s^2 "); 169 | 170 | /* Display the results (rotation is measured in rad/s) */ 171 | Serial.print("\t\tGyro X: "); 172 | Serial.print(gyro.gyro.x); 173 | Serial.print(" \tY: "); 174 | Serial.print(gyro.gyro.y); 175 | Serial.print(" \tZ: "); 176 | Serial.print(gyro.gyro.z); 177 | Serial.println(" radians/s "); 178 | Serial.println(); 179 | 180 | delay(100); 181 | 182 | // // serial plotter friendly format 183 | 184 | // Serial.print(temp.temperature); 185 | // Serial.print(","); 186 | 187 | // Serial.print(accel.acceleration.x); 188 | // Serial.print(","); Serial.print(accel.acceleration.y); 189 | // Serial.print(","); Serial.print(accel.acceleration.z); 190 | // Serial.print(","); 191 | 192 | // Serial.print(gyro.gyro.x); 193 | // Serial.print(","); Serial.print(gyro.gyro.y); 194 | // Serial.print(","); Serial.print(gyro.gyro.z); 195 | // Serial.println(); 196 | // delayMicroseconds(10000); 197 | } -------------------------------------------------------------------------------- /examples/adafruit_lsm6ds3trc_test/adafruit_lsm6ds3trc_test.ino: -------------------------------------------------------------------------------- 1 | // Basic demo for accelerometer/gyro readings from Adafruit LSM6DS3TR-C 2 | 3 | #include 4 | 5 | // For SPI mode, we need a CS pin 6 | #define LSM_CS 10 7 | // For software-SPI mode we need SCK/MOSI/MISO pins 8 | #define LSM_SCK 13 9 | #define LSM_MISO 12 10 | #define LSM_MOSI 11 11 | 12 | Adafruit_LSM6DS3TRC lsm6ds3trc; 13 | 14 | void setup(void) { 15 | Serial.begin(115200); 16 | while (!Serial) 17 | delay(10); // will pause Zero, Leonardo, etc until serial console opens 18 | 19 | Serial.println("Adafruit LSM6DS3TR-C test!"); 20 | 21 | if (!lsm6ds3trc.begin_I2C()) { 22 | // if (!lsm6ds3trc.begin_SPI(LSM_CS)) { 23 | // if (!lsm6ds3trc.begin_SPI(LSM_CS, LSM_SCK, LSM_MISO, LSM_MOSI)) { 24 | Serial.println("Failed to find LSM6DS3TR-C chip"); 25 | while (1) { 26 | delay(10); 27 | } 28 | } 29 | 30 | Serial.println("LSM6DS3TR-C Found!"); 31 | 32 | // lsm6ds3trc.setAccelRange(LSM6DS_ACCEL_RANGE_2_G); 33 | Serial.print("Accelerometer range set to: "); 34 | switch (lsm6ds3trc.getAccelRange()) { 35 | case LSM6DS_ACCEL_RANGE_2_G: 36 | Serial.println("+-2G"); 37 | break; 38 | case LSM6DS_ACCEL_RANGE_4_G: 39 | Serial.println("+-4G"); 40 | break; 41 | case LSM6DS_ACCEL_RANGE_8_G: 42 | Serial.println("+-8G"); 43 | break; 44 | case LSM6DS_ACCEL_RANGE_16_G: 45 | Serial.println("+-16G"); 46 | break; 47 | } 48 | 49 | // lsm6ds3trc.setGyroRange(LSM6DS_GYRO_RANGE_250_DPS); 50 | Serial.print("Gyro range set to: "); 51 | switch (lsm6ds3trc.getGyroRange()) { 52 | case LSM6DS_GYRO_RANGE_125_DPS: 53 | Serial.println("125 degrees/s"); 54 | break; 55 | case LSM6DS_GYRO_RANGE_250_DPS: 56 | Serial.println("250 degrees/s"); 57 | break; 58 | case LSM6DS_GYRO_RANGE_500_DPS: 59 | Serial.println("500 degrees/s"); 60 | break; 61 | case LSM6DS_GYRO_RANGE_1000_DPS: 62 | Serial.println("1000 degrees/s"); 63 | break; 64 | case LSM6DS_GYRO_RANGE_2000_DPS: 65 | Serial.println("2000 degrees/s"); 66 | break; 67 | case ISM330DHCX_GYRO_RANGE_4000_DPS: 68 | break; // unsupported range for the DS33 69 | } 70 | 71 | // lsm6ds3trc.setAccelDataRate(LSM6DS_RATE_12_5_HZ); 72 | Serial.print("Accelerometer data rate set to: "); 73 | switch (lsm6ds3trc.getAccelDataRate()) { 74 | case LSM6DS_RATE_SHUTDOWN: 75 | Serial.println("0 Hz"); 76 | break; 77 | case LSM6DS_RATE_12_5_HZ: 78 | Serial.println("12.5 Hz"); 79 | break; 80 | case LSM6DS_RATE_26_HZ: 81 | Serial.println("26 Hz"); 82 | break; 83 | case LSM6DS_RATE_52_HZ: 84 | Serial.println("52 Hz"); 85 | break; 86 | case LSM6DS_RATE_104_HZ: 87 | Serial.println("104 Hz"); 88 | break; 89 | case LSM6DS_RATE_208_HZ: 90 | Serial.println("208 Hz"); 91 | break; 92 | case LSM6DS_RATE_416_HZ: 93 | Serial.println("416 Hz"); 94 | break; 95 | case LSM6DS_RATE_833_HZ: 96 | Serial.println("833 Hz"); 97 | break; 98 | case LSM6DS_RATE_1_66K_HZ: 99 | Serial.println("1.66 KHz"); 100 | break; 101 | case LSM6DS_RATE_3_33K_HZ: 102 | Serial.println("3.33 KHz"); 103 | break; 104 | case LSM6DS_RATE_6_66K_HZ: 105 | Serial.println("6.66 KHz"); 106 | break; 107 | } 108 | 109 | // lsm6ds3trc.setGyroDataRate(LSM6DS_RATE_12_5_HZ); 110 | Serial.print("Gyro data rate set to: "); 111 | switch (lsm6ds3trc.getGyroDataRate()) { 112 | case LSM6DS_RATE_SHUTDOWN: 113 | Serial.println("0 Hz"); 114 | break; 115 | case LSM6DS_RATE_12_5_HZ: 116 | Serial.println("12.5 Hz"); 117 | break; 118 | case LSM6DS_RATE_26_HZ: 119 | Serial.println("26 Hz"); 120 | break; 121 | case LSM6DS_RATE_52_HZ: 122 | Serial.println("52 Hz"); 123 | break; 124 | case LSM6DS_RATE_104_HZ: 125 | Serial.println("104 Hz"); 126 | break; 127 | case LSM6DS_RATE_208_HZ: 128 | Serial.println("208 Hz"); 129 | break; 130 | case LSM6DS_RATE_416_HZ: 131 | Serial.println("416 Hz"); 132 | break; 133 | case LSM6DS_RATE_833_HZ: 134 | Serial.println("833 Hz"); 135 | break; 136 | case LSM6DS_RATE_1_66K_HZ: 137 | Serial.println("1.66 KHz"); 138 | break; 139 | case LSM6DS_RATE_3_33K_HZ: 140 | Serial.println("3.33 KHz"); 141 | break; 142 | case LSM6DS_RATE_6_66K_HZ: 143 | Serial.println("6.66 KHz"); 144 | break; 145 | } 146 | 147 | lsm6ds3trc.configInt1(false, false, true); // accelerometer DRDY on INT1 148 | lsm6ds3trc.configInt2(false, true, false); // gyro DRDY on INT2 149 | } 150 | 151 | void loop() { 152 | // Get a new normalized sensor event 153 | sensors_event_t accel; 154 | sensors_event_t gyro; 155 | sensors_event_t temp; 156 | lsm6ds3trc.getEvent(&accel, &gyro, &temp); 157 | 158 | Serial.print("\t\tTemperature "); 159 | Serial.print(temp.temperature); 160 | Serial.println(" deg C"); 161 | 162 | /* Display the results (acceleration is measured in m/s^2) */ 163 | Serial.print("\t\tAccel X: "); 164 | Serial.print(accel.acceleration.x); 165 | Serial.print(" \tY: "); 166 | Serial.print(accel.acceleration.y); 167 | Serial.print(" \tZ: "); 168 | Serial.print(accel.acceleration.z); 169 | Serial.println(" m/s^2 "); 170 | 171 | /* Display the results (rotation is measured in rad/s) */ 172 | Serial.print("\t\tGyro X: "); 173 | Serial.print(gyro.gyro.x); 174 | Serial.print(" \tY: "); 175 | Serial.print(gyro.gyro.y); 176 | Serial.print(" \tZ: "); 177 | Serial.print(gyro.gyro.z); 178 | Serial.println(" radians/s "); 179 | Serial.println(); 180 | 181 | delay(100); 182 | 183 | // // serial plotter friendly format 184 | 185 | // Serial.print(temp.temperature); 186 | // Serial.print(","); 187 | 188 | // Serial.print(accel.acceleration.x); 189 | // Serial.print(","); Serial.print(accel.acceleration.y); 190 | // Serial.print(","); Serial.print(accel.acceleration.z); 191 | // Serial.print(","); 192 | 193 | // Serial.print(gyro.gyro.x); 194 | // Serial.print(","); Serial.print(gyro.gyro.y); 195 | // Serial.print(","); Serial.print(gyro.gyro.z); 196 | // Serial.println(); 197 | // delayMicroseconds(10000); 198 | } 199 | -------------------------------------------------------------------------------- /examples/adafruit_lsm6ds_pedometer/adafruit_lsm6ds_pedometer.ino: -------------------------------------------------------------------------------- 1 | // Basic demo for accelerometer/gyro readings from Adafruit LSM6DS33 2 | 3 | #include 4 | #include 5 | 6 | Adafruit_LSM6DS33 lsm; // can use any LSM6DS/ISM330 family chip! 7 | //Adafruit_LSM6DS3TRC lsm; // uncomment to use LSM6DS3TR-C 8 | 9 | // For SPI mode, we need a CS pin 10 | #define LSM_CS 10 11 | // For software-SPI mode we need SCK/MOSI/MISO pins 12 | #define LSM_SCK 13 13 | #define LSM_MISO 12 14 | #define LSM_MOSI 11 15 | 16 | 17 | void setup(void) { 18 | Serial.begin(115200); 19 | while (!Serial) 20 | delay(10); // will pause Zero, Leonardo, etc until serial console opens 21 | 22 | Serial.println("Adafruit LSM6DS pedometer test!"); 23 | 24 | if (!lsm.begin_I2C()) { 25 | // if (!lsm.begin_SPI(LSM_CS)) { 26 | // if (!lsm.begin_SPI(LSM_CS, LSM_SCK, LSM_MISO, LSM_MOSI)) { 27 | Serial.println("Failed to find LSM6DS chip"); 28 | while (1) { 29 | delay(10); 30 | } 31 | } 32 | 33 | Serial.println("LSM6DS Found!"); 34 | 35 | // Set to 2G range and 26 Hz update rate 36 | lsm.setAccelRange(LSM6DS_ACCEL_RANGE_2_G); 37 | lsm.setGyroRange(LSM6DS_GYRO_RANGE_250_DPS); 38 | lsm.setAccelDataRate(LSM6DS_RATE_26_HZ); 39 | lsm.setGyroDataRate(LSM6DS_RATE_26_HZ); 40 | 41 | // step detect output on INT1 42 | lsm.configInt1(false, false, false, true); 43 | 44 | // turn it on! 45 | Serial.println("Enable ped"); 46 | lsm.enablePedometer(true); 47 | } 48 | 49 | void loop() { 50 | Serial.print("Steps taken: "); Serial.println(lsm.readPedometer()); 51 | delay(100); // can wait as long as you like! 52 | } -------------------------------------------------------------------------------- /examples/adafruit_lsm6ds_shake/adafruit_lsm6ds_shake.ino: -------------------------------------------------------------------------------- 1 | // Basic demo for accelerometer/gyro readings from Adafruit LSM6DS33 2 | 3 | #include 4 | #include 5 | 6 | // For SPI mode, we need a CS pin 7 | #define LSM_CS 10 8 | // For software-SPI mode we need SCK/MOSI/MISO pins 9 | #define LSM_SCK 13 10 | #define LSM_MISO 12 11 | #define LSM_MOSI 11 12 | 13 | 14 | Adafruit_LSM6DS33 lsm6ds; // uncomment to use LSM6DS33 15 | //Adafruit_LSM6DS3TRC lsm6ds; // uncomment to use LSM6DS3TR-C 16 | 17 | void setup(void) { 18 | Serial.begin(115200); 19 | while (!Serial) 20 | delay(10); // will pause Zero, Leonardo, etc until serial console opens 21 | 22 | Serial.println("Adafruit LSM6DS shake test!"); 23 | 24 | if (!lsm6ds.begin_I2C()) { 25 | // if (!lsm6ds.begin_SPI(LSM_CS)) { 26 | // if (!lsm6ds.begin_SPI(LSM_CS, LSM_SCK, LSM_MISO, LSM_MOSI)) { 27 | Serial.println("Failed to find LSM6DS chip"); 28 | while (1) { 29 | delay(10); 30 | } 31 | } 32 | 33 | Serial.println("LSM6DS Found!"); 34 | 35 | // enable shake detection 36 | lsm6ds.enableWakeup(true); 37 | } 38 | 39 | void loop() { 40 | // check for shake 41 | if (lsm6ds.shake()) { 42 | Serial.println("SHAKE!"); 43 | } 44 | } -------------------------------------------------------------------------------- /examples/adafruit_lsm6ds_unifiedsensors/adafruit_lsm6ds_unifiedsensors.ino: -------------------------------------------------------------------------------- 1 | // Demo for getting individual unified sensor data from the LSM6DS series 2 | 3 | // Can change this to be LSM6DSOX or whatever ya like 4 | #include 5 | #include 6 | 7 | Adafruit_LSM6DS33 lsm6ds; // can use any LSM6DS/ISM330 family chip! 8 | //Adafruit_LSM6DS3TRC lsm6ds; // uncomment to use LSM6DS3TR-C 9 | Adafruit_Sensor *lsm_temp, *lsm_accel, *lsm_gyro; 10 | 11 | void setup(void) { 12 | Serial.begin(115200); 13 | while (!Serial) 14 | delay(10); // will pause Zero, Leonardo, etc until serial console opens 15 | 16 | Serial.println("Adafruit LSM6DS test!"); 17 | 18 | if (!lsm6ds.begin_I2C()) { 19 | Serial.println("Failed to find LSM6DS chip"); 20 | while (1) { 21 | delay(10); 22 | } 23 | } 24 | 25 | Serial.println("LSM6DS Found!"); 26 | lsm_temp = lsm6ds.getTemperatureSensor(); 27 | lsm_temp->printSensorDetails(); 28 | 29 | lsm_accel = lsm6ds.getAccelerometerSensor(); 30 | lsm_accel->printSensorDetails(); 31 | 32 | lsm_gyro = lsm6ds.getGyroSensor(); 33 | lsm_gyro->printSensorDetails(); 34 | } 35 | 36 | void loop() { 37 | // /* Get a new normalized sensor event */ 38 | sensors_event_t accel; 39 | sensors_event_t gyro; 40 | sensors_event_t temp; 41 | lsm_temp->getEvent(&temp); 42 | lsm_accel->getEvent(&accel); 43 | lsm_gyro->getEvent(&gyro); 44 | 45 | Serial.print("\t\tTemperature "); 46 | Serial.print(temp.temperature); 47 | Serial.println(" deg C"); 48 | 49 | /* Display the results (acceleration is measured in m/s^2) */ 50 | Serial.print("\t\tAccel X: "); 51 | Serial.print(accel.acceleration.x); 52 | Serial.print(" \tY: "); 53 | Serial.print(accel.acceleration.y); 54 | Serial.print(" \tZ: "); 55 | Serial.print(accel.acceleration.z); 56 | Serial.println(" m/s^2 "); 57 | 58 | /* Display the results (rotation is measured in rad/s) */ 59 | Serial.print("\t\tGyro X: "); 60 | Serial.print(gyro.gyro.x); 61 | Serial.print(" \tY: "); 62 | Serial.print(gyro.gyro.y); 63 | Serial.print(" \tZ: "); 64 | Serial.print(gyro.gyro.z); 65 | Serial.println(" radians/s "); 66 | Serial.println(); 67 | 68 | delay(100); 69 | 70 | /* serial plotter friendly format 71 | Serial.print(temp.temperature); 72 | Serial.print(","); 73 | 74 | Serial.print(accel.acceleration.x); 75 | Serial.print(","); Serial.print(accel.acceleration.y); 76 | Serial.print(","); Serial.print(accel.acceleration.z); 77 | Serial.print(","); 78 | 79 | Serial.print(gyro.gyro.x); 80 | Serial.print(","); Serial.print(gyro.gyro.y); 81 | Serial.print(","); Serial.print(gyro.gyro.z); 82 | Serial.println(); 83 | delay(10); 84 | */ 85 | } -------------------------------------------------------------------------------- /examples/adafruit_lsm6dso32_test/adafruit_lsm6dso32_test.ino: -------------------------------------------------------------------------------- 1 | // Basic demo for accelerometer & gyro readings from Adafruit 2 | // LSM6DSO32 sensor 3 | 4 | #include 5 | 6 | // For SPI mode, we need a CS pin 7 | #define LSM_CS 10 8 | // For software-SPI mode we need SCK/MOSI/MISO pins 9 | #define LSM_SCK 13 10 | #define LSM_MISO 12 11 | #define LSM_MOSI 11 12 | 13 | Adafruit_LSM6DSO32 dso32; 14 | void setup(void) { 15 | Serial.begin(115200); 16 | while (!Serial) 17 | delay(10); // will pause Zero, Leonardo, etc until serial console opens 18 | 19 | Serial.println("Adafruit LSM6DSO32 test!"); 20 | 21 | if (!dso32.begin_I2C()) { 22 | // if (!dso32.begin_SPI(LSM_CS)) { 23 | // if (!dso32.begin_SPI(LSM_CS, LSM_SCK, LSM_MISO, LSM_MOSI)) { 24 | // Serial.println("Failed to find LSM6DSO32 chip"); 25 | while (1) { 26 | delay(10); 27 | } 28 | } 29 | 30 | Serial.println("LSM6DSO32 Found!"); 31 | 32 | dso32.setAccelRange(LSM6DSO32_ACCEL_RANGE_8_G); 33 | Serial.print("Accelerometer range set to: "); 34 | switch (dso32.getAccelRange()) { 35 | case LSM6DSO32_ACCEL_RANGE_4_G: 36 | Serial.println("+-4G"); 37 | break; 38 | case LSM6DSO32_ACCEL_RANGE_8_G: 39 | Serial.println("+-8G"); 40 | break; 41 | case LSM6DSO32_ACCEL_RANGE_16_G: 42 | Serial.println("+-16G"); 43 | break; 44 | case LSM6DSO32_ACCEL_RANGE_32_G: 45 | Serial.println("+-32G"); 46 | break; 47 | } 48 | 49 | // dso32.setGyroRange(LSM6DS_GYRO_RANGE_250_DPS ); 50 | Serial.print("Gyro range set to: "); 51 | switch (dso32.getGyroRange()) { 52 | case LSM6DS_GYRO_RANGE_125_DPS: 53 | Serial.println("125 degrees/s"); 54 | break; 55 | case LSM6DS_GYRO_RANGE_250_DPS: 56 | Serial.println("250 degrees/s"); 57 | break; 58 | case LSM6DS_GYRO_RANGE_500_DPS: 59 | Serial.println("500 degrees/s"); 60 | break; 61 | case LSM6DS_GYRO_RANGE_1000_DPS: 62 | Serial.println("1000 degrees/s"); 63 | break; 64 | case LSM6DS_GYRO_RANGE_2000_DPS: 65 | Serial.println("2000 degrees/s"); 66 | break; 67 | case ISM330DHCX_GYRO_RANGE_4000_DPS: 68 | break; // unsupported range for the DSO32 69 | } 70 | 71 | // dso32.setAccelDataRate(LSM6DS_RATE_12_5_HZ); 72 | Serial.print("Accelerometer data rate set to: "); 73 | switch (dso32.getAccelDataRate()) { 74 | case LSM6DS_RATE_SHUTDOWN: 75 | Serial.println("0 Hz"); 76 | break; 77 | case LSM6DS_RATE_12_5_HZ: 78 | Serial.println("12.5 Hz"); 79 | break; 80 | case LSM6DS_RATE_26_HZ: 81 | Serial.println("26 Hz"); 82 | break; 83 | case LSM6DS_RATE_52_HZ: 84 | Serial.println("52 Hz"); 85 | break; 86 | case LSM6DS_RATE_104_HZ: 87 | Serial.println("104 Hz"); 88 | break; 89 | case LSM6DS_RATE_208_HZ: 90 | Serial.println("208 Hz"); 91 | break; 92 | case LSM6DS_RATE_416_HZ: 93 | Serial.println("416 Hz"); 94 | break; 95 | case LSM6DS_RATE_833_HZ: 96 | Serial.println("833 Hz"); 97 | break; 98 | case LSM6DS_RATE_1_66K_HZ: 99 | Serial.println("1.66 KHz"); 100 | break; 101 | case LSM6DS_RATE_3_33K_HZ: 102 | Serial.println("3.33 KHz"); 103 | break; 104 | case LSM6DS_RATE_6_66K_HZ: 105 | Serial.println("6.66 KHz"); 106 | break; 107 | } 108 | 109 | // dso32.setGyroDataRate(LSM6DS_RATE_12_5_HZ); 110 | Serial.print("Gyro data rate set to: "); 111 | switch (dso32.getGyroDataRate()) { 112 | case LSM6DS_RATE_SHUTDOWN: 113 | Serial.println("0 Hz"); 114 | break; 115 | case LSM6DS_RATE_12_5_HZ: 116 | Serial.println("12.5 Hz"); 117 | break; 118 | case LSM6DS_RATE_26_HZ: 119 | Serial.println("26 Hz"); 120 | break; 121 | case LSM6DS_RATE_52_HZ: 122 | Serial.println("52 Hz"); 123 | break; 124 | case LSM6DS_RATE_104_HZ: 125 | Serial.println("104 Hz"); 126 | break; 127 | case LSM6DS_RATE_208_HZ: 128 | Serial.println("208 Hz"); 129 | break; 130 | case LSM6DS_RATE_416_HZ: 131 | Serial.println("416 Hz"); 132 | break; 133 | case LSM6DS_RATE_833_HZ: 134 | Serial.println("833 Hz"); 135 | break; 136 | case LSM6DS_RATE_1_66K_HZ: 137 | Serial.println("1.66 KHz"); 138 | break; 139 | case LSM6DS_RATE_3_33K_HZ: 140 | Serial.println("3.33 KHz"); 141 | break; 142 | case LSM6DS_RATE_6_66K_HZ: 143 | Serial.println("6.66 KHz"); 144 | break; 145 | } 146 | } 147 | 148 | void loop() { 149 | 150 | // /* Get a new normalized sensor event */ 151 | sensors_event_t accel; 152 | sensors_event_t gyro; 153 | sensors_event_t temp; 154 | dso32.getEvent(&accel, &gyro, &temp); 155 | 156 | Serial.print("\t\tTemperature "); 157 | Serial.print(temp.temperature); 158 | Serial.println(" deg C"); 159 | 160 | /* Display the results (acceleration is measured in m/s^2) */ 161 | Serial.print("\t\tAccel X: "); 162 | Serial.print(accel.acceleration.x); 163 | Serial.print(" \tY: "); 164 | Serial.print(accel.acceleration.y); 165 | Serial.print(" \tZ: "); 166 | Serial.print(accel.acceleration.z); 167 | Serial.println(" m/s^2 "); 168 | 169 | /* Display the results (rotation is measured in rad/s) */ 170 | Serial.print("\t\tGyro X: "); 171 | Serial.print(gyro.gyro.x); 172 | Serial.print(" \tY: "); 173 | Serial.print(gyro.gyro.y); 174 | Serial.print(" \tZ: "); 175 | Serial.print(gyro.gyro.z); 176 | Serial.println(" radians/s "); 177 | Serial.println(); 178 | 179 | delay(100); 180 | 181 | // // serial plotter friendly format 182 | 183 | // Serial.print(temp.temperature); 184 | // Serial.print(","); 185 | 186 | // Serial.print(accel.acceleration.x); 187 | // Serial.print(","); Serial.print(accel.acceleration.y); 188 | // Serial.print(","); Serial.print(accel.acceleration.z); 189 | // Serial.print(","); 190 | 191 | // Serial.print(gyro.gyro.x); 192 | // Serial.print(","); Serial.print(gyro.gyro.y); 193 | // Serial.print(","); Serial.print(gyro.gyro.z); 194 | // Serial.println(); 195 | // delayMicroseconds(10000); 196 | } -------------------------------------------------------------------------------- /examples/adafruit_lsm6dsox_test/adafruit_lsm6dsox_test.ino: -------------------------------------------------------------------------------- 1 | // Basic demo for accelerometer & gyro readings from Adafruit 2 | // LSM6DSOX sensor 3 | 4 | #include 5 | 6 | // For SPI mode, we need a CS pin 7 | #define LSM_CS 10 8 | // For software-SPI mode we need SCK/MOSI/MISO pins 9 | #define LSM_SCK 13 10 | #define LSM_MISO 12 11 | #define LSM_MOSI 11 12 | 13 | Adafruit_LSM6DSOX sox; 14 | void setup(void) { 15 | Serial.begin(115200); 16 | while (!Serial) 17 | delay(10); // will pause Zero, Leonardo, etc until serial console opens 18 | 19 | Serial.println("Adafruit LSM6DSOX test!"); 20 | 21 | if (!sox.begin_I2C()) { 22 | // if (!sox.begin_SPI(LSM_CS)) { 23 | // if (!sox.begin_SPI(LSM_CS, LSM_SCK, LSM_MISO, LSM_MOSI)) { 24 | // Serial.println("Failed to find LSM6DSOX chip"); 25 | while (1) { 26 | delay(10); 27 | } 28 | } 29 | 30 | Serial.println("LSM6DSOX Found!"); 31 | 32 | // sox.setAccelRange(LSM6DS_ACCEL_RANGE_2_G); 33 | Serial.print("Accelerometer range set to: "); 34 | switch (sox.getAccelRange()) { 35 | case LSM6DS_ACCEL_RANGE_2_G: 36 | Serial.println("+-2G"); 37 | break; 38 | case LSM6DS_ACCEL_RANGE_4_G: 39 | Serial.println("+-4G"); 40 | break; 41 | case LSM6DS_ACCEL_RANGE_8_G: 42 | Serial.println("+-8G"); 43 | break; 44 | case LSM6DS_ACCEL_RANGE_16_G: 45 | Serial.println("+-16G"); 46 | break; 47 | } 48 | 49 | // sox.setGyroRange(LSM6DS_GYRO_RANGE_250_DPS ); 50 | Serial.print("Gyro range set to: "); 51 | switch (sox.getGyroRange()) { 52 | case LSM6DS_GYRO_RANGE_125_DPS: 53 | Serial.println("125 degrees/s"); 54 | break; 55 | case LSM6DS_GYRO_RANGE_250_DPS: 56 | Serial.println("250 degrees/s"); 57 | break; 58 | case LSM6DS_GYRO_RANGE_500_DPS: 59 | Serial.println("500 degrees/s"); 60 | break; 61 | case LSM6DS_GYRO_RANGE_1000_DPS: 62 | Serial.println("1000 degrees/s"); 63 | break; 64 | case LSM6DS_GYRO_RANGE_2000_DPS: 65 | Serial.println("2000 degrees/s"); 66 | break; 67 | case ISM330DHCX_GYRO_RANGE_4000_DPS: 68 | break; // unsupported range for the DSOX 69 | } 70 | 71 | // sox.setAccelDataRate(LSM6DS_RATE_12_5_HZ); 72 | Serial.print("Accelerometer data rate set to: "); 73 | switch (sox.getAccelDataRate()) { 74 | case LSM6DS_RATE_SHUTDOWN: 75 | Serial.println("0 Hz"); 76 | break; 77 | case LSM6DS_RATE_12_5_HZ: 78 | Serial.println("12.5 Hz"); 79 | break; 80 | case LSM6DS_RATE_26_HZ: 81 | Serial.println("26 Hz"); 82 | break; 83 | case LSM6DS_RATE_52_HZ: 84 | Serial.println("52 Hz"); 85 | break; 86 | case LSM6DS_RATE_104_HZ: 87 | Serial.println("104 Hz"); 88 | break; 89 | case LSM6DS_RATE_208_HZ: 90 | Serial.println("208 Hz"); 91 | break; 92 | case LSM6DS_RATE_416_HZ: 93 | Serial.println("416 Hz"); 94 | break; 95 | case LSM6DS_RATE_833_HZ: 96 | Serial.println("833 Hz"); 97 | break; 98 | case LSM6DS_RATE_1_66K_HZ: 99 | Serial.println("1.66 KHz"); 100 | break; 101 | case LSM6DS_RATE_3_33K_HZ: 102 | Serial.println("3.33 KHz"); 103 | break; 104 | case LSM6DS_RATE_6_66K_HZ: 105 | Serial.println("6.66 KHz"); 106 | break; 107 | } 108 | 109 | // sox.setGyroDataRate(LSM6DS_RATE_12_5_HZ); 110 | Serial.print("Gyro data rate set to: "); 111 | switch (sox.getGyroDataRate()) { 112 | case LSM6DS_RATE_SHUTDOWN: 113 | Serial.println("0 Hz"); 114 | break; 115 | case LSM6DS_RATE_12_5_HZ: 116 | Serial.println("12.5 Hz"); 117 | break; 118 | case LSM6DS_RATE_26_HZ: 119 | Serial.println("26 Hz"); 120 | break; 121 | case LSM6DS_RATE_52_HZ: 122 | Serial.println("52 Hz"); 123 | break; 124 | case LSM6DS_RATE_104_HZ: 125 | Serial.println("104 Hz"); 126 | break; 127 | case LSM6DS_RATE_208_HZ: 128 | Serial.println("208 Hz"); 129 | break; 130 | case LSM6DS_RATE_416_HZ: 131 | Serial.println("416 Hz"); 132 | break; 133 | case LSM6DS_RATE_833_HZ: 134 | Serial.println("833 Hz"); 135 | break; 136 | case LSM6DS_RATE_1_66K_HZ: 137 | Serial.println("1.66 KHz"); 138 | break; 139 | case LSM6DS_RATE_3_33K_HZ: 140 | Serial.println("3.33 KHz"); 141 | break; 142 | case LSM6DS_RATE_6_66K_HZ: 143 | Serial.println("6.66 KHz"); 144 | break; 145 | } 146 | } 147 | 148 | void loop() { 149 | 150 | // /* Get a new normalized sensor event */ 151 | sensors_event_t accel; 152 | sensors_event_t gyro; 153 | sensors_event_t temp; 154 | sox.getEvent(&accel, &gyro, &temp); 155 | 156 | Serial.print("\t\tTemperature "); 157 | Serial.print(temp.temperature); 158 | Serial.println(" deg C"); 159 | 160 | /* Display the results (acceleration is measured in m/s^2) */ 161 | Serial.print("\t\tAccel X: "); 162 | Serial.print(accel.acceleration.x); 163 | Serial.print(" \tY: "); 164 | Serial.print(accel.acceleration.y); 165 | Serial.print(" \tZ: "); 166 | Serial.print(accel.acceleration.z); 167 | Serial.println(" m/s^2 "); 168 | 169 | /* Display the results (rotation is measured in rad/s) */ 170 | Serial.print("\t\tGyro X: "); 171 | Serial.print(gyro.gyro.x); 172 | Serial.print(" \tY: "); 173 | Serial.print(gyro.gyro.y); 174 | Serial.print(" \tZ: "); 175 | Serial.print(gyro.gyro.z); 176 | Serial.println(" radians/s "); 177 | Serial.println(); 178 | 179 | delay(100); 180 | 181 | // // serial plotter friendly format 182 | 183 | // Serial.print(temp.temperature); 184 | // Serial.print(","); 185 | 186 | // Serial.print(accel.acceleration.x); 187 | // Serial.print(","); Serial.print(accel.acceleration.y); 188 | // Serial.print(","); Serial.print(accel.acceleration.z); 189 | // Serial.print(","); 190 | 191 | // Serial.print(gyro.gyro.x); 192 | // Serial.print(","); Serial.print(gyro.gyro.y); 193 | // Serial.print(","); Serial.print(gyro.gyro.z); 194 | // Serial.println(); 195 | // delayMicroseconds(10000); 196 | } -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=Adafruit LSM6DS 2 | version=4.7.4 3 | author=Adafruit 4 | maintainer=Adafruit 5 | sentence=Arduino library for the LSM6DS sensors in the Adafruit shop 6 | paragraph=Arduino library for the LSM6DS sensors in the Adafruit shop 7 | category=Sensors 8 | url=https://github.com/adafruit/Adafruit_LSM6DS 9 | architectures=* 10 | depends=Adafruit Unified Sensor, Adafruit BusIO 11 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | Software License Agreement (BSD License) 2 | 3 | Copyright (c) 2019 Bryan Siepert for Adafruit Industries 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of the copyright holders nor the 14 | names of its contributors may be used to endorse or promote products 15 | derived from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | --------------------------------------------------------------------------------