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
# TMF8806 (Time-of-flight) Low-Power Arduino Uno application
2
2
3
-
This is a simple universal driver to show the capabilies of the time-of-flight device TMF8806.
3
+
This is a low-power example which shows how to use the TMF8806 in applications that are battery powered.
4
4
5
5
## Requirements
6
6
@@ -12,159 +12,102 @@ This is a simple universal driver to show the capabilies of the time-of-flight d
12
12
13
13
## Files
14
14
15
-
The arduino project in the folder: **tmf8806_app** is a very simple single character command line interpreter listening/printing on UART
16
-
It contains the following files:
15
+
The arduino project consists of the following files:
17
16
18
-
-**tmf8806_app.ino** - the arduino specific wrapper for the application
19
-
-**tmf8806_app.h** and **tmf8806_app.cpp** - the TMF8806 command line application
20
-
-**tmf8806.h** and **tmf8806.cpp** - the TMF8806 driver
21
-
-**tmf8806_shim.h** and **tmf8806_shim.cpp** - a shim to abstract the arduino specific I2C, UARTand GPIO functions
22
-
-**tmf8806_image.h** and **tmf8806_image.c** - the TMF8806 firmware that is downloaded by the driver as a c-struct
17
+
-**tmf8806_low_power.ino** - the arduino specific wrapper for the application
18
+
-**tmf8806_app.h** and **tmf8806_app.c** - the TMF8806 low-power application itself
19
+
-**tmf8806.h** and **tmf8806.c** - the TMF8806 driver
20
+
-**tmf8806_shim.h** and **tmf8806_shim.cpp** - a shim to abstract the arduino specific I2C, UART, GPIO and low-power functions
21
+
For the Arduino this needs to be a c++ file. However the shim layer for other platforms could also be a plain C file.
23
22
24
-
You can use application interrupt driven. For this you need to set the following define to 1: **USE_INTERRUPT_TO_TRIGGER_READ**
25
23
26
-
### Porting to another MCU
24
+
##Configuration
27
25
28
-
To port the driver and application to another platform you need to adapt the following files:
29
-
-**tmf8806_a.ino** - the arduino specific wrapper for the application, replace this with the requirements for your selected platform
30
-
-**tmf8806_shim.h** and **tmf8806_shim.cpp** - a shim to abstract the arduino specific I2C, UART and GPIO functions
31
-
32
-
## UART and command line interpreter
33
-
34
-
The project listens and talks on the UART. Baud rate is 115200, 8-bit, no parity, 1 stop bit.
35
-
36
-
The command line interpreter uses single characters followed by ENTER as input commands.
37
-
For interfacing with a zeromq server the command line interpreter also supports complex command strings with binary payload.
38
-
39
-
UART commands (single character)
40
-
41
-
- a ... dump registers
42
-
- c ... toggle configuration
43
-
- d ... disable device
44
-
- e ... enable device
45
-
- f ... factory calibration
46
-
- h ... help
47
-
- i ... I2C address change
48
-
- m ... start measure
49
-
- p ... power down
50
-
- s ... stop measure
51
-
- t ... switch persistence and thresholds
52
-
- w ... wakeup
53
-
- x ... clock correction on/off
54
-
- z ... histogram dump
55
-
-+ ... log level+
56
-
-- ... log level-
57
-
58
-
UART commands (binary payload)
59
-
60
-
- b\x30<tmf8806FactoryCalibDatadata> .. set arbitrary factory calibration data
61
-
- b\x31<tmf8806MeasureCmddata> .. set arbitrary configuration
62
-
- b\x32<pers,loThres,hiThres> .. set arbitrary persistence / threshold
63
-
64
-
## Command line interpreter application
65
-
66
-
The command line interpreter application mimics a simple host application. It allows the user to switch between 2 pre-defined configurations:
67
-
68
-
- Configuration 0: Period 33 ms, KiloIterations = 400
69
-
- Configuration 1: single shot mode, KiloIterations = 100
70
-
71
-
You can modify the configurations (e.g. choose different period or KiloIterations) in the application source file, recompile and download your own configuration application to the Arduino.
72
-
73
-
## Examples
26
+
The low power example is written with compile-time configuration. The compile time configuration can be changed by modifying the
27
+
following defines in the file **tmf8806_app.h**:
74
28
75
-
### Power up device
29
+
-**KILO_ITERATIONS** defines the number of integrations. The range is 10 - 4000, which is internally multiplied by 1000 (as these
30
+
are kilo-iterations).
31
+
-**PERIOD_NO_OBJECT_IN_MS** defines the interval with which single shot measurements are executed when no object is detected in
32
+
the specified distance range (see parameters LOW_THESHOLD_MM and HIGH_THRESHOLD_MM). Note that the arduino uno uses for this
33
+
purpose the watchdog timer which is limited in the available timing configuration to: 16ms, 32ms, 64ms, 128ms, 256ms 512ms, 512ms
34
+
1024ms 2048ms 4096ms and 8192ms. The application will use an interval that is equal or bigger than the given PERIOD_NO_OBJECT_IN_MS. If it the number is greater than 8192 it will automatically be set to 8192.
35
+
-**PERIOD_OBJECT_IN_MS** defines the interval with which single shot measurements are executed when an object is in the specified range.
36
+
Same restrictions as for PERIOD_NO_OBJECT_IN_MS apply for this constant.
37
+
-**PERSISTENCE** - defines many consecutive times any object has to be in the specified range before a "object-in-range" is signalled
38
+
(via UART and/or GPIO and/or LED). The value 0 has the special meaning that every object (including out-of-range objects) are reported.
39
+
E.g. a value of 3 means that there have to be 3 measurements in a row with: HIGH_THRESHOLD_MM >= object distance >= LOW_THRESHOLD_MM.
40
+
-**LOW_THRESHOLD_MM** - defines the minimum distance an object must have to be considered in range
41
+
-**HIGH_THRESHOLD_MM** - defines the minimum distance an object must have to be considered in range
76
42
77
-
Before the device can be used the host must power the device. The arduino uno setup function will pull the enable line to the TMF8806 low. I.e. the TMF8806 will be powered down.
43
+
-**OUTPUT_ON_UART** - if set to 1 results will be published on UART. If set to 0 the code that writes to the UART will be removed from the binary image. The configuration of the UART is 115200 baud, 8-bit data, 1 stop bit, no parity bit.
44
+
-**OUTPUT_ON_LED** - if set to 1 and if an object is for at least PERSISTENCE measurements in a series in range the arduino built-in led will be on, else the led will be off. Note that the bootloader of the arduino also uses the built-in led during boot process so it will aso be on during booting. If set to 0 the code controlling the built-in led is removed from the binary image and the led will be in the state defined by the arduino uno bootloader.
45
+
-**OUTPUT_ON_GPIO** - if set to 1 and if an object is for at least PERSISTENCE measurements in a series in range the gpio defined in file tmf8806_shim.h as **RESULT_PIN** will be high, else the pin will be low. If set to 0 the code controlling the gpio pin is removed from the binary image and the pin will be in the default state defined by the arduino uno.
78
46
79
-
Enter the character
80
47
81
-
- e
48
+
**Note:** The total integration time is the maximum of these 2 values:
49
+
1. Integration time defined through KILO_ITERATIONS plus data processing time and algorithm publishing time
50
+
2. Period of measurements
51
+
E.g. if the period is shorter than the integration time than the measurements will happen with the period of the integration time.
82
52
83
-
followed by ENTER to enable the device. If necessary the driver will automatically download the the firmware patch file to the TMF8806 RAM. The arduino uno will publish the FW version in the terminal:
53
+
## Application control flow
84
54
85
-
e.g. version 192.4.11.0
55
+
The application itself has 2 functions that are called from the arduino framework (see **tmf8806_low_power.ino** file):
56
+
1. void setup( ) - is called only once after power up of the arduino
57
+
2. void loop( ) - is called periodically while the arduino is running
The simplest way is to do a live factory calibration. I.e. do the following steps:
108
-
1. Connect your Arduino Uno and tmf8806 to the PC via USB
109
-
2. Start a terminal program
110
-
3. Configure and connect the terminal program to the arduino uno
111
-
4. Make sure you have a cover glass on top of the TMF8806. This is needed for the crosstalk.
112
-
5. Make sure there is no object in front of the TMF8806 within 40 cm.
113
-
6. Enter the following commands in your terminal console:
114
-
- e
115
-
- f
116
-
7. The application reports the calibration data: e.g. #Cal,2,0,0,A,B0,BE,BD,7C,F5,F0,F3,F7,7,4
117
-
8. If the application does not send the calibration data the calibration has failed. Check your cover glass and check if there is no object (within 40cm) in the field-of-view of the sensor.
118
-
119
-
## Crosstalk readout
120
-
121
-
The application reports the crosstalk with each measurement result. E.g.:
59
+
To have a portable application the actual code of the **setup** function and the **loop** function is implemented in the file **tmf8806_app.c**.
60
+
The flow chart below shows the control flow of the application.
To port the driver and application to another platform you need to adapt the following files:
68
+
-**tmf8806_a.ino** - the arduino specific wrapper for the application, replace this with the requirements for your selected platform
69
+
-**tmf8806_shim.h** and **tmf8806_shim.cpp** - a shim to abstract the arduino specific functions
128
70
129
-
Send the command "i" to the application to change the sensor I2C address. The application will report the new I2C address. E.g.: Addr=0x42
71
+
The shim layer contains all arduino uno specific code and defines like e.g. which pin is used for the ENABLE line of the TMF8806, which pin is used for the INTERRUPT line of the TMF8806, which pin shall be used to signal that an object is in range.
72
+
The arduino uno is an 8-bit processor which has some limitation on the I2C. the 2 most stringent are
73
+
- maximum I2C frequency is 400KHz
74
+
- maximum I2C block transfer size is 32 bytes (including the register address byte)
130
75
131
-
# Histogram dumping
132
76
133
-
The device can also dump histograms. The order the Arduino Uno driver reports these histograms is exactly the same as the TMF8806 reports them on I2C.
77
+
## Measurement result
134
78
135
-
There are five different types of histograms available
79
+
### Current measurement
80
+
Using default settings, the measured average current is only 26 uA.
136
81
137
-
- electrical calibration histograms (ID=1)
138
-
- proximity histograms (ID=2)
139
-
- distance histograms (ID=4)
140
-
- pileup-corrected distance histograms (ID=8)
141
-
- summed histogram (ID=16)
82
+
Power consumption profile:<br>
83
+

84
+
<br> x-axis: 200ms/div
85
+
<br> y-axis: 10mA/div
142
86
143
-
Type "z" and ENTER until you have the desired value for histogram dumping. E.g if the application sends:
87
+
Power consumption profile zoomed in:<br>
88
+

89
+
<br> x-axis: 10ms/div
90
+
<br> y-axis: 10mA/div
144
91
145
-
Histogram is 4
92
+
### Check functionality using default settings
93
+
Setup with no object in front. Expected period in ms: 1024
94
+
<br> Measured INT Line: 1030 ms<br>
95
+

146
96
147
-
distance histograms are configured for dumping. The application dumps ALL histograms if:
97
+
Setup with object in front. Expected period in ms: 128
98
+
<br> Measured INT Line: 130 ms<br>
99
+

148
100
149
-
Histogram is 31
101
+
Persistence: 3
102
+
<br>Low Threshold: 50
103
+
<br>High Threshold: 200<br>
104
+

150
105
151
-
For all histograms, the first number after the marker (e.g. #TG7) will give the channel this histogram contains.
106
+
Output on UART: ON<br>
107
+

152
108
153
-
There are always 10 histograms reported.
109
+
Output on LED: ON<br>
110
+

154
111
155
-
- Number 0 == TDC0, Channel0
156
-
- Number 1 == TDC0, Channel1
157
-
- ...
158
-
- Number 9 == TDC4, Channel0
159
-
- Number 10 == TDC0, Channel1
160
-
161
-
The header for the raw histograms looks like this:
0 commit comments