Skip to content

Commit 4f28202

Browse files
authored
Merge pull request #1 from davideq/main
first release
2 parents 9049938 + d14ddf8 commit 4f28202

File tree

13 files changed

+8496
-1
lines changed

13 files changed

+8496
-1
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: IIS2DULPX 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: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,50 @@
11
# IIS2DULPX
2-
Arduino library to support the IIS2DULPX intelligent ultralow-power accelerometer for industrial applications
2+
Arduino library to support the IIS2DULPX 3D sensor
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+
IIS2DULPXSensor sensor(&dev_i2c);
20+
sensor.begin();
21+
sensor.Enable_X();
22+
23+
An instance can be created and enabled when the SPI bus is used following the procedure below:
24+
25+
IIS2DULPXSensor sensor(&dev_spi, CS_PIN);
26+
sensor.begin();
27+
sensor.Enable_X();
28+
29+
The access to the sensor values is done as explained below:
30+
31+
Read sensor.
32+
33+
int32_t sensor[3];
34+
sensor.Get_X_Axes(sensor);
35+
36+
## Examples
37+
38+
* IIS2DULPX_DataLog_Terminal: This application shows how to get data from IIS2DULPX sensor and print them on terminal.
39+
40+
* IIS2DULPX_6D_Orientation: This application shows how to use IIS2DULPX sensor to find out the 6D orientation and display data on a hyperterminal.
41+
42+
* IIS2DULPX_Wake_Up_Detection: This application shows how to detect the wake-up event using the IIS2DULPX sensor.
43+
44+
## Documentation
45+
46+
You can find the source files at
47+
https://github.com/stm32duino/IIS2DULPX
48+
49+
The IIS2DULPX datasheet is available at
50+
https://www.st.com/en/mems-and-sensors/iis2dulpx.html
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/*
2+
@file IIS2DULPX_6D_Orientation.ino
3+
@author STMicroelectronics
4+
@brief Example to use the IIS2DULPX 6D Orientation
5+
*******************************************************************************
6+
Copyright (c) 2025, STMicroelectronics
7+
All rights reserved.
8+
This software component is licensed by ST under BSD 3-Clause license,
9+
the "License"; You may not use this file except in compliance with the
10+
License. You may obtain a copy of the License at:
11+
opensource.org/licenses/BSD-3-Clause
12+
*******************************************************************************
13+
*/
14+
#include <IIS2DULPXSensor.h>
15+
16+
#define INT1_pin A2
17+
18+
IIS2DULPXSensor IIS2DULPX(&Wire);
19+
// Interrupts.
20+
volatile int mems_event = 0;
21+
22+
char report[256];
23+
24+
void INT1Event_cb();
25+
void sendOrientation();
26+
27+
void setup()
28+
{
29+
30+
// Initialize serial.
31+
Serial.begin(115200);
32+
delay(1000);
33+
34+
// Initialize LED.
35+
pinMode(LED_BUILTIN, OUTPUT);
36+
37+
// Initialize I2C.
38+
Wire.begin();
39+
40+
// Enable INT1 pin.
41+
attachInterrupt(INT1_pin, INT1Event_cb, RISING);
42+
43+
// Initialize components.
44+
IIS2DULPX.begin();
45+
IIS2DULPX.Enable_X();
46+
// Enable 6D Orientation.
47+
IIS2DULPXStatusTypeDef ret = IIS2DULPX.Enable_6D_Orientation(IIS2DULPX_INT1_PIN);
48+
}
49+
50+
void loop()
51+
{
52+
if (true) {
53+
mems_event = 0;
54+
55+
// Initialize the structure to zero at the beginning of each loop using memset
56+
IIS2DULPX_Event_Status_t status;
57+
memset(&status, 0, sizeof(IIS2DULPX_Event_Status_t));
58+
59+
IIS2DULPX.Get_X_Event_Status(&status);
60+
61+
if (status.D6DOrientationStatus) {
62+
// Send 6D Orientation
63+
sendOrientation();
64+
65+
// LED blinking.
66+
digitalWrite(LED_BUILTIN, HIGH);
67+
delay(100);
68+
digitalWrite(LED_BUILTIN, LOW);
69+
}
70+
}
71+
}
72+
73+
void INT1Event_cb()
74+
{
75+
mems_event = 1;
76+
}
77+
void sendOrientation()
78+
{
79+
uint8_t xl = 0;
80+
uint8_t xh = 0;
81+
uint8_t yl = 0;
82+
uint8_t yh = 0;
83+
uint8_t zl = 0;
84+
uint8_t zh = 0;
85+
86+
IIS2DULPX.Get_6D_Orientation_XL(&xl);
87+
IIS2DULPX.Get_6D_Orientation_XH(&xh);
88+
IIS2DULPX.Get_6D_Orientation_YL(&yl);
89+
IIS2DULPX.Get_6D_Orientation_YH(&yh);
90+
IIS2DULPX.Get_6D_Orientation_ZL(&zl);
91+
IIS2DULPX.Get_6D_Orientation_ZH(&zh);
92+
93+
if (xl == 1 && yl == 0 && zl == 0 && xh == 0 && yh == 0 && zh == 0) {
94+
sprintf(report, "\r\n ________________ " \
95+
"\r\n | | " \
96+
"\r\n | * | " \
97+
"\r\n | | " \
98+
"\r\n | | " \
99+
"\r\n | | " \
100+
"\r\n | | " \
101+
"\r\n |________________| \r\n");
102+
}
103+
104+
else if (xl == 0 && yl == 1 && zl == 0 && xh == 0 && yh == 0 && zh == 0) {
105+
sprintf(report, "\r\n ________________ " \
106+
"\r\n | | " \
107+
"\r\n | * | " \
108+
"\r\n | | " \
109+
"\r\n | | " \
110+
"\r\n | | " \
111+
"\r\n | | " \
112+
"\r\n |________________| \r\n");
113+
}
114+
115+
else if (xl == 0 && yl == 0 && zl == 0 && xh == 0 && yh == 1 && zh == 0) {
116+
sprintf(report, "\r\n ________________ " \
117+
"\r\n | | " \
118+
"\r\n | | " \
119+
"\r\n | | " \
120+
"\r\n | | " \
121+
"\r\n | | " \
122+
"\r\n | * | " \
123+
"\r\n |________________| \r\n");
124+
}
125+
126+
else if (xl == 0 && yl == 0 && zl == 0 && xh == 1 && yh == 0 && zh == 0) {
127+
sprintf(report, "\r\n ________________ " \
128+
"\r\n | | " \
129+
"\r\n | | " \
130+
"\r\n | | " \
131+
"\r\n | | " \
132+
"\r\n | | " \
133+
"\r\n | * | " \
134+
"\r\n |________________| \r\n");
135+
}
136+
137+
else if (xl == 0 && yl == 0 && zl == 0 && xh == 0 && yh == 0 && zh == 1) {
138+
sprintf(report, "\r\n __*_____________ " \
139+
"\r\n |________________| \r\n");
140+
}
141+
142+
else if (xl == 0 && yl == 0 && zl == 1 && xh == 0 && yh == 0 && zh == 0) {
143+
sprintf(report, "\r\n ________________ " \
144+
"\r\n |________________| " \
145+
"\r\n * \r\n");
146+
}
147+
148+
else {
149+
sprintf(report, "None of the 6D orientation axes is set in accelerometer.\r\n");
150+
}
151+
152+
Serial.print(report);
153+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
@file IIS2DULPX_DataLog_Terminal.ino
3+
@author STMicroelectronics
4+
@brief Example to use the IIS2DULPX accelerometer sensor (X-axis only)
5+
*******************************************************************************
6+
Copyright (c) 2025, STMicroelectronics
7+
All rights reserved.
8+
This software component is licensed by ST under BSD 3-Clause license,
9+
the "License"; You may not use this file except in compliance with the
10+
License. You may obtain a copy of the License at:
11+
opensource.org/licenses/BSD-3-Clause
12+
*******************************************************************************
13+
*/
14+
15+
#include <IIS2DULPXSensor.h>
16+
17+
// Create an instance of the IIS2DULPX sensor
18+
IIS2DULPXSensor sensor(&Wire);
19+
20+
void setup()
21+
{
22+
// Initialize LED for status indication
23+
pinMode(LED_BUILTIN, OUTPUT);
24+
25+
// Initialize serial for output
26+
Serial.begin(115200);
27+
28+
// Initialize bus interface
29+
Wire.begin();
30+
31+
// Initialize the sensor
32+
if (sensor.begin() != IIS2DULPX_OK) {
33+
Serial.println("Failed to initialize IIS2DULPX sensor!");
34+
while (1);
35+
}
36+
37+
// Enable the accelerometer
38+
if (sensor.Enable_X() != IIS2DULPX_OK) {
39+
Serial.println("Failed to enable accelerometer!");
40+
while (1);
41+
}
42+
Serial.println("IIS2DULPX sensor initialized and accelerometer enabled.");
43+
}
44+
45+
void loop()
46+
{
47+
IIS2DULPX_Axes_t accel;
48+
// Get X-axis acceleration data
49+
if (sensor.Get_X_Axes(&accel) == IIS2DULPX_OK) {
50+
Serial.print("Accel-X [mg]: ");
51+
Serial.print(accel.x);
52+
Serial.print(",Accel-Y[mg]:");
53+
Serial.print(accel.y);
54+
Serial.print(",Accel-Z[mg]:");
55+
Serial.println(accel.z);
56+
// Led blinking.
57+
digitalWrite(LED_BUILTIN, HIGH);
58+
delay(100);
59+
digitalWrite(LED_BUILTIN, LOW);
60+
} else {
61+
Serial.println("Failed to read acceleration data!");
62+
}
63+
}
64+

0 commit comments

Comments
 (0)