Skip to content

Commit bcb4e58

Browse files
authored
Merge pull request #2 from davideq/main
Add ISPU examples
2 parents c491c30 + 3bacd79 commit bcb4e58

File tree

7 files changed

+24424
-0
lines changed

7 files changed

+24424
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ The access to the sensor values is done as explained below:
4141

4242
* ISM330IS_DataLog_Terminal: This application shows how to get data from ISM330IS accelerometer and gyroscope and print them on terminal.
4343

44+
* ISM330IS_ISPU_Sensor_Fusion: This application implements the sensor fusion of the accelerometer and gyroscope, configured in high-performance mode at 104 Hz. The configuration generates an interrupt on INT1 when the quaternion for the new sample is computed and available in the output registers.
45+
46+
* ISM330IS_SPU_Tap: This application implements the tap detection solution based on the accelerometer data. The configuration generates an interrupt on INT1 when the tap event for the new sample is computed and available in the output registers.
4447
## Documentation
4548

4649
You can find the source files at
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
@file ISM330IS_ISPU_Sensor_Fusion.ino
3+
@author STMicroelectronics
4+
@brief Example to use the ISM330IS ISPU Sensor Fusion of the accelerometer and gyroscope, configured in high-performance mode at 104 Hz.
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+
/*
16+
* You can display the quaternion values with a 3D model connecting for example to this link:
17+
* https://adafruit.github.io/Adafruit_WebSerial_3DModelViewer/
18+
*/
19+
20+
// Includes
21+
#include "ISM330ISSensor.h"
22+
#include "sensor_fusion.h"
23+
24+
#define INT_1 A5
25+
26+
//Interrupts.
27+
volatile int mems_event = 0;
28+
29+
ISM330ISSensor sensor(&Wire);
30+
ucf_line_ext_t *ProgramPointer;
31+
int32_t LineCounter;
32+
int32_t TotalNumberOfLine;
33+
void INT1Event_cb();
34+
35+
union data {
36+
uint8_t raw_data[16];
37+
float_t values[4];
38+
};
39+
40+
void setup()
41+
{
42+
// Led.
43+
pinMode(LED_BUILTIN, OUTPUT);
44+
45+
// Initialize serial for output.
46+
Serial.begin(115200);
47+
48+
// Initlialize i2c.
49+
Wire.begin();
50+
51+
// Initlialize components.
52+
sensor.begin();
53+
sensor.Enable_X();
54+
sensor.Enable_G();
55+
56+
// Feed the program to ISPU
57+
ProgramPointer = (ucf_line_ext_t *)ispu_conf;
58+
TotalNumberOfLine = sizeof(ispu_conf) / sizeof(ucf_line_ext_t);
59+
Serial.println("ISM330IS ISPU Sensor Fusion");
60+
Serial.print("UCF Number Line=");
61+
Serial.println(TotalNumberOfLine);
62+
63+
for (LineCounter = 0; LineCounter < TotalNumberOfLine; LineCounter++) {
64+
if (ProgramPointer[LineCounter].op == MEMS_UCF_OP_WRITE) {
65+
if (sensor.Write_Reg(ProgramPointer[LineCounter].address, ProgramPointer[LineCounter].data)) {
66+
Serial.print("Error loading the Program to ISM330ISSensor at line: ");
67+
Serial.println(LineCounter);
68+
while (1) {
69+
// Led blinking.
70+
digitalWrite(LED_BUILTIN, HIGH);
71+
delay(250);
72+
digitalWrite(LED_BUILTIN, LOW);
73+
delay(250);
74+
}
75+
}
76+
} else if (ProgramPointer[LineCounter].op == MEMS_UCF_OP_DELAY) {
77+
delay(ProgramPointer[LineCounter].data);
78+
}
79+
}
80+
Serial.println("Program loaded inside the ISM330IS ISPU");
81+
//Interrupts.
82+
pinMode(INT_1, INPUT);
83+
attachInterrupt(INT_1, INT1Event_cb, RISING);
84+
}
85+
86+
void loop()
87+
{
88+
union data quaternions;
89+
// When the quaternion for the new sample is computed and available in the output registers an interrupt is generated.
90+
if (mems_event) {
91+
ISM330IS_ISPU_Status_t ispu_status;
92+
mems_event = 0;
93+
sensor.Get_ISPU_Status(&ispu_status);
94+
// Check if the ISPU event is from the algo00.
95+
if (ispu_status.ia_ispu_0) {
96+
// Read quaternions and print them.
97+
sensor.Read_ISPU_Output(ISM330IS_ISPU_DOUT_00_L, &quaternions.raw_data[0], 16);
98+
Serial.print("Quaternion: ");
99+
Serial.print(quaternions.values[3], 4);
100+
Serial.print(", ");
101+
Serial.print(-quaternions.values[1], 4);
102+
Serial.print(", ");
103+
Serial.print(quaternions.values[0], 4);
104+
Serial.print(", ");
105+
Serial.println(quaternions.values[2], 4);
106+
}
107+
}
108+
}
109+
110+
void INT1Event_cb()
111+
{
112+
mems_event = 1;
113+
}

0 commit comments

Comments
 (0)