STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
example2_interrupt.ino
Go to the documentation of this file.
1
/*
2
example2-interrupt
3
4
This example shows the basic settings and functions for retrieving accelerometer
5
data. In addition we're setting the data ready signal to interrupt pin one in an
6
active high configuration and show additional ways in which the interrupts
7
can be configured.
8
9
Please refer to the header file for more possible settings, found here:
10
..\SparkFun_6DoF_ISM330DHCX_Arduino_Library\src\sfe_ism330dhcx_defs.h
11
12
Written by Elias Santistevan @ SparkFun Electronics, August 2022
13
14
Product:
15
16
6DoF: https://www.sparkfun.com/products/19764
17
9DoF: https://www.sparkfun.com/products/19895
18
19
Repository:
20
21
https://github.com/sparkfun/SparkFun_6DoF_ISM330DHCX_Arduino_Library
22
23
SparkFun code, firmware, and software is released under the MIT
24
License (http://opensource.org/licenses/MIT).
25
*/
26
27
#include <Wire.h>
28
#include "
STAR_ISM330DH.h
"
29
30
// Structs for X,Y,Z data
31
ISM330DH
myISM
;
32
sfe_ism_data_t
accelData
;
33
34
35
// Interrupt pin
36
byte
interrupt_pin
= D1;
37
38
void
setup
(){
39
40
// Set the interrupt to INPUT
41
pinMode
(
interrupt_pin
,
INPUT
);
42
Serial
.begin(115200);
43
44
Wire.begin();
45
46
if
( !
myISM
.begin() ){
47
Serial
.println(
"Did not begin."
);
48
while
(1);
49
}
50
51
// Reset the device to default settings. This is helpful if you're doing multiple
52
// uploads testing different settings.
53
myISM
.deviceReset();
54
55
// Wait for it to finish reseting
56
while
( !
myISM
.getDeviceReset() ){
57
delay
(1);
58
}
59
60
Serial
.println(
"Reset."
);
61
Serial
.println(
"Applying settings."
);
62
delay
(100);
63
64
myISM
.setDeviceConfig();
65
myISM
.setBlockDataUpdate();
66
67
// Set the output data rate and precision of the accelerometer
68
myISM
.setAccelDataRate(
ISM_XL_ODR_104Hz
);
69
myISM
.setAccelFullScale(
ISM_4g
);
70
71
// Turn on the accelerometer's filter and apply settings.
72
myISM
.setAccelFilterLP2();
73
myISM
.setAccelSlopeFilter(
ISM_LP_ODR_DIV_100
);
74
75
// Set the accelerometer's status i.e. the data ready to interrupt one.
76
// Commented out just below is the function to send the data ready
77
// to interrupt two.
78
79
myISM
.setAccelStatustoInt1();
80
//myISM.setAccelStatustoInt2();
81
82
83
// We can just as easily set the gyroscope's data read signal to either interrupt
84
85
//myISM.setGyroStatustoInt1();
86
//myISM.setGyroStatustoInt2();
87
88
89
// Uncommenting the function call below will change the interrupt to
90
// active LOW instead of HIGH.
91
92
//myISM.setPinMode();
93
94
// This function call will modify which "events" trigger an interrupt. No
95
// argument has been given, please refer to the datasheet for more
96
// information.
97
98
// myISM.setIntNotification(uint8_t val);
99
}
100
101
void
loop
(){
102
103
if
(
digitalRead
(
interrupt_pin
) ==
HIGH
){
104
myISM
.getAccel(&
accelData
);
105
Serial
.print(
"Accelerometer: "
);
106
Serial
.print(
"X: "
);
107
Serial
.print(
accelData
.xData);
108
Serial
.print(
" "
);
109
Serial
.print(
"Y: "
);
110
Serial
.print(
accelData
.yData);
111
Serial
.print(
" "
);
112
Serial
.print(
"Z: "
);
113
Serial
.print(
accelData
.zData);
114
Serial
.println(
" "
);
115
}
116
117
delay
(100);
118
}
119
Serial
static SerialStub Serial
Definition
Arduino.h:128
INPUT
#define INPUT
Definition
Arduino.h:21
digitalRead
int digitalRead(int)
Definition
Arduino.h:50
HIGH
#define HIGH
Definition
Arduino.h:19
pinMode
void pinMode(int, int)
Definition
Arduino.h:46
STAR_ISM330DH.h
delay
void delay(int ms)
Definition
actuator_nc.cpp:30
ISM330DH
STAR_ISM330DH — improved fork of SparkFun's SparkFun_6DoF_ISM330DHCX_Arduino_Library.
Definition
STAR_ISM330DH.h:14
myISM
ISM330DH myISM
Definition
example1_basic.ino:26
setup
void setup()
Definition
example2_interrupt.ino:38
interrupt_pin
byte interrupt_pin
Definition
example2_interrupt.ino:36
loop
void loop()
Definition
example2_interrupt.ino:101
accelData
static sfe_ism_data_t accelData
Definition
main.cpp:9
ISM_LP_ODR_DIV_100
#define ISM_LP_ODR_DIV_100
Definition
sfe_ism330dhcx_defs.h:79
ISM_4g
#define ISM_4g
Definition
sfe_ism330dhcx_defs.h:4
ISM_XL_ODR_104Hz
#define ISM_XL_ODR_104Hz
Definition
sfe_ism330dhcx_defs.h:20
sfe_ism_data_t
Definition
sfe_ism330dhcx.h:17
firmware
libraries
STAR_ISM330DH
examples
example2_interrupt
example2_interrupt.ino
Generated by
1.15.0