Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HECA dehumidifier #845

Open
wants to merge 1 commit into
base: beta
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 78 additions & 1 deletion airrohr-firmware/airrohr-firmware.ino
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ String SOFTWARE_VERSION(SOFTWARE_VERSION_STR);
#include "./DHT.h"
#include <Adafruit_HTU21DF.h>
#include <Adafruit_BMP085.h>
#include "ClosedCube_SHT31D.h" // support for Nettigo Air Monitor HECA
#include <Adafruit_SHT31.h>
#include <StreamString.h>
#include <DallasTemperature.h>
Expand Down Expand Up @@ -164,6 +165,7 @@ namespace cfg {
bool sps30_read = SPS30_READ;
bool bmp_read = BMP_READ;
bool bmx280_read = BMX280_READ;
bool heca_read = HECA_READ;
bool sht3x_read = SHT3X_READ;
bool ds18b20_read = DS18B20_READ;
bool dnms_read = DNMS_READ;
Expand Down Expand Up @@ -243,6 +245,7 @@ long int sample_count = 0;
bool htu21d_init_failed = false;
bool bmp_init_failed = false;
bool bmx280_init_failed = false;
bool heca_init_failed = false;
bool sht3x_init_failed = false;
bool dnms_init_failed = false;
bool gps_init_failed = false;
Expand Down Expand Up @@ -304,6 +307,11 @@ Adafruit_BMP085 bmp;
*****************************************************************/
BMX280 bmx280;

/*****************************************************************
* HECA (SHT30) declaration *
*****************************************************************/
ClosedCube_SHT31D heca;

/*****************************************************************
* SHT3x declaration *
*****************************************************************/
Expand Down Expand Up @@ -464,6 +472,8 @@ float last_value_NPM_P2 = -1.0;
float last_value_NPM_N0 = -1.0;
float last_value_NPM_N1 = -1.0;
float last_value_NPM_N2 = -1.0;
double last_value_HECA_T = -128.0;
double last_value_HECA_H = -1.0;
float last_value_GPS_alt = -1000.0;
double last_value_GPS_lat = -200.0;
double last_value_GPS_lon = -200.0;
Expand Down Expand Up @@ -1130,6 +1140,7 @@ static void webserver_config_send_body_get(String& page_content) {
add_form_checkbox_sensor(Config_htu21d_read, FPSTR(INTL_HTU21D));
add_form_checkbox_sensor(Config_bmx280_read, FPSTR(INTL_BMX280));
add_form_checkbox_sensor(Config_sht3x_read, FPSTR(INTL_SHT3X));
add_form_checkbox_sensor(Config_heca_read, FPSTR(INTL_HECA)); //page_content += form_checkbox_sensor("heca_read", FPSTR(INTL_HECA), heca_read);

// Paginate page after ~ 1500 Bytes
server.sendContent(page_content);
Expand Down Expand Up @@ -1501,6 +1512,11 @@ static void webserver_values() {
add_table_h_value(FPSTR(SENSORS_SHT3X), FPSTR(INTL_HUMIDITY), last_value_SHT3X_H);
page_content += FPSTR(EMPTY_ROW);
}
if (cfg::heca_read) {
add_table_t_value(FPSTR(SENSORS_HECA), FPSTR(INTL_TEMPERATURE), check_display_value(last_value_HECA_T, -128, 1, 0), unit_T);
add_table_h_value(FPSTR(SENSORS_HECA), FPSTR(INTL_HUMIDITY), check_display_value(last_value_HECA_H, -1, 1, 0), unit_H);
page_content += FPSTR(EMPTY_ROW);
}
if (cfg::ds18b20_read) {
add_table_t_value(FPSTR(SENSORS_DS18B20), FPSTR(INTL_TEMPERATURE), last_value_DS18B20_T);
page_content += FPSTR(EMPTY_ROW);
Expand Down Expand Up @@ -2413,6 +2429,27 @@ static void fetchSensorSHT3x(String& s) {
debug_outln_verbose(FPSTR(DBG_TXT_END_READING), FPSTR(SENSORS_SHT3X));
}

/*****************************************************************
* read HECA (SHT3x) sensor values *
*****************************************************************/
static string sensorHECA() {
String s;

debug_out(String(FPSTR(DBG_TXT_START_READING)) + FPSTR(SENSORS_HECA), DEBUG_MED_INFO, 1);

SHT31D result = heca.periodicFetchData();
if (result.error == SHT3XD_NO_ERROR) {
last_value_HECA_T = result.t;
last_value_HECA_H = result.rh;
} else {
last_value_HECA_T = -128.0;
last_value_HECA_H = -1.0;
}
s += Value2Json(F("HECA_temperature"), Float2String(last_value_HECA_T));
s += Value2Json(F("HECA_humidity"), Float2String(last_value_HECA_H));
return s;
}

/*****************************************************************
* read BMP280/BME280 sensor values *
*****************************************************************/
Expand Down Expand Up @@ -3659,7 +3696,7 @@ static void display_values() {
if (cfg::sps30_read) {
screens[screen_count++] = 2;
}
if (cfg::dht_read || cfg::ds18b20_read || cfg::htu21d_read || cfg::bmp_read || cfg::bmx280_read || cfg::sht3x_read) {
if (cfg::dht_read || cfg::ds18b20_read || cfg::htu21d_read || cfg::bmp_read || cfg::bmx280_read || cfg::sht3x_read || cfg::heca_read ) {
screens[screen_count++] = 3;
}
if (cfg::gps_read) {
Expand Down Expand Up @@ -3927,6 +3964,34 @@ static void initSPS30() {
}
}

/*****************************************************************
* Init HECA *
*****************************************************************/

bool initHECA() {

debug_out(F("Trying HECA (SHT30) sensor on 0x44"), DEBUG_MIN_INFO, 0);
heca.begin(0x44);
//heca.begin(addr);
if (heca.periodicStart(SHT3XD_REPEATABILITY_HIGH, SHT3XD_FREQUENCY_1HZ) != SHT3XD_NO_ERROR) {
debug_out(F(" ... not found"), DEBUG_MIN_INFO, 1);
debug_out(F(" [HECA ERROR] Cannot start periodic mode"), DEBUG_MIN_INFO, 1);
return false;
} else {
// temperature set, temperature clear, humidity set, humidity clear
if (heca.writeAlertHigh(120, 119, 63, 60) != SHT3XD_NO_ERROR) {
debug_out(F(" [HECA ERROR] Cannot set Alert HIGH"), DEBUG_MIN_INFO, 1);
}
if (heca.writeAlertLow(-5, 5, 0, 1) != SHT3XD_NO_ERROR) {
debug_out(F(" [HECA ERROR] Cannot set Alert LOW"), DEBUG_MIN_INFO, 1);
}
if (heca.clearAll() != SHT3XD_NO_ERROR) {
debug_out(F(" [HECA ERROR] Cannot clear register"), DEBUG_MIN_INFO, 1);
}
return true;
}
}

/*****************************************************************
Init DNMS - Digital Noise Measurement Sensor
*****************************************************************/
Expand Down Expand Up @@ -4080,6 +4145,14 @@ static void powerOnTestSensors() {
}
}

if (cfg::heca_read) {
debug_out_info(F("Read HECA (SHT30)..."));
if (!initHECA()) {
debug_outln_error(F("Check HECA (SHT30) wiring"));
heca_init_failed = true;
}
}

if (cfg::ds18b20_read) {
oneWire.begin(ONEWIRE_PIN);
ds18b20.begin(); // Start DS18B20
Expand Down Expand Up @@ -4481,6 +4554,10 @@ void loop(void) {
sum_send_time += sendSensorCommunity(result, SHT3X_API_PIN, FPSTR(SENSORS_SHT3X), "SHT3X_");
result = emptyString;
}
if (cfg::heca_read && (! heca_init_failed)) {
debug_out(String(FPSTR(DBG_TXT_CALL_SENSOR)) + FPSTR(SENSORS_HECA), DEBUG_MAX_INFO, 1);
result_HECA = sensorHECA(); // getting temperature, humidity and pressure (optional)
}
if (cfg::ds18b20_read) {
// getting temperature (optional)
fetchSensorDS18B20(result);
Expand Down