From cca02ca15848d62c6b91eac5f79d9d0d4e9f1a47 Mon Sep 17 00:00:00 2001 From: Benhalor Date: Thu, 21 Jan 2021 20:56:57 +0100 Subject: [PATCH 1/4] Create file basic example for i2c --- .../LSM6DOX_basic_example_i2c.ino | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 examples/LSM6DOX_basic_example_i2c/LSM6DOX_basic_example_i2c.ino diff --git a/examples/LSM6DOX_basic_example_i2c/LSM6DOX_basic_example_i2c.ino b/examples/LSM6DOX_basic_example_i2c/LSM6DOX_basic_example_i2c.ino new file mode 100644 index 0000000..f9c1ab0 --- /dev/null +++ b/examples/LSM6DOX_basic_example_i2c/LSM6DOX_basic_example_i2c.ino @@ -0,0 +1,106 @@ +/** + ****************************************************************************** + * @file LSM6DSOX_basic_example_i2c.ino + * @author Benhalor + * @version V1.0.0 + * @date January 2020 + * @brief Basic example for using the LSM6DSOX library . + ****************************************************************************** + * @attention + * + *

© COPYRIGHT(c) 2019 STMicroelectronics

+ * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + +#include "LSM6DSOXSensor.h" + +LSM6DSOXSensor lsm6dsoxSensor = LSM6DSOXSensor(&Wire); + +void setup() { + Serial.begin(115200); + Wire.begin(); + + // Default clock is 100kHz. LSM6DSOX also supports 400kHz, let's use it + Wire.setClock(400000); + + // Enable accelerometer and gyroscope, and check success + if (lsm6dsoxSensor.Enable_X() == LSM6DSOX_OK && lsm6dsoxSensor.Enable_X() == LSM6DSOX_OK) { + Serial.println("Success enabling accelero and gyro"); + } else { + Serial.println("Error enabling accelero and gyro"); + } + + // Read ID of device and check that it is correct + uint8_t id; + lsm6dsoxSensor.ReadID(&id); + if (id != LSM6DSOX_ID) { + Serial.println("Wrong ID for LSM6DSOX sensor. Check that device is plugged"); + } else { + Serial.println("Receviced correct ID for LSM6DSOX sensor"); + } + + // Set accelerometer scale at +- 2G. Available values are +- 2, 4, 8, 16 G + lsm6dsoxSensor.Set_X_FS(2); + + // Set gyroscope scale at +- 125 degres per second. Available values are +- 125, 250, 500, 1000, 2000 dps + lsm6dsoxSensor.Set_G_FS(125); + + + // Set Accelerometer sample rate to 208 Hz. Available values are +- 12.0, 26.0, 52.0, 104.0, 208.0, 416.0, 833.0, 1667.0, 3333.0, 6667.0 Hz + lsm6dsoxSensor.Set_X_ODR(208.0f); + + + // Set Gyroscope sample rate to 208 Hz. Available values are +- 12.0, 26.0, 52.0, 104.0, 208.0, 416.0, 833.0, 1667.0, 3333.0, 6667.0 Hz + lsm6dsoxSensor.Set_G_ODR(208.0f); + + +} + +void loop() { + + // Read accelerometer + uint8_t acceleroStatus; + lsm6dsoxSensor.Get_X_DRDY_Status(&acceleroStatus); + if (acceleroStatus == 1){ // Status == 1 means a new data is available + int32_t acceleration[3]; + lsm6dsoxSensor.Get_X_Axes(acceleration); + // Plot data for each axe in mg + Serial.print("AccelerationX=");Serial.print(acceleration[0]);Serial.print("mg, AccelerationY=");Serial.print(acceleration[1]);Serial.print("mg, AccelerationZ=");Serial.print(acceleration[2]);Serial.println("mg"); + } + + // Read gyroscope + uint8_t gyroStatus; + lsm6dsoxSensor.Get_G_DRDY_Status(&gyroStatus); + if (gyroStatus == 1){ // Status == 1 means a new data is available + int32_t rotation[3]; + lsm6dsoxSensor.Get_X_Axes(rotation); + // Plot data for each axe in milli degres per second + Serial.print("RotationX=");Serial.print(rotation[0]);Serial.print("mdps, RotationY=");Serial.print(rotation[1]);Serial.print("mdps, RotationZ=");Serial.print(rotation[2]);Serial.println("mdps"); + } + + delay(10); + +} From 9da16032bb876de3e5d29256897eaeb31948ec1b Mon Sep 17 00:00:00 2001 From: Benhalor Date: Thu, 21 Jan 2021 21:14:33 +0100 Subject: [PATCH 2/4] Create basic i2c fifo example --- .../LSM6DOX_fifo_example_i2c.ino | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 examples/LSM6DOX_fifo_example_i2c/LSM6DOX_fifo_example_i2c.ino diff --git a/examples/LSM6DOX_fifo_example_i2c/LSM6DOX_fifo_example_i2c.ino b/examples/LSM6DOX_fifo_example_i2c/LSM6DOX_fifo_example_i2c.ino new file mode 100644 index 0000000..f723b53 --- /dev/null +++ b/examples/LSM6DOX_fifo_example_i2c/LSM6DOX_fifo_example_i2c.ino @@ -0,0 +1,137 @@ +/** + ****************************************************************************** + @file LSM6DSOX_fifo_example_i2c.ino + @author Benhalor + @version V1.0.0 + @date January 2020 + @brief Basic example for using the LSM6DSOX library with FIFO. + ****************************************************************************** + @attention + +

© COPYRIGHT(c) 2019 STMicroelectronics

+ + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + 3. Neither the name of STMicroelectronics nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + ****************************************************************************** +*/ + +#include "LSM6DSOXSensor.h" + +LSM6DSOXSensor lsm6dsoxSensor = LSM6DSOXSensor(&Wire); + +void setup() { + Serial.begin(115200); + Wire.begin(); + + // Default clock is 100kHz. LSM6DSOX also supports 400kHz, let's use it + Wire.setClock(400000); + + // Enable accelerometer and gyroscope, and check success + if (lsm6dsoxSensor.Enable_X() == LSM6DSOX_OK && lsm6dsoxSensor.Enable_X() == LSM6DSOX_OK) { + Serial.println("Success enabling accelero and gyro"); + } else { + Serial.println("Error enabling accelero and gyro"); + } + + // Read ID of device and check that it is correct + uint8_t id; + lsm6dsoxSensor.ReadID(&id); + if (id != LSM6DSOX_ID) { + Serial.println("Wrong ID for LSM6DSOX sensor. Check that device is plugged"); + } else { + Serial.println("Receviced correct ID for LSM6DSOX sensor"); + } + + // Set accelerometer scale at +- 2G. Available values are +- 2, 4, 8, 16 G + lsm6dsoxSensor.Set_X_FS(2); + + // Set gyroscope scale at +- 125 degres per second. Available values are +- 125, 250, 500, 1000, 2000 dps + lsm6dsoxSensor.Set_G_FS(125); + + + // Set Accelerometer sample rate to 52 Hz. Available values are +- 12.0, 26.0, 52.0, 104.0, 208.0, 416.0, 833.0, 1667.0, 3333.0, 6667.0 Hz + lsm6dsoxSensor.Set_X_ODR(52.0f); + + + // Set Gyroscope sample rate to 52 Hz. Available values are +- 12.0, 26.0, 52.0, 104.0, 208.0, 416.0, 833.0, 1667.0, 3333.0, 6667.0 Hz + lsm6dsoxSensor.Set_G_ODR(52.0f); + + // Set FIFO batch data rate for each sensor. Available values are +- 12.0, 26.0, 52.0, 104.0, 208.0, 416.0, 833.0, 1667.0, 3333.0, 6667.0 Hz + lsm6dsoxSensor.Set_FIFO_X_BDR(52.0f); + lsm6dsoxSensor.Set_FIFO_G_BDR(52.0f); + + // Setup Watermark : the max number of sensor values in the FIFO. + lsm6dsoxSensor.Set_FIFO_Watermark_Level(200u); + // Enable the watermark + lsm6dsoxSensor.Set_FIFO_Stop_On_Fth(1); + + // Set FIFO to continuous mode. Continuous mode provides a continuous FIFO update: as new data arrives, the older data is discarded. + lsm6dsoxSensor.Set_FIFO_Mode(LSM6DSOX_STREAM_MODE); +} + +void loop() { + + // Given the 52Hz batch data rate, for both accelero,and gyro, aroud 2000ms will be required to reach the 200 watermark threshold. + delay(2000); + + uint8_t fifoStatus = 0; + uint16_t NumSamples = 0; + uint8_t Tag; + int32_t acceleration[3]; + int32_t rotation[3]; + + // Check that FIFO is full. + lsm6dsoxSensor.Get_FIFO_Full_Status(&fifoStatus); + if (fifoStatus == 0) { + Serial.println("Accelero Gyro sensor : Data is not ready. Waiting for data"); + Serial.print("Accelero Gyro sensor : Number of available samples :"); + Serial.println(NumSamples); + } + while (fifoStatus == 0) { // If not full, wait unit FIFO is full + lsm6dsoxSensor.Get_FIFO_Full_Status(&fifoStatus); + } + + for (int32_t i = 0; i < 200; i++) { + // both accelerometer and gyroscope write in the FIFO. Before reading a data from the FIFO, the first step is to check the TAG of this data + lsm6dsoxSensor.Get_FIFO_Tag(&Tag); + + // Tag 1 corresponds to Gyroscope data + if (Tag == 1u) { + lsm6dsoxSensor.Get_FIFO_G_Axes(rotation); + // Plot data for each axe in milli degres per second + Serial.print("RotationX="); Serial.print(rotation[0]); Serial.print("mdps, RotationY="); Serial.print(rotation[1]); Serial.print("mdps, RotationZ="); Serial.print(rotation[2]); Serial.println("mdps"); + + } + + // Tag 2 corresponds to Accelerometer data + else if (Tag == 2u) { + lsm6dsoxSensor.Get_FIFO_X_Axes(acceleration); + // Plot data for each axe in mg + Serial.print("AccelerationX="); Serial.print(acceleration[0]); Serial.print("mg, AccelerationY="); Serial.print(acceleration[1]); Serial.print("mg, AccelerationZ="); Serial.print(acceleration[2]); Serial.println("mg"); + } + } + + + + +} From 346a458c7817724ed0d038cd0140bd0437614fef Mon Sep 17 00:00:00 2001 From: Benhalor Date: Fri, 22 Jan 2021 22:30:33 +0100 Subject: [PATCH 3/4] Use begin method, and add comments about wiring --- .../LSM6DOX_basic_example_i2c.ino | 96 +++++++++++-------- .../LSM6DOX_fifo_example_i2c.ino | 16 +++- 2 files changed, 68 insertions(+), 44 deletions(-) diff --git a/examples/LSM6DOX_basic_example_i2c/LSM6DOX_basic_example_i2c.ino b/examples/LSM6DOX_basic_example_i2c/LSM6DOX_basic_example_i2c.ino index f9c1ab0..c175ec8 100644 --- a/examples/LSM6DOX_basic_example_i2c/LSM6DOX_basic_example_i2c.ino +++ b/examples/LSM6DOX_basic_example_i2c/LSM6DOX_basic_example_i2c.ino @@ -1,43 +1,52 @@ /** ****************************************************************************** - * @file LSM6DSOX_basic_example_i2c.ino - * @author Benhalor - * @version V1.0.0 - * @date January 2020 - * @brief Basic example for using the LSM6DSOX library . + @file LSM6DSOX_basic_example_i2c.ino + @author Benhalor + @version V1.0.1 + @date January 2020 + @brief Basic example for using the LSM6DSOX library . ****************************************************************************** - * @attention - * - *

© COPYRIGHT(c) 2019 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + @attention + +

© COPYRIGHT(c) 2019 STMicroelectronics

+ + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + 3. Neither the name of STMicroelectronics nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ****************************************************************************** - */ +*/ + +/* WIRING + In order to use the Adafruit lsm6dsox sensor with a ST nucleo board, + plug Nucleo "+5V" to AdafruitLSM6DOX "VIN", + plug Nucleo "GND" to AdafruitLSM6DOX "GND", + plug Nucleo "SCL"(D15) to AdafruitLSM6DOX "SCL", + plug Nucleo "SDA"(D14) to AdafruitLSM6DOX "SDA".*/ #include "LSM6DSOXSensor.h" -LSM6DSOXSensor lsm6dsoxSensor = LSM6DSOXSensor(&Wire); +// Declare LSM6DSOX sensor. Sensor address can have 2 values LSM6DSOX_I2C_ADD_L (corresponds to 0x6A I2C address) or LSM6DSOX_I2C_ADD_H (corresponds to 0x6B I2C address) +// On Adafruit lsm6dsox sensor, LSM6DSOX_I2C_ADD_L is the default address +LSM6DSOXSensor lsm6dsoxSensor = LSM6DSOXSensor(&Wire, LSM6DSOX_I2C_ADD_L); void setup() { Serial.begin(115200); @@ -45,7 +54,10 @@ void setup() { // Default clock is 100kHz. LSM6DSOX also supports 400kHz, let's use it Wire.setClock(400000); - + + // Init the sensor + lsm6dsoxSensor.begin(); + // Enable accelerometer and gyroscope, and check success if (lsm6dsoxSensor.Enable_X() == LSM6DSOX_OK && lsm6dsoxSensor.Enable_X() == LSM6DSOX_OK) { Serial.println("Success enabling accelero and gyro"); @@ -64,18 +76,18 @@ void setup() { // Set accelerometer scale at +- 2G. Available values are +- 2, 4, 8, 16 G lsm6dsoxSensor.Set_X_FS(2); - + // Set gyroscope scale at +- 125 degres per second. Available values are +- 125, 250, 500, 1000, 2000 dps lsm6dsoxSensor.Set_G_FS(125); - + // Set Accelerometer sample rate to 208 Hz. Available values are +- 12.0, 26.0, 52.0, 104.0, 208.0, 416.0, 833.0, 1667.0, 3333.0, 6667.0 Hz lsm6dsoxSensor.Set_X_ODR(208.0f); - + // Set Gyroscope sample rate to 208 Hz. Available values are +- 12.0, 26.0, 52.0, 104.0, 208.0, 416.0, 833.0, 1667.0, 3333.0, 6667.0 Hz lsm6dsoxSensor.Set_G_ODR(208.0f); - + } @@ -84,21 +96,21 @@ void loop() { // Read accelerometer uint8_t acceleroStatus; lsm6dsoxSensor.Get_X_DRDY_Status(&acceleroStatus); - if (acceleroStatus == 1){ // Status == 1 means a new data is available + if (acceleroStatus == 1) { // Status == 1 means a new data is available int32_t acceleration[3]; lsm6dsoxSensor.Get_X_Axes(acceleration); // Plot data for each axe in mg - Serial.print("AccelerationX=");Serial.print(acceleration[0]);Serial.print("mg, AccelerationY=");Serial.print(acceleration[1]);Serial.print("mg, AccelerationZ=");Serial.print(acceleration[2]);Serial.println("mg"); + Serial.print("AccelerationX="); Serial.print(acceleration[0]); Serial.print("mg, AccelerationY="); Serial.print(acceleration[1]); Serial.print("mg, AccelerationZ="); Serial.print(acceleration[2]); Serial.println("mg"); } // Read gyroscope uint8_t gyroStatus; lsm6dsoxSensor.Get_G_DRDY_Status(&gyroStatus); - if (gyroStatus == 1){ // Status == 1 means a new data is available + if (gyroStatus == 1) { // Status == 1 means a new data is available int32_t rotation[3]; lsm6dsoxSensor.Get_X_Axes(rotation); // Plot data for each axe in milli degres per second - Serial.print("RotationX=");Serial.print(rotation[0]);Serial.print("mdps, RotationY=");Serial.print(rotation[1]);Serial.print("mdps, RotationZ=");Serial.print(rotation[2]);Serial.println("mdps"); + Serial.print("RotationX="); Serial.print(rotation[0]); Serial.print("mdps, RotationY="); Serial.print(rotation[1]); Serial.print("mdps, RotationZ="); Serial.print(rotation[2]); Serial.println("mdps"); } delay(10); diff --git a/examples/LSM6DOX_fifo_example_i2c/LSM6DOX_fifo_example_i2c.ino b/examples/LSM6DOX_fifo_example_i2c/LSM6DOX_fifo_example_i2c.ino index f723b53..a33141d 100644 --- a/examples/LSM6DOX_fifo_example_i2c/LSM6DOX_fifo_example_i2c.ino +++ b/examples/LSM6DOX_fifo_example_i2c/LSM6DOX_fifo_example_i2c.ino @@ -2,7 +2,7 @@ ****************************************************************************** @file LSM6DSOX_fifo_example_i2c.ino @author Benhalor - @version V1.0.0 + @version V1.0.1 @date January 2020 @brief Basic example for using the LSM6DSOX library with FIFO. ****************************************************************************** @@ -35,9 +35,18 @@ ****************************************************************************** */ +/* WIRING + In order to use the Adafruit lsm6dsox sensor with a ST nucleo board, + plug Nucleo "+5V" to AdafruitLSM6DOX "VIN", + plug Nucleo "GND" to AdafruitLSM6DOX "GND", + plug Nucleo "SCL"(D15) to AdafruitLSM6DOX "SCL", + plug Nucleo "SDA"(D14) to AdafruitLSM6DOX "SDA".*/ + #include "LSM6DSOXSensor.h" -LSM6DSOXSensor lsm6dsoxSensor = LSM6DSOXSensor(&Wire); +// Declare LSM6DSOX sensor. Sensor address can have 2 values LSM6DSOX_I2C_ADD_L (corresponds to 0x6A I2C address) or LSM6DSOX_I2C_ADD_H (corresponds to 0x6B I2C address) +// On Adafruit lsm6dsox board, LSM6DSOX_I2C_ADD_L is the default address +LSM6DSOXSensor lsm6dsoxSensor = LSM6DSOXSensor(&Wire, LSM6DSOX_I2C_ADD_L); void setup() { Serial.begin(115200); @@ -46,6 +55,9 @@ void setup() { // Default clock is 100kHz. LSM6DSOX also supports 400kHz, let's use it Wire.setClock(400000); + // Init the sensor + lsm6dsoxSensor.begin(); + // Enable accelerometer and gyroscope, and check success if (lsm6dsoxSensor.Enable_X() == LSM6DSOX_OK && lsm6dsoxSensor.Enable_X() == LSM6DSOX_OK) { Serial.println("Success enabling accelero and gyro"); From 519df105ef1f3589799865fac2cfeed32e32932b Mon Sep 17 00:00:00 2001 From: Benhalor Date: Sun, 24 Jan 2021 16:26:44 +0100 Subject: [PATCH 4/4] change nucleo board voltage --- .../LSM6DOX_basic_example_i2c/LSM6DOX_basic_example_i2c.ino | 2 +- examples/LSM6DOX_fifo_example_i2c/LSM6DOX_fifo_example_i2c.ino | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/LSM6DOX_basic_example_i2c/LSM6DOX_basic_example_i2c.ino b/examples/LSM6DOX_basic_example_i2c/LSM6DOX_basic_example_i2c.ino index c175ec8..d43d1d7 100644 --- a/examples/LSM6DOX_basic_example_i2c/LSM6DOX_basic_example_i2c.ino +++ b/examples/LSM6DOX_basic_example_i2c/LSM6DOX_basic_example_i2c.ino @@ -37,7 +37,7 @@ /* WIRING In order to use the Adafruit lsm6dsox sensor with a ST nucleo board, - plug Nucleo "+5V" to AdafruitLSM6DOX "VIN", + plug Nucleo "+3.3V" to AdafruitLSM6DOX "VIN", plug Nucleo "GND" to AdafruitLSM6DOX "GND", plug Nucleo "SCL"(D15) to AdafruitLSM6DOX "SCL", plug Nucleo "SDA"(D14) to AdafruitLSM6DOX "SDA".*/ diff --git a/examples/LSM6DOX_fifo_example_i2c/LSM6DOX_fifo_example_i2c.ino b/examples/LSM6DOX_fifo_example_i2c/LSM6DOX_fifo_example_i2c.ino index a33141d..cc7842c 100644 --- a/examples/LSM6DOX_fifo_example_i2c/LSM6DOX_fifo_example_i2c.ino +++ b/examples/LSM6DOX_fifo_example_i2c/LSM6DOX_fifo_example_i2c.ino @@ -37,7 +37,7 @@ /* WIRING In order to use the Adafruit lsm6dsox sensor with a ST nucleo board, - plug Nucleo "+5V" to AdafruitLSM6DOX "VIN", + plug Nucleo "+3.3V" to AdafruitLSM6DOX "VIN", plug Nucleo "GND" to AdafruitLSM6DOX "GND", plug Nucleo "SCL"(D15) to AdafruitLSM6DOX "SCL", plug Nucleo "SDA"(D14) to AdafruitLSM6DOX "SDA".*/