Skip to content
Permalink
Browse files

Add files and examples for X-NUCLEO-IKS01A2 and DISCO-IOT

  • Loading branch information...
cparata committed Sep 5, 2017
1 parent b313ec3 commit 8457418977f6aad7143fe254763dba2879602af3
Showing with 14,118 additions and 0 deletions.
  1. +28 −0 README.md
  2. +191 −0 examples/DISCO_IOT_6DOrientation/DISCO_IOT_6DOrientation.ino
  3. +106 −0 examples/DISCO_IOT_DoubleTap/DISCO_IOT_DoubleTap.ino
  4. +102 −0 examples/DISCO_IOT_FreeFall/DISCO_IOT_FreeFall.ino
  5. +95 −0 examples/DISCO_IOT_LSM6DSL_DataLog_Terminal/DISCO_IOT_LSM6DSL_DataLog_Terminal.ino
  6. +223 −0 examples/DISCO_IOT_MultiEvent/DISCO_IOT_MultiEvent.ino
  7. +122 −0 examples/DISCO_IOT_Pedometer/DISCO_IOT_Pedometer.ino
  8. +102 −0 examples/DISCO_IOT_Tap/DISCO_IOT_Tap.ino
  9. +102 −0 examples/DISCO_IOT_Tilt/DISCO_IOT_Tilt.ino
  10. +102 −0 examples/DISCO_IOT_WakeUp/DISCO_IOT_WakeUp.ino
  11. +193 −0 examples/X_NUCLEO_IKS01A2_6DOrientation/X_NUCLEO_IKS01A2_6DOrientation.ino
  12. +108 −0 examples/X_NUCLEO_IKS01A2_DoubleTap/X_NUCLEO_IKS01A2_DoubleTap.ino
  13. +104 −0 examples/X_NUCLEO_IKS01A2_FreeFall/X_NUCLEO_IKS01A2_FreeFall.ino
  14. +101 −0 examples/X_NUCLEO_IKS01A2_LSM6DSL_DataLogTerminal/X_NUCLEO_IKS01A2_LSM6DSL_DataLogTerminal.ino
  15. +242 −0 examples/X_NUCLEO_IKS01A2_MultiEvent/X_NUCLEO_IKS01A2_MultiEvent.ino
  16. +125 −0 examples/X_NUCLEO_IKS01A2_Pedometer/X_NUCLEO_IKS01A2_Pedometer.ino
  17. +104 −0 examples/X_NUCLEO_IKS01A2_Tap/X_NUCLEO_IKS01A2_Tap.ino
  18. +104 −0 examples/X_NUCLEO_IKS01A2_Tilt/X_NUCLEO_IKS01A2_Tilt.ino
  19. +104 −0 examples/X_NUCLEO_IKS01A2_WakeUp/X_NUCLEO_IKS01A2_WakeUp.ino
  20. +113 −0 keywords.txt
  21. +9 −0 library.properties
  22. +2,228 −0 src/LSM6DSLSensor.cpp
  23. +265 −0 src/LSM6DSLSensor.h
  24. +6,393 −0 src/LSM6DSL_ACC_GYRO_Driver.c
  25. +2,752 −0 src/LSM6DSL_ACC_GYRO_Driver.h
@@ -1,2 +1,30 @@
# LSM6DSL
Arduino library to support the LSM6DSL 3D accelerometer and 3D gyroscope

## API

This sensor uses I2C to communicate. It is then required to create a TwoWire interface before accessing to the sensors:

dev_i2c = new TwoWire(I2C2_SDA, I2C2_SCL);
dev_i2c->begin();

An instance can be created and enbaled following the procedure below:

AccGyr = new LSM6DSLSensor(dev_i2c);
AccGyr->Enable_X();
AccGyr->Enable_G();

The access to the sensor values is done as explained below:

Read accelerometer and gyroscope.

AccGyr->Get_X_Axes(accelerometer);
AccGyr->Get_G_Axes(gyroscope);

## Documentation

You can find the source files at
https://github.com/stm32duino/LSM6DSL

The LSM6DSL datasheet is available at
http://www.st.com/content/st_com/en/products/mems-and-sensors/inemo-inertial-modules/lsm6dsl.html
@@ -0,0 +1,191 @@
/**
******************************************************************************
* @file DISCO_IOT_6DOrientation.ino
* @author WI6LABS from AST
* @version V1.0.0
* @date 07 July 2017
* @brief Arduino test application for the STMicrolectronics STM32 IOT Discovery Kit.
* MEMS Inertial and Environmental sensor expansion board.
* This application detects 6D Orientation event through the LSM6DSL sensor.
* This application makes use of C++ classes obtained from the C
* components' drivers.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/


// Includes.
#include <LSM6DSLSensor.h>

#define SerialPort Serial
#define I2C2_SCL D33
#define I2C2_SDA D34

// Components.
LSM6DSLSensor *AccGyr;
TwoWire *dev_i2c;

//Interrupts.
volatile int mems_event = 0;

char report[256];

void INT1Event_cb();
void sendOrientation();

void setup() {
// Led.
pinMode(LED_BUILTIN, OUTPUT);

// Initialize serial for output.
SerialPort.begin(9600);

// Initialize I2C bus.
dev_i2c = new TwoWire(I2C2_SDA, I2C2_SCL);
dev_i2c->begin();

//Interrupts.
attachInterrupt(D49, INT1Event_cb, RISING);

// Initlialize Components.
AccGyr = new LSM6DSLSensor(dev_i2c, LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW);
AccGyr->Enable_X();

// Enable 6D Orientation.
AccGyr->Enable_6D_Orientation();
}

void loop() {
if (mems_event)
{
mems_event = 0;
LSM6DSL_Event_Status_t status;
AccGyr->Get_Event_Status(&status);
if (status.D6DOrientationStatus)
{
// Send 6D Orientation
sendOrientation();

// Led blinking.
digitalWrite(LED_BUILTIN, HIGH);
delay(100);
digitalWrite(LED_BUILTIN, LOW);
}
}
}

void INT1Event_cb()
{
mems_event = 1;
}

void sendOrientation()
{
uint8_t xl = 0;
uint8_t xh = 0;
uint8_t yl = 0;
uint8_t yh = 0;
uint8_t zl = 0;
uint8_t zh = 0;

AccGyr->Get_6D_Orientation_XL(&xl);
AccGyr->Get_6D_Orientation_XH(&xh);
AccGyr->Get_6D_Orientation_YL(&yl);
AccGyr->Get_6D_Orientation_YH(&yh);
AccGyr->Get_6D_Orientation_ZL(&zl);
AccGyr->Get_6D_Orientation_ZH(&zh);

if ( xl == 0 && yl == 0 && zl == 0 && xh == 0 && yh == 1 && zh == 0 )
{
sprintf( report, "\r\n ________________ " \
"\r\n | | " \
"\r\n | * | " \
"\r\n | | " \
"\r\n | | " \
"\r\n | | " \
"\r\n | | " \
"\r\n |________________| \r\n" );
}

else if ( xl == 1 && yl == 0 && zl == 0 && xh == 0 && yh == 0 && zh == 0 )
{
sprintf( report, "\r\n ________________ " \
"\r\n | | " \
"\r\n | * | " \
"\r\n | | " \
"\r\n | | " \
"\r\n | | " \
"\r\n | | " \
"\r\n |________________| \r\n" );
}

else if ( xl == 0 && yl == 0 && zl == 0 && xh == 1 && yh == 0 && zh == 0 )
{
sprintf( report, "\r\n ________________ " \
"\r\n | | " \
"\r\n | | " \
"\r\n | | " \
"\r\n | | " \
"\r\n | | " \
"\r\n | * | " \
"\r\n |________________| \r\n" );
}

else if ( xl == 0 && yl == 1 && zl == 0 && xh == 0 && yh == 0 && zh == 0 )
{
sprintf( report, "\r\n ________________ " \
"\r\n | | " \
"\r\n | | " \
"\r\n | | " \
"\r\n | | " \
"\r\n | | " \
"\r\n | * | " \
"\r\n |________________| \r\n" );
}

else if ( xl == 0 && yl == 0 && zl == 0 && xh == 0 && yh == 0 && zh == 1 )
{
sprintf( report, "\r\n __*_____________ " \
"\r\n |________________| \r\n" );
}

else if ( xl == 0 && yl == 0 && zl == 1 && xh == 0 && yh == 0 && zh == 0 )
{
sprintf( report, "\r\n ________________ " \
"\r\n |________________| " \
"\r\n * \r\n" );
}

else
{
sprintf( report, "None of the 6D orientation axes is set in LSM6DSL - accelerometer.\r\n" );
}

SerialPort.print(report);
}
@@ -0,0 +1,106 @@
/**
******************************************************************************
* @file DISCO_IOT_DoubleTap.ino
* @author WI6LABS FROM AST
* @version V1.0.0
* @date 7 July 2017
* @brief Arduino test application for the STMicrolectronics STM32 IOT Discovery Kit.
* MEMS Inertial and Environmental sensor expansion board.
* This application detects double tap event through the LSM6DSL sensor.
* This application makes use of C++ classes obtained from the C
* components' drivers.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/


// Includes.
#include <LSM6DSLSensor.h>

#define SerialPort Serial
#define I2C2_SCL D33
#define I2C2_SDA D34

// Components.
LSM6DSLSensor *AccGyr;
TwoWire *dev_i2c;

//Interrupts.
volatile int mems_event = 0;

void INT1Event_cb();

void setup() {
// Led.
pinMode(LED_BUILTIN, OUTPUT);

// Initialize serial for output.
SerialPort.begin(9600);

// Initialize I2C bus.
dev_i2c = new TwoWire(I2C2_SDA, I2C2_SCL);
dev_i2c->begin();

//Interrupts.
attachInterrupt(D49, INT1Event_cb, RISING);

// Initlialize Components.
AccGyr = new LSM6DSLSensor(dev_i2c, LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW);
AccGyr->Enable_X();

// Enable Double Tap Detection.
AccGyr->Enable_Double_Tap_Detection();
}

void loop() {
if (mems_event) {
mems_event = 0;
LSM6DSL_Event_Status_t status;
AccGyr->Get_Event_Status(&status);
if (status.DoubleTapStatus)
{
// Led blinking.
digitalWrite(LED_BUILTIN, HIGH);
delay(100);
digitalWrite(LED_BUILTIN, LOW);
delay(100);
digitalWrite(LED_BUILTIN, HIGH);
delay(100);
digitalWrite(LED_BUILTIN, LOW);

// Output data.
SerialPort.println("Double Tap Detected!");
}
}
}

void INT1Event_cb()
{
mems_event = 1;
}

0 comments on commit 8457418

Please sign in to comment.
You can’t perform that action at this time.