Saturday, August 3, 2024

Using Dual Controllers with an LED Display

 



Have you ever wished that you could use two different controllers or firmware to control a single LED display?  Maybe you'd like to use both WLED and ESPHome to control an LED matrix.  Or ESPHome and Arduino/C++.  Or even a retail system like Govee with the default app, but adding the ability to also use WLED.  In this article I'll cover how you can create easily switchable controllers for your single LED display.

While using dual controllers probably makes the most sense for something like matrix displays, this method will work with any LED display that uses a single data line.  This includes LEDs like WS2812b, SK6812 and many others.  Unfortunately, if you are using something like clocked LEDs or analog LEDs that require more than a single data line, this particular design will not work... but you might use the concepts to adapt for other LED types.

If you prefer to watch a video on this topic and see the step-by-step process for building the matrix, please watch: Building a Dual Controller LED Matrix.

Building a Matrix


 
400 WS2812b LEDs - 100 LEDs/m

For this article, I'll be using a DIY matrix composed of 16 rows of 25 WS2812b LEDs each.  If you want to see the step-by-step process of building this matrix (or one with different numbers of rows and columns), you can watch the above video.  I'll only briefly cover a few brief wiring points for those that may have arrived here from the video looking for a few more details.

Matrix Parts Used


I'm only showing the particular parts here for the matrix itself or specific parts for implementing dual controllers.  Naturally you'll need a controller (or two).  But I have separate videos and blog articles for building the controllers and those contain all the parts and step-by-step build processes for the controller.  You will find links to some of those controller builds below and at the end of this article.

Part or Item

Notes

WS2812b 60 LEDs/m – 1 meter length

This is from my original build. See video

WS2812b 100 LEDs/m – 1 meter length

The ones used for this project

JST Connectors

Optional

5V 15A Power Supply

For nominal 50% bright solid white

5V 30A Power Supply

To support 100% bright solid white

3M Double Sided Tape

 

18-gauge stranded wire

Gauge needed may vary based on length

22-gauge stranded wire

For connecting LED strips

3V Relay

 

Step-down Buck Converter

 

 

 


Matrix Wiring



Incoming power and the LED data line from the controller are wired to the beginning of the first LED strip (in the lower left corner for my design).  Additional 5V power injection is added to the end of the strip at the top left corner.

Remember that with addressable LED strips (or strings), the data only flows in one direction. This is always indicated in some manner on the strip itself.


For the initial incoming power/data connection, the data should flow away from the end of the strip as indicated by the arrows on the strip itself and as indicated by the above.  The strips will alternate data direction, so that the data flow will be in a serpentine fashion from the bottom of the display to the top.  On this end of the board (for my layout), that means you will be connecting 5V to 5V with the inner pads (red), the data out to data in (green) in the middle and the outer connection will be ground to ground (white).


On the opposite end of the display, and since the data direction is still reversing, the wiring connections will also be the opposite:  The inner connection will be ground to ground (white), the data out to data in remains in the center (green) and the outer connection is 5V to 5V.  Be sure you solder carefully so that inadvertent solder bridges are not created.


At the end of the final LED strip, two additional wires are connected to 5V and GND for power injection.  While the 400 WS2812b can theoretically draw up to 24A on full brightness white, it is unlikely that you will use something like a matrix for task or room lighting.  So I will be using a 5V 15A power supply for the matrix and to power the controllers.  I will use the current limiting feature in WLED (and also implement in my own custom code) to assure the LEDs do not attempt to draw too much current.

If you want to know more about working with LED strips, proper wiring, using power injection and more, take a look at the following video: A Beginner's Guide to DIY LED Projects.

Quindor over at the YouTube channel Intermit.Tech also has an excellent video on calculating power supply, number and location of power injection points and the wiring gauge that should be used.  It is worth a watch and how I determined the power supply size, injection points and wire size for this project: Calculate LED Strip Voltage Drop... 

Connecting and Using Dual Controllers


The first matrix I build (and shown in the above link) had a WLED controller.  This was well before WLED had matrix support and matrix effects.  So while the matrix got some use for special occasions or events, it was simply off much more than it was on... which seemed like a waste.  I had previously created a 3D printed clock that used custom Arduino code.


I started looking into a way to adapt that code into a matrix format where the matrix could become a clock (along with a scoreboard, timer and text display) so it would get more use and actually be turned on most of the time.  

But I also didn't want to lose all the features of WLED for those certain times.... nor did I want to recreate all of them in my own custom Arduino code!  So I needed to find a way to have two different controllers for my single LED matrix display.

Using dual controllers in the manner I'm going to show will work with pretty much any LED display that accepts a single data line... matrix or linear, 5V, 12V or 24V.

And you can pretty much use any firmware or software that can send an appropriate data signal to the LEDs.  This means that you can use an ESP8266 or ESP32 with WLED, an Arduino board with C++, a Raspberry Pi with Python, etc.

Because the technique will work with so many different types of controllers, I will not cover how to build the controllers themselves.  But if you want to know how to build a WLED controller, you can watch the following videos with linked blog articles which have all the wiring diagrams and parts lists:


For my example, I will be using an ESP32 Mini with WLED as the first controller (WLED Controller) and an ESP8266 D1 Mini for my clock/scoreboard/timer controller (Clock Controller).  As you will see, you do not even need to have the same MCU or microprocessor for your two controllers.  I could have just as easily used an Arduino board for one and and Raspberry Pi for the other.

If you do want to know more about the clock controller, along with how it is built and a larger version of the matrix using 60 LEDs/m, you can take a look at the following article:


Manual Switching Methods


While there are a few very simple ways to swap controllers for a given LED display, they are pretty much manual and in some cases simply won't work well due to installation issues.  One of the easiest to implement however, is to simply swap out the ESP controller:


You can either use a breadboard or mount pin sockets on your prototype board and swap out matching MCUs with different firmware or features.  Of course this means that you need to have easy physical access to the controller and must power down and restart the system every time you want to switch to a new controller or firmware.  It works... but not very convenient.

A slightly better, but still very manual method is to use a three position switch:

Click to enlarge

The data line from each of the controllers is connected to one of the outer switch poles.  Then the data line to the LEDs is connected to the center common pole.  When the switch is in the left position, as shown in the diagram above, the data line from the clock controller would be connected to the LED data line.  Similarly, when the switch is in the left position, the WLED controller's data line would be connected to the LED data line.  While this is an improvement to the controller swap method, as the system does not need to be powered down and restarted, it is still very much a manual process and also requires mounting of the toggle switch somewhere on the project, which may not be attractive or desirable.

The preferred method would be a method that was automatic or one that could be controlled via automation like Home Assistant.

Using a Relay


Relays are generally used to control a power circuit (DC or AC) with a signal from a microcontroller or microprocessor.  

Click to enlarge

A low DC voltage and signal can be used to control a different or much higher DC or even AC circuit.  The relay is more or less an "electronic switch" that we can control with an ESP board.


Because the controlled circuit side of the relay has options for whether you wish to wire it as a normally-closed (NC) or normally-open (NO) switch.  It also has the common terminal that you would use in conjunction with either the NC or NO terminal.  But we can wire up the two LED controller data wires to the two outer terminals and the data wire to the LED strip to the common terminal... much like was done with the three position manual toggle switch.

Click to enlarge

Instead of switching a power load, the relay will now switch the two controller's data lines, connecting one or the other to the LED data line.  The relay itself is actually also controlled by the WLED controller in this case, but I'll talk about that more in just a bit.

A few notes on selecting and using a relay

Relays normally have two ratings related to its capacity.


One rating is the amount of power that can be handled on the switched side of the relay... the side with the NC, common and NO terminals.  For the above it can handle switching a load of up to 250 VAC at 10A or 30 VDC at 10A.  Since we will be switching an LED data line at 5V (assuming you used a shifter to shift the data line up from 3.3V... you did include a logic level shifter on your controller, right?) and the data line will have negligible current, so this rating really doesn't matter.

However, the other rating is DC voltage required to both power the actual relay and the signal voltage required to tell the relay to open or close.  Since the GPIO pins on ESP boards output voltage at 3.3V, I opted to use a 3V relay.  But this also means that the relay required 3V to operate, in addition to the data line.  Of course most ESP boards have a 3.3V pin, but you'll notice in my diagrams I'm using a buck converter to step down the 5V directly from the power supply that is running the controller (and possibly the LEDs and other controller) down to 3V for the relay.  Why not just use the 3.3V pin?  Well, the relay can actually draw a fair amount of current. The ratings for this one said 500 mA, but in my real-world testing, I found it could pull closer to 750 mA.  This may be close to the maximum current that can be safely pulled via the ESP board... especially if you've connected other powered peripherals to GPIO pins that might also be pulling current.  I've had issues with relays struggling to energize for remain energized when powered directly off the GPIO pins.  That's why I highly recommend a separate buck converter (the one I used was rated for 3A... more than enough for the relay). 

Alternatively, you could use a 5V relay and power directly from the 5V power supply and eliminate the buck converter.  However, the relay would then also need a 5V data signal, which of course is only 3.3V.  So you now have to boost this data signal.  If you already have a logic level shifter for your LEDs and have an extra channel available, you can shift the relay signal using the same shifter.  

You will certainly see forum or other posts of people claiming that they successfully used a 3.3V signal on a 5V relay, or powered a 3V relay with 5V (and didn't fry it).  But best practices say you should always use the rated voltage with your components and assure all components are rated to handle the expected current.  But ultimately it's your components and your project, so YMMV.

Now back to the main story...

Switching options and techniques


As I mentioned above, not only am I switching the LED data line for the WLED controller, but I'm also using the WLED controller to control the relay.  If one of your controllers is using WLED, this is a very simply way to control the relay for switching since WLED has built-in native support for relays.


You simply connect the relay's control terminal to an appropriate GPIO pin on the WLED controller.  By default, the relay will then toggle based on whether WLED is on or off.

Click to enlarge

When WLED is turned "on", then the relay toggles automatically and connects the data signal from the WLED controller to the LEDs and the matrix shows whatever color or effects that are sent from WLED.


Conversely, when WLED is turned "off" then the relay automatically toggles to the other switch position and connects the other controller (clock controller running Arduino/C++ code in my case) to the LEDs.

Click to enlarge


Note: If the relay appears to be working "backwards", then you can either switch the NC/NO terminals for the two controllers on the relay, or check the 'Invert' box in WLED (which you see I did above).

Now whenever WLED is turned on, the matrix will show WLED from that controller.  When WLED is turned off, then it will default back to showing the clock.  No physical manipulation at the matrix required!

What's more, since WLED integrates natively into Home Assistant, that means the process of selecting the controller can be done via a dashboard or in automations.  Any time WLED is toggled on via dashboard control or in an automation, the relay will toggle based on the new state of WLED.  Nice!

Of course there are alternative ways of controlling the relay if you don't want to use the state of WLED... or aren't even using a WLED controller.

Click to enlarge

Instead of using the WLED controller, I can control the relay with my custom Arduino/C++ controller.  I can build logic into my code to control the relay by setting a GPIO pin high or low.  I could also include MQTT so that the relay could be controlled directly as a switch entity from Home Assistant.

Click to enlarge

Or I could even include an independent controller, like a D1 Mini with ESPHome, to specifically control the relay independent of the LED controllers.  This would also give me a native switch entity in Home Assistant that could be used from a dashboard or in automations to switch between the two LED controllers and determine which one is sending its signal to the display.

Alternate switching options


Of course there any many, many other ways to switch a signal between the controllers.  The relay is only one way, but it is low cost, simple to implement and has support built in to firmware like WLED and ESPHome.

Let me know down in the comments if you've used other switching methods to control a single LED display with multiple controllers.

Other Ideas or Implementations


One question that has come up (and I'm sure it will come up again!) is whether you could use this technique to add a WLED controller to a retail LED system... like the Govee curtain LEDs while also maintaining the original retail controller and features.  It may well be possible if the retail controller has a single LED data line that you can isolate and connect to a relay.  Then using the same technique as above, you can use a WLED controller to also control the relay and have both WLED and the original Govee controller functionality.  But carefully check and assure all voltages as it may be necessary to step up or step down voltages depending on the retail system.

Also let me know down in the comments if you've successfully added a second DIY controller to a retail system.  And as always.... thanks for reading!

Links and Additional Information


Videos:
How to Quickly Build Your First LED Controller (breadboard/no solder version)  

Articles and Sites:

Supporting this blog and related YouTube channel


It takes significant time and effort (and occasionally expense) to create these articles and videos.  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 consider buying me a one-off cup of coffee or two 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.