Updated indoor examples

This commit is contained in:
Achim
2023-04-13 09:33:26 +07:00
parent 43f599a0a7
commit 6314e52770
4 changed files with 61 additions and 68 deletions

View File

@ -85,9 +85,7 @@ void setup()
if (connectWIFI) { if (connectWIFI) {
connectToWifi(); connectToWifi();
} }
updateOLED2("Warm Up", "Serial#", String(ESP.getChipId(), HEX));
updateOLED2("Warming", "up the", "sensors");
ag.CO2_Init(); ag.CO2_Init();
ag.PMS_Init(); ag.PMS_Init();
ag.TMP_RH_Init(0x44); ag.TMP_RH_Init(0x44);
@ -207,9 +205,9 @@ void sendToServer() {
WiFiManager wifiManager; WiFiManager wifiManager;
//WiFi.disconnect(); //to delete previous saved hotspot //WiFi.disconnect(); //to delete previous saved hotspot
String HOTSPOT = "AG-" + String(ESP.getChipId(), HEX); String HOTSPOT = "AG-" + String(ESP.getChipId(), HEX);
updateOLED2("Connect", "Wifi", HOTSPOT); updateOLED2("Connect", "Wifi AG-", String(ESP.getChipId(), HEX));
delay(2000); delay(2000);
wifiManager.setTimeout(60); wifiManager.setTimeout(90);
if (!wifiManager.autoConnect((const char * ) HOTSPOT.c_str())) { if (!wifiManager.autoConnect((const char * ) HOTSPOT.c_str())) {
updateOLED2("Booting", "offline", "mode"); updateOLED2("Booting", "offline", "mode");
Serial.println("failed to connect and hit timeout"); Serial.println("failed to connect and hit timeout");

View File

@ -52,14 +52,14 @@ NOxGasIndexAlgorithm nox_algorithm;
uint16_t conditioning_s = 10; uint16_t conditioning_s = 10;
// for peristent saving and loading // for peristent saving and loading
int addr = 0; int addr = 4;
byte value; byte value;
// Display bottom right // Display bottom right
//U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
// Replace above if you have display on top left // Replace above if you have display on top left
U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R2, /* reset=*/ U8X8_PIN_NONE); //U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R2, /* reset=*/ U8X8_PIN_NONE);
// CONFIGURATION START // CONFIGURATION START
@ -108,7 +108,7 @@ unsigned long previousTempHum = 0;
float temp = 0; float temp = 0;
int hum = 0; int hum = 0;
int buttonConfig=0; int buttonConfig=4;
int lastState = LOW; int lastState = LOW;
int currentState; int currentState;
unsigned long pressedTime = 0; unsigned long pressedTime = 0;
@ -143,7 +143,7 @@ void setup() {
connectToWifi(); connectToWifi();
} }
updateOLED2("Warming up the", "sensors.", ""); updateOLED2("Warming Up", "Serial Number:", String(ESP.getChipId(), HEX));
sgp41.begin(Wire); sgp41.begin(Wire);
ag.CO2_Init(); ag.CO2_Init();
ag.PMS_Init(); ag.PMS_Init();
@ -232,25 +232,25 @@ void setConfig() {
inUSAQI = true; inUSAQI = true;
} }
if (buttonConfig == 4) { if (buttonConfig == 4) {
updateOLED2("Temp. in C", "PM in ug/m3", "Display Top"); updateOLED2("Temp. in C", "PM in ug/m3", "Display Bottom");
u8g2.setDisplayRotation(U8G2_R0); u8g2.setDisplayRotation(U8G2_R0);
inF = false; inF = false;
inUSAQI = false; inUSAQI = false;
} }
if (buttonConfig == 5) { if (buttonConfig == 5) {
updateOLED2("Temp. in C", "PM in US AQI", "Display Top"); updateOLED2("Temp. in C", "PM in US AQI", "Display Bottom");
u8g2.setDisplayRotation(U8G2_R0); u8g2.setDisplayRotation(U8G2_R0);
inF = false; inF = false;
inUSAQI = true; inUSAQI = true;
} }
if (buttonConfig == 6) { if (buttonConfig == 6) {
updateOLED2("Temp. in F", "PM in ug/m3", "Display Top"); updateOLED2("Temp. in F", "PM in ug/m3", "Display Bottom");
u8g2.setDisplayRotation(U8G2_R0); u8g2.setDisplayRotation(U8G2_R0);
inF = true; inF = true;
inUSAQI = false; inUSAQI = false;
} }
if (buttonConfig == 7) { if (buttonConfig == 7) {
updateOLED2("Temp. in F", "PM in US AQI", "Display Top"); updateOLED2("Temp. in F", "PM in US AQI", "Display Bottom");
u8g2.setDisplayRotation(U8G2_R0); u8g2.setDisplayRotation(U8G2_R0);
inF = true; inF = true;
inUSAQI = true; inUSAQI = true;
@ -400,19 +400,8 @@ void sendToServer() {
WiFiManager wifiManager; WiFiManager wifiManager;
//WiFi.disconnect(); //to delete previous saved hotspot //WiFi.disconnect(); //to delete previous saved hotspot
String HOTSPOT = "AG-" + String(ESP.getChipId(), HEX); String HOTSPOT = "AG-" + String(ESP.getChipId(), HEX);
updateOLED2("60s to connect", "to Wifi Hotspot", HOTSPOT); updateOLED2("90s to connect", "to Wifi Hotspot", HOTSPOT);
wifiManager.setTimeout(60); wifiManager.setTimeout(90);
WiFiManagerParameter custom_text("<p>This is just a text paragraph</p>");
wifiManager.addParameter(&custom_text);
WiFiManagerParameter parameter("parameterId", "Parameter Label", "default value", 40);
wifiManager.addParameter(&parameter);
Serial.println("Parameter 1:");
Serial.println(parameter.getValue());
if (!wifiManager.autoConnect((const char * ) HOTSPOT.c_str())) { if (!wifiManager.autoConnect((const char * ) HOTSPOT.c_str())) {
updateOLED2("booting into", "offline mode", ""); updateOLED2("booting into", "offline mode", "");
@ -420,9 +409,6 @@ void sendToServer() {
delay(6000); delay(6000);
} }
Serial.println("Parameter 2:");
Serial.println(parameter.getValue());
} }
// Calculate PM2.5 US AQI // Calculate PM2.5 US AQI

View File

@ -1,11 +1,11 @@
/* /*
Important: This code is only for the DIY PRO PCB Version 4.2 that needs different code due to different wiring of the push button. Important: This code is only for the DIY PRO PCB Version 3.7 that has a push button mounted.
This is the code for the AirGradient DIY PRO Air Quality Sensor with an ESP8266 Microcontroller with the SGP40 TVOC module from AirGradient. This is the code for the AirGradient DIY PRO Air Quality Sensor with an ESP8266 Microcontroller with the SGP40 TVOC module from AirGradient.
It is a high quality sensor showing PM2.5, CO2, Temperature and Humidity on a small display and can send data over Wifi. It is a high quality sensor showing PM2.5, CO2, Temperature and Humidity on a small display and can send data over Wifi.
Build Instructions: https://www.airgradient.com/open-airgradient/instructions/diy-pro-v42/ Build Instructions: https://www.airgradient.com/open-airgradient/instructions/diy-pro-v37/
Kits (including a pre-soldered version) are available: https://www.airgradient.com/open-airgradient/kits/ Kits (including a pre-soldered version) are available: https://www.airgradient.com/open-airgradient/kits/
@ -23,7 +23,7 @@ If you have any questions please visit our forum at https://forum.airgradient.co
If you are a school or university contact us for a free trial on the AirGradient platform. If you are a school or university contact us for a free trial on the AirGradient platform.
https://www.airgradient.com/ https://www.airgradient.com/
License: CC BY-NC 4.0 Attribution-NonCommercial 4.0 International CC BY-SA 4.0 Attribution-ShareAlike 4.0 International License
*/ */
@ -51,8 +51,8 @@ NOxGasIndexAlgorithm nox_algorithm;
// time in seconds needed for NOx conditioning // time in seconds needed for NOx conditioning
uint16_t conditioning_s = 10; uint16_t conditioning_s = 10;
// for persistent saving and loading // for peristent saving and loading
int addr = 0; int addr = 4;
byte value; byte value;
// Display bottom right // Display bottom right
@ -108,8 +108,8 @@ unsigned long previousTempHum = 0;
float temp = 0; float temp = 0;
int hum = 0; int hum = 0;
int buttonConfig=0; int buttonConfig=4;
int lastState = HIGH; int lastState = LOW;
int currentState; int currentState;
unsigned long pressedTime = 0; unsigned long pressedTime = 0;
unsigned long releasedTime = 0; unsigned long releasedTime = 0;
@ -117,7 +117,6 @@ unsigned long releasedTime = 0;
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
Serial.println("Hello"); Serial.println("Hello");
u8g2.setBusClock(100000);
u8g2.begin(); u8g2.begin();
//u8g2.setDisplayRotation(U8G2_R0); //u8g2.setDisplayRotation(U8G2_R0);
@ -130,14 +129,12 @@ void setup() {
updateOLED2("Press Button", "Now for", "Config Menu"); updateOLED2("Press Button", "Now for", "Config Menu");
delay(2000); delay(2000);
pinMode(D7, INPUT_PULLUP);
currentState = digitalRead(D7); currentState = digitalRead(D7);
if (currentState == LOW) if (currentState == HIGH)
{ {
updateOLED2("Entering", "Config Menu", ""); updateOLED2("Entering", "Config Menu", "");
delay(3000); delay(3000);
lastState = HIGH; lastState = LOW;
inConf(); inConf();
} }
@ -146,7 +143,7 @@ void setup() {
connectToWifi(); connectToWifi();
} }
updateOLED2("Warming up the", "sensors.", ""); updateOLED2("Warming Up", "Serial Number:", String(ESP.getChipId(), HEX));
sgp41.begin(Wire); sgp41.begin(Wire);
ag.CO2_Init(); ag.CO2_Init();
ag.PMS_Init(); ag.PMS_Init();
@ -154,9 +151,6 @@ void setup() {
} }
void loop() { void loop() {
currentState = digitalRead(D7);
currentMillis = millis(); currentMillis = millis();
updateTVOC(); updateTVOC();
updateOLED(); updateOLED();
@ -170,27 +164,20 @@ void inConf(){
setConfig(); setConfig();
currentState = digitalRead(D7); currentState = digitalRead(D7);
if (currentState){ if(lastState == LOW && currentState == HIGH) {
Serial.println("currentState: high");
} else {
Serial.println("currentState: low");
}
if(lastState == HIGH && currentState == LOW) {
pressedTime = millis(); pressedTime = millis();
} }
else if(lastState == LOW && currentState == HIGH) { else if(lastState == HIGH && currentState == LOW) {
releasedTime = millis(); releasedTime = millis();
long pressDuration = releasedTime - pressedTime; long pressDuration = releasedTime - pressedTime;
if( pressDuration < 1000 ) { if( pressDuration < 1000 ) {
buttonConfig=buttonConfig+1; buttonConfig=buttonConfig+1;
if (buttonConfig>3) buttonConfig=0; if (buttonConfig>7) buttonConfig=0;
} }
} }
if (lastState == LOW && currentState == LOW){ if (lastState == HIGH && currentState == HIGH){
long passedDuration = millis() - pressedTime; long passedDuration = millis() - pressedTime;
if( passedDuration > 4000 ) { if( passedDuration > 4000 ) {
// to do // to do
@ -221,30 +208,52 @@ void inConf(){
void setConfig() { void setConfig() {
if (buttonConfig == 0) { if (buttonConfig == 0) {
updateOLED2("Temp. in C", "PM in ug/m3", "Long Press Saves"); updateOLED2("Temp. in C", "PM in ug/m3", "Display Top");
u8g2.setDisplayRotation(U8G2_R0); u8g2.setDisplayRotation(U8G2_R2);
inF = false; inF = false;
inUSAQI = false; inUSAQI = false;
} else if (buttonConfig == 1) { } else if (buttonConfig == 1) {
updateOLED2("Temp. in C", "PM in US AQI", "Long Press Saves"); updateOLED2("Temp. in C", "PM in US AQI", "Display Top");
u8g2.setDisplayRotation(U8G2_R0); u8g2.setDisplayRotation(U8G2_R2);
inF = false; inF = false;
inUSAQI = true; inUSAQI = true;
} else if (buttonConfig == 2) { } else if (buttonConfig == 2) {
updateOLED2("Temp. in F", "PM in ug/m3", "Long Press Saves"); updateOLED2("Temp. in F", "PM in ug/m3", "Display Top");
u8g2.setDisplayRotation(U8G2_R0); u8g2.setDisplayRotation(U8G2_R2);
inF = true; inF = true;
inUSAQI = false; inUSAQI = false;
} else if (buttonConfig == 3) { } else if (buttonConfig == 3) {
updateOLED2("Temp. in F", "PM in US AQI", "Long Press Saves"); updateOLED2("Temp. in F", "PM in US AQI", "Display Top");
u8g2.setDisplayRotation(U8G2_R2);
inF = true;
inUSAQI = true;
} else if (buttonConfig == 4) {
updateOLED2("Temp. in C", "PM in ug/m3", "Display Bottom");
u8g2.setDisplayRotation(U8G2_R0);
inF = false;
inUSAQI = false;
}
if (buttonConfig == 5) {
updateOLED2("Temp. in C", "PM in US AQI", "Display Bottom");
u8g2.setDisplayRotation(U8G2_R0);
inF = false;
inUSAQI = true;
} else if (buttonConfig == 6) {
updateOLED2("Temp. in F", "PM in ug/m3", "Display Bottom");
u8g2.setDisplayRotation(U8G2_R0);
inF = true;
inUSAQI = false;
} else if (buttonConfig == 7) {
updateOLED2("Temp. in F", "PM in US AQI", "Display Bottom");
u8g2.setDisplayRotation(U8G2_R0); u8g2.setDisplayRotation(U8G2_R0);
inF = true; inF = true;
inUSAQI = true; inUSAQI = true;
} else {
updateOLED2("Short Press", "Button for", "Options");
} }
// to do // to do
// if (buttonConfig == 4) { // if (buttonConfig == 8) {
// updateOLED2("CO2", "Manual", "Calibration"); // updateOLED2("CO2", "Manual", "Calibration");
// } // }
} }

View File

@ -1,5 +1,5 @@
name=AirGradient Air Quality Sensor name=AirGradient Air Quality Sensor
version=2.4.0 version=2.4.1
author=AirGradient <support@airgradient.com> author=AirGradient <support@airgradient.com>
maintainer=AirGradient <support@airgradient.com> maintainer=AirGradient <support@airgradient.com>
sentence=ESP8266 library for an air quality sensor featuring PM2.5, CO2, Temperature, TVOC and Humidity with OLED display. sentence=ESP8266 library for an air quality sensor featuring PM2.5, CO2, Temperature, TVOC and Humidity with OLED display.