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