Network Connected RGB Matrix Clock

For RTC breakouts, etc., use the Other Products from Adafruit forum

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
ishankum
 
Posts: 24
Joined: Tue Dec 21, 2021 10:46 am

Re: Network Connected RGB Matrix Clock

Post by ishankum »

Code: Select all

# Metro Matrix Clock
# Runs on Airlift Metro M4 with 64x32 RGB Matrix display & shield

import time
import board
import displayio
import terminalio
from adafruit_display_text.label import Label
from adafruit_bitmap_font import bitmap_font
from adafruit_matrixportal.network import Network
from adafruit_matrixportal.matrix import Matrix

BLINK = True
DEBUG = False

# Get wifi details and more from a secrets.py file
try:
    from secrets import secrets
except ImportError:
    print("WiFi secrets are kept in secrets.py, please add them there!")
    raise
print("    Metro Minimal Clock")
print("Time will be set for {}".format(secrets["timezone"]))

# --- Display setup ---
matrix = Matrix()
display = matrix.display
network = Network(status_neopixel=board.NEOPIXEL, debug=False)

# --- Drawing setup ---
group = displayio.Group()  # Create a Group
bitmap = displayio.Bitmap(64, 32, 2)  # Create a bitmap object,width, height, bit depth
color = displayio.Palette(4)  # Create a color palette
color[0] = 0x000000  # black background
color[1] = 0xFF0000  # red
color[2] = 0xCC4000  # amber
color[3] = 0x85FF00  # greenish

# Create a TileGrid using the Bitmap and Palette
tile_grid = displayio.TileGrid(bitmap, pixel_shader=color)
group.append(tile_grid)  # Add the TileGrid to the Group
display.show(group)

if not DEBUG:
    font = bitmap_font.load_font("/IBMPlexMono-Medium-24_jep.bdf")
else:
    font = terminalio.FONT

clock_label = Label(font)


def update_time(*, hours=None, minutes=None, show_colon=False):
    now = time.localtime()  # Get the time values we need
    if hours is None:
        hours = now[3]
    if hours >= 18 or hours < 6:  # evening hours to morning
        clock_label.color = color[1]
    else:
        clock_label.color = color[3]  # daylight hours
    if hours > 12:  # Handle times later than 12:59
        hours -= 12
    elif not hours:  # Handle times between 0:00 and 0:59
        hours = 12

    if minutes is None:
        minutes = now[4]

    if BLINK:
        colon = ":" if show_colon or now[5] % 2 else " "
    else:
        colon = ":"

    clock_label.text = "{hours}{colon}{minutes:02d}".format(
        hours=hours, minutes=minutes, colon=colon
    )
    bbx, bby, bbwidth, bbh = clock_label.bounding_box
    # Center the label
    clock_label.x = round(display.width / 2 - bbwidth / 2)
    clock_label.y = display.height // 2
    if DEBUG:
        print("Label bounding box: {},{},{},{}".format(bbx, bby, bbwidth, bbh))
        print("Label x: {} y: {}".format(clock_label.x, clock_label.y))


last_check = None
update_time(show_colon=True)  # Display whatever time is on the board
group.append(clock_label)  # add the clock label to the group

while True:
    if last_check is None or time.monotonic() > last_check + 3600:
        try:
            update_time(
                show_colon=True
            )  # Make sure a colon is displayed while updating
            network.get_local_time()  # Synchronize Board's clock to Internet
            last_check = time.monotonic()
        except RuntimeError as e:
            print("Some error occured, retrying! -", e)

    update_time()
    time.sleep(1)
Last edited by dastels on Wed Dec 22, 2021 4:34 pm, edited 1 time in total.
Reason: Add code tags

User avatar
ishankum
 
Posts: 24
Joined: Tue Dec 21, 2021 10:46 am

Re: Network Connected RGB Matrix Clock

Post by ishankum »

hope that was okay. If not you can find it here "https://learn.adafruit.com/network-conn ... trix-clock" ( on adafruit)

User avatar
dastels
 
Posts: 15656
Joined: Tue Oct 20, 2015 3:22 pm

Re: Network Connected RGB Matrix Clock

Post by dastels »

OK, it's the straight from the guide code. That should be fine then.

User avatar
dastels
 
Posts: 15656
Joined: Tue Oct 20, 2015 3:22 pm

Re: Network Connected RGB Matrix Clock

Post by dastels »

Near 6he start of the file there's a line: DEBUG = False. Change that to DEBUG = True, rerun it and tell me what gets output in the REPL.

Dave

User avatar
ishankum
 
Posts: 24
Joined: Tue Dec 21, 2021 10:46 am

Re: Network Connected RGB Matrix Clock

Post by ishankum »

same as before
Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.

Press any key to enter the REPL. Use CTRL-D to reload.

User avatar
ishankum
 
Posts: 24
Joined: Tue Dec 21, 2021 10:46 am

Re: Network Connected RGB Matrix Clock

Post by ishankum »

copied entire code to repl and got this if it's any use
Traceback (most recent call last):
File "<stdin>", line 10, in <module>
File "adafruit_matrixportal/network.py", line 31, in <module>
File "adafruit_portalbase/network.py", line 28, in <module>
File "/lib/adafruit_io/__init__.py", line 21, in <module>
File "/lib/adafruit_io/client.py", line 24, in <module>
ImportError: no module named 'platform'

User avatar
dastels
 
Posts: 15656
Joined: Tue Oct 20, 2015 3:22 pm

Re: Network Connected RGB Matrix Clock

Post by dastels »

You generally can't just copy it to the REPL. Put it in CIRCUITPY/code.py and have the REPL open when it runs.

Dave

User avatar
ishankum
 
Posts: 24
Joined: Tue Dec 21, 2021 10:46 am

Re: Network Connected RGB Matrix Clock

Post by ishankum »

by that I get the same result as before

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.

Press any key to enter the REPL. Use CTRL-D to reload.

User avatar
dastels
 
Posts: 15656
Joined: Tue Oct 20, 2015 3:22 pm

Re: Network Connected RGB Matrix Clock

Post by dastels »

Well, the board and CircuitPython are running.

Have you tried some of the simpler examples? Maybe https://learn.adafruit.com/pixel-art-matrix-display since it doesn't use WiFi.

There should be output from those prints (which show up in the REPL) right after the secrets file is loaded.

You've confirmed that the clock code is, indeed, contained in CIRCUITPY/code.py?

Dave

User avatar
ishankum
 
Posts: 24
Joined: Tue Dec 21, 2021 10:46 am

Re: Network Connected RGB Matrix Clock

Post by ishankum »

will try a simpler code today can confirm clock code is correct have re checked and saved again

User avatar
ishankum
 
Posts: 24
Joined: Tue Dec 21, 2021 10:46 am

Re: Network Connected RGB Matrix Clock

Post by ishankum »

project.jpeg
project.jpeg (247.36 KiB) Viewed 826 times
It works guess my .bmp file is not the best. but i do get something on the matrix which is good.

User avatar
dastels
 
Posts: 15656
Joined: Tue Oct 20, 2015 3:22 pm

Re: Network Connected RGB Matrix Clock

Post by dastels »

OK, so things appear to work. It comes back to whether you have the correct code in code.py.

Dave

User avatar
ishankum
 
Posts: 24
Joined: Tue Dec 21, 2021 10:46 am

Re: Network Connected RGB Matrix Clock

Post by ishankum »

code.py can't go wrong as its just copy and paste from the adafruit web page copy link is provided. same as I did with the simpler display code. did it over several times. working with mu and circuit python makes that part easy but I don't have any coding skills

User avatar
dastels
 
Posts: 15656
Joined: Tue Oct 20, 2015 3:22 pm

Re: Network Connected RGB Matrix Clock

Post by dastels »

This can be a problem with Mu. Verify that it is saving the code to CIRCUITPY/.

Dave

User avatar
ishankum
 
Posts: 24
Joined: Tue Dec 21, 2021 10:46 am

Re: Network Connected RGB Matrix Clock

Post by ishankum »

# Metro Matrix Clock
# Runs on Airlift Metro M4 with 64x32 RGB Matrix display & shield

I am using a matrix portal m4 instead of the Airlift Metro M4 and Shield as the pdf doc says you can. Could this be the issue?

Locked
Please be positive and constructive with your questions and comments.

Return to “Clock Kits (discontinued)”