ESP32 Tutorial 53 - Build an LCD Internet Clock | SunFounder's ESP32 IoT Learning kit

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi welcome to esp32 tutorial from Robojax in  this video we are going to build an internet   LCD clock based on esp32 using esp32 extension  board from SunFounder which is powered with   battery this clock is updated via the Internet  it can display time in 12 hours or 24 hours   day of the week uh and then the date month  and year the month also can be set uh with   a shorter or longer format also we are going  to test it with 204 of 20 characters and four lines and in the long and in the longer format  with the second day of the month also has changed   esp32 starter kit from SunFounder this is the  best esp32 learning kit from SunFounder it has   this esp32 microcontroller which has built in  Wi-Fi and Bluetooth this board can do everything   Arduino Uno can do or many other Arduinos can do  plus extra more features because we have Wi-Fi and   Bluetooth the possibilities are endless you can  get connected to the cloud or do the control or   read information or values via your mobile device  or your desktop or over the cloud from a far location it comes with a camera extension  kit where you can stream the video over   Wi-Fi either through the cloud or to your  network and also it comes with microSD card   where you can save images on the micro SD  card or you can write from the device any   information log the information on the device  and read it back you can power the board using   this included 18650 lithium battery and it has  built-in charger where you can connect micro USB   and charge the battery the kit comes with 320  pieces of component that you can learn tons of projects usually when we build a clock we need  to have RTC or real time module that calculates   the time and we set it and then we can build  a clock I have a I have multiple videos based   on those but those does not need any internet  and you just use a regular you can simply use   regular Oro Uno without internet and it will just  work fine of this is that you don't have to set   it up or adjust it or anything it's connected  to the internet and the time will be adjusted   automatically know the deviation because the  clock will be very uh accurate but in order to   pull that the data from internet we use ntp server  and we use Wi-Fi so this is esp32 has a Wi-Fi and   we will set it up in our code and we will get  connected so this gets and this sends a request   from ntp server and also from the government  time. n.gov from the US and it will pull up   the date and time and it will print it for us so  this is one way to have a precise clock and we   will learn a lot a lot of principles of Internet  of thing and connectivity to the internet before   coming to this lesson make sure to prepare your  Arduino ID for esp32 that is lesson one of this   course and also make sure to watch the video  that we introduce this LCD screen the link for   both will be below this video in the description  so watch those videos before coming otherwise your   project might not might not work if we come  here to ntp.org this is the page that we are   seeing here ntp refers to network time protocol  and there are servers across the world they are   working together and providing information so you  can pull up the information if I click on uh this   support and look at click on time servers  we see the servers list here and here the pool and the one that we are using is  pool.ntp.org and then you see all of   them they have pool but if you are in Asia just  use asia. poool Europe is Europe and then North   america. poool oia and then South America  depending on your geographical location   select the nearest pool and set that in  your code and let's have a look at the library so all the RFC the protocol and  everything is mentioned here and based   on RFC 8915 this is September 2020  and we can click and view the HTML here when you use esp32 with Sounders is sp32  camera extension module like this it comes also   with a battery on the package and it comes  a built-in charger so you can connect it and   charge it and disconnect and later on you can use  it with a lot of power so you can power up your   application very easily now let me show you the  wiring we are getting this male to female one side   is female the other side is male connector  and when we are connecting it first first first let me connect this first let me  connect these four wires here I connect   them like this and if I turn it around it  looks similar to this color the bottom is   orange as you can see here then yellow and  then red and the top one this is like black   and white and we have brown like that  now I'm turning this so and from here   the top one the Brown goes to ground to  the ground and then the red goes to 5 vol so this portion is done  and then yellow goes to 21 and orange goes to pin 22 and 22 between 21 and 22 there  is two there are two holes left I've started The Code by selecting file examples  and under esp32 go to time and simple time I have   taken that code and modified it and added all  the other feature so I built this internet clock   project I use this Liquid Crystal i2c Library  Crystal LCD I've already shown full details of   it right click here and paste it and you will see  that it shows LiquidCrystal by Frank D Bar bender   and it is installed so you just click and install  it you please watch the introduction to LCD video   otherwise this will not work and then from that  we have created from that Library we have created   this object called LCD and we are typing the i c  address for the for SunFounder the address is 0   x27 but some other boards will have different  address I have written them it's not written   you need to run I to see a scanner I will provide  you the code make sure to run it and then 16 mean   16 character and two line and if you have this  204 which has 20 characters and four line then   you will type 20 and four here 20 and four this is  16 to this shows seconds if you want to show the seconds if you want to show the second set this  to true so this will be shown if you want the   month to be short set this to true so this will  be shorter and if you if you want 24h hour set   it through at the moment it is set through but  if you set it to false you will see amm here as well this wi-fi is to connect to the internet  time ntp this time zone I have added the time   zone here to make sure that we can get the  different time zone based on the countries   this is your SSID for the for your Wi-Fi  this d uh in this case is Darth if you   type capital D it will not work so so  respect the case and enter the password   for your uh uh router this is a server  where we pull the date and this is the   second ntp server time. NT nist.gov and then  this offset if uh at the bottom there are two   options one is to calculate and see the city  that you are living from GMT let me show you for example if I type time in Toronto  you see here UTC minus 5 UTC minus 5   means from uh uh universal time we are  5 hours behind and let's see if I type Dubai you see here it is plus 4 so this number is that hours and because we  want it in terms of second 1 Hour 1 hour has   3,600 so we multiply it and then a delay of set  seconds 1 hour if you have delay saving time or   something like that otherwise set it to zero but  we are not going to use these two there is a trick   at the bottom of the Cod I'm going to explain  I have defined these months from the internet   we are getting in Long format so I've created the  short format and we can pull this so you can you   can change these names differently you you want  if you want so this function prints the time so   the most important function it's up to up to here  so let me explain it properly and so first uh we   are creating a structure call it time info and  we check if get local time and then we pass this   value if it's not available we say time is not not  available yet until it's available after that we   this line is simply printing it like that let me  show you this is coming from and so we understand   that a is Monday and then percent B is the name  of the month and D is the day of month one here   is the year right now it's set to 24 2024 and  then hour minute and second like that and here   I've also set it with our minute and second so we  can see it if you don't want this just comment it   like this it will disappear and then we are  setting creating a character variable called   time with five character length because there  is always with this one extra character so and   we are getting from this we are getting Capital  H the time is stored here and in this line we   are getting that time converting it to string so  we can work with this and then we are getting for   the minute these two are for the minute and we  convert it to string and this is printing this   03 I should have comment this out and here if  show hour is not true then we check it we get   the hours string converted to integer and we check  if it is more than 24 hours we get the minute and   after the minute we concatenate or add this PM  otherwise we get we add am and then we also get   second day of the week Monday Tuesday Wednesday  and this is uh month like one to3 January February   March or something like that and we convert it  to string here and this was just uh this is just   replacing the month we have created an array  that M from 0 to 11 and we check the month and   we pull it from the array at the top so this  is replacing the short and long form only if   the short month is set to true and then we get  the month uh month day of the month that's the   date in the month like first up to 23 and this  is for the year we get the year and here we we   create hour and minute together and then if the  second is set to true then we have the time and   we we get the time and we plus we add column  and we add the seconds at the end and we set   the previous screen using LCD do clear set the  cursor to line zero character Zero we print the time and this line is printing the day of the  week like Monday Tuesday Wednesday whatever it   is then we go to the character Zero first uh  line one and we print day of the week and we   print day of the month which is whatever the date  is with one space we are adding month and this   month depends on the setting either short or long  and then with one space we are printing the ear this function will run when the time is  available so this will print on the screen   and it will call the print local which I just  explained it this one all this which start from here and inside the setup we initialize a Serial  monitor with 115,200 if I open the serial monitor   this number must much the number that is  here otherwise you will not be able to see it and this is initializing the LCD this  is initializing the backlight this is just   printing the internet clock on the LCD and we  have we wait 3 seconds and this is ntp set sync notification and it checks the available  time to the it this one should be before   so this is for dhtp it is optional we  don't care about it this is the most   important part so we call the time  either using this uncommon this if   you use this then the three information  that we had remember we are at line 160 so these information the these two these  two information that you see these are very important and these two will come and the ntp  server ntp server two will come here and this   will configure the time and we'll read the time  but because if you don't like the calculation   then we can use this line but you have to  enter the TZ the a the time zone which I   I just showed you that in here this line  I've included this from this URL and it's   already here it has included so many cities  I'm sure any city that you think of might be   here the biggest cities because it has over  maybe around 470 cities so let's go back to 160 so that's why we are using just this one  we don't need any offset or anything it depends   whichever you prefer if you prefer the other one  just comment this out and uncomment this line but   configuration this is printing this on the screen  on the serial Monitor and this is initializing the   Wi-Fi with SS ID and password the connection this  function checks if there is no connection it will   just print the dot and this after that when this  passes it means we got connected otherwise it will   stay here so this will print connected inside  the loop we have 5 seconds so the time is R   every 5 seconds and then we call this function  print local time which is at the top of the code now let's see how we can select the esp32  board we can click here under the select board   and type here esp32 d as soon as you type Dev you  will see Dev board you can select it and click   okay so the board have been selected now we have  to select the port the other way to select the   board is Click On Tools board esp32 and select  the esp32 dev module now we have to select the   port if I click here it shows two port and I don't  know which one belongs to my device sometimes you   will see you will not see the number properly  so the best way to be sure the right click on   the start menu go to the device manager and you  will see here the ports if I click on this Arrow   it will show me the ports one is USB serial  ch340 one the other is USB serial device and   there now it's connected if I disconnect this one  of them disappear the one that disappears is my board so sex stays and it  it disappeared if I connect it so it is my comport ch340 now it is my  comport and I can select it or I can click   on tool port and here you will see it you can  select whichever you want ours is come eight now   we have successfully selected the board and the  port and this is very important it must be done first and here is a demonstration let me  set the time here uh we can set 12   hours through and here short month  and let's set it to false so it can   show the long man show seconds  we can also show seconds if you want let's update it and see how it shows so  I hope this fits because and then we do have   a. p.m and then Monday hopefully it will fit  and the month also should be shown in longer format hope now it's getting connected  wait until it shows here it is connected   yes we can see time and and as you can  see now it shows 02 to 48 and second and   the month everything uh looks very long  so now it shows the second the hour with   the 24-hour format and day of the month is  also shown in this long format perfect and   here I updated it with this I use now green  screen it looks much nice I've changed it   to 24 our format and I selected Toronto  so it shows 1839 still today is December 31st
Info
Channel: Robojax
Views: 1,246
Rating: undefined out of 5
Keywords: robojax, sun, founder, sunfounder, course, tutorial, kit, learn, learning, step by step, esp32, arduino, iot, wifi, ntp, clock, update, wiring, code, library, lcd, LCD1602, LCD2004
Id: 0KnuNqfiVug
Channel Id: undefined
Length: 22min 44sec (1364 seconds)
Published: Mon Jan 01 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.