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
31
32// Structs for X,Y,Z data
35
36// Set your chip select pin according to your setup.
37byte chipSelect = 1;
38
39void setup(){
40
41 SPI.begin();
42
43 Serial.begin(115200);
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
89void 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
static SerialStub Serial
Definition Arduino.h:128
#define HIGH
Definition Arduino.h:19
void pinMode(int, int)
Definition Arduino.h:46
#define OUTPUT
Definition Arduino.h:22
void digitalWrite(int, int)
Definition Arduino.h:48
void delay(int ms)
SPI driver for ISM330DHCX.
ISM330DH myISM
void setup()
byte chipSelect
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