Skip to content

Commit 94104e1

Browse files
committed
ported to TMF882X
1 parent dbfc6da commit 94104e1

File tree

1 file changed

+102
-30
lines changed

1 file changed

+102
-30
lines changed

docs/software.md

Lines changed: 102 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
## Installation
55

6-
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***
77

88
!!! note
99
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
1616
---------
1717
After installing this library in your local Arduino environment, begin with a standard Arduino sketch, and include the header file for this library.
1818
```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>
2121
```
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.
2323

24-
The user selects from one of the following classes:
25-
26-
| Class | Qwiic OLED Device |
27-
| :--- | :--- |
28-
| `QwiicMicroOLED` | [SparkFun Qwiic Micro OLED ]( https://www.sparkfun.com/products/14532)|
29-
| `QwiicNarrowOLED` | [SparkFun Qwiic OLED Display (128x32) ]( https://www.sparkfun.com/products/17153)|
30-
| `QwiicTransparentOLED` | [SparkFun Transparent Graphical OLED]( https://www.sparkfun.com/products/15173)|
31-
32-
For this example, the Qwiic Micro OLED is used.
24+
For all supported boards, the same object is used: `SparkFun_TMF882X`.
3325
```C++
34-
QwiicMicroOLED myOLED;
26+
SparkFun_TMF882X myTMF882X;
3527
```
3628
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.
3729
```C++
38-
int width, height; // global variables for use in the sketch
3930
void setup()
4031
{
4132
Serial.begin(115200);
42-
if(!myOLED.begin()){
33+
34+
if(!myTMF882X.begin()){
4335
Serial.println("Device failed to initialize");
4436
while(1); // halt execution
4537
}
4638
Serial.println("Device is initialized");
4739

4840
}
4941
```
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.
5143

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

5546
```C++
47+
void loop()
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();
5680

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
6781
}
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.
91+
92+
```C++
93+
void onMeasurementCallback(struct tmf882x_msg_meas_results *myResults)
94+
{
95+
nSample++;
96+
97+
Serial.print("Sample Number: ");
98+
Serial.println(nSample);
99+
100+
// print out results
101+
// Not Shown here - This is similar to the output shown in the
102+
// previous example.
103+
}
104+
```
105+
In the `setup()` function of this example after the device is initialized, the defined callback function is registered with the TMF882 object.
106+
107+
```C++
108+
void setup()
109+
{
110+
Serial.begin(115200);
111+
112+
if(!myTMF882X.begin()){
113+
Serial.println("Device failed to initialize");
114+
while(1); // halt execution
115+
}
116+
Serial.println("Device is initialized");
117+
118+
// set our callback function in the library.
119+
myTMF882X.setMeasurementHandler(onMeasurementCallback);
120+
}
68121
```
69122

123+
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+
void loop()
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+
```
70142

71143
Library Provided Examples
72144
--------
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.
74146

75147
For a detailed description of the examples, see the Examples section of the documentation.
76148

0 commit comments

Comments
 (0)