Compare commits

...

5 Commits

Author SHA1 Message Date
295ee2d87d update hostname and MQTT broker 2022-05-30 18:15:00 +02:00
2873d56b58 use sparkfun lib for sensors adafruit has issues 2021-07-28 08:19:40 +02:00
3d740c9387 updated gitignore 2021-07-27 08:26:54 +02:00
dd511c8e18 updated screen + added OTA 2021-07-27 08:26:12 +02:00
11b146c2d1 updated sensors 2021-07-26 18:54:25 +02:00
26 changed files with 755 additions and 330 deletions

5
.gitignore vendored
View File

@@ -1 +1,6 @@
.pio/
.vscode/
*/.DS_store
.DS_Store
.vscode/c_cpp_properties.json
.vscode/launch.json

View File

@@ -10,10 +10,15 @@
"includePath": [
"/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/include",
"/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32",
"/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/.pio/libdeps/esp32/Adafruit SGP30 Sensor",
"/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/.pio/libdeps/esp32/Adafruit SCD30",
"/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/.pio/libdeps/esp32/Adafruit BusIO",
"/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/lib/JC_Button/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/ArduinoOTA/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/ESPmDNS/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/Update/src",
"/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/lib/IP5306",
"/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/.pio/libdeps/esp32/SparkFun SGP30 Arduino Library/src",
"/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/.pio/libdeps/esp32/SparkFun SCD30 Arduino Library/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/Wire/src",
"/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/.pio/libdeps/esp32/JC_Button/src",
"/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/.pio/libdeps/esp32/TJpg_Decoder/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/SD/src",
"/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/.pio/libdeps/esp32/RunningMedian",
@@ -87,8 +92,10 @@
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/fb_gfx",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/cores/esp32",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/variants/esp32",
"/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/.pio/libdeps/esp32/Adafruit BusIO",
"/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/.pio/libdeps/esp32/Adafruit GFX Library",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/ArduinoOTA/src",
"/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/.pio/libdeps/esp32/Adafruit SCD30",
"/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/.pio/libdeps/esp32/Adafruit SGP30 Sensor",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/AsyncUDP/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/AzureIoT/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/BLE/src",
@@ -96,7 +103,6 @@
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/DNSServer/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/EEPROM/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/ESP32/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/ESPmDNS/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/FFat/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/HTTPClient/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/HTTPUpdate/src",
@@ -106,11 +112,9 @@
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/SD_MMC/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/SimpleBLE/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/Ticker/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/Update/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/WiFiClientSecure/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/WiFiProv/src",
"/Users/willemoldemans/.platformio/packages/tool-unity",
""
],
"browse": {
@@ -118,10 +122,15 @@
"path": [
"/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/include",
"/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32",
"/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/.pio/libdeps/esp32/Adafruit SGP30 Sensor",
"/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/.pio/libdeps/esp32/Adafruit SCD30",
"/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/.pio/libdeps/esp32/Adafruit BusIO",
"/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/lib/JC_Button/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/ArduinoOTA/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/ESPmDNS/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/Update/src",
"/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/lib/IP5306",
"/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/.pio/libdeps/esp32/SparkFun SGP30 Arduino Library/src",
"/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/.pio/libdeps/esp32/SparkFun SCD30 Arduino Library/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/Wire/src",
"/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/.pio/libdeps/esp32/JC_Button/src",
"/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/.pio/libdeps/esp32/TJpg_Decoder/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/SD/src",
"/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/.pio/libdeps/esp32/RunningMedian",
@@ -195,8 +204,10 @@
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/fb_gfx",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/cores/esp32",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/variants/esp32",
"/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/.pio/libdeps/esp32/Adafruit BusIO",
"/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/.pio/libdeps/esp32/Adafruit GFX Library",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/ArduinoOTA/src",
"/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/.pio/libdeps/esp32/Adafruit SCD30",
"/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/.pio/libdeps/esp32/Adafruit SGP30 Sensor",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/AsyncUDP/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/AzureIoT/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/BLE/src",
@@ -204,7 +215,6 @@
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/DNSServer/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/EEPROM/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/ESP32/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/ESPmDNS/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/FFat/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/HTTPClient/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/HTTPUpdate/src",
@@ -214,16 +224,14 @@
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/SD_MMC/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/SimpleBLE/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/Ticker/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/Update/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/WiFiClientSecure/src",
"/Users/willemoldemans/.platformio/packages/framework-arduinoespressif32/libraries/WiFiProv/src",
"/Users/willemoldemans/.platformio/packages/tool-unity",
""
]
},
"defines": [
"PLATFORMIO=50101",
"PLATFORMIO=60001",
"ARDUINO_ESP32_DEV",
"ESP32",
"ESP_PLATFORM",
@@ -238,7 +246,7 @@
],
"cStandard": "c99",
"cppStandard": "c++11",
"compilerPath": "/Users/willemoldemans/.platformio/packages/toolchain-xtensa32/bin/xtensa-esp32-elf-gcc",
"compilerPath": "/Users/willemoldemans/.platformio/packages/toolchain-xtensa32@2.50200.97/bin/xtensa-esp32-elf-gcc",
"compilerArgs": [
"-mlongcalls",
""

View File

@@ -1,7 +1,10 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
]
}
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}

14
.vscode/launch.json vendored
View File

@@ -14,7 +14,7 @@
"name": "PIO Debug",
"executable": "/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/.pio/build/esp32/firmware.elf",
"projectEnvName": "esp32",
"toolchainBinDir": "/Users/willemoldemans/.platformio/packages/toolchain-xtensa32/bin",
"toolchainBinDir": "/Users/willemoldemans/.platformio/packages/toolchain-xtensa32@2.50200.97/bin",
"internalConsoleOptions": "openOnSessionStart",
"preLaunchTask": {
"type": "PlatformIO",
@@ -27,8 +27,18 @@
"name": "PIO Debug (skip Pre-Debug)",
"executable": "/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/.pio/build/esp32/firmware.elf",
"projectEnvName": "esp32",
"toolchainBinDir": "/Users/willemoldemans/.platformio/packages/toolchain-xtensa32/bin",
"toolchainBinDir": "/Users/willemoldemans/.platformio/packages/toolchain-xtensa32@2.50200.97/bin",
"internalConsoleOptions": "openOnSessionStart"
},
{
"type": "platformio-debug",
"request": "launch",
"name": "PIO Debug (without uploading)",
"executable": "/Users/willemoldemans/Documents/PROJECTEN/AQS-main/Firmware/PM25SensorESP32/.pio/build/esp32/firmware.elf",
"projectEnvName": "esp32",
"toolchainBinDir": "/Users/willemoldemans/.platformio/packages/toolchain-xtensa32@2.50200.97/bin",
"internalConsoleOptions": "openOnSessionStart",
"loadMode": "manual"
}
]
}

View File

@@ -1,6 +1,7 @@
#include "CO2_sensor.h"
Adafruit_SCD30 scd30;
//Adafruit_SCD30 scd30;
SCD30 scd30;
#define CO2_INTERVAL 120000 //ms
#define SCD30TEMPMAX 50
@@ -8,7 +9,7 @@ Adafruit_SCD30 scd30;
#define SCD30CO2MAX 20000
#define SCD30MIN 0
uint8_t CO2_samples = 3600 / g_pms_report_period;
uint8_t CO2_samples = 3600 / 30;
AQSSensor SCD30_temperature("Temperature", SCD30_temp, "degC", device_name, CO2_samples, SCD30MIN, SCD30TEMPMAX);
AQSSensor SCD30_Humidity("Humidity", SCD30_hum, "%RH", device_name, CO2_samples, SCD30MIN, SDC30HUMMAX);
@@ -19,6 +20,7 @@ uint32_t CO2_lastUpdate = 0;
void initCO2sensor(void)
{
Serial.println("SCD30: init");
Wire.begin();
if (!scd30.begin())
{
Serial.println("SCD30: Failed to find sensor");
@@ -33,8 +35,8 @@ void initCO2sensor(void)
addSensorToList(&SCD30_CO2);
//check callibration Mode
scd30.selfCalibrationEnabled(false);
scd30.read();
//scd30.selfCalibrationEnabled(false);
//scd30.read();
Serial.println("SCD30: init OK");
}
}
@@ -42,22 +44,21 @@ void initCO2sensor(void)
void handleCO2sensor(void)
{
uint32_t currentmillis = millis();
if ((currentmillis - CO2_lastUpdate > (g_pms_report_period * 1000)) || (!CO2_lastUpdate) && (scd30.dataReady()))
if ((currentmillis - CO2_lastUpdate > (g_pms_report_period * 1000)) || (!CO2_lastUpdate))
{
if (!scd30.read())
if (!scd30.dataAvailable())
{
Serial.println("SCD30: read error!");
return;
}
SCD30_temperature.set(uint32_t(scd30.temperature));
SCD30_Humidity.set(uint32_t(scd30.relative_humidity));
SCD30_CO2.set(uint32_t(scd30.CO2));
SCD30_temperature.set(uint32_t(scd30.getTemperature()));
SCD30_Humidity.set(uint32_t(scd30.getHumidity()));
SCD30_CO2.set(uint32_t(scd30.getCO2()));
SCD30_temperature.publish();
SCD30_Humidity.publish();
SCD30_CO2.publish();
CO2_lastUpdate = currentmillis;
}
}

View File

@@ -2,9 +2,11 @@
#include "Arduino.h"
#include "config.h"
#include <wire.h>
//#include <Adafruit_SCD30.h>
//#include <Adafruit_Sensor.h>
#include "SparkFun_SCD30_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_SCD30
#include <Adafruit_SCD30.h>
#include <Adafruit_Sensor.h>
#include "sensor.h"

View File

@@ -1,37 +1,47 @@
#include "VOC_sensor.h"
#define DEBUG_SERIAL
Adafruit_SGP30 sgp;
//Adafruit_SGP30 sgp;
SGP30 sgp;
//TwoWire wire1(1);
uint8_t VOC_samples = 3600 / g_pms_report_period;
#define VOC_MIN 0
#define VOC_MAX 10000
#define VOC_RAW_MAX 30000
#define VOC_INTERVAL 120000 //ms
uint32_t lastVOCtime = 0;
//sensors
AQSSensor SGP30_tvoc("TVOC", SGP30_TVOC, "ppb", device_name, VOC_samples, VOC_MIN, VOC_MAX);
AQSSensor SGP30_eco2("eCO2", SGP30_eCO2, "ppm", device_name, VOC_samples, VOC_MIN, VOC_MAX);
AQSSensor SGP30_rawh2("Raw_H2", SGP30_rawH2, "#", device_name, VOC_samples, VOC_MIN, VOC_MAX);
AQSSensor SGP30_rawethanol("Raw_Ethanol", SGP30_rawEthanol, "#", device_name, VOC_samples, VOC_MIN, VOC_MAX);
AQSSensor SGP30_rawh2("Raw_H2", SGP30_rawH2, "#", device_name, VOC_samples, VOC_MIN, VOC_RAW_MAX);
AQSSensor SGP30_rawethanol("Raw_Ethanol", SGP30_rawEthanol, "#", device_name, VOC_samples, VOC_MIN, VOC_RAW_MAX);
void initVOCsensor(void)
{
Serial.println("VOCSensor: Init SGP30: ");
//wire1.setPins(I2C_2_SDA, I2C_2_SCL);
//if (!sgp.begin(&wire1))
Wire.begin();
if (!sgp.begin())
{
Serial.println("VOCSensor: Init Failed (SGP30 not found)");
}
else
{
Serial.printf("VOCSensor: serial =0x%X%X%X\n", sgp.serialnumber[0], sgp.serialnumber[1], sgp.serialnumber[2]);
sgp.getSerialID();
//Get version number
sgp.getFeatureSetVersion();
Serial.print("VOCSensor: serial =0x");
Serial.println((unsigned long)sgp.serialID, HEX);
addSensorToList(&SGP30_tvoc);
addSensorToList(&SGP30_eco2);
addSensorToList(&SGP30_rawh2);
addSensorToList(&SGP30_rawethanol);
sgp.IAQmeasure();
sgp.IAQmeasureRaw();
sgp.initAirQuality();
sgp.measureAirQuality();
Serial.println("VOCSensor: Init OK");
}
}
@@ -41,28 +51,13 @@ void handleVOCsensor(void)
uint32_t timenow = millis();
if ((timenow - lastVOCtime > VOC_INTERVAL) || !lastVOCtime)
{
if (!sgp.IAQmeasure())
{
Serial.println("VOCSensor: Measurement failed");
return;
}
sgp.measureAirQuality();
SGP30_tvoc.set(sgp.TVOC);
SGP30_eco2.set(sgp.eCO2);
SGP30_eco2.set(sgp.CO2);
SGP30_tvoc.publish();
SGP30_eco2.publish();
if (!sgp.IAQmeasureRaw())
{
Serial.println("VOCSensor: Raw Measurement failed");
return;
}
SGP30_rawethanol.set(sgp.rawEthanol);
SGP30_rawh2.set(sgp.rawH2);
SGP30_rawethanol.publish();
SGP30_rawh2.publish();
SGP30_eco2.publish();
lastVOCtime = timenow;
}

View File

@@ -3,8 +3,11 @@
#include "Arduino.h"
#include "config.h"
#include "sensor.h"
#include <Wire.h>
#include "Adafruit_SGP30.h"
//#include "Adafruit_SGP30.h"
#include "SparkFun_SGP30_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_SGP30
#include <Wire.h>
void initVOCsensor(void);

10
battery.cpp Normal file
View File

@@ -0,0 +1,10 @@
#include "battery.h"
void initBattery(void)
{
}
void handleBattery(void)
{
}

7
battery.h Normal file
View File

@@ -0,0 +1,7 @@
#pragma once
#include "Arduino.h"
#include "IP5306.h"
void initBattery(void);
void handleBattery(void);

View File

@@ -2,6 +2,8 @@
#include "Arduino.h"
#include "config.h"
#include "lcd.h"
#include "JC_Button.h"
void initButtons( void );
void handleButtons( void );

View File

@@ -6,16 +6,45 @@ uint8_t g_previous_mode_button_state = 1;
uint32_t g_last_debounce_time = 0;
uint32_t g_debounce_delay = 50;
Button buttonCenter(BUTTON_CENTER);
Button buttonLeft(BUTTON_LEFT);
Button buttonRight(BUTTON_RIGHT);
void initButtons(void)
{
Serial.print("initButtons:");
buttonCenter.begin();
buttonLeft.begin();
buttonRight.begin();
pinMode(MODE_BUTTON_PIN, INPUT_PULLUP); // Pin for switching screens button
Serial.println(" OK");
}
void handleButtons(void)
{
g_previous_mode_button_state = g_current_mode_button_state;
//handle buttons
buttonCenter.read();
buttonLeft.read();
buttonRight.read();
if (buttonCenter.wasPressed())
{
backlightRefresh();
}
if (buttonLeft.wasPressed())
{
previousSensor();
backlightRefresh();
}
if (buttonRight.wasPressed())
{
nextSensor();
backlightRefresh();
}
g_current_mode_button_state = digitalRead(MODE_BUTTON_PIN);
// Check if button is now pressed and it was previously unpressed
@@ -27,6 +56,7 @@ void handleButtons(void)
return;
}
Serial.println("Button pressed");
backlightRefresh();
// Increment display state
g_last_debounce_time = millis();
}

View File

@@ -4,9 +4,9 @@
/* WiFi config */
#define WIFI_SSID "poes" // Your WiFi SSID
#define WIFI_PASSWORD "Rijnstraat214" // Your WiFi password
#define HOST_NAME "AQS-monitor"
/* MQTT */
#define mqtt_broker "192.168.2.5" // IP address of your MQTT broker
#define mqtt_broker "192.168.2.3" // IP address of your MQTT broker
#define REPORT_MQTT_SEPARATE true // Report each value to its own topic
#define REPORT_MQTT_JSON true // Report all values in a JSON message
#define status_topic "events" // MQTT topic to report startup
@@ -16,9 +16,6 @@
#define g_pms_warmup_period 30 // Seconds to warm up PMS before reading
#define g_pms_report_period 120 // Seconds between reports
/* Use WiFi. If this is off, MQTT won't run */
#define ENABLE_WIFI true
/* Serial */
#define SERIAL_BAUD_RATE 115200 // Speed for USB serial console
@@ -27,28 +24,25 @@
/* ----------------- Hardware-specific Config ---------------------- */
/* Mode button connection (momentary between this pin and GND) */
#define MODE_BUTTON_PIN 0
#define MODE_BUTTON_PIN 0
#define BUTTON_CENTER 37
#define BUTTON_RIGHT 39
#define BUTTON_LEFT 38
#define I2C_SDA_PIN 21
#define I2C_SCL_PIN 22
#define I2C_2_SCL 13
#define I2C_2_SDA 14
#define PMS_RX_PIN 19 // Tx to the PMS SHOULD BE 16
#define PMS_TX_PIN 26 // Rx from the PMS SHOULD BE 17
#define TFT_BL 4 // LED back-light control pin
/* RGB LEDs */
#define WS2812B_PIN 13
#define NUM_RGB_LEDS 0
/* LCD */
// #define TFT_DC_PIN 2
// #define TFT_RST_PIN 4
// #define TFT_CS_PIN 26
// #define TFT_SCLK_PIN 18
// #define TFT_MISO_PIN 19
// #define TFT_MOSI_PIN 23
/* I2C */
#define I2C_SDA_PIN 21
#define I2C_SCL_PIN 22
//#define BME680_I2C_ADDR 0x76
//backlight defines
#define TFT_BACKLIGHT_ON HIGH // Level to turn ON back-light (HIGH or LOW)
#define TFT_BL_PWMCHANNEL 1
#define TFT_BL_FREQ 5000
#define TFT_BL_BITS 8
/* Particulate Matter Sensor */
#define PMS_BAUD_RATE 9600
#define PMS_SET_PIN 19
#define PMS_RESET_PIN 26
#define PMS_RX_PIN 4 // Tx to the PMS SHOULD BE 16
#define PMS_TX_PIN 14 // Rx from the PMS SHOULD BE 17

46
esp_ota.cpp Normal file
View File

@@ -0,0 +1,46 @@
#include "esp_ota.h"
void initEspOta(void)
{
Serial.println("ESPOTA: init");
ArduinoOTA
.onStart([]() {
String type;
if (ArduinoOTA.getCommand() == U_FLASH)
type = "sketch";
else // U_SPIFFS
type = "filesystem";
// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
Serial.println("ESPOTA: Start updating " + type);
ProgressbarVisible(true);
ledcWrite(TFT_BL_PWMCHANNEL, 64);
})
.onEnd([]() {
Serial.println("\nESPOTA: End");
})
.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("ESPOTA: Progress: %u%%\r", (progress / (total / 100)));
setOTAProgress((progress / (total / 100)));
})
.onError([](ota_error_t error) {
Serial.printf("ESPOTA: Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) Serial.println("ESPOTA: Auth Failed");
else if (error == OTA_BEGIN_ERROR) Serial.println("ESPOTA: Begin Failed");
else if (error == OTA_CONNECT_ERROR) Serial.println("ESPOTA: Connect Failed");
else if (error == OTA_RECEIVE_ERROR) Serial.println("ESPOTA: Receive Failed");
else if (error == OTA_END_ERROR) Serial.println("ESPOTA: End Failed");
});
ArduinoOTA.begin();
Serial.print("ESPOTA: IP address: ");
Serial.println(WiFi.localIP());
Serial.println("ESPOTA: init OK");
}
void handleEspOta(void)
{
ArduinoOTA.handle();
}

8
esp_ota.h Normal file
View File

@@ -0,0 +1,8 @@
#pragma once
#include "Arduino.h"
#include <ArduinoOTA.h>
#include "lcd.h"
void initEspOta(void);
void handleEspOta(void);

506
lcd.cpp
View File

@@ -1,25 +1,5 @@
#include "lcd.h"
// This example draws an animated dial with a rotating needle.
// The dial is a jpeg image, the needle is created using a rotated
// Sprite. The example operates by reading blocks of pixels from the
// TFT, thus the TFT setup must support reading from the TFT CGRAM.
// The sketch operates by creating a copy of the screen block where
// the needle will be drawn, the needle is then drawn on the screen.
// When the needle moves, the original copy of the sreen area is
// pushed to the screen to over-write the needle graphic. A copy
// of the screen where the new position will be drawn is then made
// before drawing the needle in the new postion. This technique
// allows the needle to move over other screen graphics.
// The sketch calculates the size of the buffer memory required and
// reserves the memory for the TFT block copy.
// Created by Bodmer 17/3/20 as an example to the TFT_eSPI library:
// https://github.com/Bodmer/TFT_eSPI
#define NEEDLE_LENGTH 35 // Visible length
#define NEEDLE_WIDTH 5 // Width of needle - make it an odd number
#define NEEDLE_RADIUS 90 // Radius at tip
@@ -28,33 +8,58 @@
#define DIAL_CENTRE_X 120
#define DIAL_CENTRE_Y 120
// Font attached to this sketch
#include "NotoSansBold36.h"
#define MAXGUAGE 240
#define MINGUAGE 0
#define DISPLAY_ROTATE 15 //sec
#define BACKLIGHTTIMEOUT 60000
#define BACKLIGHTONBRGT 84
#define BACKLIGHTSTEP 1
#define AA_FONT_LARGE NotoSansBold36
#include <TFT_eSPI.h>
enum DISPLAY_STATE
{
DISPLAY_PM1P0,
DISPLAY_PM2P5,
DISPLAY_PM10P0,
DISPLAY_TEMP,
DISPLAY_HUM,
DISPLAY_CO2,
DISPLAY_LAST
};
// sprite elements
TFT_eSPI tft = TFT_eSPI();
TFT_eSprite needle = TFT_eSprite(&tft); // Sprite object for needle
TFT_eSprite spr = TFT_eSprite(&tft); // Sprite for meter reading
TFT_eSprite nameSpr = TFT_eSprite(&tft);
TFT_eSprite unitSpr = TFT_eSprite(&tft);
// Jpeg image array attached to this sketch
#include "dial.h"
// Include the jpeg decoder library
#include <TJpg_Decoder.h>
TFT_eSprite ProgressBar = TFT_eSprite(&tft);
uint16_t *tft_buffer;
bool buffer_loaded = false;
uint16_t spr_width = 0;
uint16_t name_spr_width = 0;
bool progessbarActive = false;
void createNeedle(void);
void plotNeedle(int16_t angle, uint16_t ms_delay);
DISPLAY_STATE displaystate = DISPLAY_PM1P0;
uint32_t display_last_update = 0;
uint32_t backlightTimeout = 0;
uint8_t backlightBrightness = BACKLIGHTONBRGT;
// =======================================================================================
// This function will be called during decoding of the jpeg file
// Declarations
// =======================================================================================
void createNeedle(void);
void plotNeedle(int16_t angle, uint16_t ms_delay);
void setBacklight(uint8_t value);
bool tft_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t *bitmap);
void backlightRefresh(void);
// =======================================================================================
// implementation
// =======================================================================================
bool tft_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t *bitmap)
{
@@ -69,200 +74,37 @@ bool tft_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t *bitmap)
return 1;
}
// =======================================================================================
// Setup
// =======================================================================================
void initLCD()
void setBacklight(uint8_t value)
{
Serial.print("InitLCD:");
// The byte order can be swapped (set true for TFT_eSPI)
TJpgDec.setSwapBytes(true);
// The jpeg decoder must be given the exact name of the rendering function above
TJpgDec.setCallback(tft_output);
tft.begin();
tft.setRotation(0);
tft.fillScreen(TFT_BLACK);
// Draw the dial
TJpgDec.drawJpg(0, 0, dial, sizeof(dial));
tft.drawCircle(DIAL_CENTRE_X, DIAL_CENTRE_Y, NEEDLE_RADIUS - NEEDLE_LENGTH, TFT_DARKGREY);
// Load the font and create the Sprite for reporting the value
spr.loadFont(AA_FONT_LARGE);
spr_width = spr.textWidth("277");
spr.createSprite(spr_width, spr.fontHeight());
uint16_t bg_color = tft.readPixel(120, 120); // Get colour from dial centre
spr.fillSprite(bg_color);
spr.setTextColor(TFT_WHITE, bg_color);
spr.setTextDatum(MC_DATUM);
spr.setTextPadding(spr_width);
spr.drawNumber(0, spr_width / 2, spr.fontHeight() / 2);
spr.pushSprite(DIAL_CENTRE_X - spr_width / 2, DIAL_CENTRE_Y - spr.fontHeight() / 2);
// Plot the label text
nameSpr.setTextFont(3);
name_spr_width = nameSpr.textWidth("Temperature");
nameSpr.createSprite(name_spr_width, nameSpr.fontHeight() * 2 + 2);
nameSpr.fillSprite(bg_color);
nameSpr.setTextColor(TFT_WHITE, bg_color);
nameSpr.setTextDatum(MC_DATUM);
nameSpr.setTextPadding(name_spr_width);
nameSpr.drawString("Sensor Name", name_spr_width / 2, nameSpr.fontHeight() / 2);
nameSpr.drawString("Unit", name_spr_width / 2, nameSpr.fontHeight() / 2 * 3 + 2); nameSpr.pushSprite(DIAL_CENTRE_X - name_spr_width / 2, DIAL_CENTRE_Y + 40, 2);
nameSpr.pushSprite(DIAL_CENTRE_X - name_spr_width / 2, DIAL_CENTRE_Y + 40, 2);
// Define where the needle pivot point is on the TFT before
// creating the needle so boundary calculation is correct
tft.setPivot(DIAL_CENTRE_X, DIAL_CENTRE_Y);
// Create the needle Sprite
createNeedle();
// Reset needle position to 0
plotNeedle(0, 0, 0);
delay(2000);
Serial.println("OK");
ledcWrite(TFT_BL_PWMCHANNEL, value);
}
// =======================================================================================
// Loop
// =======================================================================================
enum DISPLAY_STATE
void ProgressbarVisible(bool visible)
{
DISPLAY_PM1P0,
DISPLAY_PM2P5,
DISPLAY_PM10P0,
DISPLAY_TEMP,
DISPLAY_HUM,
DISPLAY_CO2,
DISPLAY_LAST
};
DISPLAY_STATE displaystate = DISPLAY_PM1P0;
uint32_t display_last_update = 0;
#define MAXGUAGE 240
#define MINGUAGE 0
#define DISPLAY_ROTATE 10 //sec
void handleLCD()
{
static uint32_t value;
static uint16_t angle;
DISPLAY_STATE displaystate_next = DISPLAY_PM1P0;
sensor_e nextSensor = AE_1P0;
switch (displaystate)
progessbarActive = visible;
if (!visible)
{
case DISPLAY_PM1P0:
{
nextSensor = AE_1P0;
displaystate_next = DISPLAY_PM2P5;
ProgressBar.fillSprite(TFT_BLACK);
ProgressBar.pushSprite(10, 270);
}
break;
case DISPLAY_PM2P5:
{
nextSensor = AE_2P5;
displaystate_next = DISPLAY_PM10P0;
}
break;
case DISPLAY_PM10P0:
{
nextSensor = AE_10P0;
displaystate_next = DISPLAY_TEMP;
}
break;
case DISPLAY_TEMP:
{
nextSensor = SCD30_temp;
displaystate_next = DISPLAY_HUM;
}
break;
case DISPLAY_HUM:
{
nextSensor = SCD30_hum;
displaystate_next = DISPLAY_CO2;
}
break;
case DISPLAY_CO2:
{
nextSensor = SCD30_hum;
displaystate_next = DISPLAY_PM1P0;
}
break;
case DISPLAY_LAST:
default:
{
displaystate_next = DISPLAY_PM1P0;
}
break;
}
//rotate display
uint32_t timenow = millis();
if (timenow - display_last_update > (DISPLAY_ROTATE * 1000))
{
displaystate = displaystate_next;
display_last_update = timenow;
Serial.println("LCD next State");
}
//calculate value to angle
AQSSensor *sensor = getSensor(nextSensor);
if (sensor == NULL)
{
Serial.println("LCD: getSensor=NULL!");
return;
}
angle = map(value, sensor->getMin(), sensor->getMax(), MINGUAGE, MAXGUAGE);
plotNeedle(angle, 15, value);
nameSpr.drawString(sensor->getName().c_str(), name_spr_width / 2, nameSpr.fontHeight() / 2);
nameSpr.drawString(sensor->getUnit().c_str(), name_spr_width / 2, nameSpr.fontHeight() / 2 * 3 + 2);
nameSpr.pushSprite(DIAL_CENTRE_X - name_spr_width / 2, DIAL_CENTRE_Y + 40, 2);
}
// =======================================================================================
// Create the needle Sprite
// =======================================================================================
void createNeedle(void)
void setOTAProgress(uint8_t value)
{
needle.setColorDepth(16);
needle.createSprite(NEEDLE_WIDTH, NEEDLE_LENGTH); // create the needle Sprite
needle.fillSprite(TFT_BLACK); // Fill with black
// Define needle pivot point relative to top left corner of Sprite
uint16_t piv_x = NEEDLE_WIDTH / 2; // pivot x in Sprite (middle)
uint16_t piv_y = NEEDLE_RADIUS; // pivot y in Sprite
needle.setPivot(piv_x, piv_y); // Set pivot point in this Sprite
// Draw the red needle in the Sprite
needle.fillRect(0, 0, NEEDLE_WIDTH, NEEDLE_LENGTH, TFT_MAROON);
needle.fillRect(1, 1, NEEDLE_WIDTH - 2, NEEDLE_LENGTH - 2, TFT_RED);
// Bounding box parameters to be populated
int16_t min_x;
int16_t min_y;
int16_t max_x;
int16_t max_y;
// Work out the worst case area that must be grabbed from the TFT,
// this is at a 45 degree rotation
needle.getRotatedBounds(45, &min_x, &min_y, &max_x, &max_y);
// Calculate the size and allocate the buffer for the grabbed TFT area
tft_buffer = (uint16_t *)malloc(((max_x - min_x) + 2) * ((max_y - min_y) + 2) * 2);
uint16_t progress = map(value, 0, 100, 0, 212);
ProgressBar.drawRoundRect(0, 2, 220, 22, 5, TFT_BLUE);
ProgressBar.fillRoundRect(4, 5, progress, 15, 3, TFT_BLUE);
if (progessbarActive)
{
ProgressBar.pushSprite(10, 270);
}
}
void backlightRefresh(void)
{
backlightTimeout = millis();
}
// =======================================================================================
// Move the needle to a new position
// =======================================================================================
void plotNeedle(int16_t angle, uint16_t ms_delay, uint32_t value)
{
static int16_t old_angle = -120; // Starts at -120 degrees
@@ -283,7 +125,6 @@ void plotNeedle(int16_t angle, uint16_t ms_delay, uint32_t value)
// Move the needle until new angle reached
while (angle != old_angle || !buffer_loaded)
{
if (old_angle < angle)
old_angle++;
else
@@ -323,3 +164,236 @@ void plotNeedle(int16_t angle, uint16_t ms_delay, uint32_t value)
}
// =======================================================================================
// Setup
// =======================================================================================
void createProgressBar(void)
{
ProgressBar.createSprite(220, 30);
ProgressBar.fillSprite(TFT_BLACK);
ProgressBar.drawRoundRect(0, 2, 220, 22, 5, TFT_BLUE);
ProgressBar.pushSprite(10, 270);
}
void createNameSprite(void)
{
nameSpr.setTextFont(2);
name_spr_width = nameSpr.textWidth("---Sensor Name---");
nameSpr.createSprite(name_spr_width, nameSpr.fontHeight() * 2 + 2);
uint16_t bg_color = tft.readPixel(120, 120); // Get colour from dial centre
nameSpr.fillSprite(bg_color);
nameSpr.setTextColor(TFT_WHITE, bg_color);
nameSpr.setTextDatum(MC_DATUM);
nameSpr.setTextPadding(name_spr_width);
nameSpr.drawString("Sensor Name", name_spr_width / 2, nameSpr.fontHeight() / 2);
nameSpr.drawString("Unit", name_spr_width / 2, nameSpr.fontHeight() / 2 * 3 + 2);
nameSpr.pushSprite(DIAL_CENTRE_X - name_spr_width / 2, DIAL_CENTRE_Y + 40, 2);
}
void createValueSprinte(void)
{
spr.loadFont(AA_FONT_LARGE);
spr_width = spr.textWidth("277");
spr.createSprite(spr_width, spr.fontHeight());
uint16_t bg_color = tft.readPixel(120, 120); // Get colour from dial centre
spr.fillSprite(bg_color);
spr.setTextColor(TFT_WHITE, bg_color);
spr.setTextDatum(MC_DATUM);
spr.setTextPadding(spr_width);
spr.drawNumber(0, spr_width / 2, spr.fontHeight() / 2);
spr.pushSprite(DIAL_CENTRE_X - spr_width / 2, DIAL_CENTRE_Y - spr.fontHeight() / 2);
}
void createNeedle(void)
{
needle.setColorDepth(16);
needle.createSprite(NEEDLE_WIDTH, NEEDLE_LENGTH); // create the needle Sprite
needle.fillSprite(TFT_BLACK); // Fill with black
// Define needle pivot point relative to top left corner of Sprite
uint16_t piv_x = NEEDLE_WIDTH / 2; // pivot x in Sprite (middle)
uint16_t piv_y = NEEDLE_RADIUS; // pivot y in Sprite
needle.setPivot(piv_x, piv_y); // Set pivot point in this Sprite
// Draw the red needle in the Sprite
needle.fillRect(0, 0, NEEDLE_WIDTH, NEEDLE_LENGTH, TFT_MAROON);
needle.fillRect(1, 1, NEEDLE_WIDTH - 2, NEEDLE_LENGTH - 2, TFT_RED);
// Bounding box parameters to be populated
int16_t min_x;
int16_t min_y;
int16_t max_x;
int16_t max_y;
// Work out the worst case area that must be grabbed from the TFT,
// this is at a 45 degree rotation
needle.getRotatedBounds(45, &min_x, &min_y, &max_x, &max_y);
// Calculate the size and allocate the buffer for the grabbed TFT area
tft_buffer = (uint16_t *)malloc(((max_x - min_x) + 2) * ((max_y - min_y) + 2) * 2);
}
void createDail(void)
{
TJpgDec.setSwapBytes(true);
// The jpeg decoder must be given the exact name of the rendering function above
TJpgDec.setCallback(tft_output);
// Draw the dial
TJpgDec.drawJpg(0, 0, dial, sizeof(dial));
tft.drawCircle(DIAL_CENTRE_X, DIAL_CENTRE_Y, NEEDLE_RADIUS - NEEDLE_LENGTH, TFT_DARKGREY);
// Define where the needle pivot point is on the TFT before
// creating the needle so boundary calculation is correct
tft.setPivot(DIAL_CENTRE_X, DIAL_CENTRE_Y);
}
void initLCD()
{
Serial.print("InitLCD:");
// The byte order can be swapped (set true for TFT_eSPI)
tft.begin();
tft.setRotation(0);
tft.fillScreen(TFT_BLACK);
// Create the Sprites
createProgressBar();
createDail();
createValueSprinte();
createNeedle();
createNameSprite();
ledcSetup(TFT_BL_PWMCHANNEL, TFT_BL_FREQ, TFT_BL_BITS);
ledcAttachPin(TFT_BL, TFT_BL_PWMCHANNEL);
ledcWrite(TFT_BL_PWMCHANNEL, BACKLIGHTONBRGT);
// Reset needle position to 0
plotNeedle(0, 0, 0);
Serial.println("OK");
}
// =======================================================================================
// Loop
// =======================================================================================
void handleBacklight(void)
{
uint32_t timeNow = millis();
if (!backlightTimeout)
{
backlightRefresh();
}
if (timeNow - backlightTimeout > BACKLIGHTTIMEOUT)
{
if (backlightBrightness > BACKLIGHTSTEP)
{
backlightBrightness -= BACKLIGHTSTEP;
}
else
{
backlightBrightness = 0;
}
}
else
{
if (backlightBrightness < BACKLIGHTONBRGT)
{
backlightBrightness += BACKLIGHTSTEP;
}
}
ledcWrite(TFT_BL_PWMCHANNEL, backlightBrightness);
}
sensor_e displaySensor[] =
{
AE_1P0,
AE_2P5,
AE_10P0,
SCD30_temp,
SCD30_hum,
SCD30_co2,
SGP30_TVOC,
};
uint8_t displaySensorSize = 7;
uint8_t displaySensorIndex = 0;
void nextSensor(void)
{
if (displaySensorIndex < displaySensorSize - 1)
{
displaySensorIndex++;
}
else
{
displaySensorIndex = 0;
}
display_last_update = millis();
}
void previousSensor(void)
{
if (displaySensorIndex > 0)
{
displaySensorIndex--;
}
else
{
displaySensorIndex = displaySensorSize - 1;
}
display_last_update = millis();
}
void handleplotSensor(void)
{
if(!backlightBrightness)
{
return;
}
AQSSensor *sensor = getSensor(displaySensor[displaySensorIndex]);
if (sensor == NULL)
{
Serial.println("LCD: getSensor=NULL!");
nextSensor();
return;
}
uint16_t angle = map(sensor->value(), sensor->getMin(), sensor->getMax(), MINGUAGE, MAXGUAGE);
plotNeedle(angle, 15, sensor->value());
nameSpr.drawString(sensor->getName().c_str(), name_spr_width / 2, nameSpr.fontHeight() / 2);
nameSpr.drawString(sensor->getUnit().c_str(), name_spr_width / 2, nameSpr.fontHeight() / 2 * 3 + 2);
nameSpr.pushSprite(DIAL_CENTRE_X - name_spr_width / 2, DIAL_CENTRE_Y + 40, 2);
}
void handleDisplayRotate(void)
{
//rotate display
if(!backlightBrightness)
{
return;
}
uint32_t timenow = millis();
if (timenow - display_last_update > (DISPLAY_ROTATE * 1000))
{
Serial.println("LCD next State");
nextSensor();
}
}
void handleLCD()
{
handleDisplayRotate();
handleplotSensor();
handleBacklight();
}
// =======================================================================================

11
lcd.h
View File

@@ -3,7 +3,18 @@
#include "Arduino.h"
#include "sensor.h"
#include "NotoSansBold36.h"
#include <TFT_eSPI.h>
#include "dial.h"
#include <TJpg_Decoder.h>
void initLCD();
void handleLCD();
void plotNeedle(int16_t angle, uint16_t ms_delay, uint32_t value);
void setOTAProgress(uint8_t value);
void ProgressbarVisible(bool visible);
void backlightRefresh(void);
void nextSensor(void);
void previousSensor(void);

50
lib/IP5306/IP5306.cpp Normal file
View File

@@ -0,0 +1,50 @@
/*
IP5306.cpp - Library for IP5306_I2C Power controller.
Created by Sebastian Haap, December 3, 2019.
Based on https://gist.github.com/me-no-dev/7702f08dd578de5efa47caf322250b57
*/
#include "Wire.h"
#include "IP5306.h"
int ip5306_get_reg(uint8_t reg){
Wire.beginTransmission(0x75);
Wire.write(reg);
if(Wire.endTransmission(false) == 0 && Wire.requestFrom(0x75, 1)){
return Wire.read();
}
return -1;
}
int ip5306_set_reg(uint8_t reg, uint8_t value){
Wire.beginTransmission(0x75);
Wire.write(reg);
Wire.write(value);
if(Wire.endTransmission(true) == 0){
return 0;
}
return -1;
}
uint8_t ip5306_get_bits(uint8_t reg, uint8_t index, uint8_t bits){
int value = ip5306_get_reg(reg);
if(value < 0){
//Serial.printf("ip5306_get_bits fail: 0x%02x\n", reg);
return 0;
}
return (value >> index) & ((1 << bits)-1);
}
void ip5306_set_bits(uint8_t reg, uint8_t index, uint8_t bits, uint8_t value){
uint8_t mask = (1 << bits) - 1;
int v = ip5306_get_reg(reg);
if(v < 0){
//Serial.printf("ip5306_get_reg fail: 0x%02x\n", reg);
return;
}
v &= ~(mask << index);
v |= ((value & mask) << index);
if(ip5306_set_reg(reg, v)){
//Serial.printf("ip5306_set_bits fail: 0x%02x\n", reg);
}
}

110
lib/IP5306/IP5306.h Normal file
View File

@@ -0,0 +1,110 @@
/*
IP5306.h - Library for IP5306_I2C Power controller.
Created by Sebastian Haap, December 3, 2019.
Based on https://gist.github.com/me-no-dev/7702f08dd578de5efa47caf322250b57
*/
#ifndef IP5306_h
#define IP5306_h
#include "Wire.h"
#define IP5306_REG_SYS_0 0x00
#define IP5306_REG_SYS_1 0x01
#define IP5306_REG_SYS_2 0x02
#define IP5306_REG_CHG_0 0x20
#define IP5306_REG_CHG_1 0x21
#define IP5306_REG_CHG_2 0x22
#define IP5306_REG_CHG_3 0x23
#define IP5306_REG_CHG_4 0x24
#define IP5306_REG_READ_0 0x70
#define IP5306_REG_READ_1 0x71
#define IP5306_REG_READ_2 0x72
#define IP5306_REG_READ_3 0x77
#define IP5306_REG_READ_4 0x78
#define IP5306_GetKeyOffEnabled() ip5306_get_bits(IP5306_REG_SYS_0, 0, 1)
#define IP5306_SetKeyOffEnabled(v) ip5306_set_bits(IP5306_REG_SYS_0, 0, 1, v)//0:dis,*1:en
#define IP5306_GetBoostOutputEnabled() ip5306_get_bits(IP5306_REG_SYS_0, 1, 1)
#define IP5306_SetBoostOutputEnabled(v) ip5306_set_bits(IP5306_REG_SYS_0, 1, 1, v)//*0:dis,1:en
#define IP5306_GetPowerOnLoadEnabled() ip5306_get_bits(IP5306_REG_SYS_0, 2, 1)
#define IP5306_SetPowerOnLoadEnabled(v) ip5306_set_bits(IP5306_REG_SYS_0, 2, 1, v)//0:dis,*1:en
#define IP5306_GetChargerEnabled() ip5306_get_bits(IP5306_REG_SYS_0, 4, 1)
#define IP5306_SetChargerEnabled(v) ip5306_set_bits(IP5306_REG_SYS_0, 4, 1, v)//0:dis,*1:en
#define IP5306_GetBoostEnabled() ip5306_get_bits(IP5306_REG_SYS_0, 5, 1)
#define IP5306_SetBoostEnabled(v) ip5306_set_bits(IP5306_REG_SYS_0, 5, 1, v)//0:dis,*1:en
#define IP5306_GetLowBatShutdownEnable() ip5306_get_bits(IP5306_REG_SYS_1, 0, 1)
#define IP5306_SetLowBatShutdownEnable(v) ip5306_set_bits(IP5306_REG_SYS_1, 0, 1, v)//0:dis,*1:en
#define IP5306_GetBoostAfterVin() ip5306_get_bits(IP5306_REG_SYS_1, 2, 1)
#define IP5306_SetBoostAfterVin(v) ip5306_set_bits(IP5306_REG_SYS_1, 2, 1, v)//0:Closed, *1:Open
#define IP5306_GetShortPressBoostSwitchEnable() ip5306_get_bits(IP5306_REG_SYS_1, 5, 1)
#define IP5306_SetShortPressBoostSwitchEnable(v) ip5306_set_bits(IP5306_REG_SYS_1, 5, 1, v)//*0:disabled, 1:enabled
#define IP5306_GetFlashlightClicks() ip5306_get_bits(IP5306_REG_SYS_1, 6, 1)
#define IP5306_SetFlashlightClicks(v) ip5306_set_bits(IP5306_REG_SYS_1, 6, 1, v)//*0:short press twice, 1:long press
#define IP5306_GetBoostOffClicks() ip5306_get_bits(IP5306_REG_SYS_1, 7, 1)
#define IP5306_SetBoostOffClicks(v) ip5306_set_bits(IP5306_REG_SYS_1, 7, 1, v)//*0:long press, 1:short press twice
#define IP5306_GetLightLoadShutdownTime() ip5306_get_bits(IP5306_REG_SYS_2, 2, 2)
#define IP5306_SetLightLoadShutdownTime(v) ip5306_set_bits(IP5306_REG_SYS_2, 2, 2, v)//0:8s, *1:32s, 2:16s, 3:64s
#define IP5306_GetLongPressTime() ip5306_get_bits(IP5306_REG_SYS_2, 4, 1)
#define IP5306_SetLongPressTime(v) ip5306_set_bits(IP5306_REG_SYS_2, 4, 1, v)//*0:2s, 1:3s
#define IP5306_GetChargingFullStopVoltage() ip5306_get_bits(IP5306_REG_CHG_0, 0, 2)
#define IP5306_SetChargingFullStopVoltage(v) ip5306_set_bits(IP5306_REG_CHG_0, 0, 2, v)//0:4.14V, *1:4.17V, 2:4.185V, 3:4.2V (values are for charge cutoff voltage 4.2V, 0 or 1 is recommended)
#define IP5306_GetChargeUnderVoltageLoop() ip5306_get_bits(IP5306_REG_CHG_1, 2, 3) //Automatically adjust the charging current when the voltage of VOUT is greater than the set value
#define IP5306_SetChargeUnderVoltageLoop(v) ip5306_set_bits(IP5306_REG_CHG_1, 2, 3, v)//Vout=4.45V + (v * 0.05V) (default 4.55V) //When charging at the maximum current, the charge is less than the set value. Slowly reducing the charging current to maintain this voltage
#define IP5306_GetEndChargeCurrentDetection() ip5306_get_bits(IP5306_REG_CHG_1, 6, 2)
#define IP5306_SetEndChargeCurrentDetection(v) ip5306_set_bits(IP5306_REG_CHG_1, 6, 2, v)//0:200mA, 1:400mA, *2:500mA, 3:600mA
#define IP5306_GetVoltagePressure() ip5306_get_bits(IP5306_REG_CHG_2, 0, 2)
#define IP5306_SetVoltagePressure(v) ip5306_set_bits(IP5306_REG_CHG_2, 0, 2, v)//0:none, 1:14mV, *2:28mV, 3:42mV (28mV recommended for 4.2V)
#define IP5306_GetChargeCutoffVoltage() ip5306_get_bits(IP5306_REG_CHG_2, 2, 2)
#define IP5306_SetChargeCutoffVoltage(v) ip5306_set_bits(IP5306_REG_CHG_2, 2, 2, v)//*0:4.2V, 1:4.3V, 2:4.35V, 3:4.4V
#define IP5306_GetChargeCCLoop() ip5306_get_bits(IP5306_REG_CHG_3, 5, 1)
#define IP5306_SetChargeCCLoop(v) ip5306_set_bits(IP5306_REG_CHG_3, 5, 1, v)//0:BAT, *1:VIN
#define IP5306_GetVinCurrent() ip5306_get_bits(IP5306_REG_CHG_4, 0, 5)
#define IP5306_SetVinCurrent(v) ip5306_set_bits(IP5306_REG_CHG_4, 0, 5, v)//ImA=(v*100)+50 (default 2250mA)
#define IP5306_GetShortPressDetected() ip5306_get_bits(IP5306_REG_READ_3, 0, 1)
#define IP5306_ClearShortPressDetected() ip5306_set_bits(IP5306_REG_READ_3, 0, 1, 1)
#define IP5306_GetLongPressDetected() ip5306_get_bits(IP5306_REG_READ_3, 1, 1)
#define IP5306_ClearLongPressDetected() ip5306_set_bits(IP5306_REG_READ_3, 1, 1, 1)
#define IP5306_GetDoubleClickDetected() ip5306_get_bits(IP5306_REG_READ_3, 2, 1)
#define IP5306_ClearDoubleClickDetected() ip5306_set_bits(IP5306_REG_READ_3, 2, 1, 1)
#define IP5306_GetPowerSource() ip5306_get_bits(IP5306_REG_READ_0, 3, 1)//0:BAT, 1:VIN
#define IP5306_GetBatteryFull() ip5306_get_bits(IP5306_REG_READ_1, 3, 1)//0:CHG/DIS, 1:FULL
#define IP5306_GetLevelLeds() ((~ip5306_get_bits(IP5306_REG_READ_4, 4, 4)) & 0x0F)//LED[0-4] State (inverted)
#define IP5306_GetOutputLoad() ip5306_get_bits(IP5306_REG_READ_2, 2, 1)//0:heavy, 1:light
#define IP5306_LEDS2PCT(byte) \
((byte & 0x01 ? 25 : 0) + \
(byte & 0x02 ? 25 : 0) + \
(byte & 0x04 ? 25 : 0) + \
(byte & 0x08 ? 25 : 0))
int ip5306_get_reg(uint8_t reg);
int ip5306_set_reg(uint8_t reg, uint8_t value);
uint8_t ip5306_get_bits(uint8_t reg, uint8_t index, uint8_t bits);
void ip5306_set_bits(uint8_t reg, uint8_t index, uint8_t bits, uint8_t value);
#endif

1
lib/JC_Button Submodule

Submodule lib/JC_Button added at f379405f8a

View File

@@ -41,6 +41,7 @@
#include "CO2_sensor.h"
#include "VOC_sensor.h"
#include "button.h"
#include "esp_ota.h"
/*--------------------------- Program ---------------------------------------*/
/**
@@ -52,17 +53,33 @@ void setup()
Serial.println();
Serial.print("Air Quality Sensor starting up, v");
Serial.println(VERSION);
ProgressbarVisible(true);
initLCD();
setOTAProgress(10);
digitalWrite(5, false);
initWifi();
initMQTT();
initSensor();
initParticles();
initCO2sensor();
initVOCsensor();
//initLCD();
initButtons();
setOTAProgress(20);
initWifi();
setOTAProgress(30);
initEspOta();
setOTAProgress(40);
initMQTT();
setOTAProgress(50);
initSensor();
setOTAProgress(60);
initParticles();
setOTAProgress(70);
initCO2sensor();
setOTAProgress(80);
initVOCsensor();
setOTAProgress(90);
ProgressbarVisible(false);
}
/**
@@ -75,6 +92,7 @@ void loop()
handleVOCsensor();
handleButtons();
handleSensor();
//handleLCD();
handleLCD();
handleMQTT();
handleEspOta();
}

View File

@@ -87,6 +87,7 @@ bool initWifi()
}
// Connect to wifi
WiFi.setHostname(HOST_NAME);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
// Wait for connection set amount of intervals

View File

@@ -12,7 +12,7 @@ char g_command_topic[50]; // MQTT topic for receiving commands
#define PMS_STATE_READY 2 // Warmed up, ready to give data
#define PMSMAX 50
#define PSMMIN 0
#define PPDMAX 2000
#define PPDMAX 3000
uint8_t g_pms_state = PMS_STATE_WAKING_UP;
uint32_t g_pms_state_start = 0; // Timestamp when PMS state last changed

View File

@@ -21,8 +21,12 @@ lib_deps =
knolleary/PubSubClient
robtillaart/RunningMedian
bodmer/Tjpg_decoder
adafruit/Adafruit SCD30
adafruit/Adafruit BusIO
; adafruit/Adafruit SCD30
; adafruit/Adafruit BusIO
; adafruit/Adafruit SGP30 Sensor
http://192.168.2.3:3000/libs/JCButton.git
sparkfun/SparkFun SCD30 Arduino Library@^1.0.13
sparkfun/SparkFun SGP30 Arduino Library@^1.0.5
[env:esp32]
platform = espressif32
@@ -32,4 +36,15 @@ monitor_speed = 115200
lib_deps =
${common.lib_deps_builtin}
${common.lib_deps}
adafruit/Adafruit SGP30 Sensor@^2.0.0
[env:esp32_ota]
platform = espressif32
board = esp-wrover-kit
framework = arduino
monitor_speed = 115200
lib_deps =
${common.lib_deps_builtin}
${common.lib_deps}
upload_protocol = espota
upload_port = 192.168.2.165

View File

@@ -39,6 +39,8 @@ void initSensor(void)
void handleSensor(void)
{
publishAll();
}
AQSSensor* getSensor(sensor_e sensor)

View File

@@ -42,6 +42,7 @@ class AQSSensor
bool _publish = false;
const uint32_t _scaleMin;
const uint32_t _scaleMax;
bool _valid;
public:
AQSSensor(String name, sensor_e sensor, String unit,
@@ -58,14 +59,23 @@ public:
sprintf(_topic, "Sensors/%s/%s", deviceID.c_str(), name.c_str());
sprintf(_topic_1h, "Sensors/%s/%s/1h/", deviceID.c_str(), name.c_str());
sprintf(_topic_24h, "Sensors/%s/%s/24h/", deviceID.c_str(), name.c_str());
_valid = false;
}
void publish(void)
{
_publish = true;
if (_valid)
{
_publish = true;
}
else
{
Serial.printf("Sensor %s : Not published (invalid)\n", _name.c_str());
}
}
String getName(void)
String
getName(void)
{
return _name;
}
@@ -88,9 +98,18 @@ public:
virtual void set(uint32_t value)
{
_value = value;
_average1h.add(_value);
_average24h.add(_value);
if ((value > _scaleMin) && (value < _scaleMax))
{
_value = value;
_average1h.add(_value);
_average24h.add(_value);
_valid = true;
}
else
{
Serial.printf("Sensor %s set(%d): value out of bounds\n", _name.c_str(), _value);
_valid = false;
}
}
uint32_t value() { return _value; }
@@ -105,7 +124,7 @@ public:
sensor_e getSensor(void) { return _sensor; }
String getUnit(void) { return _unit;}
String getUnit(void) { return _unit; }
uint32_t getMin(void) { return _scaleMin; }
uint32_t getMax(void) { return _scaleMax; }