Skip to content

Commit

Permalink
Initial commit of project
Browse files Browse the repository at this point in the history
  • Loading branch information
guyradford committed Oct 29, 2022
1 parent a37d430 commit cbb4767
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 2 deletions.
36 changes: 34 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,34 @@
# Pi-Py-Clock
Raspberry Pi 1 LED Matrix Clock
# Pi Py Clock

## Connecting up Display to RPi1

https://raspi.tv/2013/8-x-8-led-array-driven-by-max7219-on-the-raspberry-pi-via-python

## Python 3

Installing pip:

```commandline
sudo apt update
sudo apt install python3-pip
```


## Copying the files

`pip3 install luma.led-matrix==1.6.1`

`sudo apt-get install libopenjp2-7`
`sudo apt install libtiff5`

## Setting up the Service

https://medium.com/codex/setup-a-python-script-as-a-service-through-systemctl-systemd-f0cc55a42267

Copy `service/clock.service` to `/etc/systemd/system/clock.service`

```commandline
sudo systemctl daemon-reload
sudo systemctl enable clock.service
sudo systemctl start clock.service
```
43 changes: 43 additions & 0 deletions clock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python
import time
from datetime import datetime
from pathlib import Path

from PIL import ImageFont
from luma.led_matrix.device import max7219
from luma.core.interface.serial import spi, noop
from luma.core.render import canvas
from luma.core.legacy import text
from luma.core.legacy.font import proportional, TINY_FONT, LCD_FONT


def main():
font = proportional(LCD_FONT)

# Setup for Banggood version of 4 x 8x8 LED Matrix (https://bit.ly/2Gywazb)
serial = spi(port=0, device=0, gpio=noop())
device = max7219(serial, cascaded=4, block_orientation=-90, blocks_arranged_in_reverse_order=False)
device.contrast(1)

toggle = False # Toggle the second indicator every second
while True:
toggle = not toggle

# Do the following twice a second (so the seconds' indicator blips).
# I'd optimize if I had to - but what's the point?
# Even my Raspberry PI2 can do this at 4% of a single one of the 4 cores!
hours = datetime.now().strftime('%H')
minutes = datetime.now().strftime('%M')
with canvas(device) as draw:
width = 0
for letter in hours:
width = width + len(font[ord(letter)])

text(draw, (15 - width, 1), hours, fill="white", font=font)
text(draw, (15, 1), ":" if toggle else " ", fill="white", font=proportional(TINY_FONT))
text(draw, (17, 1), minutes, fill="white", font=font)
time.sleep(0.5)


if __name__ == "__main__":
main()
11 changes: 11 additions & 0 deletions service/clock.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=Matrix cLock service
After=multi-user.target

[Service]
Type=simple
Restart=always
ExecStart=/usr/bin/python3 /root/clock/clock.py

[Install]
WantedBy=multi-user.target

0 comments on commit cbb4767

Please sign in to comment.