Skip to content

Commit 91dbe4a

Browse files
authored
Merge pull request #34 from Lyr3x/feauture/remove-config-file
v1.2
2 parents 0000ec1 + 0f95296 commit 91dbe4a

File tree

15 files changed

+113
-82
lines changed

15 files changed

+113
-82
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ jobs:
1414
run: |
1515
python -m pip install --upgrade pip
1616
pip install -U esphome
17-
- name: Build
17+
- name: Build ESP8266
1818
run: esphome compile peopleCounter.yaml
19+
- name: Build ESP32
20+
run: esphome compile peopleCounter32.yaml

README.md

Lines changed: 53 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,55 @@ ST Microelectronics define the values for the parameters as default like this:
3030

3131
The center of the ROI you set is based on the table below and the optical center has to be set as the pad above and to the right of your exact center:
3232

33-
34-
35-
| 128 | 136 | 144 | 152 | 160 | 168 | 176 | 184 | 192 | 200 | 208 | 216 | 224 | 232 | 240 | 248 |
36-
| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- |
37-
| 129 | 137 | 145 | 153 | 161 | 169 | 177 | 185 | 193 | 201 | 209 | 217 | 225 | 233 | 241 | 249 |
38-
| 130 | 138 | 146 | 154 | 162 | 170 | 178 | 186 | 194 | 202 | 210 | 218 | 226 | 234 | 242 | 250 |
39-
| 131 | 139 | 146 | 155 | 163 | 171 | 179 | 187 | 195 | 203 | 211 | 219 | 227 | 235 | 243 | 251 |
40-
| 132 | 140 | 147 | 156 | 164 | 172 | 180 | 188 | 196 | 204 | 212 | 220 | 228 | 236 | 244 | 252 |
41-
| 133 | 141 | 148 | 157 | 165 | 173 | 181 | 189 | 197 | 205 | 213 | 221 | 229 | 237 | 245 | 253 |
42-
| 134 | 142 | 149 | 158 | 166 | 174 | 182 | 190 | 198 | 206 | 214 | 222 | 230 | 238 | 246 | 254 |
43-
| 135 | 143 | 150 | 159 | 167 | 175 | 183 | 191 | 199 | 207 | 215 | 223 | 231 | 239 | 247 | 255 |
44-
| 127 | 119 | 111 | 103 | 95 | 87 | 79 | 71 | 63 | 55 | 47 | 39 | 31 | 23 | 15 | 7 |
45-
| 126 | 118 | 110 | 102 | 94 | 86 | 78 | 70 | 62 | 54 | 46 | 38 | 30 | 22 | 14 | 6 |
46-
| 125 | 117 | 109 | 101 | 93 | 85 | 77 | 69 | 61 | 53 | 45 | 37 | 29 | 21 | 13 | 5 |
47-
| 124 | 116 | 108 | 100 | 92 | 84 | 76 | 68 | 60 | 52 | 44 | 36 | 28 | 20 | 12 | 4 |
48-
| 123 | 115 | 107 | 99 | 91 | 83 | 75 | 67 | 59 | 51 | 43 | 35 | 27 | 19 | 11 | 3 |
49-
| 122 | 114 | 106 | 98 | 90 | 82 | 74 | 66 | 58 | 50 | 42 | 34 | 26 | 18 | 10 | 2 |
50-
| 121 | 113 | 105 | 97 | 89 | 81 | 73 | 65 | 57 | 49 | 41 | 33 | 25 | 17 | 9 | 1 |
51-
| 120 | 112 | 104 | 96 | 88 | 80 | 72 | 64 | 56 | 48 | 40 | 32 | 24 | 16 | 8 | 0 |
52-
33+
Set the center SPAD of the region of interest (ROI)
34+
based on VL53L1X_SetROICenter() from STSW-IMG009 Ultra Lite Driver
35+
36+
ST user manual UM2555 explains ROI selection in detail, so we recommend
37+
reading that document carefully. Here is a table of SPAD locations from
38+
UM2555 (199 is the default/center):
39+
40+
128,136,144,152,160,168,176,184, 192,200,208,216,224,232,240,248
41+
129,137,145,153,161,169,177,185, 193,201,209,217,225,233,241,249
42+
130,138,146,154,162,170,178,186, 194,202,210,218,226,234,242,250
43+
131,139,147,155,163,171,179,187, 195,203,211,219,227,235,243,251
44+
132,140,148,156,164,172,180,188, 196,204,212,220,228,236,244,252
45+
133,141,149,157,165,173,181,189, 197,205,213,221,229,237,245,253
46+
134,142,150,158,166,174,182,190, 198,206,214,222,230,238,246,254
47+
135,143,151,159,167,175,183,191, 199,207,215,223,231,239,247,255
48+
49+
127,119,111,103, 95, 87, 79, 71, 63, 55, 47, 39, 31, 23, 15, 7
50+
126,118,110,102, 94, 86, 78, 70, 62, 54, 46, 38, 30, 22, 14, 6
51+
125,117,109,101, 93, 85, 77, 69, 61, 53, 45, 37, 29, 21, 13, 5
52+
124,116,108,100, 92, 84, 76, 68, 60, 52, 44, 36, 28, 20, 12, 4
53+
123,115,107, 99, 91, 83, 75, 67, 59, 51, 43, 35, 27, 19, 11, 3
54+
122,114,106, 98, 90, 82, 74, 66, 58, 50, 42, 34, 26, 18, 10, 2
55+
121,113,105, 97, 89, 81, 73, 65, 57, 49, 41, 33, 25, 17, 9, 1
56+
120,112,104, 96, 88, 80, 72, 64, 56, 48, 40, 32, 24, 16, 8, 0 <- Pin 1
57+
58+
This table is oriented as if looking into the front of the sensor (or top of
59+
the chip). SPAD 0 is closest to pin 1 of the VL53L1X, which is the corner
60+
closest to the VDD pin on the Pololu VL53L1X carrier board:
61+
62+
+--------------+
63+
| O| GPIO1
64+
| |
65+
| O|
66+
| 128 248 |
67+
|+----------+ O|
68+
||+--+ +--+| |
69+
||| | | || O|
70+
||+--+ +--+| |
71+
|+----------+ O|
72+
| 120 0 |
73+
| O|
74+
| |
75+
| O| VDD
76+
+--------------+
77+
78+
However, note that the lens inside the VL53L1X inverts the image it sees
79+
(like the way a camera works). So for example, to shift the sensor's FOV to
80+
sense objects toward the upper left, you should pick a center SPAD in the
81+
lower right.
5382

5483

5584

@@ -79,19 +108,19 @@ There will be a specific Hardware setup (recommended brands etc.) soon!
79108
* Power Supply
80109
* Encolsure (see .stl files) - will be updated soon!
81110
Pins:
82-
#define SDA_PIN D2
83-
#define SCL_PIN D1
111+
SDA_PIN D2 or 21 (ESP32)
112+
SCL_PIN D1 or 22 (ESP32)
84113

85114
## Configuration
86115
### ESPHome
87116
Configue at least the secrets.yaml with your wifi SSID and password to connect. Check the peopleCounter.yaml to adapt the exposed sensors to your needs.
88117

89118
### Entry/Exit inverted:
90-
Set #define INVERT_DIRECTION or comment it out to invert the direction.
119+
Set INVERT_DIRECTION to true or false to invert the direction.
91120

92121

93122
## Configuration
94-
Be sure to configure your wifi credentials and adapt the Config.h to set everyhting to your needs.
123+
Be sure to configure your wifi credentials and adapt the global variables to set everyhting to your needs.
95124
The most important config part is the calibration mode. You have two different calibration modes available:
96125
Calibration v1 calibrates the distance for one zone and calculates the standard deviation and uses that value for both zones.
97126
Calibration v2 calibrates both zones individually (thanks to @andrea-fox).

STL/Back-ESP32-GY53.stl

46 KB
Binary file not shown.

STL/CP2102_mount.stl

-39.7 KB
Binary file not shown.

STL/Front-ESP32-GY53.stl

163 KB
Binary file not shown.

STL/Front_VL53L0X.stl

-615 KB
Binary file not shown.

STL/OLED_mount.stl

-91.5 KB
Binary file not shown.

STL/WallMount.stl

-89.9 KB
Binary file not shown.

common/wifi.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ wifi:
22
networks:
33
- ssid: !secret ssid1
44
password: !secret ssid1_password
5-
- ssid: !secret ssid2
6-
password: !secret ssid2_password
75
use_address: $devicename.local
6+
fast_connect: True
7+
power_save_mode: none

lib/Calibration/Calibration.h

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
#ifndef CALIBRATION_H
22
#define CALIBRATION_H
3-
#include <Config.h>
43
#include <math.h>
54
#include "esphome/core/log.h"
5+
#include <VL53L1X.h>
66

77
/*
88
##### CALIBRATION #####
99
*/
10-
#ifdef CALIBRATIONV2
1110
static int DIST_THRESHOLD_MAX[] = {0, 0}; // treshold of the two zones
1211
static int MIN_DISTANCE[] = {0, 0};
1312
static int center[2] = {0, 0}; /* center of the two zones */
1413
static int ROI_height = 0;
1514
static int ROI_width = 0;
1615
static int zone = 0;
1716

17+
18+
/*
19+
Use the VL53L1X_SetTimingBudget function to set the TB in milliseconds. The TB values available are [15, 20,
20+
33, 50, 100, 200, 500]. This function must be called after VL53L1X_SetDistanceMode.
21+
Note: 15 ms only works with Short distance mode. 100 ms is the default value.
22+
The TB can be adjusted to improve the standard deviation (SD) of the measurement.
23+
Increasing the TB, decreases the SD but increases the power consumption.
24+
*/
25+
1826
static int delay_between_measurements = 0;
1927
static int time_budget_in_ms = 0;
2028

@@ -25,19 +33,16 @@ static bool advised_orientation_of_the_sensor = true;
2533
static bool save_calibration_result = true;
2634

2735
// parameters which define the time between two different measurements in longRange mode
28-
static int delay_between_measurements_long = 55;
29-
static int time_budget_in_ms_long = 50;
36+
static int delay_between_measurements_long = 50;
37+
static int time_budget_in_ms_long = 33; // Works up to 3.1m increase to 140ms for 4m
38+
static int delay_between_measurements_short = 25;
39+
static int time_budget_in_ms_short = 15;
3040

31-
// parameters which define the time between two different measurements in longRange mode
32-
static int time_budget_in_ms_short = 20;
33-
static int delay_between_measurements_short = 22;
3441

3542
// value which defines the threshold which activates the short distance mode (the sensor supports it only up to a distance of 1300 mm)
3643
static int short_distance_threshold = 1300;
3744

38-
#endif //#ifdef CALIBRATIONV2
3945

40-
#ifdef CALIBRATIONV2
4146
void calibration(VL53L1X distanceSensor)
4247
{
4348
// the sensor does 100 measurements for each zone (zones are predefined)
@@ -49,7 +54,7 @@ void calibration(VL53L1X distanceSensor)
4954
center[0] = 167;
5055
center[1] = 231;
5156
ROI_height = 16;
52-
ROI_width = 8;
57+
ROI_width = 7;
5358
delay(500);
5459

5560
zone = 0;
@@ -257,5 +262,4 @@ void calibration_boot(VL53L1X distanceSensor)
257262
calibration(distanceSensor);
258263
ESP_LOGI("VL53L1X custom sensor", "#### calibration done ####");
259264
}
260-
#endif //#ifdef CALIBRATIONV2
261-
#endif
265+
#endif

0 commit comments

Comments
 (0)