Add support for TOF10120

Add support for TOF10120 time of flight sensor by Cyril Pawelko (#10190)
This commit is contained in:
Theo Arends 2021-01-22 16:48:41 +01:00
parent fa0e5e8f1c
commit c934a20b4f
13 changed files with 180 additions and 39 deletions

View File

@ -149,6 +149,7 @@
| USE_EZORGB | - | - | - | - | - | - | - |
| USE_EZORTD | - | - | - | - | - | - | - |
| USE_SEESAW_SOIL | - | - | - | - | - | - | - |
| USE_TOF10120 | - | - | - | - | - | - | - |
| | | | | | | | |
| Feature or Sensor | minimal | lite | tasmota | knx | sensors | ir | display | Remarks
| USE_SPI | - | - | - | - | - | - | x |

View File

@ -19,6 +19,7 @@ All notable changes to this project will be documented in this file.
- Basic support for ESP32 M5stack core2 16MB binary tasmota32-core2.bin (#10635)
- Support for Sugar Valley NeoPool Controller by Norbert Richter (#10637)
- Rule trigger string comparisons for EndsWith ``$>``, StartsWith ``$<`` and Contains ``$|`` (#10538)
- Support for TOF10120 time of flight sensor by Cyril Pawelko (#10190)
### Breaking Changed
- ESP32 switch from default SPIFFS to default LittleFS file system loosing current (zigbee) files

View File

@ -90,3 +90,4 @@ Index | Define | Driver | Device | Address(es) | Description
55 | USE_EZORGB | xsns_78 | EZORGB | 0x61 - 0x70 | Color sensor
55 | USE_EZOPMP | xsns_78 | EZOPMP | 0x61 - 0x70 | Peristaltic Pump
56 | USE_SEESAW_SOIL | xsns_81 | SEESOIL | 0x36 - 0x39 | Adafruit seesaw soil moisture sensor
57 | USE_TOF10120 | xsns_84 | TOF10120 | 0x52 | Time-of-flight (ToF) distance sensor

View File

@ -74,6 +74,7 @@ The attached binaries can also be downloaded from http://ota.tasmota.com/tasmota
- Support for FTC532 8-button touch controller by Peter Franck [#10222](https://github.com/arendst/Tasmota/issues/10222)
- Support for BS814A-2 8-button touch buttons by Peter Franck [#10447](https://github.com/arendst/Tasmota/issues/10447)
- Support for up to 4 I2C SEESAW_SOIL Capacitance & Temperature sensors by Peter Franck [#10481](https://github.com/arendst/Tasmota/issues/10481)
- Support for TOF10120 time of flight sensor by Cyril Pawelko [#10190](https://github.com/arendst/Tasmota/issues/10190)
- Support for Afrikaans language translations by Christiaan Heerze
- Support for IR inverted leds using ``#define IR_SEND_INVERTED true`` [#10301](https://github.com/arendst/Tasmota/issues/10301)
- Support for disabling 38kHz IR modulation using ``#define IR_SEND_USE_MODULATION false`` [#10301](https://github.com/arendst/Tasmota/issues/10301)

View File

@ -784,6 +784,7 @@ const char HTTP_SNS_GALLONS[] PROGMEM = "{s}%s " D_TOTAL_USAGE "{
const char HTTP_SNS_GPM[] PROGMEM = "{s}%s " D_FLOW_RATE "{m}%s " D_UNIT_GALLONS_PER_MIN "{e}";
const char HTTP_SNS_MOISTURE[] PROGMEM = "{s}%s " D_MOISTURE "{m}%d " D_UNIT_PERCENT "{e}";
const char HTTP_SNS_RANGE[] PROGMEM = "{s}%s " D_RANGE "{m}%d" "{e}";
const char HTTP_SNS_DISTANCE[] PROGMEM = "{s}%s " D_DISTANCE "{m}%d " D_UNIT_MILLIMETER "{e}";
const char HTTP_SNS_VOLTAGE[] PROGMEM = "{s}" D_VOLTAGE "{m}%s " D_UNIT_VOLT "{e}";
const char HTTP_SNS_CURRENT[] PROGMEM = "{s}" D_CURRENT "{m}%s " D_UNIT_AMPERE "{e}";
const char HTTP_SNS_POWER[] PROGMEM = "{s}" D_POWERUSAGE "{m}%s " D_UNIT_WATT "{e}";

View File

@ -558,7 +558,8 @@
// #define USE_SPS30 // [I2cDriver30] Enable Sensiron SPS30 particle sensor (I2C address 0x69) (+1.7 code)
#define USE_ADE7953 // [I2cDriver7] Enable ADE7953 Energy monitor as used on Shelly 2.5 (I2C address 0x38) (+1k5)
// #define USE_VL53L0X // [I2cDriver31] Enable VL53L0x time of flight sensor (I2C address 0x29) (+4k code)
// #define USE_VL53L1X // [I2cDriver54] Enable support for VL53L1X sensor (I2C address 0x29) using Pololu VL53L1X library (+2k9 code)
// #define USE_VL53L1X // [I2cDriver54] Enable VL53L1X time of flight sensor (I2C address 0x29) using Pololu VL53L1X library (+2k9 code)
// #define USE_TOF10120 // [I2cDriver57] Enable TOF10120 time of flight sensor (I2C address 0x52) (+0k6 code)
// #define USE_MLX90614 // [I2cDriver32] Enable MLX90614 ir temp sensor (I2C address 0x5a) (+0.6k code)
// #define USE_CHIRP // [I2cDriver33] Enable CHIRP soil moisture sensor (variable I2C address, default 0x20)
// #define USE_PAJ7620 // [I2cDriver34] Enable PAJ7620 gesture sensor (I2C address 0x73) (+2.5k code)
@ -591,6 +592,7 @@
// #define USE_EZODO // [I2cDriver55] Enable support for EZO's DO sensor (+0k3 code) - Shared EZO code required for any EZO device (+1k2 code)
// #define USE_EZORGB // [I2cDriver55] Enable support for EZO's RGB sensor (+0k5 code) - Shared EZO code required for any EZO device (+1k2 code)
// #define USE_EZOPMP // [I2cDriver55] Enable support for EZO's PMP sensor (+0k3 code) - Shared EZO code required for any EZO device (+1k2 code)
// #define USE_SEESAW_SOIL // [I2cDriver56] Enable Capacitice Soil Moisture & Temperature Sensor (I2C addresses 0x36 - 0x39) (+1k3 code)
// #define USE_DISPLAY // Add I2C Display Support (+2k code)
#define USE_DISPLAY_MODES1TO5 // Enable display mode 1 to 5 in addition to mode 0

View File

@ -701,7 +701,7 @@ void ResponseAppendFeatures(void)
#ifdef USE_BS814A2
feature7 |= 0x01000000; // xdrv_51_bs814a2.ino
#endif
#ifdef USE_SEESAW_SOIL
#if defined(USE_I2C) && defined(USE_SEESAW_SOIL)
feature7 |= 0x02000000; // xsns_81_seesaw_soil.ino
#endif
#ifdef USE_WIEGAND
@ -710,8 +710,9 @@ void ResponseAppendFeatures(void)
#ifdef USE_NEOPOOL
feature7 |= 0x08000000; // xsns_83_neopool.ino
#endif
// feature7 |= 0x10000000;
#if defined(USE_I2C) && defined(USE_TOF10120)
feature7 |= 0x10000000; // xsns_84_tof10120
#endif
// feature7 |= 0x20000000;
// feature7 |= 0x40000000;
// feature7 |= 0x80000000;

View File

@ -109,7 +109,8 @@
//#define USE_SPS30 // [I2cDriver30] Enable Sensiron SPS30 particle sensor (I2C address 0x69) (+1.7 code)
#define USE_ADE7953 // [I2cDriver7] Enable ADE7953 Energy monitor as used on Shelly 2.5 (I2C address 0x38) (+1k5)
//#define USE_VL53L0X // [I2cDriver31] Enable VL53L0x time of flight sensor (I2C address 0x29) (+4k code)
//#define USE_VL53L1X // [I2cDriver54] Enable support for VL53L1X sensor (I2C address 0x29) using Pololu VL53L1X library (+2k9 code)
//#define USE_VL53L1X // [I2cDriver54] Enable VL53L1X time of flight sensor (I2C address 0x29) using Pololu VL53L1X library (+2k9 code)
//#define USE_TOF10120 // [I2cDriver57] Enable TOF10120 time of flight sensor (I2C address 0x52) (+0k6 code)
//#define USE_MLX90614 // [I2cDriver32] Enable MLX90614 ir temp sensor (I2C address 0x5a) (+0.6k code)
//#define USE_CHIRP // [I2cDriver33] Enable CHIRP soil moisture sensor (variable I2C address, default 0x20)
//#define USE_PAJ7620 // [I2cDriver34] Enable PAJ7620 gesture sensor (I2C address 0x73) (+2.5k code)
@ -140,6 +141,7 @@
//#define USE_EZODO // [I2cDriver55] Enable support for EZO's DO sensor (+0k3 code) - Shared EZO code required for any EZO device (+1k2 code)
//#define USE_EZORGB // [I2cDriver55] Enable support for EZO's RGB sensor (+0k5 code) - Shared EZO code required for any EZO device (+1k2 code)
//#define USE_EZOPMP // [I2cDriver55] Enable support for EZO's PMP sensor (+0k3 code) - Shared EZO code required for any EZO device (+1k2 code)
//#define USE_SEESAW_SOIL // [I2cDriver56] Enable Capacitice Soil Moisture & Temperature Sensor (I2C addresses 0x36 - 0x39) (+1k3 code)
//#define USE_SPI // Hardware SPI using GPIO12(MISO), GPIO13(MOSI) and GPIO14(CLK) in addition to two user selectable GPIOs(CS and DC)
//#define USE_RC522 // Add support for MFRC522 13.56Mhz Rfid reader (+6k code)
@ -194,8 +196,8 @@
//#define USE_MAX31865 // Add support for MAX31865 RTD sensors using softSPI
#define USE_IR_REMOTE // Send IR remote commands using library IRremoteESP8266 and ArduinoJson (+4k code, 0k3 mem, 48 iram)
#define USE_IR_RECEIVE // Support for IR receiver (+5k5 code, 264 iram)
#define USE_LMT01 // Add support for TI LMT01 temperature sensor, count pulses on single GPIO (+0k5 code)
//#define USE_WIEGAND // Add support for 24/26/32/34 bit RFID Wiegand interface (D0/D1) (+1k7 code)
#define USE_TM1638 // Add support for TM1638 switches copying Switch1 .. Switch8 (+1k code)
#define USE_HX711 // Add support for HX711 load cell (+1k5 code)
//#define USE_HX711_GUI // Add optional web GUI to HX711 as scale (+1k8 code)

View File

@ -25,8 +25,11 @@
* I2C Addres: 0x29
\*********************************************************************************************/
#define XSNS_45 45
#define XI2C_31 31 // See I2CDEVICES.md
#define XSNS_45 45
#define XI2C_31 31 // See I2CDEVICES.md
#define USE_VL_MEDIAN
#define USE_VL_MEDIAN_SIZE 5 // Odd number of samples median detection
#include <Wire.h>
#include "VL53L0X.h"
@ -44,7 +47,6 @@ struct {
void Vl53l0Detect(void) {
if (!I2cSetDevice(0x29)) { return; }
if (!sensor.init()) { return; }
I2cSetActiveFound(sensor.getAddress(), "VL53L0X");
@ -61,15 +63,7 @@ void Vl53l0Detect(void) {
Vl53l0x.index = 0;
}
#ifdef USE_WEBSERVER
const char HTTP_SNS_VL53L0X[] PROGMEM =
"{s}VL53L0X " D_DISTANCE "{m}%d" D_UNIT_MILLIMETER "{e}"; // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
#endif // USE_WEBSERVER
#define USE_VL_MEDIAN
void Vl53l0Every_250MSecond(void) {
// every 200 ms
uint16_t dist = sensor.readRangeContinuousMillimeters();
if ((0 == dist) || (dist > 2000)) {
dist = 9999;
@ -79,18 +73,18 @@ void Vl53l0Every_250MSecond(void) {
// store in ring buffer
Vl53l0x.buffer[Vl53l0x.index] = dist;
Vl53l0x.index++;
if (Vl53l0x.index >= 5) {
if (Vl53l0x.index >= USE_VL_MEDIAN_SIZE) {
Vl53l0x.index = 0;
}
// sort list and take median
uint16_t tbuff[5];
uint16_t tbuff[USE_VL_MEDIAN_SIZE];
memmove(tbuff, Vl53l0x.buffer, sizeof(tbuff));
uint16_t tmp;
uint8_t flag;
for (uint32_t ocnt = 0; ocnt < 5; ocnt++) {
for (uint32_t ocnt = 0; ocnt < USE_VL_MEDIAN_SIZE; ocnt++) {
flag = 0;
for (uint32_t count = 0; count < 4; count++) {
for (uint32_t count = 0; count < USE_VL_MEDIAN_SIZE -1; count++) {
if (tbuff[count] > tbuff[count +1]) {
tmp = tbuff[count];
tbuff[count] = tbuff[count +1];
@ -100,7 +94,7 @@ void Vl53l0Every_250MSecond(void) {
}
if (!flag) { break; }
}
Vl53l0x.distance = tbuff[2];
Vl53l0x.distance = tbuff[(USE_VL_MEDIAN_SIZE -1) / 2];
#else
Vl53l0x.distance = dist;
#endif
@ -125,7 +119,7 @@ void Vl53l0Show(boolean json) {
#endif // USE_DOMOTICZ
#ifdef USE_WEBSERVER
} else {
WSContentSend_PD(HTTP_SNS_VL53L0X, Vl53l0x.distance);
WSContentSend_PD(HTTP_SNS_DISTANCE, PSTR("VL53L0X"), Vl53l0x.distance);
#endif
}
}
@ -134,8 +128,7 @@ void Vl53l0Show(boolean json) {
* Interface
\*********************************************************************************************/
bool Xsns45(byte function)
{
bool Xsns45(byte function) {
if (!I2cEnabled(XI2C_31)) { return false; }
bool result = false;

View File

@ -36,8 +36,8 @@ VL53L1X vl53l1x = VL53L1X(); // create object copy
#define VL53L1X_ADDRESS 0x29
struct {
bool ready = false;
uint16_t distance = 0;
bool ready = false;
} vl53l1x_sensors;
/********************************************************************************************/
@ -54,13 +54,7 @@ void Vl53l1Detect(void) {
vl53l1x_sensors.ready = true;
}
#ifdef USE_WEBSERVER
const char HTTP_SNS_VL53L1X[] PROGMEM =
"{s}VL53L1X " D_DISTANCE "{m}%d" D_UNIT_MILLIMETER "{e}"; // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
#endif // USE_WEBSERVER
void Vl53l1Every_250MSecond(void) {
// every 250 ms
uint16_t dist = vl53l1x.read();
if (!dist || dist > 4000) {
dist = 9999;
@ -78,15 +72,15 @@ void Vl53l1Every_Second(void) {
void Vl53l1Show(bool json) {
if (json) {
ResponseAppend_P(PSTR(",\"VL53L1X\":{\"" D_JSON_DISTANCE "\":%d}"), vl53l1x_sensors.distance);
#ifdef USE_DOMOTICZ
if (0 == TasmotaGlobal.tele_period) {
Vl53l1Every_Second();
}
#endif // USE_DOMOTICZ
ResponseAppend_P(PSTR(",\"VL53L1X\":{\"" D_JSON_DISTANCE "\":%d}"), vl53l1x_sensors.distance);
#ifdef USE_WEBSERVER
} else {
WSContentSend_PD(HTTP_SNS_VL53L1X, vl53l1x_sensors.distance);
WSContentSend_PD(HTTP_SNS_DISTANCE, PSTR("VL53L1X"), vl53l1x_sensors.distance);
#endif
}
}
@ -95,9 +89,9 @@ void Vl53l1Show(bool json) {
* Interface
\*********************************************************************************************/
bool Xsns77(uint8_t function)
{
bool Xsns77(uint8_t function) {
if (!I2cEnabled(XI2C_54)) { return false; }
bool result = false;
if (FUNC_INIT == function) {

View File

@ -1,7 +1,7 @@
/*
xsns_83_neopool.ino - Sugar Valley NeoPool Control System Modbus support for Tasmota
Copyright (C) 2021 Norbert Richter
Copyright (C) 2021 Norbert Richter
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -0,0 +1,144 @@
/*
xsns_84_tof10120.ino - TOF10120 sensor support for Tasmota
Copyright (C) 2021 Cyril Pawelko and Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef USE_I2C
#ifdef USE_TOF10120
/*********************************************************************************************\
* TOF10120 I2C Mode (Serial not supported)
*
* I2C Address: 0x52
*
* Connections:
* 1 - Black Gnd
* 2 - Red Vcc
* 3 - Yellow Rxd - Not supported
* 4 - White Txd - Not supported
* 5 - Blue I2C SDA
* 6 - Green I2C SCL
\*********************************************************************************************/
#define XSNS_84 84
#define XI2C_57 57 // See I2CDEVICES.md
#define TOF10120_ADDRESS 0x52
#define TOF10120_INCORRECT_DISTANCE 0xFFFF
struct {
uint16_t distance = 0;
bool ready = false;
} tof10120_sensor;
/********************************************************************************************/
uint16_t Tof10120Read() {
uint16_t distance;
Wire.beginTransmission(TOF10120_ADDRESS);
Wire.write(byte(0x00));
Wire.endTransmission();
delay(1);
Wire.requestFrom(TOF10120_ADDRESS, 2);
if (Wire.available() == 2) {
distance = Wire.read();
distance = distance <<8;
distance |= Wire.read();
} else { // Incorrect value read
AddLog_P(LOG_LEVEL_DEBUG, "TOF: No value read");
return TOF10120_INCORRECT_DISTANCE;
}
AddLog_P(LOG_LEVEL_DEBUG_MORE, "TOF: Distance %u", distance);
return distance;
}
void Tof10120Detect(void) {
if (!I2cSetDevice(TOF10120_ADDRESS)) { return; }
if (Tof10120Read() == TOF10120_INCORRECT_DISTANCE) { return; }
I2cSetActiveFound(TOF10120_ADDRESS, "TOF10120");
tof10120_sensor.ready = true;
}
void Tof10120Every_250MSecond(void) {
uint16_t dist = Tof10120Read();
// if ( dist < 400000) {
// dist = TOF10120_INCORRECT_DISTANCE;
// }
tof10120_sensor.distance = dist;
}
#ifdef USE_DOMOTICZ
void Tof10120Every_Second(void) {
char distance[FLOATSZ];
dtostrfd((float)tof10120_sensor.distance / 10, 1, distance);
DomoticzSensor(DZ_ILLUMINANCE, distance);
}
#endif // USE_DOMOTICZ
void Tof10120Show(bool json) {
if (json) {
ResponseAppend_P(PSTR(",\"TOF10120\":{\"" D_JSON_DISTANCE "\":%d}"), tof10120_sensor.distance);
#ifdef USE_DOMOTICZ
if (0 == TasmotaGlobal.tele_period) {
Tof10120Every_Second();
}
#endif // USE_DOMOTICZ
#ifdef USE_WEBSERVER
} else {
WSContentSend_PD(HTTP_SNS_DISTANCE, PSTR("TOF10120"), tof10120_sensor.distance);
#endif
}
}
/*********************************************************************************************\
* Interface
\*********************************************************************************************/
bool Xsns84(uint8_t function) {
if (!I2cEnabled(XI2C_57)) { return false; }
bool result = false;
if (FUNC_INIT == function) {
Tof10120Detect();
}
else if (tof10120_sensor.ready) {
switch (function) {
case FUNC_EVERY_250_MSECOND:
Tof10120Every_250MSecond();
break;
#ifdef USE_DOMOTICZ
case FUNC_EVERY_SECOND:
Tof10120Every_Second();
break;
#endif // USE_DOMOTICZ
case FUNC_JSON_APPEND:
Tof10120Show(1);
break;
#ifdef USE_WEBSERVER
case FUNC_WEB_SENSOR:
Tof10120Show(0);
break;
#endif // USE_WEBSERVER
}
}
return result;
}
#endif // USE_TOF10120
#endif // USE_I2C

View File

@ -245,7 +245,7 @@ a_features = [[
"USE_DISPLAY_ILI9488","USE_DISPLAY_SSD1351","USE_DISPLAY_RA8876","USE_DISPLAY_ST7789",
"USE_DISPLAY_SSD1331","USE_UFILESYS","USE_TIMEPROP","USE_PID",
"USE_BS814A2","USE_SEESAW_SOIL","USE_WIEGAND","USE_NEOPOOL",
"","","",""
"USE_TOF10120","","",""
]]
usage = "usage: decode-status {-d | -f} arg"
@ -273,7 +273,7 @@ else:
obj = json.load(fp)
def StartDecode():
print ("\n*** decode-status.py v20210116 by Theo Arends and Jacek Ziolkowski ***")
print ("\n*** decode-status.py v20210122 by Theo Arends and Jacek Ziolkowski ***")
# print("Decoding\n{}".format(obj))