Skip to main content

ESPCLOCK3 - The Final Version

Overview

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.

ESP-07

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).

PCF8563 RTC

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).

ATtiny85

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).

Conclusion

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.

Comments

Popular posts from this blog

Update: Line adapter for Ozito Blade Trimmer

Update (Dec 2021): If you access to a 3D printer, I would now recommend this solution , which makes it super easy to replace the trimmer line. I have been using it for a few months now with zero issue.

Attiny85 timer programming using Timer1

This Arduino sketch uses Timer1 to drive the LED blinker: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 /* * Program ATTiny85 to blink LED connected to PB1 at 1s interval. * Assumes ATTiny85 is running at 1MHz internal clock speed. */ #include <avr/io.h> #include <avr/wdt.h> #include <avr/sleep.h> #include <avr/interrupt.h> bool timer1 = false , led = true ; // Interrupt service routine for timer1 ISR(TIMER1_COMPA_vect) { timer1 = true ; } void setup() { // Setup output pins pinMode( 1 , OUTPUT); digitalWrite( 1 , led); set_sleep_mode(SLEEP_MODE_IDLE); // Setup timer1 to interrupt every second TCCR1 = 0 ; // Stop timer TCNT1 = 0 ; // Zero timer GTCCR = _BV(PSR1); // Reset prescaler OCR1A = 243 ; // T = prescaler / 1MHz = 0.004096s; OCR1A = (1s/T) - 1 = 243 OCR1C = 243 ; // Set to same value to reset timer1 to

3D Printer Filament Joiner

I have been looking at various ways of joining 3D printing filaments. One method involves running one end of a filament through a short PTFE tubing, melting it with a lighter or candle, retracting it back into the tubing and immediately plunging the filament to be fused into the tubing: One problem with this method is that you can't really control the temperature at which you melt the filament, so you frequently end up with a brittle joint that breaks upon the slightest bend. Aliexpress even sells a contraption that works along the same line. As it uses a lighter or candle as well, it suffers from the same weakness. I am not even sure why you need a special contraption when a short PTFE tubing will work just as well. Another method involves using shrink tubing/aluminium foil, and a heat gun: But a heat gun is rather expensive, so I wanted to explore other alternatives. The candle + PTFE tubing method actually works quite well when you happen to melt it at the rig