aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile10
-rw-r--r--assets/world-clock/enclosure.stlbin0 -> 1884 bytes
-rw-r--r--assets/world-clock/hardware.jpgbin0 -> 82279 bytes
-rw-r--r--assets/world-clock/world-clock.jpgbin0 -> 148673 bytes
-rw-r--r--posts/2021-06-26-simple-world-clock.md89
5 files changed, 99 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 7880fa9..84ff27c 100644
--- a/Makefile
+++ b/Makefile
@@ -5,6 +5,16 @@ provision:
5 go build \ 5 go build \
6 go install 6 go install
7 7
8dev:
9 openring -l 180 -n 4 -p 1 \
10 -s https://cronokirby.com/posts/index.xml \
11 -s https://drewdevault.com/feed.xml \
12 -s https://danluu.com/atom.xml \
13 -s https://serokell.io/blog.rss.xml \
14 < template/openring.tmpl \
15 > template/openring-build.html
16 alternator --watch
17
8build: 18build:
9 mkdir -p public 19 mkdir -p public
10 openring -l 180 -n 4 -p 1 \ 20 openring -l 180 -n 4 -p 1 \
diff --git a/assets/world-clock/enclosure.stl b/assets/world-clock/enclosure.stl
new file mode 100644
index 0000000..99f3d1a
--- /dev/null
+++ b/assets/world-clock/enclosure.stl
Binary files differ
diff --git a/assets/world-clock/hardware.jpg b/assets/world-clock/hardware.jpg
new file mode 100644
index 0000000..315a04d
--- /dev/null
+++ b/assets/world-clock/hardware.jpg
Binary files differ
diff --git a/assets/world-clock/world-clock.jpg b/assets/world-clock/world-clock.jpg
new file mode 100644
index 0000000..afdb6e2
--- /dev/null
+++ b/assets/world-clock/world-clock.jpg
Binary files differ
diff --git a/posts/2021-06-26-simple-world-clock.md b/posts/2021-06-26-simple-world-clock.md
new file mode 100644
index 0000000..29c199a
--- /dev/null
+++ b/posts/2021-06-26-simple-world-clock.md
@@ -0,0 +1,89 @@
1---
2Title: Simple world clock with eInk display and Raspberry Pi Zero
3Description: Simple world clockwith eInk display and Raspberry Pi Zero
4Slug: simple-world-clock-with-eiink-display-and-raspberry-pi-zero
5Listing: true
6Created: 2021-06-26
7Tags: []
8---
9
10Our team is spread across the world, from the USA all the way to Australia, so having some sort of world clock makes sense.
11
12Currently, 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.
13
14But 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.
15
16A 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.
17
18![Inky pHAT, Raspberry Pi Zero](/assets/world-clock/hardware.jpg)
19
20Since 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/).
21
22First, I installed the necessary software on Raspberry Pi with `pip3 install inky`.
23
24And then I created a file `clock.py` in home directory `/home/pi`.
25
26```python
27#!/usr/bin/env python
28# -*- coding: utf-8 -*-
29
30import sys
31import os
32from inky.auto import auto
33from PIL import Image, ImageFont, ImageDraw
34from font_fredoka_one import FredokaOne
35
36clocks = [
37 'America/New_York',
38 'Europe/Ljubljana',
39 'Australia/Brisbane',
40]
41
42board = auto()
43board.set_border(board.WHITE)
44board.rotation = 90
45
46img = Image.new('P', (board.WIDTH, board.HEIGHT))
47draw = ImageDraw.Draw(img)
48
49big_font = ImageFont.truetype(FredokaOne, 18)
50small_font = ImageFont.truetype(FredokaOne, 13)
51
52x = board.WIDTH / 3
53y = board.HEIGHT / 3
54
55idx = 1
56for clock in clocks:
57 ctime = os.popen('TZ="{}" date +"%a,%H:%M"'.format(clock))
58 ctime = ctime.read().strip().split(',')
59 city = clock.split('/')[1].replace('_', ' ')
60
61 draw.text((15, (idx*y)-y+10), city, fill=board.BLACK, font=small_font)
62 draw.text((110, (idx*y)-y+7), str(ctime[0]), fill=board.BLACK, font=big_font)
63 draw.text((155, (idx*y)-y+7), str(ctime[1]), fill=board.BLACK, font=big_font)
64
65 idx += 1
66
67board.set_image(img)
68board.show()
69```
70
71And because eInk displays are rather slow to refresh and the clock requires refreshing only once a minute, this can be done through cronjob.
72
73Before we add this job to cron we need to make `clock.py` executable with `chmod +x clock.py`.
74
75Then we add a cronjob with `crontab -e`.
76
77```
78* * * * * /home/pi/clock.py
79```
80
81So, we end up with a result like this.
82
83![World Clock](/assets/world-clock/world-clock.jpg)
84
85And for the enclosure that can be 3D printed, but I haven't yet something like this can be used.
86
87<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>
88
89You can download my [STL file for the enclosure here](/assets/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.