Skip to content

Commit 4d26616

Browse files
committed
added headers to the Arduino examples
1 parent 9748252 commit 4d26616

File tree

12 files changed

+354
-59
lines changed

12 files changed

+354
-59
lines changed

examples/Example-01_Basic/Example-01_Basic.ino

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
11
/*
2-
TODO - Fix Header
3-
*/
42
3+
Example-01_Basic.ino
4+
5+
This demo shows a basic use of a TMF882X device. The device is connected to,
6+
and a single reading is taken for each loop iteration.
7+
8+
Supported Boards:
9+
10+
SparkFun Qwiic dToF Imager - TMF8820 https://www.sparkfun.com/products/19036
11+
SparkFun Qwiic Mini dToF Imager - TMF8820 https://www.sparkfun.com/products/19218
12+
SparkFun Qwiic Mini dToF Imager - TMF8821 https://www.sparkfun.com/products/19451
13+
SparkFun Qwiic dToF Imager - TMF8821 https://www.sparkfun.com/products/19037
14+
15+
Written by Kirk Benell @ SparkFun Electronics, April 2022
516
6-
#include "SparkFun_TMF882X_Library.h"
17+
Repository:
18+
https://github.com/sparkfun/SparkFun_Qwiic_TMF882X_Arduino_Library
19+
20+
Documentation:
21+
https://sparkfun.github.io/SparkFun_Qwiic_OLED_Arduino_Library/
22+
23+
SparkFun code, firmware, and software is released under the MIT License(http://opensource.org/licenses/MIT).
24+
*/
25+
26+
#include "SparkFun_TMF882X_Library.h" //http://librarymanager/All#SparkFun_Qwiic_TMPF882X
727

828
SparkFun_TMF882X myTMF882X;
929

30+
// Structure to hold the measurement results - this is defined by the TMF882X SDK.
31+
1032
static struct tmf882x_msg_meas_results myResults;
1133

1234
void setup(){
@@ -18,36 +40,30 @@ void setup(){
1840
Serial.println("In setup");
1941
Serial.println("==============================");
2042

43+
// Initialize the TMF882X device
2144
if(!myTMF882X.begin())
2245
{
2346
Serial.println("Error - The TMF882X failed to initialize - is the board connected?");
2447
while(1);
2548
}else
2649
Serial.println("TMF882X started.");
2750

28-
// Get the unique identifier from our connected device.
29-
struct tmf882x_mode_app_dev_UID devUID;
30-
31-
if (myTMF882X.getDeviceUniqueID(devUID)){
32-
Serial.print("Connected Device Unique ID: ");
33-
Serial.println(devUID.uid);
34-
}
35-
Serial.println();
51+
// The device is now ready for operations
3652
}
3753

3854
void loop()
3955
{
4056
delay(2000);
4157

42-
// get a myResultsurment
58+
// get a Measurement
4359
if(myTMF882X.startMeasuring(myResults))
4460
{
4561
// print out results
4662
Serial.println("Measurement:");
4763
Serial.print(" Result Number: "); Serial.print(myResults.result_num);
4864
Serial.print(" Number of Results: "); Serial.println(myResults.num_results);
4965

50-
for (uint32_t i = 0; i < myResults.num_results; ++i) {
66+
for (int i = 0; i < myResults.num_results; ++i) {
5167
Serial.print(" conf: "); Serial.print(myResults.results[i].confidence);
5268
Serial.print(" distance mm: "); Serial.print(myResults.results[i].distance_mm);
5369
Serial.print(" channel: "); Serial.print(myResults.results[i].channel);

examples/Example-02_Callback/Example-02_Callback.ino

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,45 @@
11
/*
2-
TODO - Fix Header
32
3+
Example-02_Callback.ino
44
5+
The TMF882X Arduino library uses the TMF882X Software Development Kit (SDK) from
6+
AMS to interface with the sensor. This SDK returns results by calling a provided
7+
function and passing in a message structure.
8+
9+
This example shows how to create and regsiter a callback function to recieve results
10+
from the library.
11+
12+
Supported Boards:
13+
14+
SparkFun Qwiic dToF Imager - TMF8820 https://www.sparkfun.com/products/19036
15+
SparkFun Qwiic Mini dToF Imager - TMF8820 https://www.sparkfun.com/products/19218
16+
SparkFun Qwiic Mini dToF Imager - TMF8821 https://www.sparkfun.com/products/19451
17+
SparkFun Qwiic dToF Imager - TMF8821 https://www.sparkfun.com/products/19037
18+
19+
Written by Kirk Benell @ SparkFun Electronics, April 2022
20+
21+
Repository:
22+
https://github.com/sparkfun/SparkFun_Qwiic_TMF882X_Arduino_Library
23+
24+
Documentation:
25+
https://sparkfun.github.io/SparkFun_Qwiic_OLED_Arduino_Library/
26+
27+
SparkFun code, firmware, and software is released under the MIT License(http://opensource.org/licenses/MIT).
528
*/
6-
// Example 02 - using a callback to detect messages.
729

8-
#include "SparkFun_TMF882X_Library.h"
30+
#include "SparkFun_TMF882X_Library.h" //http://librarymanager/All#SparkFun_Qwiic_TMPF882X
931

1032
SparkFun_TMF882X myTMF882X;
1133

34+
// Each loop takes a number of samples/measurements. Define how many to take here.
35+
1236
#define NUMBER_OF_SAMPLES_TO_TAKE 4
1337

14-
int nSample =0;
15-
// Define our measurement callback function
38+
int nSample =0; // used to count how the number of measurements taken.
39+
40+
41+
// Define our measurement callback function. The Library calls this when a
42+
// measurment is taken.
1643

1744
void onMeasurementCallback(struct tmf882x_msg_meas_results *myResults){
1845

@@ -52,10 +79,10 @@ void setup(){
5279
while(1);
5380
}
5481

55-
// set our call back function
82+
// set our callback function in the library.
5683
myTMF882X.setMeasurementHandler(onMeasurementCallback);
5784

58-
// Set our delay between samples - 1 second - note it's in ms
85+
// Set our delay between samples in the processing loop - 1 second - note it's in ms
5986
myTMF882X.setSampleDelay(1000);
6087
}
6188

@@ -64,7 +91,10 @@ void loop()
6491
delay(2000);
6592

6693
// get a measurment
67-
// Have the sensor take 4 measurements, the results are sent to the above callback
94+
// Have the sensor take NUMBER_OF_SAMPLES_TO_TAKE measurements.
95+
//
96+
// As measurements are taken, the results are sent to the above function,
97+
// "onMeasurementCallback()"
6898

6999
Serial.println("---------------------------------------------------------");
70100
Serial.print("Taking ");

examples/Example-03_Stop/Example-03_Stop.ino

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,45 @@
11
/*
2-
TODO - Fix Header
32
3+
Example-03_Stop.ino
44
5+
The TMF882X Arduino library uses the TMF882X Software Development Kit (SDK) from
6+
AMS to interface with the sensor. This SDK returns results by calling a provided
7+
function and passing in a message structure.
8+
9+
This examples shows how to setup a callback, but use the stopMeasuring()
10+
to stop operation of the TMF882X.
11+
12+
Supported Boards:
13+
14+
SparkFun Qwiic dToF Imager - TMF8820 https://www.sparkfun.com/products/19036
15+
SparkFun Qwiic Mini dToF Imager - TMF8820 https://www.sparkfun.com/products/19218
16+
SparkFun Qwiic Mini dToF Imager - TMF8821 https://www.sparkfun.com/products/19451
17+
SparkFun Qwiic dToF Imager - TMF8821 https://www.sparkfun.com/products/19037
18+
19+
Written by Kirk Benell @ SparkFun Electronics, April 2022
20+
21+
Repository:
22+
https://github.com/sparkfun/SparkFun_Qwiic_TMF882X_Arduino_Library
23+
24+
Documentation:
25+
https://sparkfun.github.io/SparkFun_Qwiic_OLED_Arduino_Library/
26+
27+
SparkFun code, firmware, and software is released under the MIT License(http://opensource.org/licenses/MIT).
528
*/
6-
// Example 03 - using a callback to detect messages and calling stopMeasuring() to stop the effort.
729

8-
#include "SparkFun_TMF882X_Library.h"
30+
31+
#include "SparkFun_TMF882X_Library.h" //http://librarymanager/All#SparkFun_Qwiic_TMPF882X
932

1033
SparkFun_TMF882X myTMF882X;
1134

35+
// Define how many measurments/samples to take before calling "stopMeasuring()"
36+
1237
#define NUMBER_OF_SAMPLES_TO_TAKE 4
1338

1439
int nSample =0;
15-
// Define our measurement callback function
40+
41+
// Define our measurement callback function. The Library calls this when a
42+
// measurment is taken.
1643

1744
void onMeasurementCallback(struct tmf882x_msg_meas_results *myResults){
1845

@@ -73,16 +100,17 @@ void loop()
73100
{
74101
delay(2000);
75102

76-
// get a measurment
77-
// Have the sensor take 4 measurements, the results are sent to the above callback
78-
79103
Serial.println("---------------------------------------------------------");
80104
Serial.print("Taking ");
81105
Serial.print(NUMBER_OF_SAMPLES_TO_TAKE);
82106
Serial.println(" data samples.");
83107
Serial.println();
84108

85109
nSample=0;
110+
111+
// Start taking samples. Note - no stop condition is specified. This is handled
112+
// in the measurement callback function above.
113+
86114
myTMF882X.startMeasuring();
87115

88116
Serial.println("---------------------------------------------------------\n\n");

examples/Example-04_Timeout/Example-04_Timeout.ino

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,42 @@
11
/*
2-
TODO - Fix Header
32
3+
Example-04_Timeout.ino
44
5+
The TMF882X Arduino library uses the TMF882X Software Development Kit (SDK) from
6+
AMS to interface with the sensor. This SDK returns results by calling a provided
7+
function and passing in a message structure.
8+
9+
This example shows how to create and regsiter a callback function to recieve results
10+
from the library.
11+
12+
The library will continue to take measurments until the specified timeout value is
13+
reached.
14+
15+
Supported Boards:
16+
17+
SparkFun Qwiic dToF Imager - TMF8820 https://www.sparkfun.com/products/19036
18+
SparkFun Qwiic Mini dToF Imager - TMF8820 https://www.sparkfun.com/products/19218
19+
SparkFun Qwiic Mini dToF Imager - TMF8821 https://www.sparkfun.com/products/19451
20+
SparkFun Qwiic dToF Imager - TMF8821 https://www.sparkfun.com/products/19037
21+
22+
Written by Kirk Benell @ SparkFun Electronics, April 2022
23+
24+
Repository:
25+
https://github.com/sparkfun/SparkFun_Qwiic_TMF882X_Arduino_Library
26+
27+
Documentation:
28+
https://sparkfun.github.io/SparkFun_Qwiic_OLED_Arduino_Library/
29+
30+
SparkFun code, firmware, and software is released under the MIT License(http://opensource.org/licenses/MIT).
531
*/
6-
// Example 04 - end using a timeout
732

8-
#include "SparkFun_TMF882X_Library.h"
33+
34+
#include "SparkFun_TMF882X_Library.h" //http://librarymanager/All#SparkFun_Qwiic_TMPF882X
935

1036
SparkFun_TMF882X myTMF882X;
1137

38+
// How long to take samples
39+
1240
#define SAMPLE_TIMEOUT_MS 3000
1341

1442
// Define our measurement callback function
@@ -55,9 +83,6 @@ void loop()
5583
{
5684
delay(2000);
5785

58-
// get a measurment
59-
// Have the sensor take 4 measurements, the results are sent to the above callback
60-
6186
Serial.println("---------------------------------------------------------");
6287
Serial.print("Taking Samples over a period of: ");
6388
Serial.print(SAMPLE_TIMEOUT_MS);

examples/Example-05_Verbose/Example-05_Verbose.ino

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,33 @@
11
/*
2-
TODO - Fix Header
3-
*/
42
3+
Example-05_Verbose.ino
4+
5+
The TMF882X Arduino library uses the TMF882X Software Development Kit (SDK) from
6+
AMS to interface with the sensor.
7+
8+
The AMS SDK is able to print out informational messages during normal operation, as
9+
well as debug messages. This example shows how to enable those messages and direct
10+
them to a Serial device for output.
11+
12+
Supported Boards:
13+
14+
SparkFun Qwiic dToF Imager - TMF8820 https://www.sparkfun.com/products/19036
15+
SparkFun Qwiic Mini dToF Imager - TMF8820 https://www.sparkfun.com/products/19218
16+
SparkFun Qwiic Mini dToF Imager - TMF8821 https://www.sparkfun.com/products/19451
17+
SparkFun Qwiic dToF Imager - TMF8821 https://www.sparkfun.com/products/19037
18+
19+
Written by Kirk Benell @ SparkFun Electronics, April 2022
20+
21+
Repository:
22+
https://github.com/sparkfun/SparkFun_Qwiic_TMF882X_Arduino_Library
523
6-
#include "SparkFun_TMF882X_Library.h"
24+
Documentation:
25+
https://sparkfun.github.io/SparkFun_Qwiic_OLED_Arduino_Library/
26+
27+
SparkFun code, firmware, and software is released under the MIT License(http://opensource.org/licenses/MIT).
28+
*/
29+
30+
#include "SparkFun_TMF882X_Library.h" //http://librarymanager/All#SparkFun_Qwiic_TMPF882X
731

832
SparkFun_TMF882X myTMF882X;
933

@@ -30,7 +54,9 @@ void setup(){
3054
// Enable Info messages
3155
myTMF882X.setInfoMessages(true);
3256

33-
// Enable Debug mode
57+
// Enable Debug mode. Set this before calling begin to get initialization debug
58+
// information.
59+
3460
myTMF882X.setDebug(true);
3561

3662
if(!myTMF882X.begin())

examples/Example-06_Config/Example-06_Config.ino

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,33 @@
11
/*
2-
TODO - Fix Header
2+
3+
Example-06_Config.ino
4+
5+
6+
This example shows how to get and set the TMF882X device configuration structure. Details
7+
of this structure are in the TMF882X datasheet.
8+
9+
The example also shows how to retrieve the unique ID of the device attached.
10+
11+
Supported Boards:
12+
13+
SparkFun Qwiic dToF Imager - TMF8820 https://www.sparkfun.com/products/19036
14+
SparkFun Qwiic Mini dToF Imager - TMF8820 https://www.sparkfun.com/products/19218
15+
SparkFun Qwiic Mini dToF Imager - TMF8821 https://www.sparkfun.com/products/19451
16+
SparkFun Qwiic dToF Imager - TMF8821 https://www.sparkfun.com/products/19037
17+
18+
Written by Kirk Benell @ SparkFun Electronics, April 2022
19+
20+
Repository:
21+
https://github.com/sparkfun/SparkFun_Qwiic_TMF882X_Arduino_Library
22+
23+
Documentation:
24+
https://sparkfun.github.io/SparkFun_Qwiic_OLED_Arduino_Library/
25+
26+
SparkFun code, firmware, and software is released under the MIT License(http://opensource.org/licenses/MIT).
327
*/
428

529

6-
#include "SparkFun_TMF882X_Library.h"
30+
#include "SparkFun_TMF882X_Library.h" //http://librarymanager/All#SparkFun_Qwiic_TMPF882X
731

832
SparkFun_TMF882X myTMF882X;
933

@@ -45,6 +69,14 @@ void setup(){
4569
Serial.print("The update of the TMF882X Report Period ");
4670
Serial.println( (bConfigSet ? "Succeeded" : "Failed"));
4771

72+
// Get the unique identifier from our connected device.
73+
struct tmf882x_mode_app_dev_UID devUID;
74+
75+
if (myTMF882X.getDeviceUniqueID(devUID)){
76+
Serial.print("Connected Device Unique ID: ");
77+
Serial.println(devUID.uid);
78+
}
79+
Serial.println();
4880
}
4981

5082
void loop()

0 commit comments

Comments
 (0)