0

Adabox016 - "close enough" clock
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Adabox016 - "close enough" clock

by belsonc on Fri Nov 06, 2020 8:26 pm

I've always enjoyed different ways to represent time - this clock shows what time it is, but "close enough" to the actual time. (if it's between 703 and 708, the display says "five after 7". Took a little while to knock out some of the code issues, including having to replace one of the libraries with a different version that I found on the forums*, but I'm happy with it. Now to go back and make sure I understand the code. :-) I'm sure some of the code could be more efficient, as I'm not great with Python, and will post it if anyone would like to see it.

*I'm pinging and getting the time from Adafruit IO, and it would work for the initial call - but after that, I'd get an error message regarding a "Runtime Error - Failure to send 3 bytes." Fixed it with a different version of adafruit_requests.mpy that I found on a thread regarding the error, and all's good.
Attachments
quarter.jpg
quarter.jpg (53.26 KiB) Viewed 383 times
twenty.jpg
twenty.jpg (35.49 KiB) Viewed 383 times

belsonc
 
Posts: 37
Joined: Tue Sep 15, 2020 8:39 pm

Re: Adabox016 - "close enough" clock

by adafruit_support_bill on Fri Nov 06, 2020 8:35 pm

Nice job! Thanks for posting.

adafruit_support_bill
 
Posts: 79956
Joined: Sat Feb 07, 2009 10:11 am

Re: Adabox016 - "close enough" clock

by belsonc on Sun Nov 08, 2020 1:27 pm

Hi - so I had this up and running just now, for half an hour(?), and got an error message...

Code: Select all | TOGGLE FULL SIZE
Getting time for timezone America/New_York
Traceback (most recent call last):
  File "code.py", line 51, in <module>
  File "adafruit_matrixportal/network.py", line 198, in get_local_time
  File "adafruit_matrixportal/network.py", line 180, in get_local_time
  File "adafruit_requests.py", line 291, in get
  File "adafruit_requests.py", line 250, in request
  File "adafruit_esp32spi/adafruit_esp32spi_socket.py", line 204, in close
  File "adafruit_esp32spi/adafruit_esp32spi.py", line 769, in socket_close
  File "adafruit_esp32spi/adafruit_esp32spi.py", line 323, in _send_command_get_response
  File "adafruit_esp32spi/adafruit_esp32spi.py", line 306, in _wait_response_cmd
  File "adafruit_esp32spi/adafruit_esp32spi.py", line 290, in _wait_response_cmd
  File "adafruit_esp32spi/adafruit_esp32spi.py", line 266, in _wait_spi_char
RuntimeError: Error response to command


And I'm not sure what to make of it... line 51 is network.get_local_time(), and it's been working for repeated calls - but then it just crashes. Can anyone help me figure out what's going on? Too many sockets or something? (And maybe help me figure out how to fix it?) Can copy/paste any other code needed... Thanks!

belsonc
 
Posts: 37
Joined: Tue Sep 15, 2020 8:39 pm

Re: Adabox016 - "close enough" clock

by adafruit_support_bill on Sun Nov 08, 2020 1:40 pm

Looks like a communications error of some sort with Adafruit I/O. I'm not too familiar with the internals of that. Probably best to post this question on the Adafruit IO forum here: viewforum.php?f=56

adafruit_support_bill
 
Posts: 79956
Joined: Sat Feb 07, 2009 10:11 am

Re: Adabox016 - "close enough" clock

by belsonc on Mon Nov 09, 2020 8:06 pm

So I'm not sure why/how, but I was able to fix this issue by replacing the files involved.

belsonc
 
Posts: 37
Joined: Tue Sep 15, 2020 8:39 pm

Re: Adabox016 - "close enough" clock

by adafruit_support_bill on Mon Nov 09, 2020 8:32 pm

Good to hear you have it working. Thanks for the follow-up.

adafruit_support_bill
 
Posts: 79956
Joined: Sat Feb 07, 2009 10:11 am

Re: Adabox016 - "close enough" clock

by adafruit2 on Tue Nov 10, 2020 12:29 am

@belsonc - nice work, can you post your code somewhere? we'd love to share on the blog so others can build :)

adafruit2
Site Admin
 
Posts: 19652
Joined: Fri Mar 11, 2005 7:36 pm

Re: Adabox016 - "close enough" clock

by belsonc on Tue Nov 10, 2020 12:45 am

Holy (banned word) - absolutely! Give me a day or so and I'll let you know where it is. :-)

belsonc
 
Posts: 37
Joined: Tue Sep 15, 2020 8:39 pm

Re: Adabox016 - "close enough" clock

by belsonc on Wed Nov 11, 2020 12:14 am

So... this is my second CircuitPython project ever, and the first I've started from scratch (I have a pyportal and modified the quotes project to use local quotes instead of reaching out to a server for them). I'm also using my Adafruit stuff to teach myself Python in general. :-) And now I'm trying to figure out what I want to do next... lol

Also, the colors used? Top line is my birthday, middle line is my fiancee's birthday, bottom line is our first date :-)


Code: Select all | TOGGLE FULL SIZE
import time
import displayio
import rgbmatrix
import board
import framebufferio
from secrets import secrets
from adafruit_matrixportal.matrix import Matrix
from adafruit_bitmap_font import bitmap_font
from adafruit_display_text import label
from rtc import RTC
from adafruit_matrixportal.network import Network


network = Network(status_neopixel=board.NEOPIXEL, debug=False)
displayio.release_displays()
matrix = rgbmatrix.RGBMatrix(
    width=64, bit_depth=4,
    rgb_pins=[
        board.MTX_R1,
        board.MTX_G1,
        board.MTX_B1,
        board.MTX_R2,
        board.MTX_G2,
        board.MTX_B2
    ],
    addr_pins=[
        board.MTX_ADDRA,
        board.MTX_ADDRB,
        board.MTX_ADDRC,
        board.MTX_ADDRD
    ],
    clock_pin=board.MTX_CLK,
    latch_pin=board.MTX_LAT,
    output_enable_pin=board.MTX_OE
)
display = framebufferio.FramebufferDisplay(matrix)

type_face = bitmap_font.load_font('/fonts/helvR10.bdf')
left_side_Text = 3
top_y = 6
middle_y = 16
bottom_y = 26

hour_Names = ["midnight","one","two","three","four","five","six","seven","eight","nine","ten","eleven","noon"]
min_Names = ["just","just","just","five","five","five","five","five","ten","ten","ten","ten","ten","quarter","quarter","quarter","quarter","quarter","twenty","twenty","twenty","twenty","twenty","twenty five","twenty five","twenty five","twenty five","twenty five","half","half","half"]
min_modifier_Names = ["about","after","past","to"]



while True:
    network.get_local_time()
    datetime=time.localtime()
    print(datetime)
    current_Hour = datetime.tm_hour
    current_Min = datetime.tm_min

    if current_Min > 30:
        current_Hour = current_Hour + 1

    if current_Hour>12:
        current_Hour = current_Hour - 12

    current_hour_Name = hour_Names[current_Hour]

    if current_Min > 30:
        current_min_Name = min_Names[30-(current_Min-30)] #so if it's 33 after, 30-(33-30) = 27 - X minutes after the hour matches back to X minutes before the hour and uses the same term
        current_min_Modifier = min_modifier_Names[3]
    else:
        current_min_Name = min_Names[current_Min]
        if current_Min < 3:
            current_min_Modifier = min_modifier_Names[0]
        elif current_Min < 28:
            current_min_Modifier = min_modifier_Names[1]
        elif current_Min < 58:
            current_min_Modifier = min_modifier_Names[2]
        else:
            current_min_Modifier = min_modifier_Names[0]

    top_line_Text = label.Label(type_face,color=0x022681,text=current_min_Name)
    top_line_Text.x = left_side_Text
    top_line_Text.y = top_y

    middle_line_Text = label.Label(type_face,color=0x081677,text=current_min_Modifier)
    middle_line_Text.x = left_side_Text
    middle_line_Text.y = middle_y

    bottom_line_Text = label.Label(type_face,color=0x021518,text=current_hour_Name)
    bottom_line_Text.x = left_side_Text
    bottom_line_Text.y = bottom_y

    text_Group = displayio.Group()
    text_Group.append(top_line_Text)
    text_Group.append(middle_line_Text)
    text_Group.append(bottom_line_Text)

    display.show(text_Group)
    time.sleep(60)

belsonc
 
Posts: 37
Joined: Tue Sep 15, 2020 8:39 pm

Re: Adabox016 - "close enough" clock

by adafruit2 on Wed Nov 11, 2020 12:39 pm

nice work! :)

adafruit2
Site Admin
 
Posts: 19652
Joined: Fri Mar 11, 2005 7:36 pm

Re: Adabox016 - "close enough" clock

by belsonc on Wed Nov 11, 2020 2:58 pm

Thank you! I'll keep an eye on the blog :-)

belsonc
 
Posts: 37
Joined: Tue Sep 15, 2020 8:39 pm

Re: Adabox016 - "close enough" clock

by IdeaSandbox on Mon Nov 16, 2020 11:19 am

I have always loved these style clocks! How can I please find all the code ingredients I need to make this work? Thank you in advance! -Paul

IdeaSandbox
 
Posts: 3
Joined: Tue Jul 28, 2020 8:53 pm

Re: Adabox016 - "close enough" clock

by belsonc on Tue Nov 17, 2020 2:35 pm

I'm not sure I follow - what do you mean by ingredients?

belsonc
 
Posts: 37
Joined: Tue Sep 15, 2020 8:39 pm

Re: Adabox016 - "close enough" clock

by IdeaSandbox on Tue Nov 17, 2020 4:00 pm

I'm sorry... I meant is there a step-by-step how to install/make this work. I copied/pasted the code provided earlier and saved it as code.py but it didn't work for me. I'm thinking I'm missing some other elements I need to install? I got the Moon Project to work, and installed several files into "lib" directory to make that work. Are there lib files needed for the clock?

Thank you in advance! - Paul

IdeaSandbox
 
Posts: 3
Joined: Tue Jul 28, 2020 8:53 pm

Re: Adabox016 - "close enough" clock

by belsonc on Tue Nov 17, 2020 4:08 pm

Ah ha - that makes a little more sense. :-)

First question - do you have a secrets.py file on there? Your wifi information and Adafruit info will be in that file.

Second question - do you have an Adafruit IO key? This reaches out to Adafruit IO to pull down the updated time.

I don't remember specifically which lib files I copied across for this - you may want to cross check the code against what's in your lib folder and copy in whatever's not there. Let me know if there's anything else I can help with.

belsonc
 
Posts: 37
Joined: Tue Sep 15, 2020 8:39 pm

Please be positive and constructive with your questions and comments.