// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// CLOCK NTP: Clock with online data from pool.ntp.org TFT DISPLAY Jan.2024
// =========
// SPI displays: works with TFT display 240x320 AND with ePaper display 128x296
//
// Hardware: ESP32-S3 44pin,
// Display: TFT display 240x320 SPI
// Libraries: Adafruit_ILI9341.h (TFT)
// Processor: Selection in Arduino IDE: ESP32S3 Dev Module
// Possible Touch Pins for ESP32S3 44pin: GPIO #: 1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Possible Output Pins for ESP32S3 44pin: GPIO #: 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 46
// 0 1 2 19 20 21 35 36 37 38 39 40 41 42 43 44 45 47 48 48 (or38?): internal RGB LED
// to be added:
// -
// -
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//
// TFT ILI9341 Full color 240x320 2.8" LCD-TFT display with SPI interface
// # Name==Description===========ESP32S3/44==ESP32_urish==Arduino Uno============
// 1 VCC Supply voltage 5V 5V 5V
// 2 GND Ground GND GND GND
// 3 CS Chip select 10 15 10† † You connect CS and D/C to any digital Arduino pin. The pin numbers here are just an example.
// 4 RST Reset* 13 4 - * The RST and backlight (LED) pins are not available in the simulation.
// 5 D/C DC Data/command 14 2 9† † You connect CS and D/C to any digital Arduino pin. The pin numbers here are just an example.
// 6 MOSI DIN data (MCU→LCD) 11 23 11
// 7 SCK CLK clock 12 18 13
// 8 LED Backlight LED* - - 5V * The RST and backlight (LED) pins are not available in the simulation.
// 9 MISO SPI data (LCD→MCU)‡ - (9?) 19 12 ‡ You can leave MISO disconnected, unless you need to read data back from the LCD.
//
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// **************************************************************************************************
// D E F I N I T I O N S *
// **************************************************************************************************
#include <WiFi.h>
//#include <Wire.h> // ? needed for I2C?
//include "SPI.h" // needed for TFT and sPaper display with SPI?
#include "Adafruit_ILI9341.h" // library for TFT display with ILI9341
#include "Adafruit_GFX.h" // needed? Core graphics library
// ===== CONSTRUCTOR in Wokwi apparently needs Hardware pins 11 (data) and 12 (clock) and 13 (RST), CS and DC can be defined, LED and MISO unconnected
#define CS 10 // CS chipsel pin# std.S3 10 (ESP32 5)
#define DC 14 // DC datcom pin# std.S3 14 (ESP32 2)
Adafruit_ILI9341 TFT = Adafruit_ILI9341(CS, DC); // Hardware Constructor for TFT ILI9341 Full color 240x320 2.8" display with SPI interface
// ===== CONSTRUCTOR might need ESP32s3/44p Hardware pins 11 (data) / 12 (clock) / 13 (RST), CS and DC can be defined, LED and MISO unconnected
//#define CS 10 // CS chipsel pin# std.S3 10 (ESP32 5)
//#define DC 14 // DC datcom pin# std.S3 14 (ESP32 2)
//#define MOSI 11 // MOSI data pin# std.S3 11 (ESP32 23)
//#define CLK 12 // CLK clock pin# std.S3 12 (ESP32 18)
//#define RST 13 // RST reset pin# std.S3 13 (ESP32 16)
//#define MISO -1? 3 ? // MISO unconnected or e.g. pin# std.S3 3 (ESP32 ?)
//Adafruit_ILI9341 TFT = Adafruit_ILI9341(CS, DC, MOSI, CLK, RST, MISO); // Software Constructor for TFT ILI9341
//Adafruit_ILI9341 TFT = Adafruit_ILI9341(CS, DC); // Hardware constructor (11 data) (12 clock) (13 RST)
#define NTP_SERVER "pool.ntp.org" // NTP time server
#define UTC_OFFSET 3600 // 3600 (sec) add 1 hour offset to GMT/UTC
#define UTC_OFFSET_DST 3600 // 3600 (sec) mean: summer/winter 1h difference, daylight offset
// ===== LEFT ROW: INPUTS/OUTPUTS for ESP32-S3 44pin ==================================
// 3.3V
// 3.3V
// RST
// GPIO04 touch ADC
// GPIO05 touch ADC
// GPIO06 touch ADC
// GPIO07 touch ADC
// GPIO15 ADC
// GPIO16 ADC
// GPIO17 ADC
// GPIO18 ADC
// GPIO08 touch ADC I2C HW! SDA data
// GPIO03 touch ADC
// GPIO46 no ADC! - SPI BLK? SPI: BLK (RST?)
// GPIO09 touch ADC - SPI BUSY Busy, I2C HW! SCL clock SPI: DC (14)
// GPIO10 touch ADC SPI CS chip select = SPI: CS
// GPIO11 touch ADC SPI HW! DIN/SDI MOSI Hardware data! = SPI: MOSI
// GPIO12 touch ADC SPI HW! CLK SCLK Hardware clock! = SPI: CLK
// GPIO13 touch ADC - SPI RST Reset
// GPIO14 touch ADC SPI DC D/C data command
// 5.0V
// GND
// ===== RIGHT ROW: INPUTS/OUTPUTS ===================================
// GND
// GPIO43 TX avoid
// GPIO44 RX avoid
// GPIO01 touch ADC
// GPIO02 touch ADC
// GPIO42
// GPIO41
// GPIO40
// GPIO39
// GPIO38 RGB LED
// GPIO37
// GPIO36
// GPIO35
// GPIO00 avoid
// GPIO45
// GPIO48
// GPIO47
// GPIO21
// GPIO20 ADC
// GPIO19 ADC
// GND
// GND
// ===== VARIABLES: ================================================================================
struct tm timeinfo; // https://cplusplus.com/reference/ctime/tm/
int hrs=0; // starting values for definition
int mins=0;
int secs=0;
// **************************************************************************************************
// F U N C T I O N S *
// **************************************************************************************************
// **************************************************************************************************
// S E T U P *
// **************************************************************************************************
void setup()
{
Serial.begin(115200);
TFT.begin(); // TFT begin TFT display ILI9341 Full color 240x320 2.8" SPI
TFT.setRotation(1); // vertical (0), horizontal (1), vertical down (2), horizontal down (3), vertical (4)
TFT.fillScreen(ILI9341_BLACK); // screen color standard: TFT.fillScreen(ILI9341_BLACK); BLUE, WHITE, ...
TFT.setCursor(0, 10);
TFT.setTextColor(ILI9341_RED);
TFT.setTextSize(3);
TFT.println("Hello, TFT!");
TFT.setCursor(0, 40);
TFT.setTextColor(ILI9341_GREEN);
TFT.setTextSize(2);
TFT.println("Show something");
// ===== WiFi Setup ====== Hotspot Marcel: const char* ssid = "Mi 9 SE"; const char* password = "Schnaegg99";
// Standard WiFi connection code from Wokwi. Note: Specify WiFi channel number (6) when calling WiFi.begin().
// This skips the WiFi scanning phase and saves about 4 seconds when connecting to the WiFi.
Serial.print("Connecting to WiFi... ");
WiFi.begin("Wokwi-GUEST", "", 6); // WiFi.begin("Wokwi-GUEST", ""); Opt. (6) means: skip WiFi scanning phase, save ~4 seconds when connecting
//WiFi.begin("Mi 9 SE", "Schnaegg99", 6); // WiFi.begin for Hotspot Handy Gm
while (WiFi.status() != WL_CONNECTED)
{ delay(100);
Serial.print(".");
}
Serial.print(" Connected to IP address: ... ");
Serial.println(WiFi.localIP());
configTime(UTC_OFFSET, UTC_OFFSET_DST, NTP_SERVER);
}
// **************************************************************************************************
// L O O P *
// **************************************************************************************************
void loop()
{
// %A/a full/short weekday, %B/b full/short month, %d day of month, %Y year, %H hour 24h, %I hour 12h, %M minute, %S second, %Z UTC
//struct tm timeinfo;
getLocalTime(&timeinfo);
//if (!getLocalTime(&timeinfo))
//{ TFT.setCursor(0, 40);
// TFT.print("Connection Err");
// return;
Serial.println(&timeinfo, "%H:%M:%S");
//TFT.fillScreen(ILI9341_BLACK); // screen color standard: TFT.fillScreen(ILI9341_BLACK); BLUE, WHITE, ...
TFT.setCursor(0, 80);
TFT.setTextColor(ILI9341_RED);
TFT.setTextSize(2);
TFT.println("Time from pool.ntp.org");
TFT.setCursor(0, 120);
TFT.setTextColor(ILI9341_GREEN);
TFT.setTextSize(2);
TFT.print(&timeinfo, "%H:%M:%S");
TFT.setCursor(0, 140);
TFT.print(&timeinfo, "%a %d.%m.%Y %b");
//delay(250);
}