aboutsummaryrefslogtreecommitdiff
path: root/posts/2021-06-26-simple-world-clock.md
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2021-07-01 22:22:56 +0200
committerMitja Felicijan <mitja.felicijan@gmail.com>2021-07-01 22:22:56 +0200
commita3e2611466f1ab0825bf38f135c36c5cfb29f5c4 (patch)
tree80035b9473bcb92b5fbf7efb40cab6baf9ef9ae0 /posts/2021-06-26-simple-world-clock.md
parent6fb0a55087cb13c2dd839720753f82f106c30b3d (diff)
downloadmitjafelicijan.com-a3e2611466f1ab0825bf38f135c36c5cfb29f5c4.tar.gz
Added new post - world clock
Diffstat (limited to 'posts/2021-06-26-simple-world-clock.md')
-rw-r--r--posts/2021-06-26-simple-world-clock.md89
1 files changed, 89 insertions, 0 deletions
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.