I'm building an automated watering system using a NodeMCU module and a 128X64 OLED display (I2C interface) to present information. I'm trying to get the OLED to refresh the current system status and time on the display. To simplify the display activity on the OLED I wrote the below function that receives a phrase pointer and should output the phrase and current time-stamp to the display.
For some reason I can't figure out, each time I call the PrintToLCD()
function within the loop()
segment, nothing is output to the display. I do see relevant information on the serial monitor.
Please advise.
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <TimeLib.h>
#include <DS3231.h>
#include <Wire.h>
#include <SoftwareSerial.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 display(OLED_RESET);
void setup() {
Serial.begin(9600);
Serial.println();
......some setup code.......
// initialize Oled display with the I2C addr 0x3D (for the 128x64)
display.begin(SSD1306_SWITCHCAPVCC, 0x3C, false);
// Show image buffer on the display hardware.
// Since the buffer is intialized with an Adafruit splash screen
// internally, this will display the splash screen.
display.display();
delay(500);
// Clear the display buffer.
display.clearDisplay();
}
void loop() {
// Get UTC time
//--------------------------------------------------------
if (timeStatus() != timeNotSet) {
if (now() != prevDisplay) {
//update the display only if time has changed
prevDisplay = now();
digitalClockDisplay(timeString);
PrintToLCD(timeString,0,30);
//***this works fine and prints to display***
}
}
......some business logic code.......
PrintToLCD("Current watering Valve",0,30);
//This does not display any output
}
void PrintToLCD(const String& phrase, int XOffset, int YOffset) {
display.setCursor(XOffset,YOffset);
display.setTextSize(1);
display.setTextColor(WHITE);
display.println(phrase);
display.println(" ");
digitalClockDisplay(timeString);
display.println(timeString);
display.display();
delay(1000);
}
void digitalClockDisplay(String timeString) {
// digital clock display of the time
String sHour=String(hour());
String sMinute=String(minute());
String sSec=String(second());
String sDay=String(day());
String sMonth=String(month());
String sYear=String(year());
timeString=String(sDay + "/" + month() + "/" + year() + " "+ hour()+
":"+minute()+":"+second());
if (minute()<10) {
timeString=String(sDay + "/" + sMonth + "/" + year() + " "+ hour()+ ":0" + minute()+":"+second());
} else if (second()<10) {
timeString=String(sDay + "/" + sMonth + "/" + year() + " "+ hour()+ ":"+minute()+":0"+second());
}
Serial.println("Function: digitalClockDisplay");
Serial.println(timeString);
}