MAX6675 @Serghei63

This commit is contained in:
Dmitry Borisenko
2022-03-15 15:59:26 +01:00
parent 617ce425f4
commit 185a949a80
10 changed files with 204 additions and 109 deletions

View File

@@ -293,9 +293,23 @@
"round": 1
},
{
"name": "22. Датчик CO2 MHZ-19 UART",
"name": "22. Cенсор температуры MAX6675",
"num": 22,
"type": "Reading",
"subtype": "Max6675t",
"id": "maxtmp",
"widget": "anydataTmp",
"page": "Сенсоры",
"descr": "MAX Температура",
"int": 15,
"DO": 12,
"CS": 13,
"CLK": 14
},
{
"name": "23. Датчик CO2 MHZ-19 UART",
"num": 23,
"type": "Reading",
"subtype": "Mhz19uart",
"id": "co2uart",
"widget": "anydataPpm",
@@ -312,8 +326,8 @@
"ABC": 1
},
{
"name": "23. Датчик CO2 MHZ-19 PWM",
"num": 23,
"name": "24. Датчик CO2 MHZ-19 PWM",
"num": 24,
"type": "Reading",
"subtype": "Mhz19pwm",
"id": "co2pwm",
@@ -327,8 +341,8 @@
"int": 300
},
{
"name": "24. Cенсор температуры от MHZ-19 UART",
"num": 24,
"name": "25. Cенсор температуры от MHZ-19 UART",
"num": 25,
"type": "Reading",
"subtype": "Mhz19temp",
"id": "Mhz19temp",
@@ -344,8 +358,8 @@
"int": 30
},
{
"name": "25. Рабочий диапазон от MHZ-19 UART",
"num": 25,
"name": "26. Рабочий диапазон от MHZ-19 UART",
"num": 26,
"type": "Reading",
"subtype": "Mhz19range",
"id": "Mhz19range",
@@ -362,8 +376,8 @@
"int": 30
},
{
"name": "26. Автокалибровка от MHZ-19 UART",
"num": 26,
"name": "27. Автокалибровка от MHZ-19 UART",
"num": 27,
"type": "Reading",
"subtype": "Mhz19ABC",
"id": "Mhz19ABC",
@@ -377,8 +391,8 @@
"int": 30
},
{
"name": "27. Датчик пыли SDS011 PM25",
"num": 27,
"name": "28. Датчик пыли SDS011 PM25",
"num": 28,
"type": "Reading",
"subtype": "Sds011_25",
"id": "pmuart25",
@@ -395,8 +409,8 @@
"period": 300
},
{
"name": "28. Датчик пыли SDS011 PM10",
"num": 28,
"name": "29. Датчик пыли SDS011 PM10",
"num": 29,
"type": "Reading",
"subtype": "Sds011_10",
"id": "pmuart10",
@@ -413,8 +427,8 @@
"period": 300
},
{
"name": "29. Cенсор температуры Sht20",
"num": 29,
"name": "30. Cенсор температуры Sht20",
"num": 30,
"type": "Reading",
"subtype": "Sht20t",
"id": "tmp2",
@@ -425,8 +439,8 @@
"round": 1
},
{
"name": "30. Cенсор влажности Sht20",
"num": 30,
"name": "31. Cенсор влажности Sht20",
"num": 31,
"type": "Reading",
"subtype": "Sht20h",
"id": "Hum2",
@@ -440,8 +454,8 @@
"header": "Экраны"
},
{
"name": "31. LCD экран 2004",
"num": 31,
"name": "32. LCD экран 2004",
"num": 32,
"type": "Reading",
"subtype": "Lcd2004",
"id": "Lcd",
@@ -455,8 +469,8 @@
"id2show": "id датчика"
},
{
"name": "32. LCD экран 1602",
"num": 32,
"name": "33. LCD экран 1602",
"num": 33,
"type": "Reading",
"subtype": "Lcd2004",
"id": "Lcd",

View File

@@ -33,13 +33,11 @@ data_dir = data_svelte
[common_env_data]
lib_deps_external =
bblanchon/ArduinoJson @6.18.0
;me-no-dev/ESP Async WebServer
Links2004/WebSockets
knolleary/PubSubClient
[env:esp8266_4mb_fromitems]
lib_deps =
adafruit/Adafruit MCP23017 Arduino Library@^2.0.2
adafruit/Adafruit ADS1X15 @ ^2.3.0
Adafruit AHTX0
@@ -49,13 +47,13 @@ lib_deps =
milesburton/DallasTemperature@^3.9.1
https://github.com/JonasGMorsch/GY-21.git
ClosedCube HDC1080
adafruit/MAX6675 library
Nova Fitness Sds dust sensors library@1.5.1
robtillaart/SHT2x@^0.1.1
marcoschwartz/LiquidCrystal_I2C@^1.1.4
[env:esp32_4mb_fromitems]
lib_deps =
adafruit/Adafruit MCP23017 Arduino Library@^2.0.2
adafruit/Adafruit ADS1X15 @ ^2.3.0
Adafruit AHTX0
@@ -65,6 +63,7 @@ lib_deps =
milesburton/DallasTemperature@^3.9.1
https://github.com/JonasGMorsch/GY-21.git
ClosedCube HDC1080
adafruit/MAX6675 library
Nova Fitness Sds dust sensors library@1.5.1
robtillaart/SHT2x@^0.1.1
marcoschwartz/LiquidCrystal_I2C@^1.1.4

View File

@@ -14,6 +14,7 @@ void* getAPI_Dht1122(String subtype, String params);
void* getAPI_Ds18b20(String subtype, String params);
void* getAPI_GY21(String subtype, String params);
void* getAPI_Hdc1080(String subtype, String params);
void* getAPI_Max6675(String subtype, String params);
void* getAPI_Mhz19(String subtype, String params);
void* getAPI_Sds011(String subtype, String params);
void* getAPI_Sht20(String subtype, String params);
@@ -35,6 +36,7 @@ if ((tmpAPI = getAPI_Dht1122(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Ds18b20(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_GY21(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Hdc1080(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Max6675(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Mhz19(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Sds011(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Sht20(subtype, params)) != nullptr) return tmpAPI;

View File

@@ -10,60 +10,68 @@
#include "classes/IoTItem.h"
#include "Wire.h"
#include <Adafruit_ADS1X15.h> // Библиотека для работы с модулями ADS1115 и ADS1015
#include <Adafruit_ADS1X15.h> // Библиотека для работы с модулями ADS1115 и ADS1015
// to do убрать глобальный экземпляр
Adafruit_ADS1115 ads;
class Ads1115 : public IoTItem {
int _pin;
bool _isRaw;
bool _isInited = false;
int _pin;
bool _isRaw;
bool _isInited = false;
public:
Ads1115(String parameters): IoTItem(parameters) {
String tmp;
jsonRead(parameters, "pin", tmp);
_pin = tmp.toInt();
Ads1115(String parameters) : IoTItem(parameters) {
String tmp;
jsonRead(parameters, "pin", tmp);
_pin = tmp.toInt();
jsonRead(parameters, "mode", tmp);
_isRaw = tmp == "raw";
jsonRead(parameters, "mode", tmp);
_isRaw = tmp == "raw";
if (!ads.begin()) {
Serial.println("Failed to initialize ADS.");
_isInited = false;
} else _isInited = true;
if (!ads.begin()) {
Serial.println("Failed to initialize ADS.");
_isInited = false;
} else
_isInited = true;
String gain;
jsonRead(parameters, "gain", gain);
if (gain == "1x") ads.setGain(GAIN_ONE);
else if (gain == "2x") ads.setGain(GAIN_TWO);
else if (gain == "4x") ads.setGain(GAIN_FOUR);
else if (gain == "8x") ads.setGain(GAIN_EIGHT);
else if (gain == "16x") ads.setGain(GAIN_SIXTEEN);
else ads.setGain(GAIN_TWOTHIRDS);
// ВОЗМОЖНЫЕ ВАРИАНТЫ УСТАНОВКИ КУ:
// ads.setGain(GAIN_TWOTHIRDS); //| 2/3х | +/-6.144V | 1bit = 0.1875mV |
// ads.setGain(GAIN_ONE); //| 1х | +/-4.096V | 1bit = 0.125mV |
// ads.setGain(GAIN_TWO); //| 2х | +/-2.048V | 1bit = 0.0625mV |
// ads.setGain(GAIN_FOUR); //| 4х | +/-1.024V | 1bit = 0.03125mV |
// ads.setGain(GAIN_EIGHT); //| 8х | +/-0.512V | 1bit = 0.015625mV |
// ads.setGain(GAIN_SIXTEEN); //| 16х | +/-0.256V | 1bit = 0.0078125mV |
String gain;
jsonRead(parameters, "gain", gain);
if (gain == "1x")
ads.setGain(GAIN_ONE);
else if (gain == "2x")
ads.setGain(GAIN_TWO);
else if (gain == "4x")
ads.setGain(GAIN_FOUR);
else if (gain == "8x")
ads.setGain(GAIN_EIGHT);
else if (gain == "16x")
ads.setGain(GAIN_SIXTEEN);
else
ads.setGain(GAIN_TWOTHIRDS);
// ВОЗМОЖНЫЕ ВАРИАНТЫ УСТАНОВКИ КУ:
// ads.setGain(GAIN_TWOTHIRDS); //| 2/3х | +/-6.144V | 1bit = 0.1875mV |
// ads.setGain(GAIN_ONE); //| 1х | +/-4.096V | 1bit = 0.125mV |
// ads.setGain(GAIN_TWO); //| 2х | +/-2.048V | 1bit = 0.0625mV |
// ads.setGain(GAIN_FOUR); //| 4х | +/-1.024V | 1bit = 0.03125mV |
// ads.setGain(GAIN_EIGHT); //| 8х | +/-0.512V | 1bit = 0.015625mV |
// ads.setGain(GAIN_SIXTEEN); //| 16х | +/-0.256V | 1bit = 0.0078125mV |
}
void doByInterval() {
if (_isInited) {
if (_isRaw) value.valD = ads.readADC_SingleEnded(_pin); // Чтение АЦП нулевого канала(rawdata)
else value.valD = ads.computeVolts(ads.readADC_SingleEnded(_pin)); // Чтение АЦП нулевого канала (Вольты)
regEvent(value.valD, "ADC1115");
}
if (_isInited) {
if (_isRaw)
value.valD = ads.readADC_SingleEnded(_pin); // Чтение АЦП нулевого канала(rawdata)
else
value.valD = ads.computeVolts(ads.readADC_SingleEnded(_pin)); // Чтение АЦП нулевого канала (Вольты)
regEvent(value.valD, "ADC1115");
}
}
~Ads1115() {};
~Ads1115(){};
};
void *getAPI_Ads1115(String subtype, String param)
{
void *getAPI_Ads1115(String subtype, String param) {
if (subtype == F("Ads1115")) {
return new Ads1115(param);
} else {
@@ -71,25 +79,22 @@ void *getAPI_Ads1115(String subtype, String param)
}
}
// {
// "name": "26. Датчик напряжения ADS1115",
// "num": 26,
// "type": "Reading",
// "subtype": "Ads1115",
// "id": "Ads3",
// "widget": "anydataVlt",
// "page": "Сенсоры",
// "descr": "ADS_3",
// "pin": "0",
// "mode": "volt",
// "gain": "3/4x",
// {
// "name": "26. Датчик напряжения ADS1115",
// "num": 26,
// "type": "Reading",
// "subtype": "Ads1115",
// "id": "Ads3",
// "widget": "anydataVlt",
// "page": "Сенсоры",
// "descr": "ADS_3",
// "pin": "0",
// "mode": "volt",
// "gain": "3/4x",
// "plus": 0,
// "multiply": 1,
// "round": 100,
// "int": 10
// }
// "plus": 0,
// "multiply": 1,
// "round": 100,
// "int": 10
// }

View File

@@ -6,55 +6,56 @@
adapted for version 4 @Serghei63
******************************************************************/
#include "Global.h"
#include "classes/IoTItem.h"
#include "Adafruit_AHTX0.h"
#include <map>
// to do убрать глобальный экземпляр
Adafruit_AHTX0 aht;
sensors_event_t temp, humidity;
class Aht20t : public IoTItem {
public:
Aht20t(String parameters): IoTItem(parameters) { }
Aht20t(String parameters) : IoTItem(parameters) {}
void doByInterval() {
value.valD = temp.temperature;
if (value.valD != -200) regEvent(value.valD, "Aht20t"); // TODO: найти способ понимания ошибки получения данных
else SerialPrint("E", "Sensor AHTt", "Error");
if (value.valD != -200)
regEvent(value.valD, "Aht20t"); // TODO: найти способ понимания ошибки получения данных
else
SerialPrint("E", "Sensor AHTt", "Error");
}
~Aht20t() {};
~Aht20t(){};
};
class Aht20h : public IoTItem {
public:
Aht20h(String parameters): IoTItem(parameters) { }
Aht20h(String parameters) : IoTItem(parameters) {}
void doByInterval() {
value.valD = humidity.relative_humidity;
if (value.valD != -200) regEvent(value.valD, "Aht20h"); // TODO: найти способ понимания ошибки получения данных
else SerialPrint("E", "Sensor AHTt", "Error");
if (value.valD != -200)
regEvent(value.valD, "Aht20h"); // TODO: найти способ понимания ошибки получения данных
else
SerialPrint("E", "Sensor AHTt", "Error");
}
~Aht20h() {};
~Aht20h(){};
};
void* getAPI_Aht20(String subtype, String param) {
if (subtype == F("Aht20t")) {
aht.begin();
aht.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data
aht.getEvent(&humidity, &temp); // populate temp and humidity objects with fresh data
return new Aht20t(param);
} else if (subtype == F("Aht20h")) {
aht.begin();
aht.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data
aht.getEvent(&humidity, &temp); // populate temp and humidity objects with fresh data
return new Aht20h(param);
} else {
return nullptr;
}
}

View File

@@ -12,33 +12,37 @@
#include "ClosedCube_HDC1080.h"
#include <map>
//создаем объект HDC1080
// to do убрать глобальный экземпляр
ClosedCube_HDC1080 hdc1080;
class Hdc1080t : public IoTItem {
public:
Hdc1080t(String parameters): IoTItem(parameters) { }
Hdc1080t(String parameters) : IoTItem(parameters) {}
void doByInterval() {
value.valD = hdc1080.readTemperature();
if (value.valD < 124) regEvent(value.valD, "Hdc1080t");
else SerialPrint("E", "Sensor Hdc1080t", "Error");
if (value.valD < 124)
regEvent(value.valD, "Hdc1080t");
else
SerialPrint("E", "Sensor Hdc1080t", "Error");
}
~Hdc1080t() {};
~Hdc1080t(){};
};
class Hdc1080h : public IoTItem {
public:
Hdc1080h(String parameters): IoTItem(parameters) { }
Hdc1080h(String parameters) : IoTItem(parameters) {}
void doByInterval() {
value.valD = hdc1080.readHumidity();
if (value.valD < 99 ) regEvent(value.valD, "Hdc1080h");
else SerialPrint("E", "Sensor Hdc1080h", "Error");
if (value.valD < 99)
regEvent(value.valD, "Hdc1080h");
else
SerialPrint("E", "Sensor Hdc1080h", "Error");
}
~Hdc1080h() {};
~Hdc1080h(){};
};
void* getAPI_Hdc1080(String subtype, String param) {

View File

@@ -0,0 +1,45 @@
/******************************************************************
Used MAX6675 Driver (temperature sensor)
Support for MAX6675
https://github.com/adafruit/MAX6675-library
adapted for version 4 @Serghei63
******************************************************************/
#include "Global.h"
#include "Classes/IoTItem.h"
#include "max6675.h"
#include <map>
MAX6675* thermocouple = nullptr;
class MAX6675t : public IoTItem {
public:
MAX6675t(String parameters) : IoTItem(parameters) {
int thermoDO = jsonReadInt(parameters, "DO");
int thermoCS = jsonReadInt(parameters, "CS");
int thermoCLK = jsonReadInt(parameters, "CLK");
thermocouple = new MAX6675(thermoCLK, thermoCS, thermoDO);
}
void doByInterval() {
value.valD = thermocouple->readCelsius();
if (String(value.valD) != "nan") {
regEvent(value.valD, "Max6675t");
} else {
SerialPrint("E", "Sensor Max6675t", "Error");
}
}
~MAX6675t(){};
};
void* getAPI_Max6675(String subtype, String param) {
if (subtype == F("Max6675t")) {
return new MAX6675t(param);
} else {
return nullptr;
}
}

View File

@@ -0,0 +1,16 @@
[
{
"name": "Cенсор температуры MAX6675",
"num": 31,
"type": "Reading",
"subtype": "Max6675t",
"id": "maxtmp",
"widget": "anydataTmp",
"page": "Сенсоры",
"descr": "MAX Температура",
"int": 15,
"DO": 12,
"CS": 13,
"CLK": 14
}
]

View File

@@ -0,0 +1,8 @@
[env:esp8266_4mb]
lib_deps =
adafruit/MAX6675 library
[env:esp32_4mb]
lib_deps =
adafruit/MAX6675 library

View File

@@ -17,6 +17,7 @@ extern IoTGpio IoTgpio;
//встроена в ядро для 8266, для 32 по этому же имени обращаемся к другой библиотеке plerup/EspSoftwareSerial
#include <SoftwareSerial.h>
// to do убрать глобальный экземпляр
#ifdef ESP8266
int rxPinSDS = 13; // D7 подключаем к Tx сенсора
int txPinSDS = 12; // D6 подключаем к Rx сенсора