From 11ff3e77a818f40c41e3559c5c2688e24d05e0f9 Mon Sep 17 00:00:00 2001 From: Carlo Parata Date: Tue, 25 May 2021 17:10:22 +0200 Subject: [PATCH] Rename FIFO sketches and add Hello World sketch --- .../LSM6DSOX_FIFO_Interrupt.ino} | 10 +- .../LSM6DSOX_FIFO_Polling.ino} | 9 +- .../LSM6DSOX_HelloWorld.ino | 114 ++++++++++++++++++ 3 files changed, 131 insertions(+), 2 deletions(-) rename examples/{fifo_interrupt.ino => LSM6DSOX_FIFO_Interrupt/LSM6DSOX_FIFO_Interrupt.ino} (95%) rename examples/{fifo_polling.ino => LSM6DSOX_FIFO_Polling/LSM6DSOX_FIFO_Polling.ino} (95%) create mode 100644 examples/LSM6DSOX_HelloWorld/LSM6DSOX_HelloWorld.ino diff --git a/examples/fifo_interrupt.ino b/examples/LSM6DSOX_FIFO_Interrupt/LSM6DSOX_FIFO_Interrupt.ino similarity index 95% rename from examples/fifo_interrupt.ino rename to examples/LSM6DSOX_FIFO_Interrupt/LSM6DSOX_FIFO_Interrupt.ino index b97254f..70362a8 100644 --- a/examples/fifo_interrupt.ino +++ b/examples/LSM6DSOX_FIFO_Interrupt/LSM6DSOX_FIFO_Interrupt.ino @@ -1,6 +1,6 @@ /** ****************************************************************************** - * @file fifo_interrupt.ino + * @file LSM6DSOX_FIFO_Interrupt.ino * @author alvaro-oliver * @version V1.0.0 * @date May 2021 @@ -35,6 +35,14 @@ ****************************************************************************** */ +/* WIRING + In order to use the Adafruit lsm6dsox sensor with a ST nucleo board, + 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", + plug Nucleo "A0" to AdafruitLSM6DOX "I1".*/ + #include "LSM6DSOXSensor.h" #define SR 417.0f // Sample rate. Options are: 12.5, 26, 52, 104, 208, 417, 833, 1667, 3333 and 6667 Hz diff --git a/examples/fifo_polling.ino b/examples/LSM6DSOX_FIFO_Polling/LSM6DSOX_FIFO_Polling.ino similarity index 95% rename from examples/fifo_polling.ino rename to examples/LSM6DSOX_FIFO_Polling/LSM6DSOX_FIFO_Polling.ino index 4832123..e1832bb 100644 --- a/examples/fifo_polling.ino +++ b/examples/LSM6DSOX_FIFO_Polling/LSM6DSOX_FIFO_Polling.ino @@ -1,6 +1,6 @@ /** ****************************************************************************** - * @file fifo_polling.ino + * @file LSM6DSOX_FIFO_Polling.ino * @author alvaro-oliver * @version V1.0.1 * @date May 2021 @@ -35,6 +35,13 @@ ****************************************************************************** */ +/* WIRING + In order to use the Adafruit lsm6dsox sensor with a ST nucleo board, + 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".*/ + #include "LSM6DSOXSensor.h" #define SR 417 // Sample rate. Options are: 12.5, 26, 52, 104, 208, 417, 833, 1667, 3333 and 6667 Hz. diff --git a/examples/LSM6DSOX_HelloWorld/LSM6DSOX_HelloWorld.ino b/examples/LSM6DSOX_HelloWorld/LSM6DSOX_HelloWorld.ino new file mode 100644 index 0000000..09d5dab --- /dev/null +++ b/examples/LSM6DSOX_HelloWorld/LSM6DSOX_HelloWorld.ino @@ -0,0 +1,114 @@ +/** + ****************************************************************************** + @file LSM6DSOX_HelloWorld.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. + ****************************************************************************** +*/ + +/* WIRING + In order to use the Adafruit lsm6dsox sensor with a ST nucleo board, + 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".*/ + +#include "LSM6DSOXSensor.h" + +// 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); + Wire.begin(); + + // 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"); + } 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); + +} \ No newline at end of file