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
27
28// Structs for X,Y,Z data
31
32void 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
78void 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
static SerialStub Serial
Definition Arduino.h:128
void delay(int ms)
STAR_ISM330DH — improved fork of SparkFun's SparkFun_6DoF_ISM330DHCX_Arduino_Library.
void setup()
ISM330DH myISM
void loop()
static sfe_ism_data_t gyroData
Definition main.cpp:10
static sfe_ism_data_t accelData
Definition main.cpp:9
#define ISM_GY_ODR_104Hz
#define ISM_MEDIUM
#define ISM_LP_ODR_DIV_100
#define ISM_4g
#define ISM_500dps
#define ISM_XL_ODR_104Hz