Merge pull request #99 from DmitryBorisenko33/ver3

добавил AHTX0 HDC1080
This commit is contained in:
Dmitry Borisenko
2021-12-15 21:08:34 +01:00
committed by GitHub
4 changed files with 68 additions and 20 deletions

View File

@@ -1,4 +1,7 @@
#pragma once #pragma once
#include <Arduino.h> #include <Arduino.h>
float yourSensorReading(String type); float yourSensorReading(String type, String addr);
void HDC1080_init(String &addr);
void AHTX0_init();

View File

@@ -41,6 +41,8 @@ lib_deps =
adafruit/Adafruit CCS811 Library adafruit/Adafruit CCS811 Library
milesburton/DallasTemperature milesburton/DallasTemperature
robtillaart/SHT2x@^0.1.1 robtillaart/SHT2x@^0.1.1
ClosedCube HDC1080
Adafruit AHTX0
monitor_filters = esp8266_exception_decoder monitor_filters = esp8266_exception_decoder
upload_speed = 921600 upload_speed = 921600
monitor_speed = 115200 monitor_speed = 115200
@@ -65,6 +67,8 @@ lib_deps =
adafruit/Adafruit CCS811 Library adafruit/Adafruit CCS811 Library
milesburton/DallasTemperature milesburton/DallasTemperature
robtillaart/SHT2x@^0.1.1 robtillaart/SHT2x@^0.1.1
ClosedCube HDC1080
Adafruit AHTX0
monitor_filters = esp8266_exception_decoder monitor_filters = esp8266_exception_decoder
upload_speed = 921600 upload_speed = 921600
monitor_speed = 115200 monitor_speed = 115200
@@ -82,7 +86,6 @@ lib_deps =
ESPAsyncUDP ESPAsyncUDP
CTBot @2.1.6 CTBot @2.1.6
MySensors @2.3.2 MySensors @2.3.2
robtillaart/SHT2x@^0.1.1
monitor_filters = esp8266_exception_decoder monitor_filters = esp8266_exception_decoder
upload_speed = 921600 upload_speed = 921600
monitor_speed = 115200 monitor_speed = 115200
@@ -108,6 +111,8 @@ lib_deps =
adafruit/Adafruit CCS811 Library adafruit/Adafruit CCS811 Library
milesburton/DallasTemperature milesburton/DallasTemperature
robtillaart/SHT2x@^0.1.1 robtillaart/SHT2x@^0.1.1
ClosedCube HDC1080
Adafruit AHTX0
monitor_filters = esp32_exception_decoder monitor_filters = esp32_exception_decoder
upload_speed = 921600 upload_speed = 921600
monitor_speed = 115200 monitor_speed = 115200

View File

@@ -1,23 +1,63 @@
#include "YourSensor.h" #include "YourSensor.h"
float yourSensorReading(String type) { #include "Utils/StringUtils.h"
//подключаем необходимые файлы библиотеки
#include <Adafruit_AHTX0.h>
#include "ClosedCube_HDC1080.h"
//создаем объект HDC1080
ClosedCube_HDC1080 hdc1080;
//создаем объект AHTX0
Adafruit_AHTX0 aht;
Adafruit_Sensor *aht_humidity, *aht_temp;
sensors_event_t tmpEvent_t;
float yourSensorReading(String type, String addr) {
float value; float value;
if (type == "type1") { // type1 - замените на название вашего датчика, потом это же название указывайте в type[], в вебе //========================================================HDC1080================================================================
//сюда вставляем процедуру чтения одного датчика if (type == "HDC1080_temp") {
static int a; HDC1080_init(addr);
a++; value = hdc1080.readTemperature();
value = a; } else if (type == "HDC1080_hum") {
} else if (type == "type2") { HDC1080_init(addr);
//сюда вставляем процедуру чтения другого датчика value = hdc1080.readHumidity();
static int b; }
b--; //==========================================================AHTX0=================================================================
value = b; if (type == "AHTX0_temp") {
} else if (type == "type3") { AHTX0_init();
//сюда третьего и так далее, создавайте сколько угодно else if.... aht_temp->getEvent(&tmpEvent_t);
//если у одного датчика несколько параметров то под каждый из них делайте свой else if и свое имя type value = tmpEvent_t.temperature;
static int c; } else if (type == "typeAHTX0_hum") {
c++; AHTX0_init();
value = c * 10; aht_humidity->getEvent(&tmpEvent_t);
value = tmpEvent_t.relative_humidity;
} }
return value; return value;
} }
void HDC1080_init(String &addr) {
static bool HDC1080_flag = true;
if (HDC1080_flag) {
hdc1080.begin(hexStringToUint8(addr));
HDC1080_flag = false;
}
}
void AHTX0_init() {
static bool AHTX0_flag = true;
if (AHTX0_flag) {
if (!aht.begin()) {
Serial.println("Failed to find AHT10/AHT20 chip");
// return -127;
}
aht_temp = aht.getTemperatureSensor();
aht_temp->printSensorDetails();
aht_humidity = aht.getHumiditySensor();
aht_humidity->printSensorDetails();
AHTX0_flag = false;
}
}

View File

@@ -29,7 +29,7 @@ void SensorAny::loop() {
} }
void SensorAny::read() { void SensorAny::read() {
float value = yourSensorReading(_type); float value = yourSensorReading(_type, _addr);
value = value * _c; value = value * _c;