Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Christmas Village Control System, Using ESP32

For The Popcorn

Active Member
[Not trying to steal MrDEB's thunder....]

Last year, a very short time before Christmas, a friend asked if I could add some bang to his large Christmas village scene. "Sure.... oh wait, you mean THIS Christmas!" Fortunately, I had some boards I had made to drive LED strips and the parts to assemble them, and we were able to 32 groups of lights on a semi-random basis. My friend was thrilled with the results of the quickly created system.

There were a few shortcomings to the system, including the need to run a multitude of wires back to a central location and making all of the connections to 5mm terminal blocks.

I have been thinking of ways to make a more distributed system, where 'local' controllers would connect back to a central controller over some kind of network, possibly RS-422. Then the thought hit to use wifi-connected local controllers. This is even better than a wired network, as it would allow separate installations with no need for wires between them. I'm not sure what the control system between the boards will be yet – possibly MQTT, which is used for home IoT device control.

The Bah Hum board has an ESP32 NodeMCU devkit 1 module, an MCP23018 16-bit peripheral expanded and 16 N-channel mosfets to control the LEDs. The ESP32 module does have 18 I/O pins available, all of which support PWM, but many of the pins have shared functions and restrictions, so there always seem to be less pins available then you plan on. Using the port expander may also simplify control a bit. Sending a 16-bit word to each local controller will control the on/off state of all of the LEDs.

I did want some provision for twinkling/flashing/dimming some of the channels, so four of the port expander's 16 lines are connected to the mosfets via a quad AND gate with four of the ESP's I/O lines (capable of PWM). Global on/off control with the option of special effects.

In the upper left corner of the board is a DC-DC converter to supply ~300 mA to the ESP32 – it can draw a lot of current. The AP1509 can handle 24 volts maximum but I am planning on 12 volt power supplies.

The mosfets can each handle several amps. The entire board is limited to 10 amps, by the series reverse-polarity-protection diode. Reverse polarity protection is a good idea since the user is inexperienced. The downside of this arrangement is the maximum current draw of the board is limited by this diode.

If anybody has OCD, the rotated labels on R21 and R22 will be annoying. I didn't forget to align the labels. R21 and R22 are the 4.7k pullup resistors for the IC2 SDA and SCL lines. All of the remaining resistors are 10k pullup resistors, primarily for the open drain outputs of the MCP23018. Rotating those labels is a reminder when I assemble the boards. The PWM lines have pullup resistors to ensure the AND gates are enabled even if the PWM lines are not initialized.

Schematic_ESP Christmas Village V1_2022-08-04.png



PCB_PCB_ESP Christmas Village V1_3_2022-08-04.png


Notes_220805_093213_908.jpg
 

For The Popcorn

Active Member
I did make one change – instead of the series diode for reverse polarity protection, I changed to a p-channel mosfet circuit. The long and short of it is less voltage drop and power dissipation, and a beefier mosfet is cheaper than a higher-current diode. This increases the board current limit to upwards of 20 amps from 10 – this shouldn't be much of a limitation as finding a 20 amp supply would be tough.
 

rjenkinsgb

Well-Known Member
Most Helpful Member
It sounds like you are well on the way to recreating DMX512, the standard protocol for lighting effect control??

Isn't the ESP32 fast enough to do software PWM? I'd have expected it to be able to do a lot more than that.

Note that simple shift registers would be far faster for controlling low-side FETs; you can run them easily from an SPI port.

eg. a 74HCT595 can run at 20MHz+, compared to 400KHz (?) for the I2C expanders. The I2C expanders are nice if you need mixed I/O or special or configurable functions, but for simple banks of inputs & outputs you can't beat shift registers.
 

rjenkinsgb

Well-Known Member
Most Helpful Member
I wasn't expecting to be able to find one of these - a [rather battered] custom four channel AC mains light controller we did some time back. These run software PWM (phase control) at 256x half cycle frequency with a software PLL lock to 50/60Hz, on a 20MHz PIC16C73.

I'm pretty sure the ESP32 is more than four times faster, to do 16 channel software PWM? Challenge yourself!

IMG_7523.jpg
 

For The Popcorn

Active Member
The ESP32 will do 18 channels of hardware PWM. But if you've used the ESP8266 or ESP32, you will have found that the stated number of I/O pins can be misleading. Some of them, if connected during boot halt the process. Some of them output signals during boot. And some of them are used for flash memory.

I don't need to do anything very fast here – just control and flash some lights in a Christmas village scene (where 'some' might reach a hundred or more).
 

Nigel Goodwin

Super Moderator
Most Helpful Member
I wasn't expecting to be able to find one of these - a [rather battered] custom four channel AC mains light controller we did some time back. These run software PWM (phase control) at 256x half cycle frequency with a software PLL lock to 50/60Hz, on a 20MHz PIC16C73.

I'm pretty sure the ESP32 is more than four times faster, to do 16 channel software PWM? Challenge yourself!

View attachment 138125

Serious heatsink - did it need it?, or was it something you had to hand?.

I suspect the ESP32 is considerably more than 4 times as fast, they are pretty speedy things, but as 'For The Popcorn' said, they do have a number of I/O restrictions and limitations.
 

rjenkinsgb

Well-Known Member
Most Helpful Member
Serious heatsink - did it need it?, or was it something you had to hand?.
They were a long run we did for a customer to drive arrays of filament lamps, up to 500W or more per channel with phase control in some products, though most were used with much lower loads.

The heatsink is not all that big, it's an "L" shape with the opto triac drivers etc. hidden underneath; same series as this one:

Heatsink.jpg
 

rjenkinsgb

Well-Known Member
Most Helpful Member
The ESP32 will do 18 channels of hardware PWM. But if you've used the ESP8266 or ESP32, you will have found that the stated number of I/O pins can be misleading. Some of them, if connected during boot halt the process. Some of them output signals during boot. And some of them are used for flash memory.
That's why I never suggested hardware PWM, purely software.
The only hardware peripherals you need are a timer to create fast interrupts and the SPI port (or I2C) to output to the drivers.

If you make the software compatible with DMX512 at the most basic level, even if via another ESP on a serial port to buffer or broadcast for WiFi, there is a vast range of free lighting control software you can use to set up sequences, random changes or even music-reactive etc.

This is one of the classic christmas light show videos & that's done using DMX512 stuff:

 

Nigel Goodwin

Super Moderator
Most Helpful Member
They were a long run we did for a customer to drive arrays of filament lamps, up to 500W or more per channel with phase control in some products, though most were used with much lower loads.

The heatsink is not all that big, it's an "L" shape with the opto triac drivers etc. hidden underneath; same series as this one:

View attachment 138134
It's still a pretty big heatsink, losses in triacs are pretty low, so they don't usually need big heatsinks, and 500W per channel isn't a great deal. I used to replace a LOT of triacs in light units used in discos, when bulbs fail they commonly take out the triac on that channels. It was a nice little earner :D
 

rjenkinsgb

Well-Known Member
Most Helpful Member
They are convenient, and it makes the overall unit less prone to handling or shipping damage than with smaller flimsier ones.

It's also fused everywhere so pretty bombproof - and we always try to rate things way above the basic requirements to avoid failures in (mis)use.

We never had any warranty returns due to failed outputs as far as I remember.
 

Nigel Goodwin

Super Moderator
Most Helpful Member
They are convenient, and it makes the overall unit less prone to handling or shipping damage than with smaller flimsier ones.

It's also fused everywhere so pretty bombproof - and we always try to rate things way above the basic requirements to avoid failures in (mis)use.

We never had any warranty returns due to failed outputs as far as I remember.
PAR38's in particular were extremely prone to taking out TRIAC's, as with most incendescent bulbs they commonly go S/C as they blow - and special fuses (which 'might' protect the TRIAC's) cost considerably more than the TRIAC's did.

Nice heatsink though, and I'm fine with the extra mechanical protection it affords.

Oh, and the video was pretty spectacular! :D
 

For The Popcorn

Active Member
After talking to my friend, who explained "that several channels died and the ICs were too hot touch with only a few LEDs, but they worked fine when we switched them to another channel" (a few LEDs that should have drawn 10mA or less powered by motor drivers that could supply an amp or more), I decided I needed to add some additional protection.

First, I changed the reverse polarity protection to a p-channel mosfet that will support 25 amps, instead of the series diode that could only handle 10 amps. This should exceed the capacity of any power supply he might us.

Next, I added a TI INA219 power monitor chip to monitor current being delivered to the 16 channels. It will monitor current delivered to all the channels, but since I can control which channels are on, I can measure current supplied to each channel. During setup, I can monitor each channel and warn that a channel has too many LEDs connected. During use, I can periodically run through the channels, and shut off any that have developed excessive current draw.

Of course, a "simple addition" is never all that simple and a lot of things had to be moved to make room. The picture below is from a neat add-on to EasyEDA called iBom. On one side of the screen is a picture like this of the front and/or back of the board. On the other side of the screen is the BOM. As you click each row the part(s) are highlighted on the picture to make assembly easier.

PCB_ESP Christmas Village V1_3.0.F.png
 

Latest threads

New Articles From Microcontroller Tips

Top