WiFi Stepper controlled Clock - Page 1
Forum section: electronics / projects

author: Bootalito
author_rank: Unknown
timestamp: October 28, 2017, 06:06:41 pm
content: I was commissioned by a friend of a friend to make a small box that controls a stepper motor which controls the minute hand of an analog clock art piece. He has made and sold about 5 of these artistic clocks, but he has a regular engineering job that pays the bills so this is a side hobby for him.The requirements were as follows:1. Use off the shelf parts for price and availibility2. Three boxes needed immediately, total of about 10 total3. Allow the user to control the clock backwards and forwards at different speeds to set the time and for amusement. I think most of his customers are rich are businesses, so maybe at parties they want to make it go backwards real fast as an amusement piece.His previous controllers were slapped together by a friend and used an Arduino Uno, a stepper shield, a RTC, a potentiometer (for speed control), and two toggle switches: one to control direction(CW or CCW) and another to toggle between using the potentiometer for speed or using the RTC. His boxes were custom milled aluminum because he has his own CNC machine. He uses 4 conductor twisted pair (belkthrough a small cable gland to connect the box which would hang on the wall next to the clock.My solution was to design a custom PCB to connect an ESP8266 (wemos D1 mini), a stepper shield (A4988), a RTC (DS3231), and a single center detent potentiometer for control. The potentiometer when positioned at the 50% mark has a detent and this would enable clockwise motion using the RTC. Going to the right or left would of course make the clock go CW or CCW faster.The ESP8266 has a Serial interface, a telnet interface, and hosts a webpage to configure the wifi, stepper motor, RTC, etc. The web interface also allows manual control over the stepper in speed, angle, or number of steps/pulse width.Total BOM cost = $28The only interaction with the RTC was to use the SQW pin to generate an interupt to add the number of steps that the motor needed to move to have a continual "deficit". I programmed the stepper to make up this deficit at 99% speed, so it slowely makes up the deficiet and looks like smooth motion. If the deficit of steps gets more than like 2 seconds, then I linearly scale up the speed (by reducing the pulse width) to get there quickerProgrammed a fork of TimeLib.h that includes proper daylight savings time calcuations. This took a long time to get right. But the clock hands will go forward and backwards to correct for DST.Jumper to enable/disable WiFi for customers who are afraid of security. Its a soft enable/disable.Used ASyncTCP library from me-no-dev for good speed. Used websockets and javascript to make interacting with the controller via the web page instantaneous, instead of using POSTS and stuff.ArduinoOPA enabled, as well as an update page that will allow the user to upload a new firmware binary and update itself. Like updating your routers firmware.Here is a picture of the finished product. Note that I designed a stainless steel faceplate acid etched but it was going to cost too much. I reached out to the AliExpress store after I had shipped the first three units with the crappy labels on them, and they said they could customize the entire box with laser etching, laser cutting the holes, etc. Damn it. So the next revision will have a professional look on the outside, and the cost of the box only goes from $5 to like $15Here is a link to the schematic and PCBhttps://easyeda.com/terryjmyers/Ed_Roland_Clock_copy-cceff46c90584db2845bfdf14a96a14dAnd here is a zip file containing the schematic(pdf printout from EasyEDA), gerber files (from EasyEDA), source code (Visual Studio project using vmicro plugin), compiled binaries (that one could use the espressif ESP8266 DownloadTool), users manual (quick draft ATM), BOM costs, and original faceplate design.https://www.dropbox.com/s/cembuggfofro8p1/RolandHorologyTowerClock0.2.7z?dl=0And here is a cute video of my daughter demonstrating itLessons learned / things I'm changing becuase they are crappy:1. Using a JST 2.0 header to connect potentiometer instead of dupont wires2. Using black annodized box, laser etchedhttps://www.dropbox.com/s/0un4uprzn72rmn3/RolandHorologyTowerClockv0.3FaceplateDesign.docx?dl=03. Its REALLY hard to find center detent potentiometers. Digi-Key doesn't have them. Mouse does but they aren't stock. AliExpress doesn't have them!! Ebay does, but not solder lug style4. enclosing a WiFi controller in a metal box is bad m'key? You can still connect to it when you are near it, but that's about it.5. Need to switch to bootstrap library6. Switch to ESP32 to allow use of HTTPS, more speed, etc.7. Add Alexa Integration using FauxMo library8. The code is not great. I'm a professional control systems engineer so I know how to program, but never went to school for it, and much of the code I developed for other personal projects while I was learning c++ a few years ago. I had a Senior level programmer do a code review and he picked it apart like a vulture. So don't expect my code to be a shining example of professional IOT code.If you are interested in obtaining a PCB (as of coruse I had to buy 10 of them), a fully finished box (makes a good general stepper controller especially with the web interface), or want to collaborate on something, feel free to contact me TerryJMyers@gmail.comIf you want to buy a cool artistic analog clock and have money to burn I can put you in touch with the artist. He doesn't have a web presence for this venture, so I can't show you any finished clocks.

author: Mjolinor
author_rank: Frequent Contributor
timestamp: October 28, 2017, 07:10:35 pm
content: I made a semaphore clock using an ESP and two of the small geared steppers. It moved the arms of a 12 inch Napoleonic soldier. Got it all working OK then lsot interest.The one thing I could not do was to take time from the beacon packets of wifi signals so it did not have to connect to anything to get the correct time. I think it should be possible but no way could I work out how to make the ESP do it.

author: Ian.M
author_rank: Super Contributor
timestamp: October 28, 2017, 07:57:16 pm
content: The wifi issue could probably be solved by using a plastic end plate at the other end of the box, and moving the WiFi module so its antennae is in the center of that board edge, as close as possible to the end plate.It may also be worth adding a choice in the software between sweep second hand, stepped second hand and Vetinari clock modes.

author: Bootalito
author_rank: Unknown
timestamp: October 28, 2017, 11:39:37 pm
content: The firmware saves its configuration in a json on SPIFFS. one of the parameters is a ratio between stepper shaft and minute hand. This was needed because the artist has a 36:1 ratio gear. However this could be any number to drive any hand directly. So this is already built in. In fact in the video I had it set to 500:1 just to show it better.Each second tick(from rtc) adds the number of steps required in DOUBLE format so a fractional step cold be added. Only when this number is greater than 1.00 does it trigger a stepSent from my VS990 using Tapatalk