Thursday, April 15, 2021

WS2812b LED Matrix Clock, Scoreboard and More

 



Time & Temperature, Countdown timer, Scoreboard and Text Display


Yet Another Clock!

After building a 3D printed clock, scoreboard and more, I wondered if I could adapt this code for an LED matrix I previously built for WLED.  The answer was a resounding 'yes'... and the matrix that was rarely used before is now on 24/7 and is a great addition to the man cave!

So, a little over a year ago, I built my own LED matrix using WS2812b LED strips.  I wanted to use the outstanding WLED firmware to display effects and sync these up to other LED lights in my basement.  It worked great... but it was rarely turned on.  WLED is outstanding and has hundreds of patterns and effects, but the one thing it can't do (yet) is display text or other information.  And the 3D printed LED clock was limited to 4 seven-segment sections and really couldn't do much beyond numbers either.  But with the 400 pixels in the matrix and some significant alterations to the LED clock code, the skies opened to the possibilties.

Feature Highlights

Before drilling into the details, here are some of the highlights of the LED Matrix Clock:
  • Time/Temperature modes: 12/24 hour time and inside or outside temperature in C or F
  • Multiple number styles (fonts) 
  • Countdown timer with optional expiration buzzer
  • Scoreboard with 3 character custom team names (e.g. CHI, BOS, IND)
  • Text display with multiple effect options (flash, appear, fade, rainbow, etc.)
  • All modes and displays colors can be customized
  • Control options include MQTT/Home Assistant integration, local buttons or built-in web server
  • Maintains original WLED controller for dual-functionality/previous pattern options

Matrix Build

This is going to cover the original 400 pixel build (16 rows of 25 pixels per row) that I created for WLED.  If I were to build something from scratch for the purposes of a clock, scoreboard, etc., I might take a different approach.  But this design still worked out well for the clock option.

Parts List
Some links below may be affiliate links.  This means that while you pay the same price, this blog may earn a small commission to use towards future projects.

Lumber/Hardware

QTY

Description

3

4” x 1” x 4’ Quality pine board

1

¼” Plywood sheet (at least 2’ x 2’)

1

Acrylic Sheet – 0.060” (minimum of 20” x 14”)

1

8’ x 2” trim or casing (style of your choice – but back should be flat/non-beveled

 

Wood screws

 

Wood glue

 

Optional Items

 

Wood putty

 

Paint – your choice of color

1

Frosted glass spray pain

1

3M Mounting Tape – 0.4”


Electronics, wiring and controls

QTY

Description / Link

2

WS2812b LED strips (60 pixels/m – need 400 pixels total)

1 or 2

Wemos D1 Mini (one for clock only, two for dual-controller with WLED)

1 or 2

Logic Level Shifter

1 or 2

ElectroCookie Prototype Board

1

5V 40A Power Supply

1

DS3231 Real-time clock module

1

AC extension or power cord for 5V power supply (length as desired)

 

Miscellaneous wire 20 – 24 gauge

 

 

 

Optional Items

1

Mini-Buzzer (optional for countdown timer)

1

Pololu 5V step up/step down voltage regulator (needed for buzzer)

3

Normally-open momentary push button

20

JST 3-Pin LED strip connectors (you can direct wire if you don’t want these)

1

CR2032 Coin battery (for clock backup power)

 1

Mini Toggle Switch (if using dual controller option)

 

Braided Wire Sleeve

 

Various heat shrink tubing


Building the Matrix Frame

The frame is a pretty simple box.  Routed grooves hold the plywood back board and acrylic sheet in place.  The dimensions I used are as follows:



Note that the plywood backer board is narrower than the frame opening.  This is to leave a gap on each side for the LED wiring.  The gap will be hidden by the 2" trim that is installed after the box is assembled.

Route the grooves for the plywood and acrylic sheet in the pine frame.  Note that the acrylic groove is routed on all four sides, but the plywood groove is routed on the top and bottom only.  To assure alignment, it is best to route the pine before cutting to size.


Groove dimensions are as follows:

Acrylic (small) groove - all four sides:
1/4" wide x 5/16" deep, centered 1/4" from edge

Plywood (large) groove - top and bottom only
5/16" wide x 5/16" wide, centered 11/16" from edge

Cut all materials to size, but do not assemble yet. 


Optional steps:
  • I painted the 'display side' of the plywood with a medium flat grey.  I would have preferred black, but I needed to be able to make/see pencil layout marks for the LED strips.  I also masked off about 1/2" along the edges.
  • I also applied a few coats of frosted glass spray paint to the acrylic sheet to 'soften' the LEDs.  The LED's can be really intense, so this softens it a bit, but you don't want to overdo it or the display will appear blurry.  It's a personal preference.  I'd recommend that if you have an LED strip that you can light, apply a couple of coats and hold the acrylic sheet about 1/4" inch in front of the lit strip.  Continue to apply coats of the frosted glass paint until you find the proper balance for you.  For me, two or three coats on each side of the acrylic was about right.
Put all parts aside except for the plywood board.  The frame won't be assembled until the LED strips are installed.

Laying out the LED Matrix

Now comes the most critical step... installing the LED strips onto the plywood panel.  This is critical because the spacing between rows and the alignment of pixels vertically between strips must be precise or your text and numbers will be 'crooked' and look off.  Having built a couple of these now, here's the technique that I use that has worked pretty well, given the following info:
  • The nominal distance between pixels of a WS2812b 60 pixels/meter is 11 mm.  This might vary slightly, but I've found it pretty consistent with the BFT-Lighting brand which is why I stick with them.
  • The LED strip is 10 mm wide.  This means if we allow a 'gap' of 6 mm between strips, we'll have a pretty close consistency from pixel to pixel both horizontally and vertically.
  • My design calls for installation of a 2" trim attached to the front of the frame.  This means that the part of the plywood panel will be 'hidden' behind the trim.  But if you start in the center and work outwards, with 6 mm between each strip, all pixels will be within the "display area" with a little space to spare around all sides.
  1. Carefully cut a 25-pixel strip from the LEDs.  Cut as closely as possible to the exact center of the copper pads on both ends.  This will be our 'measuring' stick.
  2. Mark the center of the plywood panel both horizontally and vertically and draw a light pencil line for both.  There will be 8 strips above the horizontal line and 8 strips below.  The center of the 13th pixel of each strip should center on the vertical center line.
  3. Come up 3 mm from the horizontal center line and draw a parallel horizontal line.  Come up another 10 mm and draw another line.  This is the first led strip outline above the center.  Come up 6 mm for the space between strips, then another 10 mm for the second strip.  Keep alternating between 6 mm and 10 mm until you have 8 strips above the line.  Repeat for the strips below the horizontal center line (remembering to use only 3 mm on the first strip below the line) until you have marked 8 strips below the line.
  4. Now take the 25 pixel strip.  Align the 13th pixel precisely on the center line and smooth out the strip to the left, assuring no bubble or wrinkles in the strip.  Mark the center of the first pixel.  Repeat to the left and mark the 25th pixel.  Repeat on a number of rows until you can draw a straight vertical line marking the centers of the 1st and 25th pixel (the prior center line is the center of the 13th pixel).  
Your final layout should appear similar to this:

Preparing the pixel strips
We now need the 16 strips of 25 pixels each.  Cut each strip carefully, trying to cut exactly in the center of the copper pads.

Next, tin each of the copper pads on all 16 strips with a bit of solder.


If you are going to be using JST 3-pin connectors to join your LED strips together, go ahead and solder the connectors onto the end of each strip.  Assure you are soldering the red wire to the +5V pad, the green wire to the DI/DO pad and the white wire to the GND pad.  Also assure you are using the male and female connectors properly.  The standard is that the female connector is used on the DATA IN end of the strip (indicated by the small white arrow on the strip) and the male connectors on the DATA OUT end.


Why use JST connectors?
For one, I'm lazy.  These connectors come with pre-tinned ends and saves me the step of tinning a total of 96 wire ends myself.

Next, by adding the JST connectors, I can complete all the soldering and bench test the entire 400-pixel strand before installing on the plywood panel (and then enclosing in the frame).  If I made a bad solder joint.. or reversed the wiring... or found I can't connect the strips because I used two female connectors on the same strip, etc., it's much easier to correct before installing.  And while rare, it is also possible that a strip could be faulty.  Again, easier to swap out and replace before installation than after (trust me on this one!).

If you opt not to use JST connectors, that's fine.  Proceed with the strip installation and then wire your strips together with short runs of 22-24 gauge wire.

Installing the pixel strips on the plywood panel
OK... again, careful precision is needed here to get everything aligned.  While not absolutely necessary, I highly recommend putting down double-sided tape and then applying the pixel strips.  While the pixel strips do have an adhesive backing, this isn't the world's strongest adhesive.  Add to the fact that your sticking on painted plywood and that the pixels will generate some heat, and there is a very strong possibility that the strip adhesive will fail at some point, leaving you with a "drooping" strip inside of your frame.  And the only way to repair this is to take the entire frame apart.  You can hopefully avoid this by using good double-sided tape.  My first matrix is over a year old and to-date, no pixels have come loose.

I use 3M 0.4" wide mounting tape.  The advantage of this is that 0.4" = 10.16 mm, so I can carefully lay down strips of tape evenly over the lines made earlier for each strip.  The tape will then serve as my guide for the actual strips themselves.


Pixel number 1 in the matrix is the first pixel on the lower left corner.   This also where our control box and DC power will connect to the LED strip, so we'll start there.  Carefully remove both the tape cover and the paper backing on the LED strip.  ASSURE THAT THE DATA DIRECTION IS MOVING FROM LEFT-TO-RIGHT on this first strip.  Carefully center the first pixel on the first pixel vertical line made earlier and make sure that no bubbles or wrinkles occur.  The 13th pixel should center on the center line and the 25th pixel should center on the rightmost vertical line made earlier.  Take your time here!

Now move to the second strip, REMEMBERING TO ALTERNATE THE DATA DIRECTION FOR EACH ROW.  The second strip data should be pointing from right to left.  Basically, the data for the entire matrix needs to 'snake' from pixel 1 on the lower left to pixel 400 on the upper left:
Continue working your way from bottom to top, assuring that the data flow for each row is the proper direction and, if you used JST connectors, that you have the proper male/female connector to join the strips as shown above.


As you lay down each strip, check carefully for horizontal and vertical alignment.  Gently pull up and adjust strips as necessary.  Again, if the vertical alignment is off, it will be be very visible when the LEDs are used to show numbers and letters.

Once all 16 strips are installed, if you did not use JST connectors, then wire the strips together as shown in the above data flow diagram... +5V to +5V, data out to data in, and GND to GND. If you did use JST connectors, connect all the strips together appropriately.

At the end of the final strip (pixel 400 in the upper right corner), you will need to solder lead wires to the +5V and GND pads on the LED strip (there should NOT be a JST connector here).  These will be connected to the power supply to provide power injection to the LED matrix.  I'd recommend 20 gauge wire, with each about 14" long (you can always trim to length later).

Once all wiring is completed, I'd highly recommend one final bench test.  After the next step, the individual strips will no longer be accessible without disassembling the frame and case.  If you are building the dual controller version with WLED, you can go ahead and flash the latest WLED on one D1 Mini and create a temporary breadboard version as I describe in this post


Once you are sure all 400 pixels are lighting and responding as expected, you are ready for final frame assembly.  Note that if you don't connect the power injection leads during this test, you may observe some color changes and/or flickering due to voltage drop over the 400 pixels.  This is OK for the bench test... as you really are just assuring that all 400 pixels are lit. The color drop/flicker will be resolved once the power injection leads are connected.

Final Frame Assembly

Once again... assure that your LED strips are securely attached to the plywood panel and that all solder joints are secure before final assembly.  Should something come loose, you will need to disassemble the frame to access the LED strips. And if you countersink and putty over the wood screws, this could be quite a challenge!

But the actual assembly is pretty straightforward.  Insert the acrylic sheet in the frame grooves, the plywood into the grooves on the top and bottom frame (assuring it is centered), and glue/screw the four pieces together.  Butt joints are used, as the entire front will be covered with mitered trim.


Countersink and putty over the screws if desired and optionally paint the frame in your choice of color.  Finally, paint, miter and install the 2" trim, aligning the outside edges of the trim with the outside part of the frame.


Note the small holes drilled in the bottom for the power cord and toggle to switch between the dual controllers.  There is also a small hole drilled on the right hand side for the eventual button controls.  Your locations may be different (or not needed), but you'll want to determine and drill these prior to final electronic installation.  See below for more details.

At this point, you are ready to install the electronics and controls.

Electronics and Controls

If you have a 3D printer or access to one, you can find .stl files for enclosures for the control boxes, clock module and buttons/toggle switches in the Github repo. But the use of these 3D printed parts is totally optional. If you do not have access to a 3D printer, you will just need to find alternate ways of mounting some of the controls.

Preparing the control board
First, if you haven't done so, prepare the D1 Mini with the firmware. The Arudino sketch and instructions for installation onto the D1 Mini can be found in the Github repository, and I'll refer you there, as the repository will always have the latest files and information.

Here's the wiring diagram for the control box and buttons:


(Note that this is for a single controller version - clock/scoreboard only.  If you wish to use dual-controllers with WLED, there are some slight modifications to the above.  See below for details on a dual-controller installation).

If you'd like step-by-step details for wiring the above, see my other post on creating a 3D Printed LED Clock, as the controller is the same, except this version only uses three buttons instead of 5.  

I highly recommend using pin headers for the D1 Mini as opposed to soldering directly to the proto board.  While the Arduino sketch supports over-the-air (OTA) updates, in the event that a code update goes sideways, the board ends up in a boot loop, or simply fails, you don't want to have to rebuild or replace the entire control board.  By using a pin header, you can simply pop out the D1 Mini and reflash via USB or even replace with a new board.




Configuring for dual-controller (Clock and WLED)

If you wish to have the ability to also take full advantage of the light patterns and effects of WLED in addition the clock/countdown/scoreboard features, you can add a second controller and a basic toggle to switch between controllers.

First, build and configure the WLED controller via the instructions provided in the Build your own LED light strip controller.  However, since the matrix LED only accepts a single signal line, you'll need to take the signal lines (green wires) from each controller that would normally connect to the JST connector and run them each to a SPDT (three-way) toggle switch:

With this configuration, you can set the switch to the right position to send the signal from one controller through to the LED matrix or to the left position to send the signal from the other controller.  Placing the toggle in the center position will effectively turn off the matrix by not sending any signal.

The toggle switch can be mounted anywhere on the outside of the frame.  If you have a 3D printer (or access to one), a .stl file is provided in the Github repo for a box that will hold the three buttons and the toggle switch:


Installing the controls in the frame


The above shows my final placement of components on the back side of the frame.  The power supply is mounted with 1/4" screws, using spacers to assure that the screws do not protrude thru to the front... use caution here... you do not want to punch through the front and potentially into a LED strip! All other components are simply hot glued to the back panel.

The power supply is connected directly to both controllers, the JST connector and the power injection leads.  In my case, the matrix was going to be mounted high enough on a wall that I ran a sheathed cable to the control box with buttons and toggle switch, but you could optionally attach these controls directly to the outside of the frame itself.

Home Assistant/MQTT Integration

The current clock project supports over 40 MQTT states and over 30 MQTT commands for controlling the clock.  Details on how to setup MQTT and optionally integrate into Home Assistant can be found in the Github wiki.

I was so happy with the first matrix, I've now built a second version to place in the garage.  It is unlikely I'll really need a scoreboard and countdown timer in the garage, but the functionality is there if ever needed!  And maybe I'll find some automations that can utilize these additional functions (e.g. door open message, countdown timers for auto-lights off or overhead door closures, etc.).


Let me know in the comments if you have any questions or recommendations for improvements.  You can also submit issues or PRs via the Github repo for this project.


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:



2 comments:

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.