Skip to content

Commit 8b80d2f

Browse files
committed
Adds comments to examples
1 parent 2a2ccba commit 8b80d2f

File tree

4 files changed

+169
-25
lines changed

4 files changed

+169
-25
lines changed

examples/example1_basic/example1_basic.ino

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,31 @@
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+
123
#include <Wire.h>
224
#include "SparkFun_ISM330DHCX.h"
325

426
SparkFun_ISM330DHCX myISM;
27+
28+
// Structs for X,Y,Z data
529
sfe_ism_data_t accelData;
630
sfe_ism_data_t gyroData;
731

@@ -16,8 +40,11 @@ void setup(){
1640
while(1);
1741
}
1842

43+
// Reset the device to default settings. This if helpful is you're doing multiple
44+
// uploads testing different settings.
1945
myISM.deviceReset();
2046

47+
// Wait for it to finish reseting
2148
while( !myISM.getDeviceReset() ){
2249
delay(1);
2350
}
@@ -29,15 +56,19 @@ void setup(){
2956
myISM.setDeviceConfig();
3057
myISM.setBlockDataUpdate();
3158

59+
// Set the output data rate and precision of the accelerometer
3260
myISM.setAccelDataRate(ISM_XL_ODR_104Hz);
3361
myISM.setAccelFullScale(ISM_4g);
3462

35-
myISM.setGyroFullScale(ISM_500dps);
63+
// Set the output data rate and precision of the gyroscope
3664
myISM.setGyroDataRate(ISM_GY_ODR_104Hz);
65+
myISM.setGyroFullScale(ISM_500dps);
3766

67+
// Turn on the accelerometer's filter and apply settings.
3868
myISM.setAccelFilterLP2();
3969
myISM.setAccelSlopeFilter(ISM_LP_ODR_DIV_100);
4070

71+
// Turn on the gyroscope's filter and apply settings.
4172
myISM.setGyroFilterLP1();
4273
myISM.setGyroLP1Bandwidth(ISM_MEDIUM);
4374

@@ -46,6 +77,7 @@ void setup(){
4677

4778
void loop(){
4879

80+
// Check if both gyroscope and accelerometer data is available.
4981
if( myISM.checkStatus() ){
5082
myISM.getAccel(&accelData);
5183
myISM.getGyro(&gyroData);

examples/example2_interrupt/example2_interrupt.ino

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,43 @@
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+
127
#include <Wire.h>
228
#include "SparkFun_ISM330DHCX.h"
329

30+
// Structs for X,Y,Z data
431
SparkFun_ISM330DHCX myISM;
532
sfe_ism_data_t accelData;
6-
sfe_ism_data_t gyroData;
733

834

35+
// Interrupt pin
936
byte interrupt_pin = D1;
1037

1138
void setup(){
1239

40+
// Set the interrupt to INPUT
1341
pinMode(interrupt_pin, INPUT);
1442
Serial.begin(115200);
1543

@@ -20,8 +48,11 @@ void setup(){
2048
while(1);
2149
}
2250

51+
// Reset the device to default settings. This is helpful if you're doing multiple
52+
// uploads testing different settings.
2353
myISM.deviceReset();
2454

55+
// Wait for it to finish reseting
2556
while( !myISM.getDeviceReset() ){
2657
delay(1);
2758
}
@@ -33,35 +64,44 @@ void setup(){
3364
myISM.setDeviceConfig();
3465
myISM.setBlockDataUpdate();
3566

36-
// Accelerometer config and enable
67+
// Set the output data rate and precision of the accelerometer
3768
myISM.setAccelDataRate(ISM_XL_ODR_104Hz);
3869
myISM.setAccelFullScale(ISM_4g);
3970

40-
/// Accelerometer filter settings
71+
// Turn on the accelerometer's filter and apply settings.
4172
myISM.setAccelFilterLP2();
4273
myISM.setAccelSlopeFilter(ISM_LP_ODR_DIV_100);
4374

44-
// Accelerometer Interrupt Settings
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+
4579
myISM.setAccelStatustoInt1();
4680
//myISM.setAccelStatustoInt2();
4781

48-
// Gyro config and enable
49-
//myISM.setGyroDataRate(ISM_GY_ODR_104Hz);
50-
//myISM.setGyroFullScale(ISM_500dps);
5182

52-
// Gyro Interrupt Settings
83+
// We can just as easily set the gyroscope's data read signal to either interrupt
84+
5385
//myISM.setGyroStatustoInt1();
5486
//myISM.setGyroStatustoInt2();
5587

5688

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.
5797

98+
// myISM.setIntNotification(uint8_t val);
5899
}
59100

60101
void loop(){
61102

62103
if( digitalRead(interrupt_pin) == HIGH ){
63104
myISM.getAccel(&accelData);
64-
// myISM.getGyro(&gyroData);
65105
Serial.print("Accelerometer: ");
66106
Serial.print("X: ");
67107
Serial.print(accelData.xData);
@@ -72,16 +112,6 @@ void loop(){
72112
Serial.print("Z: ");
73113
Serial.print(accelData.zData);
74114
Serial.println(" ");
75-
Serial.print("Gyroscope: ");
76-
Serial.print("X: ");
77-
Serial.print(gyroData.xData);
78-
Serial.print(" ");
79-
Serial.print("Y: ");
80-
Serial.print(gyroData.yData);
81-
Serial.print(" ");
82-
Serial.print("Z: ");
83-
Serial.print(gyroData.zData);
84-
Serial.println(" ");
85115
}
86116

87117
delay(100);

examples/example3_sensor_hub/example3_sensor_hub.ino

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,59 @@
1+
/*
2+
example3-sensor_hub
3+
4+
This example demonstrates the "sensor hub" feature of the ISM330DHCX.
5+
The ISM330DHCX acts as a controller for external sensors connected to this
6+
alternate bus (SDX/SCX). In this example, the ISM330DHCX is connected to the
7+
MMC5983MA Magnetometer. You might notice that we have a 9DoF with these two
8+
parts but not in this configuration. The reason is that the magnetometer requires
9+
an initiate measurement bit to be flipped before every reading, while this is
10+
possible (it's demonstrated below) it's also not ideal for this setup. A more
11+
ideal setup would be a sensor that is just turned on and data is pulled
12+
periodically.
13+
14+
Written by Elias Santistevan @ SparkFun Electronics, August 2022
15+
16+
Product:
17+
18+
6DoF: https://www.sparkfun.com/products/19764
19+
9DoF: https://www.sparkfun.com/products/19895
20+
21+
Repository:
22+
23+
https://github.com/sparkfun/SparkFun_6DoF_ISM330DHCX_Arduino_Library
24+
25+
SparkFun code, firmware, and software is released under the MIT
26+
License (http://opensource.org/licenses/MIT).
27+
*/
28+
129
#include <Wire.h>
230
#include "SparkFun_ISM330DHCX.h"
331

4-
// 8 bit addressing for Sensor Hub
32+
// 8 bit addressing is required for the 6DoF
33+
// to communicate with its' external sensors.
534
#define MAG_ADDR_READ 0x61 // (0x30 << 1) | 1)
635
#define MAG_ADDR_WRITE 0x60 // (0x30 << 1)
736

837
#define MAG_READ_REG 0x00 // Read from 0x00
938
#define MAG_READ_LEN 0x07 // Read seven times consecutively
10-
#define MAG_WRITE_REG 0x09 // INT_CTRL0 - register to initiate measurements on Magnetometer
39+
40+
// INT_CTRL0 (0x09) - contains the bit to initiate measurement.
41+
// It must be written before each read and is cleared automatically.
42+
#define MAG_WRITE_REG 0x09
1143
#define MAG_WRITE_DATA 0x01 // Value to write to INT_CTRL0
1244

1345
SparkFun_ISM330DHCX myISM;
1446

47+
// Structs for X,Y,Z data
1548
sfe_ism_data_t accelData;
1649
sfe_ism_data_t gyroData;
1750

18-
// Settings for sensor hub
51+
// The settings for the sensor hub have three specific fields.
52+
// In addition there are different settings for reads and writes as
53+
// indicated above.
1954
sfe_hub_sensor_settings_t readMMC, writeMMC;
2055

56+
// Magnetometer data fields.
2157
uint8_t shRawData[MAG_READ_LEN] = {};
2258
unsigned int magXVal;
2359
unsigned int magYVal;
@@ -30,10 +66,12 @@ double normalizedZ;
3066
void setup(){
3167

3268

69+
// Sensor hub settings for writing to the magnetometer.
3370
writeMMC.address = MAG_ADDR_WRITE;
3471
writeMMC.subAddress = MAG_WRITE_REG;
3572
writeMMC.lenData = MAG_WRITE_DATA;
3673

74+
// Sensor hub settings for reading from the magnetometer.
3775
readMMC.address = MAG_ADDR_READ;
3876
readMMC.subAddress = MAG_READ_REG;
3977
readMMC.lenData = MAG_READ_LEN;
@@ -47,9 +85,12 @@ void setup(){
4785
while(1);
4886
}
4987

88+
// Reset the device and the sensor hub to default settings.
89+
// This is helpful if you're doing multiple uploads testing different settings.
5090
myISM.deviceReset();
5191
myISM.resetSensorHub();
5292

93+
// Wait for it to finish reseting
5394
while( !myISM.getDeviceReset() ){
5495
delay(1);
5596
}
@@ -104,12 +145,16 @@ void loop(){
104145
myISM.getAccel(&accelData);
105146
myISM.getGyro(&gyroData);
106147

148+
// If you've given the 6DoF the wrong address for the external sensor, this
149+
// bit will tell you. The zero argument is the external sensor to check (0-3).
107150
if( myISM.getExternalSensorNack(0) )
108151
Serial.println("MMC Nacked...");
109152

153+
// CHeck if the sensor hub is finished.
110154
if( myISM.getHubStatus() )
111155
{
112156

157+
// Get the data stored in the 6DoF's registers.
113158
myISM.readPeripheralSensor(shRawData, (uint8_t)MAG_READ_LEN);
114159

115160
// Shift raw data
@@ -146,6 +191,7 @@ void loop(){
146191
myISM.setHubSensorRead(0, &readMMC);
147192
myISM.enableSensorI2C(true);
148193

194+
// Turn the accelerometer and gyrocope back on.
149195
myISM.setAccelDataRate(ISM_XL_ODR_104Hz);
150196
myISM.setGyroDataRate(ISM_GY_ODR_104Hz);
151197

@@ -197,7 +243,6 @@ bool writeControlBit(sfe_hub_sensor_settings_t toWrite)
197243

198244
// Wait for write to complete
199245
while( !myISM.getHubStatus() ){
200-
// Serial.print(".");
201246
delay(1);
202247
}
203248

0 commit comments

Comments
 (0)