Inspired by seeing Xmas-themed-PCBs on Twitter throughout November and December, an idea popped into my head. Two days later, I’d sent off a new PCB for manufacture.
Having previously experimented with reverse-mounted LEDs on my Skeletor badge, I thought they'd work really well in this fireplace design as flickering flames.
The fireplace has 12 LEDs mounted on the reverse of the PCB that shine through the FR4. They're controlled by an ATtiny25 (programmed using an Arduino UNO) and powered by a CR2032 coin cell battery (or optional external power source).
I sell assembled ornaments on Tindie if you're interested in buying one!
Features- PCB art!
- 12 reverse mounted LEDs
- 6 pre-programmed animations
- Automatic animation cycling
- Animation selection using the 'mode' button
- Power switch
- Programming header for hacking
- External power options (via programming header or JST connector)
The ornament has 6 pre-programmed animation modes. When the ornament is switched on, the animations will automatically cycle (approximately every 10 seconds). Pressing the 'mode' button stops the auto-cycling and continues to run the current animation. Further presses of the 'mode' button will manually cycle through the remaining animations.
The default animations are described below and can be seen in the video at the top of this article:
- Random LED blinking
- Blink LEDs in order
- Blink pairs of LEDs
- Blink a chain of LEDs
- Alternately blink the top and bottom rows
- Chaser
By changing a single variable in the code, it's possible to easily add variations of each animation that run at different speeds.
DesignUp until now I've only created a couple of 'dumb' badges (Clamps and Skeletor), I really wanted to tackle something meaty this time and design a festively coloured PCB that took advantage of the limited colour palette available.
Since I was struggling for gift ideas as I usually do, I thought I’d design some nice bauble PCBs to give to family and friends as presents. However after a trawl through Google Images for inspiration there wasn’t really anything that caught my eye, until I stumbled on these tealight holders:
I loved the look of this festive fireplace and an idea took root. Here's how the design came together in Inkscape:
Designing first in Inkscape is really handy as it allows me to easily tweak layers and play with colours. Part way throught I swapped the colour of the bricks with the mortar for more contrast.
This is probably the quickest I’ve taken a PCB from concept to finished-design. That’s mainly because I couldn’t stop thinking about it and grabbed every free moment over a weekend to work on it. The workflow was the same as for my Skeletor badge, designing the art in Inkscape and converting it to a KiCAD board using the svg2shenzhen plugin.
In order to allow the LEDs to shine through the board, I had to export the bottom copper layer back into Inkscape from KiCAD. This allowed me to position cutouts for each LED in the bottom soldermask layer. Fortunately I didn't have to re-position the cathode marker on the silkscreen layer.
This could alternatively be done by updating the footprint for the 1206 SMD LEDs that I was using, but since I was in a rush, I used the Inkscape method.
Here’s the finished design visualised in the excellent OSHPark previewer:
I always use the OSHPark viewer as a last check before exporting my gerber files. You can see in the above image the cutouts added for the reverse mounted LEDs.
Originally I was only going to add a handful of LEDs, but I ended up with 12 charlie-plexed LEDs – using up all the spare pins on the ATtiny. I happened to have a whole bunch left over from my Chronometer project which was an added bonus!
Since I didn't want to have any traces/vias on the front of the board the routing was a little bit difficult, but I started by routing pairs of LEDs at a time and finally had all of them hooked up. Resistors come in handy as I can pass traces through the middle of them, something I can't do with the reverse mounted LEDs.
This board is essentially just a bigger version of my Clamps v2.0 badge. However this time I’ve added footprints for an actual programming header and a LiPo battery connector. RSComponents came in handy for getting these and a quantity of ATtinys to me at short notice.
FabricationBrian Lough had had some issues with his first batch of Xmas Tree boards from JLCPCB (watermarks on the FR4 and product numbers on the wrong side) but given how well PCBWay handled the Skeletor badges I was fairly confident there wouldn’t be any problems. I’m always impressed with how quickly they turn around PCBs and a week after ordering, these arrived:
I always get nervous once I’ve submitted an order for PCBs, I seem to imagine all the ways that I could have messed something up. Apart from some of the silkscreen being a little patchy, these turned out exactly as I imagined, plus I ended up with an extra PCB on top of the 10 I ordered!
BOM- 1 PCB
- 1 ATtiny25-SSU
- 1 programming header
- 1 JST 2-pin (optional)
- 1 CR2032 battery clip
- 1 Power slide switch
- 1 Mode tactile button
- 4 150 Ohm 1206 resistors
- 6 orange 1206 LEDs
- 6 yellow 1206 LEDs
I used a mixture of RSComponents and ebay for these components.
AssemblyOnce I had the boards in hand, I couldn’t resist getting one soldered up. The trickiest part is probably soldering the 1206 LEDs upside down, but this was surprisingly easier after switching from my fine soldering tip to my chunkier one.
The trick is to load up one of the LED pads with solder and tack down that end of the LED. Then you're able to solder the other end of the LED without too much trouble. I tended to go back and add a bit more solder to the other end to ensure a good connection.
ProgrammingIn my Clamps 2.0 project, I left an un-populated header on the back of the badge. This proved fiddly and so this time I've added a male programming header.
This allows me to program the ATtiny25 once it’s soldered onto the badge. To do this I re-purposed my Arduino Uno and turned it into a programmer. This article proved immensely useful in figuring out the connections.
I had some initial teething issues with my code and ended up bricking one of my micro-controllers and ruining a board trying to replace it. Note to self, check your board connection is solid before trying to burn the bootloader.
Eventually though I got something working and spent the rest of the week adding animations.
CodeI'm a software engineer by trade, so I totally over-engineered the code for this. I really wanted to decouple the multiplexing of the LEDs from the code that was responsible for the animations. I began with code from my Clamps 2.0 project. This allows 15 brightness steps for each of the 12 LEDs (which just happen to be 4 RGB LEDs).
I had some issues translating this to work with the Fireplace (mainly because the code was designed to use 3-in-12 multiplexing rather than the 1-in-12 that the Fireplace uses). So I stripped it all back to allow just 2 brightness levels per LED (on and off) and I was able to get something working. I may revisit this once I’ve finished the boards I’m giving as gifts.
The code is partitioned as such:
- An interrupt service routine which is responsible for updating (on/off) each LED in turn.
- The main loop which for the current animation, determines the state of each LED.
This makes the process of adding animations much easier. Once I'd got this working I added the first animation, "random" mode. This animation simply turns on the LEDs in their electrical connection order.
The hardest task was understanding the layout of the LEDs. The silkscreen labelling wasn't consistent with how they were electrically connected which wasn't consistent with the 'logical' arrangement (displayed below).
In the end I added a lookup table to translate from the logical number to the electrical number.
As ever, the code is on my GitHub page. It’s great fun figuring out a concise way to represent an animation. All of the animations are parameterised to allow them to be easily modified.
Going a step further, a single variable can be changed to introduce speed variations to each of the animations. Did I mention I went a little overboard?
In order to keep the program size as small as possible, direct register accesses are used for setting up timers and toggling pins.
As a result of the multiplexing, the LEDs do appear a little dimmer than normal, but even running on a 3V coin cell with 150ohm resistors they look pretty nice. The LiPo connector and programming header add a few different options for powering the board.
Finishing TouchesI scoured some local craft shops to find some festive ribbon so that the ornament can be hung from a tree. Though as I found at work this week, a LiPo battery makes for a great kickstand!
The space on the back is a perfect place to write a message to the recipient.
ImprovementsThis little test run was great to work out some of the kinks with the project. Here are some things I’d change in a potential second version:
- Add a copper pour over the whole of the back side of the board. The FR4 was more translucent than expected and when viewed from the front, the right side of the board does appear slightly darker because of the copper pour on the bottom layer.
- Add some extra ‘LED circles’ to break up the areas between each LED.
- I was running short on time, so chose to re-use footprints that I’d had some experience with. But in this case a higher-profile tactile switch might have been better for the ‘Mode’ button.
- With the current LED wiring, I’m forced to use 1-in-12 multiplexing. A slightly different layout would have allowed me use 1-in-4 for brighter LEDs at the cost of more difficult routing.
- In the end the code came to 1360 bytes for the ATtiny25, it’d be an interesting exercise to try and squeeze this into an ATtiny13 at some point.
- The current header sits a little proud, a right angle programming header would solve this issue.
- Some extra labelling on the silk screen for the programming header and battery terminals would make hacking the ornament a bit easier.
Despite leaving it a bit late, I had intended to sell a few of these on Tindie, but in the end I decided I didn’t need the added stress of getting more of these soldered up right before Xmas. I did get them on Tindie eventually so if you fancy an early Xmas 2019 gift for somebody, you can find them here.
Comments