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