Skip to main content

Posts

Showing posts from October, 2016

Hacking an analog clock to sync with NTP - Part 5

This is how it looks after I have put everything together. The Arduino sketch is available here . The 2 jumper wires soldered to the clock mechanism are connected to pins D0 and D1 on the ESP-12 (in any order). When the device first boots up, it presents an access point which can be connected to via the PC or smartphone. Once connected, the captive portal redirects the web browser to the configuration page:     A custom field has been added to the WiFi configuration page to enter the current clock time in HHMMSS format. Try to set the clock time to as close to the current time as possible using the radial dial at the back of the clock so the clock will have less work to do catching up. In the config page, the HTML5 Geolocation API is also used to obtain your current location (so if your web browser asks if you would like to share your location, answer "yes"). This is then passed to the Google Time Zone API to obtain the time and DST offset of your time z

Hacking an analog clock to sync with NTP - Part 4

Assuming the jumper wires from the clock are connected to pins D1 and D2 on the ESP-12, the following Arduino sketch will make it function as a normal clock that ticks every second: 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 tickPin = D1; os_timer_t secTimer; // Triggered by system timer every second void timerCallback ( void * pArg) { tickOccured = true ; } void setup () { // Setup GPIO outputs pinMode(D1, OUTPUT); pinMode(D2, OUTPUT); digitalWrite(D1, LOW); digitalWrite(D2, LOW); // Start system timer which triggers every second os_timer_setfn( & secTimer, timerCallback, NULL ); os_timer_arm( & secTimer, 1000 , true ); } void loop () { if (tickOccured) { tickOccurred - false ; tickPin = (tickPin == D1 ? D2 : D1); digitalWrite(tickPin, HIGH); delay( 100 ); digitalWrite(tickPin, LOW); delay( 100 ); } delay( 250 ); } To be continued... ESPCLOCK1  / 

Hacking an analog clock to sync with NTP - Part 3

Most battery-operated analog quartz clock on the market today are quite similarly internally. They are usually based on an oscillator driving a Lavet type stepper motor , Movement is made by alternating the current running through a copper coil in every step, followed by an interval without current so as to provide time for the magnetic gear to turn to its new position. I am going to disassemble the Ikea clock and connect two jumper wires to the clock mechanism. These two wires will then be connected to the GPIO pins of the ESP-12 for ours to control. To remove the plastic cover over the clock face, turn the clock over and disengage the 3 plastic tabs holding the cover using a flathead screwdriver. Once that is done, pull out the second hand, followed by the minute then the hour hands. With a butter knife (I used a plastic pry bar), gently pry the clock mechanism out of its holding cavity. There are tabs on both sides of the clock mechanism holding the front and back

Hacking an analog clock to sync with NTP - Part 2

Since I am more familiar with C/C++, it makes sense for me to use the Arduino IDE (rather than Lua, the other alternative). Everything was surprisingly easy to setup. I first installed the Arduino IDE , Then I followed the instructions here to setup the board manager within the IDE. I really wanted to base the WiFi configuration part of the project on WiFi Manager , so I added that to the IDE using the library manager. I also setup the board type under "Tools". There is no entry for ESP-12F, so I went with the ESP-12E since the two should be virtually identical as mentioned previously. With all the setup done, I went with the simplest possible WiFi Manager sample code, which looks like this: 1 2 3 4 5 6 7 8 9 10 11 12 #include <DNSServer.h> #include <ESP8266WiFi.h> #include <ESP8266WebServer.h> #include <WiFiManager.h> void setup () { WiFiManager wifiManager; wifiManager.autoConnect( "ESPCLOCK" ); } void lo

Hacking an analog clock to sync with NTP - Part 1

Inspired by this blog post detailing how to control the ticking mechanism on an analog clock with an Arduino, and having recently come across this gem of a WIFI-enabled micro-controller called ESP8266 ,  I decided to try and see if I can tether an analog clock to the ESP8266 and make it sync with a time server so that it is always on time (and is able to deal with daylight saving as well). Not being much of a hardware geek myself, I opted to get the dev board for the ESP8266, the ESP-12E . That way, I can connect it straightaway with my laptop via a USB cable and start coding right away. Cost: ~$6. Note: What I received turns out to be the ESP-12F, which appears to be virtually identical to ESP-12E . For the analog clock, I chose to use the $2 RUSCH wall clock from Ikea. Now this is a cheap and nasty clock, made using the cheapest possible material. The second hand doesn't even line up with some of the tick marks as it makes its rounds. But cheap is good for experimen