- I make a digital clock NTP with esp8266 that clock is displayed time date and day.But the code is taken from YouTube channel void loop rbotech nomber36 . But the code is shown an error get formatted Date.then i red your code that said the NTP library is not have date and day.the code is taken from YouTube is that
-
#include <NTPClient.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const char *ssid = “**********”;
const char *password = “*********”;
WiFiUDP ntpUDP;
/*
for PAKISTAN 5
5X60X60 = 18000*/
NTPClient timeClient(ntpUDP, “pool.ntp.org”, 18000, 60000);
String ImtiazTech[] = {“I”, “m”, “t”, “i”, “a”, “z”, “T”, “e”, “c”, “h”};
String arr_days[] = {“Sun”, “Mon”, “Tue”, “Wed”, “Thu”, “Fri”, “Sat”};
String date_time;
void setup() {
Serial.begin(115200);
lcd.begin();
lcd.backlight();
lcd.clear();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
for (int i = 0; i <= 10; i++)
{
lcd.setCursor(i + 3, 0);
lcd.print(ImtiazTech[i]);
delay(250);
Serial.print ( “.” );
}
}
Serial.println(“connected… :)”);
timeClient.begin();
lcd.clear();
}
void loop() {
timeClient.update(); // time update from NTP server
Serial.print(timeClient.getFormattedTime());
Serial.print(” “);
date_time = timeClient.getFormattedDate();
int index_date = date_time.indexOf(“T”);
String date = date_time.substring(0, index_date);
Serial.println(date);
int hh = timeClient.getHours();
int mm = timeClient.getMinutes();
int ss = timeClient.getSeconds();
lcd.setCursor(1, 0);
if (hh > 12)
{
hh = hh – 12;
if (hh < 10) {
lcd.print(0);
lcd.print(hh);
}
else
{
lcd.print(hh);
}lcd.print(“:”);
if (mm < 10) {
lcd.print(0);
lcd.print(mm);
}
else
{
lcd.print(mm);
}
lcd.print(“:”);
if (ss < 10) {
lcd.print(0);
lcd.print(ss);
}
else
{
lcd.print(ss);
}
lcd.print(” PM”);
}
else
{
if (hh < 10) {
lcd.print(0);
lcd.print(hh);
}
else
{
lcd.print(hh);
}lcd.print(“:”);
if (mm < 10) {
lcd.print(0);
lcd.print(mm);
}
else
{
lcd.print(mm);
}
lcd.print(“:”);
if (ss < 10) {
lcd.print(0);
lcd.print(ss);
}
else
{
lcd.print(ss);
}
lcd.print(” AM”);
}
int day = timeClient.getDay();
lcd.print(” “);
lcd.print(arr_days[day]); // it will print day
lcd.print(” “);
lcd.setCursor(3, 1);
lcd.print(date);
} - That code is shown “get formatted day” you men “get formatted time”.
- Please given the answer what can I do
- But your code is shown only on serial monitor how can display on LCD 16*2
- Please help me
- Iam thankfully to you.
Hi.
Your problem is probably because you’re not using the right library.
In our example we use
NTP Client library forked by Taranais. Follow the next steps to install this library in your Arduino IDE:
- Click here to download the NTP Client library. You should have a .zip folder in your Downloads folder.
- Go to Sketch > Library > Include ZIP library and select the library you just downloaded.
- Finally, re-open your Arduino IDE
Try to compile the code again.
Regards,
Sara
sir
I downloaded library and compil the sketch but problem is not solve.The code is shown the same error. “get formatted day” . what can i do . sir that code is why not worked. that project is upsed my mind. Please and Please
solbed this problem i am thankfuly to you. I am a hobist of electronics but not have knowledg of coding but i larning more whith your books. thanksfully to you.
Hi.
Did you install the library that I’ve sent you?
What is the exact error message? Can you paste it?
Remove any other library related to this that you might have instaled previously and install the one that I’ve sent you.
Regards,
Sara
Sir,
I am sanjay kumar rastogi . I am very very happy to hellp in my project “NTPClient” LCD 1602 display time.
Sara Santos i have not more word in english how to thanks to you.I am from INDEA .Whot can i do for you.
thanks a lot Sanjay Kumar Rastogi
Email== rastogi.rastogisanjay.sanjay@gmail.com