diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2021-07-01 22:22:56 +0200 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2021-07-01 22:22:56 +0200 |
| commit | a3e2611466f1ab0825bf38f135c36c5cfb29f5c4 (patch) | |
| tree | 80035b9473bcb92b5fbf7efb40cab6baf9ef9ae0 | |
| parent | 6fb0a55087cb13c2dd839720753f82f106c30b3d (diff) | |
| download | mitjafelicijan.com-a3e2611466f1ab0825bf38f135c36c5cfb29f5c4.tar.gz | |
Added new post - world clock
| -rw-r--r-- | Makefile | 10 | ||||
| -rw-r--r-- | assets/world-clock/enclosure.stl | bin | 0 -> 1884 bytes | |||
| -rw-r--r-- | assets/world-clock/hardware.jpg | bin | 0 -> 82279 bytes | |||
| -rw-r--r-- | assets/world-clock/world-clock.jpg | bin | 0 -> 148673 bytes | |||
| -rw-r--r-- | posts/2021-06-26-simple-world-clock.md | 89 |
5 files changed, 99 insertions, 0 deletions
| @@ -5,6 +5,16 @@ provision: | |||
| 5 | go build \ | 5 | go build \ |
| 6 | go install | 6 | go install |
| 7 | 7 | ||
| 8 | dev: | ||
| 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 | |||
| 8 | build: | 18 | build: |
| 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 | --- | ||
| 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. | ||
