Clock synchronizer with I2C bus with time downloaded from the Internet

Hello everyone.
This time I would like to present the I2C clock synchronizer with time downloaded from the Internet. Using the previously presented clock on the Z8, I thought it would be worth extending it with this possibility, hence the presented circuit was created.
The system itself is based on the ESP8266-01 module, which obtains the time from the NTP server after logging into the WiFi network. The module cooperates with the ATtiny4313 microcontroller, whose task is generally to be seen as an I2C slave with address 0x0A by the clock cooperating with this system, which is an I2C master. In addition to serving as an I2C slave device, the microcontroller also operates the ESP8266 module via UART and supports an optional LCD display as a monitor of data exchanged via I2C with the master. You may ask why I didn't implement the I2C slave function in the ESP itself? Well, I didn't succeed. Multiple attempts (also using external interrupts to which ESP can respond) did not bring the expected effect. Here: https://github.com/esp8266/Arduino/issues/5762
there is even a discussion about it. So, in order to continue with this project, I decided to use an additional microcontroller. The microcontroller periodically sends data received from the I2C master to the WiFi module to log in to the WiFi network. Cyclic, because after turning on the power, the I2C master sends the SSID and password (both ending with CR and LF) needed to log in to the described synchronizer system once, and at that moment the WiFi network may not be available. After the ESP8266 module successfully establishes a connection to WiFi, the module periodically sends the received RSSI, time and date data to the microcontroller in the form of an 8-element int16 array. The ATtiny4313 microcontroller receives this data from the module, makes sure that the data is in the right order, and then transfers the ordered data to a buffer intended for reading by the I2C master. The optional display presents the SSID on the first line and the password received from the I2C master on the second line, and after establishing an Internet connection, displays the contents of the buffer for reading by the I2C master.
The representation of data placed in the correct order in the buffer and ready to be read by the I2C master is as follows:

Where:
first element of this buffer: RSSI; a value less than 0 (0xFFC7 from LCD) means establishing an Internet connection; the lack of this connection is signaled by the value 0x001F
second element of this buffer: seconds in BCD (0057 from LCD)
third element of this buffer: minutes in BCD (0049 from LCD)
fourth element of this buffer: hours in BCD (0018 from LCD)
the fifth element of this buffer: day of the week; 1 - Monday, ..., 7 - Sunday (0001 from LCD)
sixth element of this buffer: day of the month in BCD (0023 from LCD)
seventh element of this buffer: month in BCD (0010 from LCD)
eighth element of this buffer: year in BCD (2023 from LCD).
The video on YT shows the synchronization of the clock, deliberately set to January 1, 2001, with the time downloaded from the Internet by the described module.
Now a little about the preparations for this project. When I was thinking about this project, I first came across the website: https://randomnerdtutorials.com/esp8266-nodemcu-date-time-ntp-client-server-arduino/
This is almost the finished product on which I based my sketch in the Arduino environment. Even this worked, but the inconvenience was the lack of automatic change of summer/winter time (despite the presence of the tm_isdst component in the tm structure, however, the value of this component did not change when switching from winter to summer time in spring). Moreover, the author asked us to add/subtract the number of hours expressed in seconds to the UTC time received by the module programmed with this example sketch, depending on the expected time zone. While looking for how to solve the above problems, I finally found the website: https://werner.rothschopf.net/202011_arduino_esp8266_ntp_en.htm
and after matching this sketch to our time zone using #define MY_TZ, the program began to correctly display the time in Poland on the terminal. After that, it remained only to adapt the sketch to the needs of cooperation with the described system.
A few more words about preparing the ESP8266 module itself to work with this system. Apart from adjusting the voltage levels on UART (module powered by 3.3V, ATTiny powered by 5V), which I implemented as described at http://mirekk36.blogspot.com/2015/05/konwerter-levelow-33v-ttl.html, the module itself must be programmed with the NTP_time_date.ino sketch. To do this you need:
1. Disconnect power from the module.
2. Short-circuit pins 2-1 with jumper JP1
3. Connect e.g. the ZL4USB adapter to the J2 socket. The pin arrangement in the J2 socket is adapted to the adapter I have.
4. Short pin 5 (GPIO0/Flash) of the ESP8266-01 module to ground using a microswitch.
5. With pin 5 shorted to ground, supply power to the module
6. You can now disconnect the connection from point 4. The module is now in firmware update mode.
7. In the Arduino 1.8.5 environment (this is what I use), compile and upload the NTP_time_date.ino sketch to the module
8. After uploading the sketch, disconnect and connect the power supply to the module again
9. Open e.g. RealTerm and connect to the module, connection parameters 19200.8N1.
10. Send the module the SSID name and password (both strings ending with CR LF, max. 14 characters in the string) for the WiFi network to which we want to connect. The characters of the sent SSID and password should be displayed in the appropriate lines on the connected LCD.
11. After successful connection, the module should periodically send data to RealTerm, as in the screenshot. This data will also be presented on the connected LCD.

If you are unable to complete the above points 7...11 (the firmware in the module may be inappropriate), you should update the firmware (which works for it). For this purpose:
1. Download the firmware with flasher from https://www.elektroda.pl/rtvforum/topic3844441.html.
2. Follow steps 1...6 above to enter firmware update mode.
3. Run the ESP8266Flasher.exe file
4. In this program, in the Config tab, indicate the files eagle.app.v6.flash.bin and eagle.app.v6.irom0text.bin as in the screenshot:

5. Then, in the Operation tab of this program, select the appropriate COM Port and press the Flash button.
6. After successfully uploading the firmware, try again to upload the NTP_time_date.ino sketch according to the above points 1...11
I wrote the program for ATtiny4313 in the Rowley Crossworks for AVR ver.1.4 IDE.
To sum up: the clock with this synchronizer works well, at least I have a reference time according to which I can set other clocks in the house. I also had to equip the described system with:a 220uF capacitor connected to the 5V side (visible in one of the photos), because during startup it turned out that when the WiFi network was lost (e.g. when the router was turned off), the Z8681 clock microcontroller could hang. The reason was a drop in the 5V voltage supplying the clock. An example of the cooperation of the described system with the Z8681 clock is here:
https://www.elektroda.pl/rtvforum/topic3795375.html
Regards, KT


Comments
I think it would be possible to get rid of the attina. ESP01 can support I2C. [Read more]
The title is a bit awkwardly written. This is not an I2C clock synchronizer because you do not synchronize the bus, but it is a clock synchronizer WITH an I2C INTERFACE :D At first I thought your clock... [Read more]
@tos18, I didn't manage to do it, as I already mentioned. If you could present a working sketch or at least a concept of how to do it, that would be great :) And it would definitely be used. @szymon122,... [Read more]
Have you considered DCF-77? Then the Internet and ESP would be redundant. What is a dip? It reminds me of some military exercises abroad. [Read more]
DCF77 requires a large antenna (the ferrite one is a few cm long) and range. WiFi is now practically everywhere, and certainly at home. That's why you also have BOD and WD in the MCU. It's worth... [Read more]
Failed to run I2C in Slave mode on ESP8266? You should have asked on the forum. Examples from Arduino SDK ( Link ) are insufficient? This design looks as if a carriage was pulling a car. [Read more]
There is something like this: https://pl.wikipedia.org/wiki/Zapad_napi%C4%99cia I know it's worth using, but Z8 doesn't have such inventions ;) These are not the times yet ;) Perhaps... [Read more]
I confirm problems with the operation of the I2C bus on the ESP 8266. I once tried to connect two ESP8266 via I2C. Only when setting Wire.setClock(20000); somehow it worked... [Read more]
You wrote that you use ATtiny4313, which has these inventions.... BOD is especially important, because when the voltage increases slowly, the MCU may enter some undefined state from which it cannot recover... [Read more]
There is also mentioned the alternative Brzo I2C library for ESP8266, which I used. It is more difficult to use, but sometimes it is worth using such solutions if the "popular" Arduin ones fail. Generally,... [Read more]
ABOUT! And that's great news. It is worth knowing about the existence of such a module. Then indeed, ATtiny would no longer be needed. There is something like this in Botland: https://botland.com.pl/plytki-zgodne-z-arduino-dfrobot/21227-beetle-esp32-c3-risc-vz-mikrokontrolerem-espressif-esp32-c3-risc-v-wifi-bluetooth-dfrobot-... [Read more]
On Ali, similar ESP32-C3 MINI boards are priced at approximately PLN 15. [Read more]
Have you had problems with UART on ESP8266? Unlike I2C, UART is hardware-based and has quite a large I/O buffer. [Read more]
They are available on Ali, but delivery is expensive. [Read more]
My friend @krzbor made me realize that in fact, I don't remember ever having a problem with communication. Very often, ESP8266 in my projects is used to generate a wireless GUI with data to other MCUs. ... [Read more]
Somehow I couldn't find one for PLN 4. [Read more]
https://obrazki.elektroda.pl/6885509500_1700421147_thumb.jpg PLN 43 applies to purchases that will be shipped within 14 days. And this is the minimum purchase amount to deliver them within 14 days. [Read more]
It's not a question of AVR, but of mathematics. Calculate the error for a given quartz and baudrate and the puzzle is solved.... [Read more]
Of course. What I meant was that with e.g. AVR you need to match the quartz to the baudrate or vice versa. With ESP, we actually have no influence on the timing and this UART works as it should. [Read more]