Skip to content

Commit

Permalink
Diagnostics (#13)
Browse files Browse the repository at this point in the history
* OLED (I2C based) support. Also added some #defines for altitude offset on barometer and batter low voltage limit

* copied altitude offset defines to sec.h
  • Loading branch information
jhughes1010 authored Jul 6, 2022
1 parent 622ec93 commit d329e88
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 16 deletions.
8 changes: 8 additions & 0 deletions sec.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ const char mainTopic[20] = "MainTopic/";
//===========================================
//#define USE_EEPROM

//===========================================
//BME280 altitude offsets (set by user)
//===========================================
#define ALTITUDE_OFFSET_IMPERIAL 5.58
#define ALTITUDE_OFFSET_METRIC 142.6


//===========================================
//BH1750 Enable
//===========================================
Expand Down Expand Up @@ -77,6 +84,7 @@ const int UpdateIntervalSeconds = 5 * 60; //Sleep timer (60s) testing
//===========================================
//batteryCalFactor = measured battery voltage/ADC reading
#define batteryCalFactor .0011804
#define batteryLowVoltage 3.3

//===========================================
//Timezone information
Expand Down
17 changes: 13 additions & 4 deletions sensors.ino
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void readBattery (struct sensorData *environment)
environment->batteryVoltage = environment->batteryADC * batteryCalFactor;
MonPrintf("Battery digital ADC :%i voltage: %6.2f\n", environment->batteryADC, environment->batteryVoltage);
//check for low battery situation
if (environment->batteryVoltage < 3.78)
if (environment->batteryVoltage < batteryLowVoltage)
{
lowBattery = true;
}
Expand All @@ -74,9 +74,8 @@ void checkBatteryVoltage (void)
float voltage;
adc = analogRead(VOLT_PIN);
voltage = adc * batteryCalFactor;
//MonPrintf("Battery digital ADC :%i voltage: %6.2f\n", environment->batteryADC, environment->batteryVoltage);
//check for low battery situation
if (voltage < 3.78)
if (voltage < batteryLowVoltage)
{
lowBattery = true;
}
Expand Down Expand Up @@ -126,8 +125,10 @@ void readBME(struct sensorData *environment)
{
#ifndef METRIC
bme.read(environment->barometricPressure, environment->BMEtemperature, environment->humidity, BME280::TempUnit_Fahrenheit, BME280::PresUnit_inHg);
environment->barometricPressure += ALTITUDE_OFFSET_IMPERIAL;
#else
bme.read(environment->barometricPressure, environment->BMEtemperature, environment->humidity, BME280::TempUnit_Celsius, BME280::PresUnit_Pa);
environment->barometricPressure += ALTITUDE_OFFSET_METRIC;
#endif

}
Expand Down Expand Up @@ -168,4 +169,12 @@ void readESPCoreTemp(struct sensorData *environment)

environment->coreF = coreF;
environment->coreC = coreC;
}
}


void printADCLCD( void)
{
int adc;
adc = analogRead(VOLT_PIN);
display.printf("ADC: %i\n", adc);
}
12 changes: 11 additions & 1 deletion time.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,24 @@ struct tm timeinfo;
//=======================================================================
void printLocalTime()
{
if (!getLocalTime(&timeinfo))
if (!getLocalTime(&timeinfo))
{
MonPrintf("Failed to obtain time\n");
return;
}
Serial.printf("Date:%02i %02i %i Time: %02i:%02i:%02i\n", timeinfo.tm_mday, timeinfo.tm_mon + 1, timeinfo.tm_year + 1900, timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec);
}

void printLocalTimeLCD(void)
{
if (!getLocalTime(&timeinfo))
{
MonPrintf("Failed to obtain time\n");
return;
}
display.printf("Date:%02i %02i %i\nTime: %02i:%02i:%02i\n", timeinfo.tm_mday, timeinfo.tm_mon + 1, timeinfo.tm_year + 1900, timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec);
}

//=======================================================================
// printTimeNextWake: diagnostic routine to print next wake time
//=======================================================================
Expand Down
48 changes: 37 additions & 11 deletions weather.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
//
//Supporting the following project: https://www.instructables.com/Solar-Powered-WiFi-Weather-Station-V30/

//version 1.3.1
#define VERSION "1.3.1"
#define VERSION "1.3.2"

//=============================================
// Changelog
//=============================================
/*
* v1.3.1
* 1. Corrects missing quotes on #define VERSION statement
* 2. max retry if 15 connect attempts added and then we bail on WiFi connect. This prevents us from hitting the WDT limit and rebooting
*
*
* v1.3 supports 24h rainfall data, not 23h
/*
* v1.3.2
* 1. I2C OLED diagnostics added (if needed)
* 2.
v1.3.1
1. Corrects missing quotes on #define VERSION statement
2. max retry if 15 connect attempts added and then we bail on WiFi connect. This prevents us from hitting the WDT limit and rebooting
v1.3 supports 24h rainfall data, not 23h
supports current 60 min rainfall, not
current "hour" that looses data at top
of the hour.
Expand Down Expand Up @@ -70,6 +72,12 @@
#include <esp_task_wdt.h>
#include <esp_system.h>
#include <driver/rtc_io.h>
//OLED diagnostics board
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

//===========================================
// Defines
Expand Down Expand Up @@ -201,12 +209,26 @@ void setup()
Serial.begin(115200);
delay(25);




//Title message
MonPrintf("\nWeather station - Deep sleep version.\n");
MonPrintf("Version %s\n\n", VERSION);
BlinkLED(1);
bootCount++;

display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64)
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
printLocalTimeLCD();
printADCLCD();
display.printf("SSID: %s\n", ssid);
display.print("BOOT: ");
display.println(bootCount);
display.display();

updateWake();
wakeup_reason();
if (WiFiEnable)
Expand All @@ -220,7 +242,7 @@ void setup()
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
printLocalTime();
printTimeNextWake();
processSensorUpdates();
processSensorUpdates();
WiFi.disconnect();
esp_wifi_stop();
}
Expand All @@ -233,6 +255,7 @@ void setup()
}
//pet the dog!
esp_task_wdt_reset();
BlinkLED(2);
sleepyTime(UpdateIntervalModified);
}

Expand Down Expand Up @@ -278,6 +301,9 @@ void processSensorUpdates(void)
{
SendDataMQTT(&environment);
}
display.printf("Temp: %4.1f F\n", environment.temperatureF);
display.printf("Pressure: %4.1f inHg\n", environment.barometricPressure);
display.display();
}

//===========================================================
Expand Down Expand Up @@ -370,7 +396,7 @@ void BlinkLED(int count)
delay(150);
//LED OFF
digitalWrite(LED_BUILTIN, LOW);
delay(500);
delay(350);
}
}

Expand Down

0 comments on commit d329e88

Please sign in to comment.