esp32 oled display HELP!!

Hi please can someone help me,

i am trying to display a clock on my oled but unfortunately struggling.

here is the code that i would like to display. i can serial print and it looks fine but how can i write it to my oled display.
Many Thanks Gareth

#include <WiFi.h>
#include "time.h"
#include "SSD1306Wire.h"
SSD1306Wire display(0x3c, 5, 4);

const char* ssid = "AndroidAP";
const char* password = "vaze1985";

const char* ntpServer = "pool.ntp.org";
const long gmtOffset_sec = 0;
const int daylightOffset_sec = 0;

void printLocalTime()
{
struct tm timeinfo;
if(!getLocalTime(&timeinfo)){
Serial.println("Failed to obtain time");
return;
}
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S"); // this is the line i want to print to my oled

display.setFont(ArialMT_Plain_10);
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.drawStringMaxWidth(0, 0, 128,"DISPLAY THE TIME HERE" ); // HOW DO I PUT IT HERE
display.display();
delay(1000);
delay(1000);
}

void setup()
{
Serial.begin(115200);
display.init();
//connect to WiFi
Serial.printf("Connecting to %s ", ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println(" CONNECTED");

//init and get the time
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
printLocalTime();

//disconnect WiFi as it's no longer needed
WiFi.disconnect(true);
WiFi.mode(WIFI_OFF);
}

void loop()
{
delay(1000);
printLocalTime();
}

Maybe look here for a code example: https://www.instructables.com/id/ESP32-With-Integrated-OLED-WEMOSLolin-Getting-Star/

Thank you for your reply. The examples are good, but they are quite difficult to work into my own project. i am just after something very simple. The code above seems to be good i just do not understand the strut part of the the code for the print time.

OK. Do you get so far that you see the date and time correctly formatted on the serial console and "DISPLAY THE TIME HERE" on the display ?
If not, you have other problems.

The struct tm is defined here: http://www.cplusplus.com/reference/ctime/tm/

You could first try this:

display.drawStringMaxWidth(0, 0, 128, String( timeinfo.tm_year )  );   // HOW DO I PUT IT HERE

to see if you get 118, that is years since 1900, then progress from there.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

What does the code you posted do?

Thanks.. Tom... :slight_smile: