Skip to content

Commit 28d2aca

Browse files
committed
First release
1 parent 2825525 commit 28d2aca

File tree

24 files changed

+18884
-0
lines changed

24 files changed

+18884
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: LSM6DSV16BX Continuous Integration
2+
on:
3+
push:
4+
branches:
5+
- main
6+
paths-ignore:
7+
- '*'
8+
- '**.md'
9+
- '**.txt'
10+
pull_request:
11+
paths-ignore:
12+
- '*'
13+
- '**.md'
14+
- '**.txt'
15+
jobs:
16+
astyle_check:
17+
runs-on: ubuntu-latest
18+
name: AStyle check
19+
steps:
20+
# First of all, clone the repo using the checkout action.
21+
- name: Checkout
22+
uses: actions/checkout@main
23+
24+
- name: Astyle check
25+
id: Astyle
26+
uses: stm32duino/actions/astyle-check@main
27+
28+
# Use the output from the `Astyle` step
29+
- name: Astyle Errors
30+
if: failure()
31+
run: |
32+
cat ${{ steps.Astyle.outputs.astyle-result }}
33+
exit 1
34+
codespell:
35+
name: Check for spelling errors
36+
runs-on: ubuntu-latest
37+
steps:
38+
- name: Checkout
39+
uses: actions/checkout@main
40+
41+
# See: https://github.com/codespell-project/actions-codespell/blob/master/README.md
42+
- name: Spell check
43+
uses: codespell-project/actions-codespell@master
44+
with:
45+
check_filenames: true
46+
check_hidden: true
47+
# In the event of a false positive, add the word in all lower case to this file:
48+
ignore_words_file: ./extras/codespell-ignore-words-list.txt
49+
lib_build:
50+
runs-on: ubuntu-latest
51+
name: Library compilation
52+
steps:
53+
54+
# First of all, clone the repo using the checkout action.
55+
- name: Checkout
56+
uses: actions/checkout@main
57+
58+
- name: Compilation
59+
id: compile
60+
uses: stm32duino/actions/compile-examples@main
61+
with:
62+
board-pattern: "NUCLEO_L476RG"
63+
64+
# Use the output from the `Compilation` step
65+
- name: Compilation Errors
66+
if: failure()
67+
run: |
68+
cat ${{ steps.compile.outputs.compile-result }}
69+
exit 1

README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,78 @@
11
# LSM6DSV16BX
22
Arduino library to support the LSM6DSV16BX 3D accelerometer and 3D gyroscope
3+
4+
## API
5+
6+
This sensor uses I2C or SPI to communicate.
7+
For I2C it is then required to create a TwoWire interface before accessing to the sensors:
8+
9+
TwoWire dev_i2c(I2C_SDA, I2C_SCL);
10+
dev_i2c.begin();
11+
12+
For SPI it is then required to create a SPI interface before accessing to the sensors:
13+
14+
SPIClass dev_spi(SPI_MOSI, SPI_MISO, SPI_SCK);
15+
dev_spi.begin();
16+
17+
An instance can be created and enabled when the I2C bus is used following the procedure below:
18+
19+
LSM6DSV16BXSensor AccGyr(&dev_i2c);
20+
AccGyr.begin();
21+
AccGyr.Enable_X();
22+
AccGyr.Enable_G();
23+
24+
An instance can be created and enabled when the SPI bus is used following the procedure below:
25+
26+
LSM6DSV16BXSensor AccGyr(&dev_spi, CS_PIN);
27+
AccGyr.begin();
28+
AccGyr.Enable_X();
29+
AccGyr.Enable_G();
30+
31+
The access to the sensor values is done as explained below:
32+
33+
Read accelerometer and gyroscope.
34+
35+
int32_t accelerometer[3];
36+
int32_t gyroscope[3];
37+
AccGyr.Get_X_Axes(accelerometer);
38+
AccGyr.Get_G_Axes(gyroscope);
39+
40+
## Examples
41+
42+
* LSM6DSV16BX_DataLog_Terminal: This application shows how to get data from LSM6DSV16BX accelerometer and gyroscope and print them on terminal.
43+
44+
* LSM6DSV16BX_6D_Orientation: This application shows how to use LSM6DSV16BX accelerometer to find out the 6D orientation and display data on a hyperterminal.
45+
46+
* LSM6DSV16BX_Double_Tap_Detection: This application shows how to detect the double tap event using the LSM6DSV16BX accelerometer.
47+
48+
* LSM6DSV16BX_Free_Fall_Detection: This application shows how to detect the free fall event using the LSM6DSV16BX accelerometer.
49+
50+
* LSM6DSV16BX_MLC: This application shows how to detect the activity using the LSM6DSV16BX Machine Learning Core.
51+
52+
* LSM6DSV16BX_Pedometer: This application shows how to use LSM6DSV16BX accelerometer to count steps.
53+
54+
* LSM6DSV16BX_Qvar_Polling: This application shows how to use LSM6DSV16BX Qvar features in polling mode.
55+
56+
* LSM6DSV16BX_Sensor_Fusion: This application shows how to use LSM6DSV16BX Sensor Fusion features for reading quaternions.
57+
58+
* LSM6DSV16BX_Single_Tap_Detection: This application shows how to detect the single tap event using the LSM6DSV16BX accelerometer.
59+
60+
* LSM6DSV16BX_Tilt_Detection: This application shows how to detect the tilt event using the LSM6DSV16BX accelerometer.
61+
62+
* LSM6DSV16BX_Wake_Up_Detection: This application shows how to detect the wake-up event using the LSM6DSV16BX accelerometer.
63+
64+
* LSM6DSV16BX_FIFO_Polling: This application shows how to get accelerometer and gyroscope data from FIFO in pooling mode and print them on terminal.
65+
66+
* LSM6DSV16BX_FIFO_Interrupt: This application shows how to get accelerometer and gyroscope data from FIFO using interrupt and print them on terminal.
67+
68+
* LSM6DSV16BX_Test_IMU: This application shows how to perform the accelerometer and gyroscope test.
69+
70+
* LSM6DSV16BX_Temperature: This application shows how to get temperature data from LSM6DSV16BX sensor.
71+
72+
## Documentation
73+
74+
You can find the source files at
75+
https://github.com/stm32duino/LSM6DSV16BX
76+
77+
The LSM6DSV16BX datasheet is available at
78+
https://www.st.com/content/st_com/en/products/mems-and-sensors/inemo-inertial-modules/lsm6dsv16bx.html
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
2+
#include <LSM6DSV16BXSensor.h>
3+
4+
#define INT_1 A5
5+
6+
//I2C_ADD_L for compatibility with X-NUCLEO-IKS01A3
7+
LSM6DSV16BXSensor LSM6DSV16BX(&Wire, LSM6DSV16BX_I2C_ADD_L);
8+
9+
//Interrupts.
10+
volatile int mems_event = 0;
11+
12+
char report[256];
13+
14+
void INT1Event_cb();
15+
void sendOrientation();
16+
17+
void setup()
18+
{
19+
// Initlialize serial.
20+
Serial.begin(115200);
21+
delay(1000);
22+
23+
// Initlialize Led.
24+
pinMode(LED_BUILTIN, OUTPUT);
25+
26+
// Initlialize i2c.
27+
Wire.begin();
28+
29+
// Enable INT1 pin.
30+
attachInterrupt(INT_1, INT1Event_cb, RISING);
31+
32+
// Initlialize components.
33+
LSM6DSV16BX.begin();
34+
LSM6DSV16BX.Enable_X();
35+
36+
// Enable 6D Orientation.
37+
LSM6DSV16BX.Enable_6D_Orientation(LSM6DSV16BX_INT1_PIN);
38+
}
39+
40+
void loop()
41+
{
42+
if (mems_event) {
43+
mems_event = 0;
44+
LSM6DSV16BX_Event_Status_t status;
45+
LSM6DSV16BX.Get_X_Event_Status(&status);
46+
47+
if (status.D6DOrientationStatus) {
48+
// Send 6D Orientation
49+
sendOrientation();
50+
51+
// Led blinking.
52+
digitalWrite(LED_BUILTIN, HIGH);
53+
delay(100);
54+
digitalWrite(LED_BUILTIN, LOW);
55+
}
56+
}
57+
}
58+
59+
void INT1Event_cb()
60+
{
61+
mems_event = 1;
62+
}
63+
64+
void sendOrientation()
65+
{
66+
uint8_t xl = 0;
67+
uint8_t xh = 0;
68+
uint8_t yl = 0;
69+
uint8_t yh = 0;
70+
uint8_t zl = 0;
71+
uint8_t zh = 0;
72+
73+
LSM6DSV16BX.Get_6D_Orientation_XL(&xl);
74+
LSM6DSV16BX.Get_6D_Orientation_XH(&xh);
75+
LSM6DSV16BX.Get_6D_Orientation_YL(&yl);
76+
LSM6DSV16BX.Get_6D_Orientation_YH(&yh);
77+
LSM6DSV16BX.Get_6D_Orientation_ZL(&zl);
78+
LSM6DSV16BX.Get_6D_Orientation_ZH(&zh);
79+
80+
if (xl == 0 && yl == 0 && zl == 0 && xh == 0 && yh == 1 && zh == 0) {
81+
sprintf(report, "\r\n ________________ " \
82+
"\r\n | | " \
83+
"\r\n | * | " \
84+
"\r\n | | " \
85+
"\r\n | | " \
86+
"\r\n | | " \
87+
"\r\n | | " \
88+
"\r\n |________________| \r\n");
89+
}
90+
91+
else if (xl == 1 && yl == 0 && zl == 0 && xh == 0 && yh == 0 && zh == 0) {
92+
sprintf(report, "\r\n ________________ " \
93+
"\r\n | | " \
94+
"\r\n | * | " \
95+
"\r\n | | " \
96+
"\r\n | | " \
97+
"\r\n | | " \
98+
"\r\n | | " \
99+
"\r\n |________________| \r\n");
100+
}
101+
102+
else if (xl == 0 && yl == 0 && zl == 0 && xh == 1 && yh == 0 && zh == 0) {
103+
sprintf(report, "\r\n ________________ " \
104+
"\r\n | | " \
105+
"\r\n | | " \
106+
"\r\n | | " \
107+
"\r\n | | " \
108+
"\r\n | | " \
109+
"\r\n | * | " \
110+
"\r\n |________________| \r\n");
111+
}
112+
113+
else if (xl == 0 && yl == 1 && zl == 0 && xh == 0 && yh == 0 && zh == 0) {
114+
sprintf(report, "\r\n ________________ " \
115+
"\r\n | | " \
116+
"\r\n | | " \
117+
"\r\n | | " \
118+
"\r\n | | " \
119+
"\r\n | | " \
120+
"\r\n | * | " \
121+
"\r\n |________________| \r\n");
122+
}
123+
124+
else if (xl == 0 && yl == 0 && zl == 0 && xh == 0 && yh == 0 && zh == 1) {
125+
sprintf(report, "\r\n __*_____________ " \
126+
"\r\n |________________| \r\n");
127+
}
128+
129+
else if (xl == 0 && yl == 0 && zl == 1 && xh == 0 && yh == 0 && zh == 0) {
130+
sprintf(report, "\r\n ________________ " \
131+
"\r\n |________________| " \
132+
"\r\n * \r\n");
133+
}
134+
135+
else {
136+
sprintf(report, "None of the 6D orientation axes is set in accelerometer.\r\n");
137+
}
138+
139+
Serial.print(report);
140+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
#include <LSM6DSV16BXSensor.h>
3+
4+
#define INT_1 A5
5+
6+
//I2C_ADD_L for compatibility with X-NUCLEO-IKS01A3
7+
LSM6DSV16BXSensor sensor(&Wire, LSM6DSV16BX_I2C_ADD_L);
8+
9+
int32_t accGyro[3];
10+
11+
void setup()
12+
{
13+
pinMode(LED_BUILTIN, OUTPUT);
14+
15+
//PULL DOWN for compatibility with X-NUCLEO-IKS01A3
16+
pinMode(INT_1, OUTPUT);
17+
digitalWrite(INT_1, LOW);
18+
19+
Serial.begin(115200);
20+
Wire.begin();
21+
22+
sensor.begin();
23+
sensor.Enable_X();
24+
sensor.Enable_G();
25+
}
26+
27+
void loop()
28+
{
29+
digitalWrite(LED_BUILTIN, HIGH);
30+
delay(250);
31+
digitalWrite(LED_BUILTIN, LOW);
32+
delay(250);
33+
34+
sensor.Get_X_Axes(accGyro);
35+
36+
Serial.print("Accel X[mg]:");
37+
Serial.print(accGyro[0]);
38+
Serial.print(" Y[mg]:");
39+
Serial.print(accGyro[1]);
40+
Serial.print(" Z[mg]:");
41+
Serial.println(accGyro[2]);
42+
43+
sensor.Get_G_Axes(accGyro);
44+
Serial.print("AngRate X[mdps]:");
45+
Serial.print(accGyro[0]);
46+
Serial.print(" Y[mdps]:");
47+
Serial.print(accGyro[1]);
48+
Serial.print(" Z[mdps]:");
49+
Serial.println(accGyro[2]);
50+
51+
Serial.println("");
52+
}

0 commit comments

Comments
 (0)