Moon and Tide Clock
Want a clock that can't tell time but instead uses the current time to calculate the lunar phase and an incredibly specific oceanographic prediction for a tiny subset of the UK coastline. THEN HAVE I GOT THE CLOCK FOR YOU. presenting the worlds first Tide and Moon clock.
This clock displays
- The current lunar phase
- The current date
- The high tide times for Whitstable (UK) harbor complete with heights.
- The low tide times for Whitstable (UK) harbor complete with heights.
Supplies
- Vintage Brass Carriage Clock.
- Raspberry Pi Pico W (https://thepihut.com/products/raspberry-pi-pico-w)
- Waveshare 3.7 inch Eink display (https://www.waveshare.com/pico-epaper-3.7.htm)
- 3.7 lithium battery (https://thepihut.com/products/2000mah-3-7v-lipo-battery)
- charge controller (https://thepihut.com/products/lipo-charger-type-c)
- this isnt the charge controller i used but USB-c is better and i had a load of old controllers lying around.
- (optional)Big old fashioned flick switch.(https://thepihut.com/products/mini-panel-mount-dpdt-toggle-switch)
- you dont actually need a big external switch as this uses power save mode to hibernate and it will spend most of its time in the on position but its a bit steam punk so i like it.
- (optional) if you want your clock to work away from a wifi connection. an external RTC with battery backup. (https://thepihut.com/products/precision-rtc-module-for-raspberry-pi-pico-ds3231)
Tools:
- soldering iron
- micro usb and computer to program pico
- (optional for external switch) hand drill with step hole bit.
- code https://github.com/SuitGuy/Tide_Clock
Dissect Carriage Clock and Wire Screen
The first question a lot of you might be thinking when looking at this clock is. Why use an E-Ink display? Well my dear readers, this clock isn't actually going to tell you the time the date is only updated once... per day... . so by using an E-ink display we can wake up the Pico, perform the calculations, update the display then send the whole device to sleep for a set period of time. this allows us to run for at least a month on a simple lithium polymer battery.
All these brass carriage clocks are build in pretty much the same way. They are all essentially extruded aluminum box sections which have been coated to appear like solid brass as a result by removing the 4 screws located in the base we can slide out the glass the clock mechanism and take of the back door. Luckily for me there was already a hole in center of the clock for the original movement so it was simple for me to run the wires for the 3.7 inch display through the casing into the back.
You can find the wiring information on the waveshare page linked in supplies or alternatively if your clock has the space you can plug the Pico directly into the back of the display. I have included a screen grab of the wiring above incase their link goes down. p.s if you are struggling to get the wiring to work for the screen try plugging the Pico directly into the display for debugging purposes.
POWER!!!
PROCEED WITH CAUTION: lithium polymer batteries are dangerous and if handled incorrectly they WILL set your desk on fire. you have been warned.
Now in the above pictures I had some old charging circuits lying around so I soldered a connector to it (to make battery replacement and removal far easier). But the charging circuit I have linked above has a connector already attached which will work with the connector supplied with most lithium polymer batteries. CAUTION if you change the connector yourself DONT!! cut both wires at once and short the battery.
I have included a wiring diagram from https://electrocredible.com/ to show you how to wire the battery into the pico. You can ignore the diode in the diagram, as that is in there to prevent you from breaking the raspberry pi pico if you put the battery in the wrong way round. If however, you think you are going to accidentally put the battery in the wrong way round then you should indeed get a diode.
MOOOOOON
So I am going to walk you though a lot of my pain and suffering here. Don't worry I have just included the final images in the repo. But don't expect it to be easy to use alternative photos of the moon.
The Pico has basically no onboard memory. The library that the display uses to render image rasters onto the eink display is expecting an array of bytes for each pixel of the image. We want 24 different phases of the moon. Simply put that's too much data for the pico to store. What's the answer? COMPRESSION. I have included some phase.txt files above which include a lossless compressed version of the array which we can decompress at run time and render onto the screen.
This isnt really a step, I have already done the hard work for you. but it was a interesting limitation of the Pico which can be overcome with a little computery magic.
Tides
Tide prediction is extremely hard. I mean like PHD level complicated. I have included in my code both the functionality to get the tide data from a website and the ability to read the tide information from a set of long term predictions. This allows my clock to work when not connected to the WIFI as it can calculate both the tide times based on the prediction data and the lunar phase from the RTC unit in the clock. you will need to alter the URL within the get_tide_data function to have the correct ID for the tide station you would like to monitor in order for the pico to use wifi to get the predictions. https://github.com/SuitGuy/Tide_Clock/blob/b821d99226da8fc5d80009623134766bd219fab7/main.py#L112
you will also need to enter in your own wifi credentials for your home network.
If however you would like the clock to work offline like mine you will need to calculate the future tide predictions yourself and supply them in the csv format that i have used in the github code. i used the software wxtide32 to get text based predictions then used a quick bit of cut and paste into a small python script to generate the csv. this will be different for every tide location so i have not provided the script to discourage any non tidal experts from attempting this madness.
Configure the Pico and Upload the Code
Git Hub https://github.com/SuitGuy/Tide_Clock
The code I have above is written in micro python. This will require you to configure the Raspberry Pi Pico to run micropython and to install all of the required libraries for:
compression
eink display
RTC
The easiest way to do this is to follow a tutorial for setting up Thonny on raspberry pi Pico. https://projects.raspberrypi.org/en/projects/getting-started-with-the-pico/2
Above is a really detailed tutorial for setting up your Pico. once set up Thonny should recognize that some of the libraries are missing from the project and suggest to install them. if not please do refer to the manufacturers pages for the required libraries such as Waveshare for the display and RTC modules.
I have included a modified version of their micro python driver to make rendering the images easier.
Place RTC Unit Between Pico and Screen
Place the RTC unit between the Pico and the display wiring and shown in the image. This is a "Hat" style of unit so all of the pins of the Pico are passed through to the RTC unit allowing you to connect up the screen as shown in the original wiring diagram. this offboard. By connecting this unit you will ensure that the date and the lunar phase will work guaranteed regardless of wifi availability.
If your clock has room you can stack this again and plug the RTC into the display to make a large Pico RTC Display sandwich. just bare in mind you will need to do some fiddly soldering to supply power and ground without any left over pins.
Assemble and Add a Cover If Needed.
After putting it all together I thought it looked a little bland. So with some precision and care I used a craft knife and a thick card stock to cut out a face cover for the clock out of card and then spray painted it gold for the complete brass aesthetic.
If you have gone to the effort of making your clock work offline (congratulations), you will need to run connected to wifi or a computer at least once in order to ensure that the RTC unit is set to the correct time and running.