Digital and analog clock on a TFT touch display.

ESP32 with Micropython and a TFT touch display. Together they form a digital and analog clock with touch keys for setting and operation.
General description project.
The project concerns a clock with both a digital and analog display. The settings and operation of the clock is done by means of touch buttons. The clock condsists of an ESP32 and a TFT touchscreen mounted on a self designed PCB.
The project concerns a clock with both a digital and analog display. The settings and operation of the clock is done by means of touch buttons. The clock condsists of an ESP32 and a TFT touchscreen mounted on a self designed PCB.
Settings and operating the clock module.
When the clock (the ESP32) starts it will look for a program main.py and start it automaticly.
The clock will then try to connect to your local network and tries to synchronise with a NTP-server to get the Date and time information.
If it is no able to connect to your network it wil dsplay "no network" instead of the date. You can than set the time by using the touch buttons.
If you have an connection to your network but the synchronising with the NTP-server fails, you will see istead of the date the text "NTP failed" and next to the DATE a green circle outlin wil appear. By toutching the outline you can retry the synchrosation with the NTP-server till you get the current date and time.
Setting the time:
You ca set the time manualy by touching the white circle "time" on the screen. When it turs red you can set the hour by touching the green circle and the minute by touching the purple circle.
when the correct time is set touch again the red circle below the text "time" it wil turn white and the digital and analog clock display wil refresh with the time you have set.
Setting the alarm:
You can set the alarm vy touching the blue circle "alarm" on the screen. When it turns red you can set the alarm hour by touching the green circle and the alarm minute by touching the purple circle. When the alarm time is correct touch again the now red "alarm" circle, it wil turn white again and the alarm is set but not active. The screen wil show that the alarm is off. To activate the alarm touch the yellow circle it will togle the alarm and the set alarm time wil be shown on the screen.
Hardware
BOM
ESP32 Dev Module 1
2.8 TFT SPI 240x320 V1.2 1
PCB assembly board 1
Sliding switch 1
Capacitor 10uF 1
Capacitor 0.1uF 1
voltage regulator AMS1117 5V 1
Barreljack connector 1
LED red 1
Resistor 330 Ohm 1
Speaker 1
Female and male headers
3D printed stand
Spacers, screws and nuts 4
Software
The main program is written in mycropython using Thonny 4.1.3.
for more information see:
https://thonny.org/
https://docs.micropython.org/en/latest/esp32/tutorial/intro.html
The PCB is designed using KiCad version 8.
The 3D printed stand is designed in FreeCAD 0.21 and printed with Ultimaker Cura 5.5.
The micropython program main.py:
using the name main.py insures that the program is started after the ESP32 has booted.
Libraries used in the program:
Machine
ESP32 specific libraries (Pin, SPI, RTC, PWM).
network
This library is neede to connect to the local network.
time
Library for working with date and time.
ili9341
Library to connect to and write on the TFT display.
xglcd_font
Font library for use with the TFT display.
xpt2046
Library for the TFT touchscreen.
math
Necessary for making calculations used for the analog clock
npttime
The library used to synchronise with the NTP-server the correct time and date.
The structure of the program.
-The program starts with importing the necessary libraries.
-Next step setting up SPI for the TFT display and the touchscreen.
The pins used correspond to the PCB design. On the PCB the backlight is always on because the LED pin of the TFT display on the PCB is connected to VCC.
-The WiFi connection parameters id and psw are set, you have to change them with the ssid and password of your local network.
-To receive the correct date and time for your location you wil need to change the TIMEZONE_OFFSET to the value corresponding to your timezone.
-To receive the correct date and time for your location you wil need to change the TIMEZONE_OFFSET to the value corresponding to your timezone.
-Declaring and setting the (default) values for the variables and the colors we will use.
-Functions
The program is a collection of functions that are called during the program loop at each change. In this case a change in time, date or a touchscreen action.
List of functions:
.setNTPtime (synchronize date and time with a NTP-server)
.touchscreen_press (touchscreen handler reaction if the screen is pressed at a certain location)
.connect (tries to connect to your local network)
.disconnect (disconnect from the local network)
.read_time (returns current time)
.read_date (returns current date)
.show_date (displays date on the TFT screen)
-show_time (displays time on the TFT screen)
.show_alarm (displays alarm time or off on the TFT screen)
.show_clock (displays the analog clock on the TFT screen)
.set_time (manual setting of the time with the touch buttons)
.set_alarm (setting the alarm time with the touch buttons)
.sirene (sound the alarm)
.minutes (used display the minutes on the analog clock)
After the defining of the functions the program starts with connecting to the local network and start RTC (Real Time Clock) on the ESP32. Then synchronizing with he NTC-server. and building the display with all the information received.
Now the program loop starts. This loop changes the time every minute and reacts when the touchscreen is touched on the defined positions.
-Functions
The program is a collection of functions that are called during the program loop at each change. In this case a change in time, date or a touchscreen action.
List of functions:
.setNTPtime (synchronize date and time with a NTP-server)
.touchscreen_press (touchscreen handler reaction if the screen is pressed at a certain location)
.connect (tries to connect to your local network)
.disconnect (disconnect from the local network)
.read_time (returns current time)
.read_date (returns current date)
.show_date (displays date on the TFT screen)
-show_time (displays time on the TFT screen)
.show_alarm (displays alarm time or off on the TFT screen)
.show_clock (displays the analog clock on the TFT screen)
.set_time (manual setting of the time with the touch buttons)
.set_alarm (setting the alarm time with the touch buttons)
.sirene (sound the alarm)
.minutes (used display the minutes on the analog clock)
After the defining of the functions the program starts with connecting to the local network and start RTC (Real Time Clock) on the ESP32. Then synchronizing with he NTC-server. and building the display with all the information received.
Now the program loop starts. This loop changes the time every minute and reacts when the touchscreen is touched on the defined positions.
Discussion (0 commentaire(s))