aboutsummaryrefslogtreecommitdiff
path: root/_posts/posts/2021-06-26-simple-world-clock.md
diff options
context:
space:
mode:
Diffstat (limited to '_posts/posts/2021-06-26-simple-world-clock.md')
-rw-r--r--_posts/posts/2021-06-26-simple-world-clock.md108
1 files changed, 0 insertions, 108 deletions
diff --git a/_posts/posts/2021-06-26-simple-world-clock.md b/_posts/posts/2021-06-26-simple-world-clock.md
deleted file mode 100644
index d1b53b4..0000000
--- a/_posts/posts/2021-06-26-simple-world-clock.md
+++ /dev/null
@@ -1,108 +0,0 @@
1---
2title: Simple world clock with eInk display and Raspberry Pi Zero
3permalink: /simple-world-clock-with-eiink-display-and-raspberry-pi-zero.html
4date: 2021-06-26T12:00:00+02:00
5layout: post
6type: post
7draft: false
8---
9
10Our team is spread across the world, from the USA all the way to Australia, so
11having some sort of world clock makes sense.
12
13Currently, I am using an extension for Gnome called [Timezone
14extension](https://extensions.gnome.org/extension/2657/timezones-extension/),
15and it serves the purpose quite well.
16
17But I also have a bunch of electronics that I bought through the time, and I am
18not using any of them, and it's time to stop hording this stuff and use it in a
19project.
20
21A while ago I bought a small eInk display [Inky
22pHAT](https://shop.pimoroni.com/products/inky-phat?variant=12549254217811) and I
23have a bunch of [Raspberry Pi's
24Zero](https://www.raspberrypi.org/products/raspberry-pi-zero/) lying around that
25I really need to use.
26
27![Inky pHAT, Raspberry Pi Zero](/assets/posts/world-clock/hardware.jpg){:loading="lazy"}
28
29Since the Inky [Inky
30pHAT](https://shop.pimoroni.com/products/inky-phat?variant=12549254217811) is
31essentially a HAT, it can easily be added on top of the [Raspberry Pi
32Zero](https://www.raspberrypi.org/products/raspberry-pi-zero/).
33
34First, I installed the necessary software on Raspberry Pi with `pip3 install
35inky`.
36
37And then I created a file `clock.py` in home directory `/home/pi`.
38
39```python
40#!/usr/bin/env python
41# -*- coding: utf-8 -*-
42
43import sys
44import os
45from inky.auto import auto
46from PIL import Image, ImageFont, ImageDraw
47from font_fredoka_one import FredokaOne
48
49clocks = [
50 'America/New_York',
51 'Europe/Ljubljana',
52 'Australia/Brisbane',
53]
54
55board = auto()
56board.set_border(board.WHITE)
57board.rotation = 90
58
59img = Image.new('P', (board.WIDTH, board.HEIGHT))
60draw = ImageDraw.Draw(img)
61
62big_font = ImageFont.truetype(FredokaOne, 18)
63small_font = ImageFont.truetype(FredokaOne, 13)
64
65x = board.WIDTH / 3
66y = board.HEIGHT / 3
67
68idx = 1
69for clock in clocks:
70 ctime = os.popen('TZ="{}" date +"%a,%H:%M"'.format(clock))
71 ctime = ctime.read().strip().split(',')
72 city = clock.split('/')[1].replace('_', ' ')
73
74 draw.text((15, (idx*y)-y+10), city, fill=board.BLACK, font=small_font)
75 draw.text((110, (idx*y)-y+7), str(ctime[0]), fill=board.BLACK, font=big_font)
76 draw.text((155, (idx*y)-y+7), str(ctime[1]), fill=board.BLACK, font=big_font)
77
78 idx += 1
79
80board.set_image(img)
81board.show()
82```
83
84And because eInk displays are rather slow to refresh and the clock requires
85refreshing only once a minute, this can be done through cronjob.
86
87Before we add this job to cron we need to make `clock.py` executable with `chmod
88+x clock.py`.
89
90Then we add a cronjob with `crontab -e`.
91
92```txt
93* * * * * /home/pi/clock.py
94```
95
96So, we end up with a result like this.
97
98![World Clock](/assets/posts/world-clock/world-clock.jpg){:loading="lazy"}
99
100And for the enclosure that can be 3D printed, but I haven't yet something like
101this can be used.
102
103<iframe id="vs_iframe" src="https://www.viewstl.com/?embedded&url=https%3A%2F%2Fmitjafelicijan.com%2Fposts%2Fworld-clock%2Fenclosure.stl&color=gray&bgcolor=white&edges=no&orientation=front&noborder=no" style="border:0;margin:0;width:100%;height:400px;"></iframe>
104
105You can download my [STL file for the enclosure
106here](/assets/posts/world-clock/enclosure.stl), but make sure that dimensions make
107sense and also opening for USB port should be added or just use a drill and some
108hot glue to make it stick in the enclosure.