Dear ElectroFriends,

It has been a while’ of time that I do not see new publications .... I hope it's not the fault of some virus and I hope you are all in good health. I personally don't have (Luckily) problems, but from the social point of view I would have an industrial quantity. I live to 1000 meters in a country that should be a tourist destination: but walking around the country in this period is like being in a desert. Indeed, perhaps the desert is more alive.

But let's leave it alone and come to the purpose of this article. By now you know that I am obsessed with watches and I think I have produced a few dozen of the current ones and others that are more ancient and disused.
This time I have produced a clock that only marks the hours. E and minutes ?. Yes even those but each 5 minutes.
This photo represents the finished product (so to speak: have pity for aesthetics): I used it as a basis for the 12 LEDs representing the hours, a disk cannibalized by a failed Hard_Disk. Each LED represents an hour according to the classic arrangement of all watch faces.

The following photos: front of the clock and internal hardware:

E and minutes ??. They too are represented but with a step of 5 using the hour leds and making them blink precisely for 5 minutes. The two central LEDs define AM / PM.
Let's take an example: Ore 10 e 17 minutes: The hour led lights up 10 and the hour led “3” which flashes until the minutes pass a 20 making the hour led “4” flash and so on. What happens for the moment (eg) like the 10,10. Only the hour led “10” will flash to indicate the 10 e 10 minutes. And this system is valid for all the minutes that coincide with the hours.

Let's say then that the clock never strikes the exact time !. But knowing the trick we can always say that it is the X hours straddling 5 minutes. Instead, the watch IS accurate. Because ?.
Because I got tired of the various DS1307-type RTCs, DS3231 and others that are never accurate over time and that always need some adjustment. There are other ways to have an accurate time schedule: for example, obtain from the 220V network i 50 Hz available with a very simple circuit and that with a suitable divider circuit it is possible to obtain the frequency of 1 HZ able to drive the counting circuits starting from the seconds. But this solution was fine a few decades ago: I used it myself to produce the first digital watch. It is clear that today this path is not viable for a number of reasons: 1) the tension 220 it's dangerous, 2) you need several integrated to make it all, 3) It's not convenient. So in this project I relied on the INTERNET now. That is, retrieving the time and date from the NTP servers that manage the time. I had already produced a clock which, through an LCD, displayed the complete date and time taken from the NTP servers.

So let's see the construction features:

The hardware used:
• Micro Arduino Nano 328 as the main engine for managing the clock
• Micro ESP8266_1 for managing the NTP server
MAX7219 for the management of the LEDs. Great: with 3 wires fly 64 led with only one integrated with the possibility to connect other chips in series.
12 led (cold white high brightness cylinder model).
• N.1 Bidirectional level converter 3V / 5V to adapt the ESP levels to those of Arduino
• N.1 Modulo AMS1117 controller (da 5V a 3V) to power the micro ESP

The level converter is necessary as the ESP only works at 3V and therefore all PIN levels are managed with this level. The voltage regulator to have the 3V is used to power the ESP independently from the Micro Arduino_Nano (which in turn has a 3V output).


IDE of ARDUINO for the compilation and programming of the sketch relating to the management of the NTP server. The IDE must be configured appropriately to recognize the ESP series from the smallest to the most versatile in terms of functionality and presence of PIN. The list of "CARDS"And"BOOKCASES”. The MAIN sketch for management can be managed by the ARDUINO IDE: I personally prefer to use another much better performing IDE: CODE:BLOCK. It works perfectly for what concerns almost all the ARDUINO versions including standard libraries. It is very fast and has a practical "automatic completion" for each function / instruction. And the error messages are much clearer than those of the Arduino IDE. It is not updated to the WIFI libraries. And if there are no libraries needed for the sketch, just insert them into the "project" both as a .h and .cpp file.

For the management of MAX7219 I use a "custom" library expanded and modified by myself compared to the original libraries (present in the network). It does not have the features and shapes of a standard library (it has no .h and .cpp files) but it's an .ino file. It is able to manage any type of LED, any type of display 7 segments and matrix display modules 8×8 e 7×5. Per i display a 7 segments type a is also provided COMMON_ANODE: this is because the chip only handles devices a COMMON_CATODE. In this case, a small hardware addition is required. Someone will now wonder why to use two Micro to produce a watch that is never "ACCURATE". It would have been much easier to use an ESP32 that is equipped with more than enough pins to drive the devices used in the project. But I have several ESP8266s purchased at the time and I had no interest in getting an ESP32 and having to re-discover the features..

Ma, I repeat, they are personal choices.

Let's see now how all the management software was developed:

ESP side: this micro produced by "Espressif”Allows the complete management of an internet connection for the development of WEB pages (via WIFI) to be viewed on a common tablet or PC. I made several sketches to try to build WEB pages in various sizes and dimensions. In my project "CIABATTA ELETTRONICA" the management of the relays is carried out by a WEB page in which the ON / OFF status of the 5 relay.

Unfortunately this ESP is very stingy with PINs: in practice they are only 2 usabili GPIO / 0 and GPIO / 2. I pin RX/TX they are used as a serial interface. It is very important to have an interface between the arduino IDE and the micro itself for programming: if the levels of GPIO/0, they are not in the correct condition NON you will never be able to program it: the IDE does not recognize the serial port even if connected.
When I bought the first ESP I also bought a module "DEBUGGER”. This module is seen as a serial port. By inserting the ESP into the connector, the IDE recognizes the port and the programming (ground to GPIO / 0 automatically) is done correctly. The module also has a reset button to restart the ESP.

Before moving on to the physical structure of the project, let's see the logic with which the sketches were developed:

Sketch su ESP8266_1:
After the usual settings for the WIFI (with connection to the router and assignment of the dynamic IP address) a serial port is opened (baud_rate 19200) managed by the standard library "Software_Serial”Using the pins GPIO / 0 and GPIO / 1 come RX/TX which through the level converter module are connected to two Arduino pins. A "HAND_SHAKE" or "I send you data, you reply that you have received them”Using defined RX / TX. This first interview is used to manage winter / summer time: the sketch expects to receive the code from Arduino "36"For solar time or"72"For summer time. This is because the NTP server only transmits the time in solar time but the library that manages it with the "SetTimeOffset”Update the time to daylight saving time by setting the value to 7200. All this is managed in the "Setup".

Nel “loop”: you are waiting to receive a specific character from the Arduino to indicate that the Arduino itself is ready to receive the HOUR and MINUTE values ​​that are used to update the clock. Received this character, the ESP asks the NTP server to send the hourly values ​​and they are received 8 characters in the form HH:MM:SS and stored in a string. The NTP server can also send date values ​​which are not needed in this case. Beware that there are several libraries that manage NTP servers but not all of them manage both date and time values. The library used is instead complete. We then proceed to convert the hour and minute values ​​into binary format, obtaining two bytes: he bytes NOW (values ​​from 00 a 23) and the byte MINUTI (values ​​in groups of 5) after a simple decimal / binary conversion. These two bytes are sent in sequence via serial to ARDUINO which will use them to update the clock. The cycle then resumes from the beginning.

NOTE: The system just described is the latest in a series of tests: initially the ESP sent the HH string:MM:Complete SS that Arduino received and stored in turn in a similar string to then carry out the conversions and update the time. This system worked correctly up to a certain point: then it "went crazy" in the sense that the string received was "DIRTY" with values ​​absolutely out of control. This compromised the correctness of the values. I was able to detect all this through the usual "debug" system, on serial monitor, of messages to verify what Arduino actually received. And the ESP sent correct values !.

Sketch your Arduino (micro used Arduino_Nano):

Also in this sketch made the usual settings of the ports including the standard serial ones and the one related to “Software_Serial” and initialized the library for the management of MAX719 and relative LEDs, the first operation that is carried out is to send the code "36" or "72" to the ESP to set the summer / winter time. This choice derives from a jumper on an arduino pin brought to ground or left free. After this sending and confirmation by the ESP, the setup cycle ends.

The section LOOP it's simpler than you can imagine: they are launched in sequence 3 functions: the first to receive the time values (the two bytes that are sent by the ESP), the second to update the hour LEDs and the third to update the minutes LED. And the cycle resumes.
The "lion" part is the routine that must receive the "HH" and "MM" values ​​from the ESP: also in this case the "HAND_SHAKE”: a character is sent to notify the ESP. The ESP responds by sending the two converted byes. The test on the hours value determines the switching on of the AM / PM LEDs placed on the front of the clock. The other two routines take care of testing the HH and MM values ​​and accessing their LEDs.

Let's see the logic with which the LEDs for the hours light up, therefore also for the minutes:
The MAX7219 can individually manage up to 64 led or a matrix 8×8 (64 led). A register addresses the individual chains (D0/D7) while another register defines which led (or point of the matrix) switch on (or turn off) depending on how another register is set according to the following configuration:

DP, A/G refer respectively to the position of the segments of a classic display a 7 segments + the decimal point (DP). Oppure a 8 connected LEDs (common cathode) in the same way by assigning a position from DP to G to each LED. The clock has 12 led: in order to address them all I have defined two chains each of 6 led: in this case: the register "D0”Will direct the LEDs from the hours 12(00) all 5(17), while the register "Dl”Will direct the hours from 6(18) all 11(23). The LEDs will remain on until the hours or minutes are changed. This is because the MAX7219 also cares about Multiplexing. And no limiting resistors are needed for the LEDs.

In the MAIN sketch on arduino_Nano a special table of 12 elements contains the coding of the data register with the bits to be switched on or off and the DP bit is used to discriminate which chain to use for switching on the hours / minutes. The LEDs light up by bringing the relative position to "1" or to "0" to turn it off. This is the table:

byte Tab_Led_Ore [12] =
DPABCDEFG ORE MIN HEX Nota: the "G" bit is never used
B01000000, // Offset 0 ore “0” “12” 00 0x40
B00100000, // Offset 1 ore “1” “13” 5 0x20
B00010000, // Offset 2 ore “2” “14” 10 0x10
B00001000, // Offset 3 ore “3” “15” 15 0x08
B00000100, // Offset 4 ore “4” “16” 20 0x04
B00000010, // Offset 5 ore “5” “17” 25 0x02
B11000000, // Offset 6 ore “6” “18” 30 0xC0
B10100000, // Offset 7 ore “7” “19” 35 0xA0
B10010000, // Offset 8 ore “8” “20” 40 0x90
B10001000, // Offset 9 ore “9” “21” 45 0x88
B10000100, // Offset A ore “10” “22” 50 0x84
B10000010 // Offset B ore “11” “23” 55 0x82

CAUTION: There is no obligation to use the D0 / D1 registers. The others D2 to D7 can also be used if they are not used for other purposes. The chip has no specific preferences.


Having no special equipment, I have to be content with producing small PCBs using the "PRESS_AND_PEEL”. After a series of experiences, however, I managed to have a sufficiently valid final product. The three PCBs of this project are: the first houses the Arduino Nano micro and the MAX7219 chip, the second the ESP and the interface electronics and the third i 12 clock LED.

Layout of the first PCB:

On the right the connector to insert the micro Arduino Nano, on the left the MAX7219 housing. There is no specific power supply as the USB socket of the micro is connected to any battery charger for mobile phones or tablets with 5V 1 / A output, it is enough to support the whole. A small button is connected to the reset that resets the Nano and the ESP at the same time. One connector carries RESET signals,V5, GND, TX, RX towards the PCB that houses the ESP. The AM / PM pin is connected to the small plate with the two AM / PM LEDs. Finally a bridge 36/72 to set the so-called summer / winter time.

Layout of the second PCB:

This pcb supports: the 5V regulator > 3V to power the ESP, the level converter to adjust the levels 5v to 3v, and finally the connector to house the ESP. I 5 pins at the top are connected respectively to 5 pin del pcb main. The incoming RX / TX signals are regularly connected to the TX / RX pins of the ESP via the level converter. NOTE: a voltage divider would also have been sufficient.

Layout of the third PCB:

Accommodation i 12 led with the two connectors (A_F) for the respective chains and the two DG0 / DG1 pins. The A / F connections are then joined in parallel (A with A, B con B, etc) to be then connected to the respective pins of the MAX7219. As well as DG0 / DG1.

I forgot this last PCB: it relates to the two AM / PM LEDs which light up according to the level 0/1 present on the input pin.



In conclusion:

To date, the only problem to be solved is to enclose everything in a suitable box or something like that. Being a landslide in DIY, I never manage to do something, at least aesthetically, valid.

In the meantime, I thank you for your attention and look forward to your comments, bearing in mind that everything is perfectible and feasible with better results. I remain just a hobbyist who delights, with their own ignorance, to always discover new things.

gvsoft march 2021

2 replies
  1. Picmicro675
    Picmicro675 says:

    Congratulations on the job.
    I am trying a similar one, but with 7SD. Nano is not used because ESP-03 (what I use) it allows me to interface a DS3231 and the SPI to the MAX7912.
    At the moment I don't have free time. Maybe I'll pick up later.


Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply