diff options
Diffstat (limited to 'posts/2021-06-26-simple-world-clock.md')
| -rw-r--r-- | posts/2021-06-26-simple-world-clock.md | 89 |
1 files changed, 0 insertions, 89 deletions
diff --git a/posts/2021-06-26-simple-world-clock.md b/posts/2021-06-26-simple-world-clock.md deleted file mode 100644 index 29c199a..0000000 --- a/posts/2021-06-26-simple-world-clock.md +++ /dev/null | |||
| @@ -1,89 +0,0 @@ | |||
| 1 | --- | ||
| 2 | Title: Simple world clock with eInk display and Raspberry Pi Zero | ||
| 3 | Description: Simple world clockwith eInk display and Raspberry Pi Zero | ||
| 4 | Slug: simple-world-clock-with-eiink-display-and-raspberry-pi-zero | ||
| 5 | Listing: true | ||
| 6 | Created: 2021-06-26 | ||
| 7 | Tags: [] | ||
| 8 | --- | ||
| 9 | |||
| 10 | Our team is spread across the world, from the USA all the way to Australia, so having some sort of world clock makes sense. | ||
| 11 | |||
| 12 | Currently, 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 | |||
| 14 | But 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 | |||
| 16 | A 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 |  | ||
| 19 | |||
| 20 | Since 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 | |||
| 22 | First, I installed the necessary software on Raspberry Pi with `pip3 install inky`. | ||
| 23 | |||
| 24 | And 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 | |||
| 30 | import sys | ||
| 31 | import os | ||
| 32 | from inky.auto import auto | ||
| 33 | from PIL import Image, ImageFont, ImageDraw | ||
| 34 | from font_fredoka_one import FredokaOne | ||
| 35 | |||
| 36 | clocks = [ | ||
| 37 | 'America/New_York', | ||
| 38 | 'Europe/Ljubljana', | ||
| 39 | 'Australia/Brisbane', | ||
| 40 | ] | ||
| 41 | |||
| 42 | board = auto() | ||
| 43 | board.set_border(board.WHITE) | ||
| 44 | board.rotation = 90 | ||
| 45 | |||
| 46 | img = Image.new('P', (board.WIDTH, board.HEIGHT)) | ||
| 47 | draw = ImageDraw.Draw(img) | ||
| 48 | |||
| 49 | big_font = ImageFont.truetype(FredokaOne, 18) | ||
| 50 | small_font = ImageFont.truetype(FredokaOne, 13) | ||
| 51 | |||
| 52 | x = board.WIDTH / 3 | ||
| 53 | y = board.HEIGHT / 3 | ||
| 54 | |||
| 55 | idx = 1 | ||
| 56 | for 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 | |||
| 67 | board.set_image(img) | ||
| 68 | board.show() | ||
| 69 | ``` | ||
| 70 | |||
| 71 | And because eInk displays are rather slow to refresh and the clock requires refreshing only once a minute, this can be done through cronjob. | ||
| 72 | |||
| 73 | Before we add this job to cron we need to make `clock.py` executable with `chmod +x clock.py`. | ||
| 74 | |||
| 75 | Then we add a cronjob with `crontab -e`. | ||
| 76 | |||
| 77 | ``` | ||
| 78 | * * * * * /home/pi/clock.py | ||
| 79 | ``` | ||
| 80 | |||
| 81 | So, we end up with a result like this. | ||
| 82 | |||
| 83 |  | ||
| 84 | |||
| 85 | And 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 | |||
| 89 | You 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. | ||
