Skip to main content

ESPCLOCK3 - The Final Version


This is the latest, and probably final iteration of my ESPCLOCK project. You can find ESPCLOCK1 here, and ESPCLOCK2 here.

The main differences between ESPCLOCK3 and ESPCLOCK2 are:
  • Use barebones ESP-07 instead of WeMOS D1 Mini to reduce deep sleep power draw.
  • Use PCF8563 RTC to clock the ATtiny85. PCF8563 is chosen over the more popular DS3231 RTC due its vastly lower power consumption. Using a RTC to clock the ATtiny85 allow us to use the POWER_DOWN instead of IDLE sleep mode, which minimizes power draw. As a result, the ATtiny85 code is also vastly simplified because we don't have to play with Timer1 to get an accurate 1Hz signal.
  • Use diode clamp to limit the voltage pulsing the analog clock. Connecting to the analog clock directly using the ATtiny85 pins running at ~3V requires the clock pulse to be longer (~200ms) and increases power draw (due to reduced MCU sleep time). In addition, the higher voltage causes ticks to miss occasionally. The diode clamp limits the pulses to ~1.2V, which is much closer to the working voltage expected from the clock's lavet motor. As a result, the clock pulses can be shortened to 40ms (can be even shorter depending on the actual clock, but 40ms is a good compromise), and the clock ticks are 100% stable with no misses.
  • Use HT7833 LDO to provide power to the circuit. HT7833 provides up to 500mA, which is more than sufficient to support the power-hungry ESP8266. I am using 4 x 2450mA NiMH AA batteries (the popular IKEA LADDA rechargeables) to power the entire circuit, though other modes of power could conceivably be used eg. 2x or 4x 18650 cells.
  • The reset circuitry has been redesigned, so it doubles as a factory reset button if you hold it down for a few seconds as the ESP-07 powers up.
The project finally made the leap from breadboard to PCB. I tried using a prototype board, but the circuit has just enough connections to make the endeavour difficult and messy, so a simple PCB was designed using KiCAD.

A simple housing was printed for the PCB. The housing and battery holder are hot-glued to the back of the clock, leaving the clock dial and mounting hole exposed. The clock can be hung to the wall as designed, but with a long mounting screw. As you can see from the photo, there is a gap between the clock and the wall due to the extra gear, but from the front, it actually looks quite normal.

To summarize, the working circuit consumes an average of 1.2mA in operation (measured using the current meter described here). With the 4 x 1.2V 2450mA batteries, the circuit should run for 3563 hours (4 x 1.2 x 2450 / 3.3 / 1.2). That translates to 148 days, which is about 5 months. That's the ideal number, but 4 months is definitely achievable.

I am currently running a long term test on the working prototype so that I can check whether the numbers work out, or I have made a mistake somewhere in my calculations.

The Arduino source files and KiCAD design files can be found on Github.


Compared to ESPCLOCK2, there haven't been much change to the ESP8266 side of the code. Its main role continues to be running a web server (via WifiManager) to assist in setup. Once setup is done, it checks the actual time via the Internet every 2 hours, and sends that information via I2C to the ATtiny85.

The hardware setup for the ESP-07 is pretty basic:

The Arduino setup for the ESP-07 is as follows:

Software/board/library versions:
  • Arduino 1.8.11
  • ESP8266 2.6.3
  • WifiManager 1.5
The only thing extra is to program the PCF8653 RTC to generate a 1HZ clock signal in setup(). The library used is:

Reset circuitry

Besides hooking the RST pin to GPIO16 so that the ESP-07 can wake up from deep sleep, the RST pin is also hooked up to this reset circuitry:

I got the idea for the reset circuitry from here.

How this works is when the pushbutton is open, RST is HIGH. When the pushbutton is closed, RST is brought to LOW (since there is no charge in the capacitor) while the capacitor begins charging up. The RC time constant chosen means RST will cross the 2.475V threshold within ~150ms even if the pushbutton is still held down. Effectively, this means a LOW pulse will occur on the RST pin which will reset the ESP-07.

However, GPIO12 stays LOW as long as the pushbutton is held down. This means on startup, setup() can read its state and determine whether to perform a factory reset (i.e. bring up the built-in hotspot/web server for configuration).


The PCF8563 RTC is hooked up to the ESP-07 via the I2C bus.

The 1Hz clock outputs to PB1 of the ATtiny85, which wakes the latter from POWER_DOWN sleep every 1 second to tick the analog clock (well technically it wakes the latter twice a second since the ATtiny85 can only be configured for a pin-change interrupt; you cannot tell it to respond only to a rising or falling edge on the pin; so at the start of the ISR, we read the pin state and only respond if it is LOW).


The code on the ATtiny85 is actually much simplified on the new design. Previously, a lot of code is utilized in running and tuning Timer1 dynamically to provide an accurate 1Hz clock. All that is now removed. A simple pin-change ISR is used to respond to the clock signal from the PCF8563.

Everything else remains the same. There's the I2C code to respond to commands from the ESP8266 to set/run the clock. The code to detect low power via built-in ADC and save the clock state to EEPROM is also there.

The ATtiny85 code is compiled using the following board config:

Diode Clamp

In previous designs, the analog clock is driven by 2 pins from the MCU directly. The pin voltage ranges from 3~3.3V, while the analog clock is designed to work with 1.2~1.5V. As a result, 2 problems were observed:
  • The pulse width needs to be longer than necessary. At 1.xV, the pulse width only needs to be 30ms or shorter. At 3.xV, the pulse width needs to be 150ms or longer. This means the MCU driving the clock needs to be awake longer than necessary.
  • In addition, at the higher voltage, there is the occasional missed tick which causes the external and internal clock states to slowly go out-of-sync.
I found a possible solution here, which is to use 4 small signal diodes (1N4148) to function as a voltage clamp in both directions.
Since the drop across each diode is ~0.6V, the drop across 2 diodes in one direction is ~1.2V. This turned out to work remarkably well. The pulse width could be pushed to the ~30ms range (ended up using 40ms in the code for some allowance), and there were no missed ticks. The setup is stressed tested using some code that makes the clock fast forward for 60s, stop, then repeat. With this test, it was easy to verify that there were no missed ticks even after running the test for many hours (because you can check that the second hand always stop at the same spot after every minute).


As mentioned at the start, this is probably my final iteration of the ESPCLOCK project because I have exhausted all ideas for additional power reduction.

The current design allows for at least 4 months of runtime from 4 x 1.2V AA NiMH rechargeables. Using eg. 4 x 18650 cells connected in series would increase the runtime even more. For example, 4 x 2000mAH cells should yield about 9 months of runtime. I decided to use the NiMH rechargeables for testing because these are cheap and readily available.

If I have time, I will also look into adapting the circuit/code to work with "smooth" clocks (the second hand doesn't tick-tock but runs smoothly and continuously) and figure out the power draw for that.


Popular posts from this blog

Adding "Stereo Mixer" to Windows 7 with Conexant sound card

This procedure worked for my laptop (Thinkpad E530) with a Conexant 20671 sound card, but I suspect it will work for other sound cards in the Conexant family. I was playing with CamStudio to do a video capture of a Flash-based cartoon so that I can put it on the WDTV media player and play it on the big screen in the living room for my kids. The video capture worked brilliantly, but to do a sound capture, I needed to do some hacking. Apparently, there was this recording device called "Stereo Mixer" that was pretty standard in the Windows XP days. This allowed you to capture whatever was played to the speaker in all its digital glory. Then under pressure from various organizations on the dark side of the force, Microsoft and soundcard makers starting disabling this wonderful feature from Windows Vista onwards. So after much Googling around, I found out that for most sound cards, the hardware feature is still there, just not enabled on the software side. Unfortunately, to

Hacking a USB-C to slim tip adapter cable to charge the Thinkpad T450s

This hack is inspired by this post . A year ago, I bought an adapter cable for my wife's Thinkpad X1 Carbon (2nd Gen) that allows her to power her laptop with a 60W-capable portable battery (20V x 3A). A USB-C cable goes from the battery into the adapter, which converts it to the slim tip output required by the laptop. Everything works out of the box, so I didn't give much thought about it. Recently, I decided to buy a similar cable for my Thinkpad T450s. I know technically it should work because the T450s can go as low as 45W (20V x 2.25A) in terms of charging (though I have the 65W charger - 20V x 3.25A).  I went with another adapter cable because it was cheaper and also I prefer the single cable design. So imagine my surprise when the cable came and I plugged it into my laptop and it didn't work! The power manager just cycle in and out of charging mode before giving up with an error message saying there is not enough power. After much research and reading the Thinkwiki

Using Google Dashboard to manage your Android device backup

I used to use AppBrain/Fast Web Install to keep track of which apps I have installed on my phone, and to make it easier to reinstall those apps when the phone gets wiped or replaced. But AppBrain had been going down the tubes, and Fast Web Install had always been a hit-and-miss affair. Android's own "backup to the cloud" system had previously been even more unusable. There isn't a place where you can see what has been backed up. And when you setup a new phone with your Google account, you just have to wait and pray that your favorite apps will be restored to the phone. Typically all the stars have to be aligned just right for this to happen. More often than not, after waiting for an hour or so and nothing happens, you just curse under your breath and proceed to install your favorites apps manually via the Play Store. But I just looked again recently and was pleasantly surprised that things are much more civilized now. Firstly there is a place now where you can loo