diff options
Diffstat (limited to 'content/posts/2021-06-26-simple-world-clock.md')
| -rw-r--r-- | content/posts/2021-06-26-simple-world-clock.md | 107 |
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 | --- | ||
| 2 | title: Simple world clock with eInk display and Raspberry Pi Zero | ||
| 3 | url: simple-world-clock-with-eiink-display-and-raspberry-pi-zero.html | ||
| 4 | date: 2021-06-26T12:00:00+02:00 | ||
| 5 | draft: false | ||
| 6 | --- | ||
| 7 | |||
| 8 | Our team is spread across the world, from the USA all the way to Australia, so | ||
| 9 | having some sort of world clock makes sense. | ||
| 10 | |||
| 11 | Currently, I am using an extension for Gnome called [Timezone | ||
| 12 | extension](https://extensions.gnome.org/extension/2657/timezones-extension/), | ||
| 13 | and it serves the purpose quite well. | ||
| 14 | |||
| 15 | But I also have a bunch of electronics that I bought through the time, and I am | ||
| 16 | not using any of them, and it's time to stop hording this stuff and use it in a | ||
| 17 | project. | ||
| 18 | |||
| 19 | A while ago I bought a small eInk display [Inky | ||
| 20 | pHAT](https://shop.pimoroni.com/products/inky-phat?variant=12549254217811) and I | ||
| 21 | have a bunch of [Raspberry Pi's | ||
| 22 | Zero](https://www.raspberrypi.org/products/raspberry-pi-zero/) lying around that | ||
| 23 | I really need to use. | ||
| 24 | |||
| 25 |  | ||
| 26 | |||
| 27 | Since the Inky [Inky | ||
| 28 | pHAT](https://shop.pimoroni.com/products/inky-phat?variant=12549254217811) is | ||
| 29 | essentially a HAT, it can easily be added on top of the [Raspberry Pi | ||
| 30 | Zero](https://www.raspberrypi.org/products/raspberry-pi-zero/). | ||
| 31 | |||
| 32 | First, I installed the necessary software on Raspberry Pi with `pip3 install | ||
| 33 | inky`. | ||
| 34 | |||
| 35 | And 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 | |||
| 41 | import sys | ||
| 42 | import os | ||
| 43 | from inky.auto import auto | ||
| 44 | from PIL import Image, ImageFont, ImageDraw | ||
| 45 | from font_fredoka_one import FredokaOne | ||
| 46 | |||
| 47 | clocks = [ | ||
| 48 | 'America/New_York', | ||
| 49 | 'Europe/Ljubljana', | ||
| 50 | 'Australia/Brisbane', | ||
| 51 | ] | ||
| 52 | |||
| 53 | board = auto() | ||
| 54 | board.set_border(board.WHITE) | ||
| 55 | board.rotation = 90 | ||
| 56 | |||
| 57 | img = Image.new('P', (board.WIDTH, board.HEIGHT)) | ||
| 58 | draw = ImageDraw.Draw(img) | ||
| 59 | |||
| 60 | big_font = ImageFont.truetype(FredokaOne, 18) | ||
| 61 | small_font = ImageFont.truetype(FredokaOne, 13) | ||
| 62 | |||
| 63 | x = board.WIDTH / 3 | ||
| 64 | y = board.HEIGHT / 3 | ||
| 65 | |||
| 66 | idx = 1 | ||
| 67 | for 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 | |||
| 78 | board.set_image(img) | ||
| 79 | board.show() | ||
| 80 | ``` | ||
| 81 | |||
| 82 | And because eInk displays are rather slow to refresh and the clock requires | ||
| 83 | refreshing only once a minute, this can be done through cronjob. | ||
| 84 | |||
| 85 | Before we add this job to cron we need to make `clock.py` executable with `chmod | ||
| 86 | +x clock.py`. | ||
| 87 | |||
| 88 | Then we add a cronjob with `crontab -e`. | ||
| 89 | |||
| 90 | ``` | ||
| 91 | * * * * * /home/pi/clock.py | ||
| 92 | ``` | ||
| 93 | |||
| 94 | So, we end up with a result like this. | ||
| 95 | |||
| 96 |  | ||
| 97 | |||
| 98 | And for the enclosure that can be 3D printed, but I haven't yet something like | ||
| 99 | this 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 | |||
| 103 | You can download my [STL file for the enclosure | ||
| 104 | here](/assets/world-clock/enclosure.stl), but make sure that dimensions make | ||
| 105 | sense and also opening for USB port should be added or just use a drill and some | ||
| 106 | hot glue to make it stick in the enclosure. | ||
| 107 | |||
