STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
example4_spi.ino
Go to the documentation of this file.
1
/*
2
example4-spi
3
4
This example shows the basic settings and functions for retrieving accelerometer
5
and gyroscopic data but using the SPI interface. Everything other than that is
6
identical to the "basic" example.
7
8
Please refer to the header file for more possible settings, found here:
9
..\SparkFun_6DoF_ISM330DHCX_Arduino_Library\src\sfe_ism330dhcx_defs.h
10
11
Written by Elias Santistevan @ SparkFun Electronics, August 2022
12
13
Products:
14
15
6DoF: https://www.sparkfun.com/products/19764
16
9DoF: https://www.sparkfun.com/products/19895
17
18
Repository:
19
20
https://github.com/sparkfun/SparkFun_6DoF_ISM330DHCX_Arduino_Library
21
22
SparkFun code, firmware, and software is released under the MIT
23
License (http://opensource.org/licenses/MIT).
24
*/
25
26
#include <
SPI.h
>
27
#include "
STAR_ISM330DH.h
"
28
29
// SPI instance class call
30
ISM330DH_SPI
myISM
;
31
32
// Structs for X,Y,Z data
33
sfe_ism_data_t
accelData
;
34
sfe_ism_data_t
gyroData
;
35
36
// Set your chip select pin according to your setup.
37
byte
chipSelect
= 1;
38
39
void
setup
(){
40
41
SPI.begin();
42
43
Serial
.begin(115200);
44
pinMode
(
chipSelect
,
OUTPUT
);
45
digitalWrite
(
chipSelect
,
HIGH
);
46
47
48
if
( !
myISM
.begin(
chipSelect
) ){
49
Serial
.println(
"Did not begin."
);
50
while
(1);
51
}
52
53
// Reset the device to default settings. This if helpful is you're doing multiple
54
// uploads testing different settings.
55
myISM
.deviceReset();
56
57
// Wait for it to finish reseting
58
while
( !
myISM
.getDeviceReset() ){
59
delay
(1);
60
}
61
62
Serial
.println(
"Reset."
);
63
Serial
.println(
"Applying settings."
);
64
delay
(100);
65
66
myISM
.setDeviceConfig();
67
myISM
.setBlockDataUpdate();
68
69
// Set the output data rate and precision of the accelerometer
70
myISM
.setAccelDataRate(
ISM_XL_ODR_104Hz
);
71
myISM
.setAccelFullScale(
ISM_4g
);
72
73
// Set the output data rate and precision of the gyroscope
74
myISM
.setGyroDataRate(
ISM_GY_ODR_104Hz
);
75
myISM
.setGyroFullScale(
ISM_500dps
);
76
77
// Turn on the accelerometer's filter and apply settings.
78
myISM
.setAccelFilterLP2();
79
myISM
.setAccelSlopeFilter(
ISM_LP_ODR_DIV_100
);
80
81
// Turn on the gyroscope's filter and apply settings.
82
myISM
.setGyroFilterLP1();
83
myISM
.setGyroLP1Bandwidth(
ISM_MEDIUM
);
84
85
86
87
}
88
89
void
loop
(){
90
91
// Check if both gyroscope and accelerometer data is available.
92
if
(
myISM
.checkStatus() ){
93
myISM
.getAccel(&
accelData
);
94
myISM
.getGyro(&
gyroData
);
95
Serial
.print(
"Accelerometer: "
);
96
Serial
.print(
"X: "
);
97
Serial
.print(
accelData
.xData);
98
Serial
.print(
" "
);
99
Serial
.print(
"Y: "
);
100
Serial
.print(
accelData
.yData);
101
Serial
.print(
" "
);
102
Serial
.print(
"Z: "
);
103
Serial
.print(
accelData
.zData);
104
Serial
.println(
" "
);
105
Serial
.print(
"Gyroscope: "
);
106
Serial
.print(
"X: "
);
107
Serial
.print(
gyroData
.xData);
108
Serial
.print(
" "
);
109
Serial
.print(
"Y: "
);
110
Serial
.print(
gyroData
.yData);
111
Serial
.print(
" "
);
112
Serial
.print(
"Z: "
);
113
Serial
.print(
gyroData
.zData);
114
Serial
.println(
" "
);
115
}
116
117
delay
(100);
118
}
119
Serial
static SerialStub Serial
Definition
Arduino.h:128
HIGH
#define HIGH
Definition
Arduino.h:19
pinMode
void pinMode(int, int)
Definition
Arduino.h:46
OUTPUT
#define OUTPUT
Definition
Arduino.h:22
digitalWrite
void digitalWrite(int, int)
Definition
Arduino.h:48
SPI.h
STAR_ISM330DH.h
delay
void delay(int ms)
Definition
actuator_nc.cpp:30
ISM330DH_SPI
SPI driver for ISM330DHCX.
Definition
STAR_ISM330DH.h:35
myISM
ISM330DH myISM
Definition
example1_basic.ino:26
setup
void setup()
Definition
example4_spi.ino:39
chipSelect
byte chipSelect
Definition
example4_spi.ino:37
loop
void loop()
Definition
example4_spi.ino:89
gyroData
static sfe_ism_data_t gyroData
Definition
main.cpp:10
accelData
static sfe_ism_data_t accelData
Definition
main.cpp:9
ISM_GY_ODR_104Hz
#define ISM_GY_ODR_104Hz
Definition
sfe_ism330dhcx_defs.h:34
ISM_MEDIUM
#define ISM_MEDIUM
Definition
sfe_ism330dhcx_defs.h:46
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_500dps
#define ISM_500dps
Definition
sfe_ism330dhcx_defs.h:10
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
example4_spi
example4_spi.ino
Generated by
1.15.0