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