0

Internet clock 1st project....HELP
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Internet clock 1st project....HELP

by Ju5tAN00b2000 on Wed Nov 17, 2021 4:24 pm

## Before i begin I have bought a Matrix portal ##

Earlier this year I bought a wifi clock from a chineese vendor. A little circuit board on the back of a 64x32 matrix. It synced with time over the internet. It had a web page login to change:
time server (ntp i think)
location
colours
wifi settings

It also showed the weather and date.

wifi clock 1.jpg
wifi clock 1.jpg (252.61 KiB) Viewed 1166 times


Then it stopped working. Wifi side no longer works. So I thought I would have a crack at replicating it or at least make one simalar.
Is it possible to get the code off the board and somehow port it onto my Matrix portal board?

I am trying the 2 clock guides but I keep hitting problems when following the guides:

Network Connected RGB Matrix Clock
Matrix Portal New Guide Scroller

Do I need to flash the firmware mentioned on "Upgrading ESP32 Firmware" ??

Please note I am totally new, 1st project.

Ju5tAN00b2000
 
Posts: 12
Joined: Wed Nov 17, 2021 3:09 pm

Re: Internet clock 1st project....HELP

by Ju5tAN00b2000 on Wed Nov 17, 2021 4:29 pm

The chineese one. Is it possible to port it over to Adafruit Matrix ??
IMG_20211117_200726.jpg
IMG_20211117_200726.jpg (139.44 KiB) Viewed 1165 times

IMG_20211117_200811.jpg
IMG_20211117_200811.jpg (123.2 KiB) Viewed 1165 times

Ju5tAN00b2000
 
Posts: 12
Joined: Wed Nov 17, 2021 3:09 pm

Re: Internet clock 1st project....HELP

by adafruit_support_carter on Wed Nov 17, 2021 8:14 pm

There's no easy way to port the code over. That module appears to be using an ESP8266. The Matrix Portal uses a totally different processor - an ARM M4.

What issues did you run into when trying to go through the Matrix Clock guide?
https://learn.adafruit.com/network-conn ... trix-clock

Not all RGB matrices are the same. So there's no guarantee that the Matrix Portal can drive that display.

adafruit_support_carter
 
Posts: 24055
Joined: Tue Nov 29, 2016 2:45 pm

Re: Internet clock 1st project....HELP

by Ju5tAN00b2000 on Wed Nov 17, 2021 9:08 pm

adafruit_support_carter wrote:Not all RGB matrices are the same. So there's no guarantee that the Matrix Portal can drive that display.


Matrix portal board and the matrix hub75d 64x32 display works 100% it worked soon as i rigged it all up. It showed the protomatter dust demo.

libs are all in place and code.py is duplicated from under code
https://learn.adafruit.com/network-conn ... trix-clock


Not sure what to do on this page under Connecting to the Serial Console.
https://learn.adafruit.com/adafruit-mat ... et-connect
Are these commands or code to be added to code.py?

The secrets.py file is seems in order with aio username and pass

IP lookup adafruit.com: 104.20.38.240
Ping google.com: 20 ms
Fetching text from http://wifitest.adafruit.com/testwifi/index.html
----------------------------------------
This is a test of Adafruit WiFi!
If you can read this, its working :)

----------------------------------------

Fetching json from http://api.coindesk.com/v1/bpi/currentprice/USD.json
----------------------------------------
{'time': {'updated': 'Nov 18, 2021 00:49:00 UTC', 'updatedISO': '2021-11-18T00:49:00+00:00', 'updateduk': 'Nov 18, 2021 at 00:49 GMT'}, 'disclaimer': 'This data was produced from the CoinDesk Bitcoin Price Index (USD). Non-USD currency data converted using hourly conversion rate from openexchangerates.org', 'bpi': {'USD': {'code': 'USD', 'description': 'United States Dollar', 'rate_float': 60639.4, 'rate': '60,639.3748'}}}
----------------------------------------
Done!

Code done running.

######################

Nothing displayed on matrice display.

Ju5tAN00b2000
 
Posts: 12
Joined: Wed Nov 17, 2021 3:09 pm

Re: Internet clock 1st project....HELP

by adafruit_support_carter on Wed Nov 17, 2021 9:32 pm

Cool. If the sands demo came up, then yah, you should be good to go with the Matrix Portal and that matrix.

It does seem like the basic are at least working. How did you see the output you saw? That's essentially what "connecting to serial console" means. Like this output:
Code: Select all | TOGGLE FULL SIZE
This is a test of Adafruit WiFi!

was sent to the serial console and you saw that.

So if you go back and try the Matrix Clock code, do you see any new messages in that same place?

adafruit_support_carter
 
Posts: 24055
Joined: Tue Nov 29, 2016 2:45 pm

Re: Internet clock 1st project....HELP

by Ju5tAN00b2000 on Wed Nov 17, 2021 10:26 pm

Time will be set for Europe/London
Traceback (most recent call last):
File "code.py", line 49, in <module>
File "adafruit_display_text/label.py", line 86, in __init__
File "adafruit_display_text/__init__.py", line 240, in __init__
File "adafruit_display_text/__init__.py", line 261, in _get_ascent_descent
File "adafruit_bitmap_font/bdf.py", line 75, in ascent
OSError: [Errno 22] Invalid argument

Code done running.

line 49
clock_label = Label(font)
Not sure what to do with line 49

The matrice now shows a bird and serial output.

Ju5tAN00b2000
 
Posts: 12
Joined: Wed Nov 17, 2021 3:09 pm

Re: Internet clock 1st project....HELP

by Ju5tAN00b2000 on Wed Nov 17, 2021 10:54 pm

It works =) , just the clock is small in the middle and im really tired.

Ju5tAN00b2000
 
Posts: 12
Joined: Wed Nov 17, 2021 3:09 pm

Re: Internet clock 1st project....HELP

by adafruit_support_carter on Thu Nov 18, 2021 12:26 pm

Good job getting it working. Now it's just a matter of customizing to get the look you want. Here's a guide that covers font usage:
https://learn.adafruit.com/custom-fonts ... on-display

adafruit_support_carter
 
Posts: 24055
Joined: Tue Nov 29, 2016 2:45 pm

Re: Internet clock 1st project....HELP

by Ju5tAN00b2000 on Thu Nov 18, 2021 9:16 pm

Excellent I will have a look but first I need to make a backup.

Other things I want to do is show the date and weather. Is that possible?

Is it possible to import some kind of calendar and set it up so on certain days it flashes up a message every hour?
Like "happy birthday name" with a animation and "happy christmas"? with a animation.

Or would the portal run out of space?

Ju5tAN00b2000
 
Posts: 12
Joined: Wed Nov 17, 2021 3:09 pm

Re: Internet clock 1st project....HELP

by Ju5tAN00b2000 on Fri Nov 19, 2021 10:13 am

I cannot seem to change the font. It seems to use the terminalio.FONT. It changes colour through out the day. If I change the font on line 45 it stays the same and if debug is false i just get terminal display and this

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Metro Minimal Clock
Time will be set for Europe/London
Traceback (most recent call last):
File "code.py", line 49, in <module>
File "adafruit_display_text/label.py", line 86, in __init__
File "adafruit_display_text/__init__.py", line 240, in __init__
File "adafruit_display_text/__init__.py", line 261, in _get_ascent_descent
File "adafruit_bitmap_font/bdf.py", line 75, in ascent
OSError: [Errno 22] Invalid argument

Here is my code.py
Code: Select all | TOGGLE FULL SIZE
# 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 = True

# 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 adafruit_support_carter on Fri Nov 19, 2021 12:53 pm, edited 1 time in total.
Reason: added [code] tags

Ju5tAN00b2000
 
Posts: 12
Joined: Wed Nov 17, 2021 3:09 pm

Re: Internet clock 1st project....HELP

by adafruit_support_carter on Fri Nov 19, 2021 12:56 pm

Do you have a copy of the font file IBMPlexMono-Medium-24_jep.bdf on the board?

adafruit_support_carter
 
Posts: 24055
Joined: Tue Nov 29, 2016 2:45 pm

Re: Internet clock 1st project....HELP

by Ju5tAN00b2000 on Sun Nov 21, 2021 3:34 pm

Yes unzipped

Ju5tAN00b2000
 
Posts: 12
Joined: Wed Nov 17, 2021 3:09 pm

Re: Internet clock 1st project....HELP

by Ju5tAN00b2000 on Sun Nov 21, 2021 6:28 pm

I have recopied the code.py file, Downloaded the font file and unzip copied it over. Checked the font filename matches in the code.py file. All checks out.

As soon as i turn Debug to false it goes wrong. Can someone test the font file? Or give me a link to a known working font file.
Or am I missing something?

Ju5tAN00b2000
 
Posts: 12
Joined: Wed Nov 17, 2021 3:09 pm

Re: Internet clock 1st project....HELP

by adafruit_support_carter on Mon Nov 22, 2021 12:19 pm

How are you downloading the zip file that contains the code and the font file?

adafruit_support_carter
 
Posts: 24055
Joined: Tue Nov 29, 2016 2:45 pm

Re: Internet clock 1st project....HELP

by Ju5tAN00b2000 on Tue Nov 23, 2021 7:40 am

adafruit_support_carter wrote:How are you downloading the zip file that contains the code and the font file?


Got it working. I was setting it up using my laptop. Changed to my desktop and it worked 1st time. How strange.
Now to play with the font and try and introduce the date, possibly weather.

Ju5tAN00b2000
 
Posts: 12
Joined: Wed Nov 17, 2021 3:09 pm

Please be positive and constructive with your questions and comments.