Merge pull request #9113 from jkostorz/development

Add support DYP ME007 ultrasonic distance sensor (serial port version)
This commit is contained in:
Theo Arends 2020-08-17 15:35:21 +02:00 committed by GitHub
commit 44e2c6b6a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 193 additions and 2 deletions

View File

@ -684,6 +684,7 @@
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
#define D_SENSOR_DYP_RX "DYP Rx"
#define D_SENSOR_ELECTRIQ_MOODL "MOODL Tx"
#define D_SENSOR_AS3935 "AS3935"
#define D_SENSOR_WINDMETER_SPEED "WindMeter Spd"

View File

@ -684,6 +684,7 @@
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
#define D_SENSOR_DYP_RX "DYP Rx"
#define D_SENSOR_ELECTRIQ_MOODL "MOODL Tx"
#define D_SENSOR_AS3935 "AS3935"
#define D_SENSOR_WINDMETER_SPEED "WindMeter Spd"

View File

@ -684,6 +684,7 @@
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
#define D_SENSOR_DYP_RX "DYP Rx"
#define D_SENSOR_ELECTRIQ_MOODL "MOODL Tx"
#define D_SENSOR_AS3935 "AS3935"
#define D_SENSOR_WINDMETER_SPEED "WindMeter Spd"

View File

@ -684,6 +684,7 @@
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
#define D_SENSOR_DYP_RX "DYP Rx"
#define D_SENSOR_ELECTRIQ_MOODL "MOODL Tx"
#define D_SENSOR_AS3935 "AS3935"
#define D_SENSOR_WINDMETER_SPEED "WindMeter Spd"

View File

@ -684,6 +684,7 @@
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
#define D_SENSOR_DYP_RX "DYP Rx"
#define D_SENSOR_ELECTRIQ_MOODL "MOODL Tx"
#define D_SENSOR_AS3935 "AS3935"
#define D_SENSOR_WINDMETER_SPEED "WindMeter Spd"

View File

@ -684,6 +684,7 @@
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
#define D_SENSOR_DYP_RX "DYP Rx"
#define D_SENSOR_ELECTRIQ_MOODL "MOODL Tx"
#define D_SENSOR_AS3935 "AS3935"
#define D_SENSOR_WINDMETER_SPEED "WindMeter Spd"

View File

@ -684,6 +684,7 @@
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
#define D_SENSOR_DYP_RX "DYP Rx"
#define D_SENSOR_ELECTRIQ_MOODL "MOODL Tx"
#define D_SENSOR_AS3935 "AS3935"
#define D_SENSOR_WINDMETER_SPEED "WindMeter Spd"

View File

@ -684,6 +684,7 @@
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
#define D_SENSOR_DYP_RX "DYP Rx"
#define D_SENSOR_ELECTRIQ_MOODL "MOODL Tx"
#define D_SENSOR_AS3935 "AS3935"
#define D_SENSOR_WINDMETER_SPEED "WindMeter Spd"

View File

@ -684,6 +684,7 @@
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
#define D_SENSOR_DYP_RX "DYP Rx"
#define D_SENSOR_ELECTRIQ_MOODL "MOODL Tx"
#define D_SENSOR_AS3935 "AS3935"
#define D_SENSOR_WINDMETER_SPEED "WindMeter Spd"

View File

@ -684,6 +684,7 @@
#define D_SENSOR_CC1101_GDO0 "CC1101 - GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 - GDO2"
#define D_SENSOR_HRXL_RX "HRXL - RX"
#define D_SENSOR_DYP_RX "DYP Rx"
#define D_SENSOR_ELECTRIQ_MOODL "MOODL - TX"
#define D_SENSOR_AS3935 "AS3935"
#define D_SENSOR_WINDMETER_SPEED "Velocità vento"

View File

@ -684,6 +684,7 @@
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
#define D_SENSOR_DYP_RX "DYP Rx"
#define D_SENSOR_ELECTRIQ_MOODL "MOODL Tx"
#define D_SENSOR_AS3935 "AS3935"
#define D_SENSOR_WINDMETER_SPEED "WindMeter Spd"

View File

@ -684,6 +684,7 @@
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
#define D_SENSOR_DYP_RX "DYP Rx"
#define D_SENSOR_ELECTRIQ_MOODL "MOODL Tx"
#define D_SENSOR_AS3935 "AS3935"
#define D_SENSOR_WINDMETER_SPEED "WindMeter Spd"

View File

@ -684,6 +684,7 @@
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
#define D_SENSOR_DYP_RX "DYP Rx"
#define D_SENSOR_ELECTRIQ_MOODL "MOODL Tx"
#define D_SENSOR_AS3935 "AS3935"
#define D_SENSOR_WINDMETER_SPEED "WindMeter Spd"

View File

@ -684,6 +684,7 @@
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
#define D_SENSOR_DYP_RX "DYP Rx"
#define D_SENSOR_ELECTRIQ_MOODL "MOODL Tx"
#define D_SENSOR_AS3935 "AS3935"
#define D_SENSOR_WINDMETER_SPEED "WindMeter Spd"

View File

@ -684,6 +684,7 @@
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
#define D_SENSOR_DYP_RX "DYP Rx"
#define D_SENSOR_ELECTRIQ_MOODL "MOODL Tx"
#define D_SENSOR_AS3935 "AS3935"
#define D_SENSOR_WINDMETER_SPEED "WindMeter Spd"

View File

@ -684,6 +684,7 @@
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
#define D_SENSOR_DYP_RX "DYP Rx"
#define D_SENSOR_ELECTRIQ_MOODL "MOODL Tx"
#define D_SENSOR_AS3935 "AS3935"
#define D_SENSOR_WINDMETER_SPEED "WindMeter Spd"

View File

@ -684,6 +684,7 @@
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
#define D_SENSOR_DYP_RX "DYP Rx"
#define D_SENSOR_ELECTRIQ_MOODL "MOODL Tx"
#define D_SENSOR_AS3935 "AS3935"
#define D_SENSOR_WINDMETER_SPEED "WindMeter Spd"

View File

@ -684,6 +684,7 @@
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
#define D_SENSOR_DYP_RX "DYP Rx"
#define D_SENSOR_ELECTRIQ_MOODL "MOODL Tx"
#define D_SENSOR_AS3935 "AS3935"
#define D_SENSOR_WINDMETER_SPEED "WindMeter Spd"

View File

@ -684,6 +684,7 @@
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
#define D_SENSOR_DYP_RX "DYP Rx"
#define D_SENSOR_ELECTRIQ_MOODL "MOODL Tx"
#define D_SENSOR_AS3935 "AS3935"
#define D_SENSOR_WINDMETER_SPEED "WindMeter Spd"

View File

@ -684,6 +684,7 @@
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
#define D_SENSOR_DYP_RX "DYP Rx"
#define D_SENSOR_ELECTRIQ_MOODL "MOODL Tx"
#define D_SENSOR_AS3935 "AS3935"
#define D_SENSOR_WINDMETER_SPEED "WindMeter Spd"

View File

@ -684,6 +684,7 @@
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
#define D_SENSOR_DYP_RX "DYP Rx"
#define D_SENSOR_ELECTRIQ_MOODL "MOODL Tx"
#define D_SENSOR_AS3935 "AS3935"
#define D_SENSOR_WINDMETER_SPEED "WindMeter Spd"

View File

@ -684,6 +684,7 @@
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
#define D_SENSOR_DYP_RX "DYP Rx"
#define D_SENSOR_ELECTRIQ_MOODL "MOODL Tx"
#define D_SENSOR_AS3935 "AS3935"
#define D_SENSOR_WINDMETER_SPEED "WindMeter Spd"

View File

@ -684,6 +684,7 @@
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
#define D_SENSOR_DYP_RX "DYP Rx"
#define D_SENSOR_ELECTRIQ_MOODL "MOODL Tx"
#define D_SENSOR_AS3935 "AS3935"
#define D_SENSOR_WINDMETER_SPEED "WindMeter Spd"

View File

@ -619,6 +619,7 @@
// #define USE_FLOG // Add support for GPS logging in OTA's Flash (Experimental) (+2k9 code, +8 bytes RAM)
//#define USE_HM10 // (ESP8266 only) Add support for HM-10 as a BLE-bridge (+9k3 code)
//#define USE_HRXL // Add support for MaxBotix HRXL-MaxSonar ultrasonic range finders (+0k7)
//#define USE_DYP // Add support for DYP ME-007 ultrasonic distance sensor, serial port version (+0k5 code)
//#define USE_TASMOTA_CLIENT // Add support for Arduino Uno/Pro Mini via serial interface including flashing (+2k6 code, 64 mem)
#define USE_TASMOTA_CLIENT_FLASH_SPEED 57600 // Usually 57600 for 3.3V variants and 115200 for 5V variants
#define USE_TASMOTA_CLIENT_SERIAL_SPEED 57600 // Depends on the sketch that is running on the Uno/Pro Mini

View File

@ -242,6 +242,7 @@ enum UserSelectablePins {
GPIO_IEM3000_TX, // IEM3000 Serial interface
GPIO_IEM3000_RX, // IEM3000 Serial interface
GPIO_ZIGBEE_RST, // Zigbee reset
GPIO_DYP_RX,
GPIO_SENSOR_END };
// Programmer selectable GPIO functionality
@ -337,7 +338,8 @@ const char kSensorNames[] PROGMEM =
D_SENSOR_TELEINFO_RX "|" D_SENSOR_TELEINFO_ENABLE "|"
D_SENSOR_LMT01_PULSE "|"
D_SENSOR_IEM3000_TX "|" D_SENSOR_IEM3000_RX "|"
D_SENSOR_ZIGBEE_RST
D_SENSOR_ZIGBEE_RST "|"
D_SENSOR_DYP_RX
;
const char kSensorNamesFixed[] PROGMEM =
@ -704,6 +706,9 @@ const uint8_t kGpioNiceList[] PROGMEM = {
#ifdef USE_HRXL
GPIO_HRXL_RX,
#endif
#ifdef USE_DYP
GPIO_DYP_RX,
#endif
#ifdef USE_AS3935
GPIO_AS3935,
#endif

View File

@ -138,6 +138,7 @@ enum UserSelectablePins {
GPIO_LMT01, // LMT01 input counting pin
GPIO_IEM3000_TX, GPIO_IEM3000_RX, // IEM3000 Serial interface
GPIO_ZIGBEE_RST, // Zigbee reset
GPIO_DYP_RX,
GPIO_SENSOR_END };
enum ProgramSelectablePins {
@ -238,7 +239,8 @@ const char kSensorNames[] PROGMEM =
D_SENSOR_TELEINFO_RX "|" D_SENSOR_TELEINFO_ENABLE "|"
D_SENSOR_LMT01_PULSE "|"
D_SENSOR_IEM3000_TX "|" D_SENSOR_IEM3000_RX "|"
D_SENSOR_ZIGBEE_RST
D_SENSOR_ZIGBEE_RST "|"
D_SENSOR_DYP_RX
;
const char kSensorNamesFixed[] PROGMEM =
@ -551,6 +553,9 @@ const uint16_t kGpioNiceList[] PROGMEM = {
#ifdef USE_HRXL
AGPIO(GPIO_HRXL_RX),
#endif
#ifdef USE_DYP
AGPIO(GPIO_DYP_RX),
#endif
#ifdef USE_AS3935
AGPIO(GPIO_AS3935),
#endif

157
tasmota/xsns_76_dyp.ino Normal file
View File

@ -0,0 +1,157 @@
/*
xsns_76_dyp.ino - DYP ME007 serial interface
Copyright (C) 2020 Janusz Kostorz
This program is free software: you can reDYPDistanceribute 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 DYPDistanceributed 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_DYP
/*********************************************************************************************\
* DYP ME007 ultrasonic distanceance sensor (300...4000mm), serial version
*
* Every one second code check last received value from sensor via serial port and return:
* -1 for checksum error
* 0 for distance below 300mm
* 300...4000 for measured distance
* 4999 for distance above 4000mm
* 5999 for not connected sensor
*
\*********************************************************************************************/
#define XSNS_76 76
#include <TasmotaSerial.h>
TasmotaSerial *DYPSerial = nullptr;
#define DYP_CRCERROR -1
#define DYP_BELOWMIN 0
#define DYP_MIN 300
#define DYP_MAX 4000
#define DYP_ABOVEMAX 4999
#define DYP_NOSENSOR 5999
uint16_t DYPDistance = 0; // distance in milimeters
bool DYPSensor = false; // sensor available
/*********************************************************************************************/
void DYPInit(void)
{
DYPSensor = false;
if (PinUsed(GPIO_DYP_RX))
{
DYPSerial = new TasmotaSerial(Pin(GPIO_DYP_RX), -1, 1);
if (DYPSerial->begin(9600))
{
if (DYPSerial->hardwareSerial())
ClaimSerial();
DYPSensor = true;
}
}
}
void DYPEverySecond(void)
{
if (!DYPSensor)
return;
// check for serial data
if (DYPSerial->available() < 6)
{
DYPDistance = DYP_NOSENSOR;
return;
}
// trash old data (only 7 last bytes are needed for calculate distance)
while (DYPSerial->available() > 7)
DYPSerial->read();
// read data from serial port - * 0xFF MSB LSB CRC *
while (DYPSerial->available() > 3)
{
// check for start byte signature
if (DYPSerial->read() != 0xFF)
continue;
// check for data bytes
if (DYPSerial->available() > 2)
{
uint8_t msb = DYPSerial->read();
uint8_t lsb = DYPSerial->read();
if (((uint16_t)(0xFF + msb + lsb) & 0xFF) == DYPSerial->read()) {
uint16_t data = (msb << 8) | lsb;
if (data < DYP_MIN)
data = DYP_BELOWMIN;
if (data > DYP_MAX)
data = DYP_ABOVEMAX;
DYPDistance = data;
}
else {
DYPDistance = DYP_CRCERROR;
}
}
}
}
void DYPShow(bool json)
{
char types[5] = "DYP";
if (json)
{
ResponseAppend_P(PSTR(",\"%s\":{\"" D_DISTANCE "\":%d}"), types, DYPDistance);
#ifdef USE_WEBSERVER
}
else
{
WSContentSend_PD(HTTP_SNS_RANGE, types, DYPDistance);
#endif // USE_WEBSERVER
}
}
/*********************************************************************************************\
* Interface
\*********************************************************************************************/
bool Xsns76(uint8_t function)
{
if (!PinUsed(GPIO_DYP_RX))
return false;
switch (function)
{
case FUNC_INIT:
DYPInit();
break;
case FUNC_EVERY_SECOND:
DYPEverySecond();
break;
case FUNC_JSON_APPEND:
DYPShow(1);
break;
#ifdef USE_WEBSERVER
case FUNC_WEB_SENSOR:
DYPShow(0);
break;
#endif // USE_WEBSERVER
}
return false;
}
#endif // USE_DYP