Saturday, February 13, 2021

3D Printed Clock, Scoreboard and more with Home Assistant Integration

 

Clock, Countdown Timer, Temperature and Scoreboard


Yet another 7-segment LED Clock








You can find a multitude of variations on a 7-segment LED clock on YouTube and other web sites.  In fact, this one is an enhancement and variation of the original design by YouTuber Leon van den Beukel, but adds features like local push button control, a host of additional default settings and optional Home Assistant (or other  system) integration via MQTT. View a short highlight of the features on my YouTube video


You can see Leon's original video here: Large 7 Segment Digital Clock V2 .  I'd encourage you to watch his video first (13:37), as it will provide a general overview to the steps we are about to take.  However, the video is scant in details in certain areas as reflected in the numerous follow-up questions in the video comments. I spent substantial time trying to fill in the blanks.  This blog post will hopefully provide those missing details, especially for beginners or those not familiar with Arduino sketches or general wiring of microcontrollers.  If you have substantial experience in these areas, you may wish to skip or scan over some of the details, as I'm going to get really down in the weeds in some areas to assist those that have little-to-no experience with these types of projects.

As alluded to above, I've updated the original design and added the following features:

  • Physical buttons on the side of the clock to:
    • Switch between clock modes
    • Increase, decrease and reset the scoreboard scores 
    • Start, pause, set and clear the countdown timer
  • Adds a buzzer that sounds upon countdown timer expiration
  • Fixes for midnight hour display for 12 and 24 hours displays.
  • Expanded option settings in code for default colors and other features
  • Optional Home Assistant integration via MQTT with full clock control.
Skills Needed:

About the only skill needed to complete this project is the ability to solder small components.  Not tiny, microscopic size components, but small gauge wire (18-24 AWG) and pins on a microcontroller, logic level shifter, etc.  There will also be a lot of soldering on the LED strip contacts.  Here's an idea of the sort of soldering that will be needed:




A good soldering iron and the proper solder is key here.  But if you soldered small electronics before, there is nothing here that you can't handle.

Obviously, you also need a 3D printer or access to one to print the actual clock case, components and enclosures.  All the necessary design files for the parts are linked below, so you do not need to design any parts yourself.

Parts List

You may be able to find these parts cheaper elsewhere, or you may be able to substitute in some cases with parts you already have laying around.  But I'm linking to the exact parts that I used.  You can determine if, when and where substitutions might be appropriate for your design. Note that these are Amazon affiliate links.  It does not impact your pricing, but the blog may earn a small commission if you purchase using these links.

Qty.

Item

Special Notes

2

WS2812B LED Strips - 1 Meter / 60 LEDs

 

1

ESP8266 D1 Mini / 4M

 

1

Real Time Clock Module

 

1

CR2032 Lithium Coin Battery

 

1

Logic Level Converter

 

1

5V Step Up/Step Down Regulator

 

1

5V 8A Power Supply

 

5

Normally Open Push Buttons - Assorted Colors

 

1

Mini Buzzer with Leads

 

20+

M3 Bolts, nuts and washers

8, 10 or 12 mm

1

ElectroCookie Solderable Breadboard

 

4

M2 Screws

Attach ElectroCookie board to case

1 box

24 AWG Solid Wire - Assorted colors

LED/PCB wiring

1 box

20 AWG Stranded Wire - Assorted Colors

Power leads/wiring

1 box

24 AWG Stranded Wire - Assorted Colors

Button/misc wiring

1 box

Assorted Spade Connectors

 

1

1/4" Braided Sleeving - 25'

Optional, wire management

1

Assorted Heat Shrink Tubing

 

1

PLA 3D Printer Filament 1.75mm - Black

 

1

PLA 3D Printer FIlament 1.75mm - White

 

 

Recommended for testing, but not required

 

1

Breadboard

 

1

Assorted Dupont Connectors

 

1

Assorted Alligator Clips / Test Leads

 

 

 

 


Notes on items:  The items shaded in light yellow are the items that will be required, at a minimum, to build the clock as described.  Substitution of these items may require a change in the 3D printed parts or other designs.  For example, all connections of the 3D printed panels are designed to accept M3 screws.

Unshaded items may be substituted... and if you've done any DIY electronics, you likely already have many of these items.

Finally, many of these links are to quantities greater than needed for this single project.  Often, these items are not offered in single or small quantities (at least on Amazon).  In addition, I tend to buy in larger quantities for the price breaks and will likely use the 'leftovers' on future projects.

3D Printing








This process will very likely be the most time consuming part of the entire build!  Just for a point of reference, my printer ran for six days, averaging 16 hours a day to finally get all the necessary parts printed.  You mileage may vary, based on your particular printer, printer settings, etc.  But unless you have multiple printers or a really high-end printer, printing the parts will be a multi-day process.

First, all of the clock enclosure parts, except for the button case and ElectroCookie enclosure, were designed and published by Leon van den Beukel and can be found on his Github page as well.  For these parts, all I did was create multiple versions within a single .stl file.  For example, instead of printing each individual white LED segment as a separate job, I combined those into printing 6 or 8 at a time.  If you want to remix the originals from single items, again, visit Leon's Github page.

You can find my remixes of the .stl files, along with my button case enclosure and the ElectroCookie enclosure for the D1 Mini on my Github, or individually by clicking each link in the table below. 

One thing that Leon's instructions were missing were how many of each item (such as attachment supports) were needed.  Based on my remixes, here are the minimum quantities of each .stl file that you will need to print, and my approximate time to print each (based on my printer settings... see below):

Qty

Descrip

.stl File Link

Color

Est. Time each*

4

Bottom digit plates

Bottom.stl

Black

6:10

4

Top digit plates

Top.stl

Black

8:45

1

Middle section top/bottom

Middle.stl

Black

5:00

1

Attach Brackets – lrg & sml

AttachBrackets_x6.stl

Black

1:15

1

Back lid (cover for RTC)

Backlid.stl

Black

0:45

1

Stand and spacers

Stand_Spacers.stl

Black

1:55

1

Button Case

ButtonCase.stl

Black

2:30

1

Control Enclosure

ControlEnclosure.stl

Black

4:30

2

Horizontal segments (6 each)

Segment_hor_x6.stl

White

2:30

2

Vertical segments (8 each)

Segment_vert_x8.stl

White

2:45

1

Dots (2)

Dot_x2.stl

White

0:50


*Your printing time will likely vary.  My times are based on the following printer settings:
  • Printer: Ender 3 Pro
  • Layer Height: 0.2 mm
  • Infill: 20%
  • Supports: No (EXCEPT for ElectroCookie enclosure, which uses 'Touching Bed only' for supports).
In addition, due to my use of a magnetic build surface, my digit faceplates (tops) were a bit dull and had some whiteish discoloration after removal.  I addressed this by applying a very light coat of semi-gloss black spray paint to these parts.

LED Wiring

Before starting this step, you will need to print at least the 4 bottom plates and the middle section.  I'd also recommend having at least one top plate on hand to test wire runs and to assure the top plate will fit on the bottom without pinching wires.

Layout the bottom plates, including the middle bottom side-by-side.

(This photo shows the LED segments already installed - that will come next)


Be sure the small cut-out for the wall hanging option is on the top of each back plate.  (Note: The design as described here will have the control box, buzzer and push buttons attached to the back of these plates, resulting in the inability to use these cut-outs to hang the clock on the wall.  If you wish to wall mount the clock, you will need to extend some of the wiring lengths to reach the externally mounted control box, buttons and buzzer.  I'll note where this is necessary as each item comes up.)

The middle piece back plate does not have a top or bottom.  I'd recommend sticking a piece of masking tape on each section and numbering them, starting with 1 on the right (where power and data will enter) and ending with 5 on the far left piece.  It is extremely important to wire the LED strips in the proper order and orientation or the clock will not function.

*Assembly improvement note
If you have already printed all your parts... or at least printed the button control enclosure, you may wish to align this box to your desired location on the back of the right most panel and go ahead and drill the mounting holes now, instead of after all the LED strips are installed and wired (like I did).  Even though we won't mount the box until final assembly, drilling these holes now will be much easier now than later.  Jump ahead to the Final Clock Assembly section for information on aligning and drilling these holes.  You'll be glad you did!


Cutting and installing the LED strip segments
Now, take your LED strips and cut 28 three pixel segments and two single pixel segments. If you are starting with a new LED strip, I'd recommend simply cutting off the first pixel with the pre-existing wiring/connector. We'll reuse the actual connector a bit later, so don't discard it.

If you have not worked with LED strips before, they can easily be cut with a sharp pair of scissors at any point along the strip by cutting the copper pads between individual pixels.


You want to cut across the copper pads as closely to the center as possible.  Since you will be soldering wire to both sides of the cut segments, you want adequate copper pad on every end.

Also, carefully note the directional arrows along the LED strip.  While the DC power can flow either direction along your strip, data only flows in one direction as indicated by these arrows.  It is imperative that you install your LED strips in the proper direction as shown below.  If a single segment is reversed or the flow isn't precisely as designated, the segments will not light or not light properly.

Remove the paper backing from the rear of the LED segment and carefully place each of your cut strips in the pattern shown here:


The yellow arrows in the diagram indicates the direction of data flow.  The arrow on each LED segment should match the direction of the yellow arrows.  The red arrows indicate where we are going to make soldered wired connections next.

Wiring the LED Segments
Connections now need to be made between each of the individual segments.  Each connection will consist of three wires.... +5V to +5V, DO to DI (data out to data in), and GND to GND. 

I would recommend first making all the solder connections within an individual digit/panel before establishing the connection between digits/panels. 


When soldering the strips together, the wires needs to fit within the provided channels so that the top section will fit without binding the wires.  For this reason, I opted to use 24 gauge solid wire.  The solid wire was easier to form and keep in position than stranded wire.  
Try a test fit of the front panel as you go along to assure all your wire runs fit and to not prevent the top/lid from properly joining to the back plates.

Once all the individual back panels are wired, it's time to make the connections between the panels.  


Again, I used solid wire here and tried to keep everything within the provided channels.

Finally, there are two more connections to make.  For these connections, we'll be using 20 gauge stranded wire.  First is the incoming power and data connection, just prior to the first pixel.



Remember the first pixel and connector we cut off before creating our LED segments?  Pull it out and cut the female connector off from the LED strip.  Solder the red lead to +5V, the green lead to DIN and the white lead to GND.  You don't want this connection to be too long, but need the connector to be able to extend out the back by a couple of inches.  In my case, I needed to extend the wires just a bit, so I soldered and applied heat shrink tubing so that the wires would neatly fit in the provided channel and give me the right length. (Wall mounting note: If you desire to wall mount this clock, then you will need to lengthen the leads to the connector to be able to reach wherever you plan on mounting or placing the control box).

Again, using 20 gauge stranded wire, we now need to provide power injection along the LED strip.  This is needed to overcome voltage drop and to avoid flickering of the LEDs on the first and second digit.


On the top LED segment of the second panel from the left, solder a 20 gauge stranded black lead to GND and a 20 gauge stranded red lead to +5V between the first and second pixel of the segment.  These wires will eventually feed through the holes immediately above and below the middle pixel and out the back side of the clock.  If you are planning on attaching the buzzer, control box and buttons to the back side of this clock, as described in this design, you only need 6-8" of wire for each lead (we'll trim them to size later... so better a little longer than being too short.  However, if you wish to wall mount the clock, these leads need to be long enough to reach the mounting/location of the external control box.

It is probably a good idea to stop here and test the LED lights before proceeding.  To do this, you'll need to solder pin headers to the D1 Mini board and then load the Arduino sketch.  If you are confident in your soldering, you can skip the breadboard testing section below.

D1 Mini Prep


You'll need to solder the appropriate pin headers onto the D1 Mini board.  Various pin headers should be included in the same package as the board.  In this case, we want to use the straight pin headers:


Solder the short end of the headers through the holes on the D1 Mini.  Assure the pins are straight and vertical.  One of the easiest ways to do this is to place the pins into a breadboard, place the D1 Mini on top and then solder.



Arduino Sketch Installation


All the instructions for installation of the necessary files to the D1 Mini can be found in the Github wiki installation steps.  I'm going to point you there, as the wiki will always contain the most up-to-date information should instructions change with new releases.

Once you have completed the installation and verified you can connect to the integrated web server as detailed in the installation, you are ready to proceed with the optional breadboard testing. 

Breadboard Testing

We are going to make the minimal connections to test the LEDs and display the various clock modes.  First, insert the CR2032 coin cell into the real-time clock module.  This will retain the time, once set, if the clock is powered down or restarted.

Also, do not make the connection to a live 5V power supply until all other connections have been made.




Here are the connections to make:

  1. Connect a positive and negative lead to the power rail on one side of breadboard (but do not connect leads to live power yet).
  2. Connect the power rails on each side of the breadboard together - positive to positive and negative to negative.
  3. Connect the D1 Mini 5V pin to the positive power rail
  4. Connect the D1 Mini G (ground) pin to the negative power rail
  5. Connect the VCC and GND pins on the clock module to positive and negative power rails, respectively.
  6. Connect the SDA (data) pin on the clock module to the D2 pin on the D1 Mini.
  7. Connect the SCL (clock) pin on the clock module to the D1 pin on the D1 Mini.
  8. Connect a positive power lead to the positive lead of the power injection line.  Repeat for the negative power.
  9. Connect positive power, negative power and a data line from pin D6 on the D1 Mini to the female LED connector of the clock.  Be sure to observe polarity on the power connections and that the positive power supply is connected to the +5V line on the connector.
Keep the data line connection between the breadboard and LED connector in step 9 as short as possible by positioning the breadboard next to the clock.  This is necessary to minimize voltage drop of the data line since we haven't included the logic level shifter to boost the data signal yet.

Once you have completed the connections, connect the power leads to the power supply and plug in the power supply.  If everything is connected properly, you should see pixels begin to light up green in series, starting with pixel 1, as the board boots and connects to WiFi.  Once connected, the clock should switch over to normal time mode.  If this is the very first power up and the real time clock module has not had the time set, the display may not be correct and will be the time the .ino sketch was last compiled.

Enter the IP address of the D1 Mini into a browser on your phone or computer (you should have determined the IP address during the Arduino sketch install process).  Set the current date and time via the web app and see if the time is now shown properly.  Try a few other settings, such as scoreboard with the score set to 88-88 to assure all segments are lighting properly.  If all LEDs seem to be lighting and responding correctly, congratulations!  Unplug the power supply and tear down the breadboard connections.

At this point, I'd recommend apply a small amount of hot glue to each end of the LED segments over the solder connections.  This isn't required, but will help strengthen the connections and help prevent them from coming loose or having any bare wiring touching another wire or solder joint when time comes to jostle the base plates around and attach to the fronts during final assembly.  You don't want to do all this work to only have to undo it all because a solder joint came loose at the tail end of the build!

You are now ready to start building the actual controller.

Troubleshooting steps if testing doesn't pass:

Nothing happens. No lights at all upon power up.
  • Check all connections, be sure polarity is not reversed anywhere along the way... from the power supply to the LED strip connection.
  • Verify solder joints at start of strip (pixel 1). Assure no bare wires are touching or shorted across solder joints along the LED strip.
  • Assure that your LED strips (including the first one) is aligned with the data flow in the proper direction and that the incoming data line is connected to the 'DI (Data IN)' end of the strip.
  • Be sure your data line is connected to the proper pin on the D1 Mini.  This should be D6.  
  • Finally, there is a remote possibility that the data signal is not strong enough to reach the strip.  Shorten the distance between the breadboard and first LED connection.  It may be necessary to temporarily install the logic level shifter.  See the Control Box Wiring section below for how to wire and include the logic level shifter.

The sequential green light "boot up" mode starts, but just keeps continuing beyond the first digit or so.
  • The most likely cause here is that the D1 Mini cannot connect to your WiFi.  Assure you have entered the correct SSID and password in the Credential.h file.  Be sure you have a strong wifi signal where the clock is located. Unless you changed the sketch, the clock should begin broadcasting a local (or soft) SSID and default over to this after 60 seconds of attempting to connect to your wifi. By default, this is named 'CLOCK_AP'.  Try to connect to this using a phone, tablet or laptop located near the clock, using the password and IP address as specified in the sketch.  If you can connect and control the clock using the 'soft AP', then the issue is with your wifi.
  • Something in the sketch has crashed, hung or is otherwise caught in a loop.  Try recompiling and reflashing the sketch to the D1 Mini again. 
Clock shows "gibberish" or various pixels flash off and on, seemingly at random.
  • Again, this is most likely caused by a weak data signal.  Try some different settings or values via the web application.  If the behavior continues, try shortening the distance between the D1 Mini and the connection to the LED strip and/or temporarily add a logic level shifter as described in Wiring the Control Box
Not all pixels light up when trying the 88-88 scoreboard test.

  • Usually the lights will stop at some point along the data path from pixel 1 to pixel 86.  At the point where the lights stop is where you will likely find a bad or broken solder connection.  Double-check, and re-solder if necessary, all connections at both ends of the connection prior to the first unlit LED segment.
  • While unlikely, it is possible that the LED strip/segment is damaged or broken. De-solder the first unlit segment and replace with a new segment, ideally from a totally different original strip.


Wiring up the controls

To provide you an idea of how long your wire runs need to be, here's a photo of the completed clock, with all controls, from the rear:


Wall mounting note:  If you plan on wall mounting the clock, you obviously will not be able to mount the button box, main control box or buzzer on the rear of the clock and these will need to be placed next to the clock or mounted elsewhere.  You will need to extend your wire lengths accordingly, specifically the leads to the LED strip and the power injection point.

Button Control Wiring

You will need to print the button case before beginning this step if you didn't do so previously.  Ideally, you will use five buttons each of a different color if you have them.  The sketch documentation and button control documentation refer to these buttons by color, so you will need to adjust accordingly if you do not have the same colors. For the documentation, the button colors are (from top to bottom when mounted): white, red, green, yellow and blue.  Be sure the buttons are normally-open buttons.  If you have buttons with three terminals that can function as normally-open or normally-closed, assure you use the common and normally-open terminals.  I used 24 gauge stranded wire for all button connections.


Begin by connecting the buttons together, daisy-chain style for the common/ground.  You want the length between buttons to be just long enough to allow the buttons to easily fit in the case, but not so long that the wiring has to bunch up.  Test fit the buttons in the case as you go along.  Note that the lead connected to the last button (blue in my case) needs to be the long lead that will connect to the main control box.  Better that this lead be longer than needed and cut later than to find out it is just a hair too short!


Now wire a separate lead to each button's other terminal.  Again, each of these leads will need to reach the main control box.  Ideally, use the same wire color as the button to which it is connected.  If this isn't possible, then carefully label which wire goes to which button as you'll need to know which wire is which when wiring up the main control box.  I also added a very small piece of heat shrink tubing to these terminals, both to help reinforce the solder joint and to assure nothing come in contact in the event that the wires shift during final install.

Feed all the leads through the small hole in the bottom of the base (left end in above photo) and carefully feed each button through the appropriate hole of the case and attach the corresponding nut to hold the button in place.  If you have no wires bunching, the lid to the case should snap on.

While optional, but it will make for a much neater final install, slide a section of 1/4" braided wire sleeve over the leads.  The length will depend on how much slack you want between the button and main control boxes, but you don't want it to be really tight.  Glance at the photo of the completed back side of the clock above for a general idea. Be sure to leave 3-4" of exposed wire on the end.  Secure both ends of the braided sleeve with a small piece of heat shrink tubing.

Real Time Clock Module Wiring

You can see the RTC module in the photo above as well.  You can opt to solder connections to this, but I opted to use the Dupont connectors instead.  This will make it easier to replace the battery when needed, since the module can be unplugged.  I simply cut the end off of four different colored Dupont female connectors.  For my design (and as color coded in the diagram below), I connected a black lead to GND, a red lead to VCC, purple to SDA (data), and blue to SCL (clock).  Again, you can use any colors, but you'll need to remember or label which wires are connected to each pin.  A small amount of hot glue applied to the Dupont connectors to hold them together will make connecting/disconnecting the clock module for battery replacement a bit easier.

Again, optionally, you can use a section of 1/4" braided sleeve and some heat shrink tubing to make the wiring neater. 

A side note on the RTC module battery
If your clock is going to be removed from main power for any significant length of time, you may wish to either remove the CR2032 battery from the RTC module, or disconnect the 5V lead.  Because the battery is connected to the control box, when no power is supplied, the board and other components will begin drawing power from the coin battery.  Since the coin battery is only 3V, it will be unable to power the components, but instead will drain to dead (rather quickly).  I drained three batteries during development because I was powering down so often to apply updates before I figured out why my battery kept dying. Obviously removing the battery means you need to reset the initial time again when you first restart the clock.  But at least you'll save money on batteries!

Control Box Wiring 

The control board is created so that the D1 Mini can easily be removed or replaced from the control box without any disassembly.  You might need to do this to reprogram it with newer or your own modified versions of the sketch or to change some of the default settings or to install a later update.  You may also change your wifi at some point and need to update the wifi credentials.  Here's what the top side and bottom side of the board will look like when we are done (don't worry, I'll describe all the wiring below):

Top side in the control box.  D1 Mini removed for this view.

And from the bottom.

Before beginning, there are a couple of other parts to gather.  First, we'll need the pin headers for mounting the D1 Mini.  The D1 Mini should have come with two pin headers in the package that look like this:

We are going to use these pin headers to make it easy to remove the D1 mini from the clock for the reasons listed above. Also note that you cannot program the D1 Mini when it is installed in the clock because the TX/RX pins will be repurposed for the buttons.  In addition, never connect the USB cable and the power supply to the D1 mini at the same time!  This will almost surely damage or destroy the D1 mini and may also destroy other connected components.  

Next, when we wired up the LED strips, we used the female connector we originally cut off the strip.  In the LED strip package, you should find an extra male connector.  You'll need that, as we will wire to the control box use it to connect the control box to the LEDs.  You will also need the 3D printed control enclosure.

Here is the wiring schematic I'll refer to:

A few notes about this diagram:

The D1 Mini has been removed from the above schematic, but it is important that the D1 Mini be inserted into the headers in the proper orientation:

Proper orientation of the D1 Mini - Do not reverse!

Basically, the 5V pin should be on the bottom and the 3V3 pin on the top.  DO NOT reverse the D1 Mini.  If you do, you will likely fry the D1 Mini at a minimum and may also damage other components.  The easiest way to be sure is that the micro-USB port on the D1 Mini should always be pointing to the outside.  You can place and remove the D1 Mini during the wiring process to assure you are making the right connection to the right pin.  The schematic shows which leads connect to which pin on the D1 Mini.  There are two exceptions here.  The LED data lead (D6) and the buzzer lead (D5) pass through the logic level shifter and 5V Step-up regulator, respectively, and those devices are then connected to the D6 and D5 pins.

The diagram shows the connections, not necessarily the wire runs or path.  All wiring will need to feed through the openings in the two ends of the enclosure.  The buzzer leads and power injection leads will feed through one side of the enclosure.  All other wiring feeds through either the upper or lower openings on the opposite side.

To facilitate both the wire runs and soldering, some wires are passed through from the bottom of the board and soldered on top.  Others pass through from the top and are soldered from the bottom.  You can run these any way you best see fit and make it easiest for you to solder.  The important thing is to assure the proper connections are made as shown.  

For me, I soldered all "internal wires" (those that connect two points on the board), and the 3 wires for the LED connection from underneath, passing through the holes from the top.  All other wires were passed through from the bottom and soldered on top.

I used 24 gauge solid wire for all internal connections and 20 gauge stranded wire for all power lead connections (power supply, buzzer and power injection leads).

You can pretty much make the connections in any order you desire, but you'll want to connect the button leads and the LED connector leads last.  This is because you'll need to pass those wires through the enclosure openings BEFORE soldering to the board.  This means you'll have to deal with navigating around the dangling enclosure when trying to solder these.  All other connections can be soldered before the board is placed in the enclosure.  Here's the order I used:

1. Connect the two power rails of the board together, using a short piece of solid wire and the provided holes on each end of the board... positive to positive and negative to negative.  This will result in both rails carrying 5V so power connections can be made on either side of the board.

2. Solder the pin headers for the D1 Mini to the board.  These need to be inset at least to the 3rd column of holes (labeled as "3" on the board) to assure the D1 Mini fits inside the enclosure.

3. Solder the logic level shifter onto the board (soldering on the supplied header pins to the shifter first if you haven't already done so).  The LV side of the board needs to face "up" or towards the same side as the 3V3 side of the D1 Mini when it is installed.

4. Solder on the 5V Step up regulator... again soldering on pin headers if needed.  Note which side is labeled as IN and which is OUT as this is only printed on the bottom of the board and won't be visible after soldering in place.

5. Make all "internal connections", using short lengths of 24 gauge of solid wire:

    a. Connect the 5V pin of the D1 Mini to the + 5V rail.
    b. Connect the G pin of the D1 Mini to the ground (-) 5V rail.
    c. Connect the HV pin of the logic level converter to +5V rail.
    d. Connect the 3V3 pin of the D1 Mini to the LV pin of the logic level converter.
    e. Connect the G pins on both sides of the logic level converter to the (-) rail.
    f.  Connect the D6 pin to the LV4 pin of the logic level converter.
    g. Connect the D7 pin to the 'IN' pin on the 5V step up

6. Connect the real-time clock module as shown in the schematic.

7. For the buzzer and power injection, I created short leads and attached spade connectors.  I only did this to facilitate soldering and to have the option to disconnect the buzzer if desired.  Note that the positive lead from the buzzer connects to the 'OUT' pin of the 5V step-up regulator and not the +5V rail.  Also, be sure not to confuse these two sets of leads.  Either mark them, or if you use spade connectors, use male connectors for the buzzer and female connectors for the power injection leads.  This will prevent inadvertently connecting the wrong wires to the wrong leads.

8. Button leads:  You now need to pass the button wires through the enclosure opening before soldering.  I recommend passing through the bottom opening in the enclosure and passing each button lead through the bottom of the board and soldering from the top side.  All the buttons connect directly to the D1 Mini pins and the black common lead connects to the ground (-) rail.  See both the schematic and photo of the bottom board above to guide these connections.

9. LED Connection leads:  Now, take the male connector for the LEDs and pass those wires through the enclosure opening (same end as button wires, but this time through the upper opening).  For me, the existing wires were a good length, but test fit yours and either shorten or add soldered wire length if needed.  Connect the red and white lead to the +5 and ground (-) rail respectively.  The green data wire connects to the HV4 pin of the logic level converter.

This completes the board wiring.  Now carefully feed any other leads through the enclosure openings and seat the board to the screw posts.  The board should rest flat on these posts.  If it does not, check the under side wiring and assure no wire is in the way.  Attach the board to the enclosure using four M2 screws.  Tighten these screws just to 'snug'.  Do not overtighten or you may break the mounting posts.  You just want the board held in place so it doesn't move or jiggle within the enclosure.

If desired, you can perform one final test by connecting all your leads and powering up the clock.  At this point, all functionality should be present.  If something doesn't work, you'll need to check and verify all your wiring and solder connections.
 

Final Clock assembly

If you didn't drill the mounting holes for the button enclosure before installing the LED strips, now is that time that you must complete that step.

Drill holes for mounting button enclosure

The original 3D .stl design files did not include mounting holes for attaching the button enclosure to the rear of clock (because button control was not part of the original design).  I considered modifying the design to include the mounting holes, but that was going to result in either a different back panel from the rest or extra holes in all the panels that would not be needed or used.  In addition, it would leave no flexibility if you wanted to mount the buttons lower on the clock than the top right corner.  Maybe you prefer the buttons on top instead of the side.  By not modifying the design, it provides more flexibility in the final design.  The trade off is that you now need to drill two small holes to accommodate two short M3 screws and nuts. 


Align the button enclosure so that the two tabs (or at least one of the tabs) align within the highlighted 'safety zones' above.  Mark the hole locations of the tabs and very carefully drill 1/8" holes through the back panel.  If you opt to install the button enclosure in a different location, use extreme care not to drill into any of the LED strips or wiring... or you'll be starting over with the LED strip soldering!  Attach and secure the button enclosure with M3 screws, washers and nuts.  Do not over-tighten or you may crack the read panel.

If your really don't want to risk drilling holes at this point, you can attach the button enclosure to the back panel with hot glue.  But these buttons will experience a little pressure during use, so hot glue may not provide enough long term holding power.  If you can only find one 'safe zone' mounting location, go ahead with the single hole and reinforce with hot glue after mounting.

Assembly of the Front Panels

If you haven't already, insert the white horizontal and vertical segments into the top/front faceplates.  Place the segments and middle section 'face down' and align the holes in the sides.  There is one decision you need to make here:

The front faceplates have an M3 screw mounting post on only one end.  This is intended for fastening the back lid cover plate over the clock module.  You can opt to either expose these posts by flipping the front faceplates so these posts are on the bottom of the clock, or hide them by orientating the faceplates so the posts will be at the top.  You can also mix and match... expose the post only on the digit where the clock module will be mounted and hide the rest.  But you want to make this decision now, because changing later will require disassembly of the entire clock body enclosure.  I opted not to use any of the posts, as I found the back lid could more or less be snapped into place without the screw, so changing the battery would not require a screwdriver or any other tools.

You will now connect the various panels together using M3 screws, washers and nuts in the provided holes.  If you wish to see a short video of this process, you can watch the Front panel layout section of Leon's original video.

But in a nutshell, after the front panels are all bolted together, you will place the front panel assembly over the top of the back panel/LED sections, using care not to pinch any wires.  The two halves (top and bottom) should align together without any major gaps.  Carefully hold the sections together and flip over so that the rear of the clock is now face up.

Attach a large 3-hole bracket across top of the middle section and the two inner digit sections.  Attach with M3 screws.  Repeat for the bottom. 

Use the small 2-hole brackets to join the outer digits to the inner digits, again with M3 screws.  There will be a total of four of these.

Finally, use four M3 screws to attach the four outer corners of rear panels to the front panels.

Attachment of control enclosures and buzzer

Again, here's a photo of my completed clock from the rear:

The main control box and buzzer are simply attached with hot glue to the rear of the clock.  Placement is somewhat up to you, but I placed mine to try to keep the wire runs neat.

Attach everything together:  LED lead, clock leads, buzzer and power injection leads. Finally connect to 5V power supply and plug in.

App Control

I'm not going to go into substantial detail regarding the use of the app here.  It is pretty basic and self-explanatory.  Simply open a web browser on your device of choice (phone, tablet, computer) and enter the IP address of your D1 Mini.

If you wish to see the web app demonstration, again refer to Leon's original video here.

Manual Button Control

Here are the default configuration and use of the control buttons.  I will refer to them by color here, but if your colors are different, my order of colors from top to bottom are:

White > Red > Green > Yellow > Blue

The white button always cycles the clock to the next mode.  The other buttons have different functions depending upon the current display mode:

Button Color

 

 

White – change mode

Cycle: Clock -> Countdown -> Temperature -> Scoreboard -> Clock

 

Countdown Timer Mode

Scoreboard mode

Red

Add one minute to start time (when timer paused/stopped)

Add one to the visitor (left) score

Green

Add five seconds to the start time (when timer paused/stopped)

Subtract one from the visitor (left) score

Yellow

Start/resume the countdown timer                 

Add one to the home (right) score

Blue

Stop/pause countdown if running Reset to last start time if stopped

Subtract one from the home (right) score

Red + Blue (press and hold)

Clear last start time and reset countdown to 0:00

Clear the scoreboard and set both scores to ‘00’.



Updating the Arduino Sketch

Once you have the clock powered up and try it out for a bit, you may find you wish to change some of the default boot options (like colors, 12/24 hour display, etc.).  Since pin headers were used for the D1 Mini during the install, this is pretty easy to accomplish.

Unplug or disconnect the power supply from the clock.  Carefully pull out the D1 Mini from the headers on the control board.  Make whatever desired changes you like in the Arduino sketch, then connect the D1 mini via USB and upload.  Replace the D1 Mini onto the control board and reconnect the power supply.  That's it!  I must have of removed, updated and reinstalled the D1 Mini over 100 times during the development process and I'm really, really glad that I put those pin headers in the design!  And just a reminder:  Never connect the USB cable and external power supply to the D1 Mini at the same time.  You've been warned... twice now!

And remember, you only need to upload the .ino file when making changes or updates.  You do not need to upload the /data files to flash memory again.  The only exception would be if you modified the web server files located in the /data folder.

Home Assistant (MQTT) Integration

Sample screen shot of Home Assistant Integration


All aspects of the clock can be controlled from Home Assistant via MQTT commands.  In addition, most of the functions also report back so that sensors or other entities can be created in Home Assistant.  Currently, the MQTT integration is not automatic, so you will need to create sensors, switches and other controls via YAML or the UI automation.  Here is a list of commands and states that are available:

MQTT COMMANDS

MQTT STATES

GENERAL

 

Set/Change Mode

Mode

Set Brightness

Brightness

Sound the Buzzer

CLOCK

Set Clock Display 12/24 hour

Clock Display 12/24

Set Clock Color

Clock Color

Set Time


COUNTDOWN

Set Countdown Time

Initial Countdown start time

Set Countdown Color

Countdown Color

Set Color for Last Minute

Color for Last Minute

Set Color when Paused

Color when paused

Start Countdown

Countdown status (running/stopped)

Stop/Pause Countdown

Reset/Clear starting Countdown time

TEMPERATURE

Set Temperature Mode (°C/°F)

Temperature Mode (°C/°F)

Set Temperature Correction

Temperature Correction

Set Temperature Color

Temperature Color

Temperature (measured)

SCOREBOARD

Scoreboard Color Left

Scoreboard Color Left

Scoreboard Color Right

Scoreboard Color Right

Scoreboard Score Right

Scoreboard Score Right

Scoreboard Score Left

Scoreboard Score Left

Scoreboard Score Up

Scoreboard Score Down

Scoreboard Reset


Using these commands and states, it is possible to create all sorts of interesting automations, scripts and Lovelace displays.  You can find a full list of MQTT topics and payloads in the Github MQTT folder.

You can also find sample Home Assistant automations, sensor setups and example Lovelace cards in the Github Home Assistant folder.

Other options and possible enhancements

If you've made it this far, thank you!  I know this was an extremely long post and probably too detailed for most folks.  But again, I wanted to include enough information so that a "newbie" might be able to complete the project.  And as I stated above, I am not proficient (in the slightest) with Arduino/C++ code.  I'm sure there are numerous improvements and efficiencies that could be made to my code.  If you are interested in contributing, feel free to submit a PR on my Github or post your comments below.

There are also numerous other enhancements or improvement that I have thought of since the initial build.  Some of these ideas include:

  • Addition of a photoresistor to auto-adjust the clock brightness based on ambient light levels.
  • Upgrading to a NodeMCU to have additional input options (likely required to add the photoresistor as all usable pins except A0 are used on the D1).
  • Substantial improvements to the web app, especially for those not using MQTT.
  • Creating a "stacked" two-level version of the clock, so it could function much like a true scoreboard... countdown timer on top, with home/visitor scores below.  This could be used at junior sporting events or in the backyard as a mobile scoreboard/timer system.
Please feel free to add your thoughts or comments below.  This was a fun, albeit a time-consuming project, but I'm not opposed to coming up with a version 2.0 in the future and would welcome your thoughts on what might be included in the next round.

Supporting this blog and related YouTube channel

If you'd like to support future content on this blog and the related YouTube channel, or just say thanks for something that helped you out, you can use any of my Amazon links to make a purchase at absolutely no cost to you.  Or if you prefer to say thanks directly, you can buy me a one-off cup of coffee at:


No comments:

Post a Comment

To help eliminate spam and to keep all conversations civil, submitted comments are moderated. Therefore your post may not show up immediately. Please be patient as most reviews are completed within a few hours.