You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The SparkFun Qwiic OLED Arduino Library is available within in the Arduino library manager, which is launched via the `Sketch > Include Libraries > Manage Libraries …` menu option in the Arduino IDE. Just search for ***SparkFun Qwiic OLED Library***
6
+
The SparkFun Qwiic TMF882X Arduino Library is available within in the Arduino library manager, which is launched via the `Sketch > Include Libraries > Manage Libraries …` menu option in the Arduino IDE. Just search for ***SparkFun Qwiic TMF882X Library***
7
7
8
8
!!! note
9
9
This guide assumes you are using the latest version of the Arduino IDE on your desktop. The following resources available at [SparkFun](https://www.sparkfun.com) provide the details on setting up and configuring Arduino to use this library.
@@ -16,61 +16,133 @@ General Use Pattern
16
16
---------
17
17
After installing this library in your local Arduino environment, begin with a standard Arduino sketch, and include the header file for this library.
18
18
```C++
19
-
// Include the SparkFun qwiic OLED Library
20
-
#include<SparkFun_Qwiic_OLED.h>
19
+
// Include the SparkFun Qwiic TMF882X Library
20
+
#include<SparkFun_TMF882X_Library.h>
21
21
```
22
-
The next step is to declare the object for the SparkFun qwiic OLED device used. Like most Arduino sketches, this is done at a global scope (after the include file declaration), not within the ```setup()``` or ```loop()``` functions.
22
+
The next step is to declare the object for the SparkFun Qwiic TMF882X device used. Like most Arduino sketches, this is done at a global scope (after the include file declaration), not within the ```setup()``` or ```loop()``` functions.
23
23
24
-
The user selects from one of the following classes:
For all supported boards, the same object is used: `SparkFun_TMF882X`.
33
25
```C++
34
-
QwiicMicroOLED myOLED;
26
+
SparkFun_TMF882X myTMF882X;
35
27
```
36
28
In the ```setup()``` function of this sketch, like all of the SparkFun qwiic libraries, the device is initialized by calling the ```begin()``` method. This method returns a value of ```true``` on success, or ```false``` on failure.
37
29
```C++
38
-
int width, height; // global variables for use in the sketch
39
30
voidsetup()
40
31
{
41
32
Serial.begin(115200);
42
-
if(!myOLED.begin()){
33
+
34
+
if(!myTMF882X.begin()){
43
35
Serial.println("Device failed to initialize");
44
36
while(1); // halt execution
45
37
}
46
38
Serial.println("Device is initialized");
47
39
48
40
}
49
41
```
50
-
Now that the library is initialized, the desired graphics are drawn. Here we erase the screen and draw simple series of lines that originate at the screen origin and fan out across the height of the display.
42
+
Now that device is initialized, the `loop()` function can call the library to retrieve a single data sample from the connected TMF882X device.
51
43
52
-
!!! note
53
-
Graphics are not send to the OLED device when drawn. Updates are only sent to the device when the `display()` method is called. This minimizes data transfers to the OLED device, delivering a responsive display response.
44
+
Taken from the libraries Example 1, once a measurement is taken, the relevant data is output to the Serial device.
54
45
55
46
```C++
47
+
voidloop()
48
+
{
49
+
delay(2000);
50
+
51
+
// get a Measurement
52
+
if(myTMF882X.startMeasuring(myResults))
53
+
{
54
+
// print out results
55
+
Serial.println("Measurement:");
56
+
Serial.print(" Result Number: ");
57
+
Serial.print(myResults.result_num);
58
+
Serial.print(" Number of Results: ");
59
+
Serial.println(myResults.num_results);
60
+
61
+
for (int i = 0; i < myResults.num_results; ++i)
62
+
{
63
+
Serial.print(" conf: ");
64
+
Serial.print(myResults.results[i].confidence);
65
+
Serial.print(" distance mm: ");
66
+
Serial.print(myResults.results[i].distance_mm);
67
+
Serial.print(" channel: ");
68
+
Serial.print(myResults.results[i].channel);
69
+
Serial.print(" sub_capture: ");
70
+
Serial.println(myResults.results[i].sub_capture);
71
+
72
+
}
73
+
Serial.print(" photon: ");
74
+
Serial.print(myResults.photon_count);
75
+
Serial.print(" ref photon: ");
76
+
Serial.print(myResults.ref_photon_count);
77
+
Serial.print(" ALS: ");
78
+
Serial.println(myResults.ambient_light);
79
+
Serial.println();
56
80
57
-
myOLED.erase(); // Erase the screen
58
-
myOLED.display(); // Send erase to device
59
-
60
-
delay(1000); // Slight pause
61
-
62
-
// Draw our lines from point (0,0) to (i, screen height)
63
-
64
-
for(int i=0; i < width; i+= 6){
65
-
myOLED.line(0, 0, i, height-1); // draw the line
66
-
myOLED.display(); // Send the new line to the device for display
67
81
}
82
+
83
+
}
84
+
```
85
+
86
+
## Advanced Data Collection
87
+
88
+
The TMF882X is unique when compared to our other qwiic libraries. Instead of data being returned directly from a method, measured data is passed back to the user via a callback function. This is how the underlying TMF882X SDK framework is designed and works well for interactive sensors like the TMF882X.
89
+
90
+
To receive data, a callback function is defined. For this example, we define a callback that prints out the detected data.
For this example, in the `loop()` function, a measurement session is started, requesting that four samples be taken before returning from the method call. When data is detected by the TMF882X, the `onMeasurementCallback()` function, is called with the detected results. Once four measurements are taken, the measurement is finished and the TMF882X sensing session is stopped.
124
+
125
+
```C++
126
+
voidloop()
127
+
{
128
+
delay(2000);
129
+
130
+
// get a measurement
131
+
// Have the sensor take 4 measurements.
132
+
//
133
+
// As measurements are taken, the results are sent to the above function,
134
+
// "onMeasurementCallback()"
135
+
136
+
nSample=0; // simple counter
137
+
myTMF882X.startMeasuring(4);
138
+
139
+
}
140
+
141
+
```
70
142
71
143
Library Provided Examples
72
144
--------
73
-
The SparkFun Qwiic OLED Arduino Library, includes a wide variety of examples. These are available from the Examples menu of the Arduino IDE, and in the [`examples`](https://github.com/sparkfun/SparkFun_Qwiic_OLED_Arduino_Library/blob/main/examples)folder of this repository.
145
+
The SparkFun Qwiic TMF882X Arduino Library, includes a wide variety of examples. These are available from the Examples menu of the Arduino IDE, and in the [`examples`](https://github.com/sparkfun/SparkFun_Qwiic_TMF882X_Arduino_Library/blob/main/examples)folder of this repository.
74
146
75
147
For a detailed description of the examples, see the Examples section of the documentation.
0 commit comments