Browsing posts in: Electronics

Backyard controller design #4 – Software

The controller software lives here on github. My current software development environment is Visual Studio Code with Platform IO installed on top of it. It’s quite a bit better than the Arduino IDE for my usage patterns.

I’ve done my best to build a flexible and well-abstracted design. With the exception of main.cpp, all of the C++ classes are written in the include (.h) files so that I don’t have to deal with multiple files per class.

Here are the classes and a brief description of what they do:

  • Action – takes in a textual description of an action (on, off, toggle, plus some dim levels) and converts it to a numeric value. This is a nicer pattern to use than an enum as the parsing code can live here.
  • Device – an abstraction for a device that I want to be able to control. It has a text name, a group name, an output pin, and a timeout (in 10 mS units). If you pass it a name and an action, if will implement that action if the name matches either the text name or the group name of the device.
  • HardWiredController – the physical controller (not yet built) has a group of switches connected via resistors to the input line, giving a varying voltage based on which switch is pressed. This code uses the ADC in the ESP to get the current value, figures out what button was pushed, and performs the appropriate command.
  • Main.cpp – the main setup and loop code. Mostly just delegates out to other classes.
  • MainPage.h – the text of the web interface page for the controller
  • Manager.h – the manager for all the devices. It creates an array of devices and then handles dispatching commands to them, getting status strings, handling timeouts, etc.
  • OnIfAnyDevice.h – the 12V power supply needs to be turned on if any of the lights are on. This class looks at the state of the devices passed in through the constructor and turns itself on if any of them are on.
  • StairSensing.h – The program needs to turn on the house lights if the stair lights are turned on. This code tracks whether the stair lights have been turned on and switches the house lights on and off as necessary.
  • WebServer.h – The code that handles requests for the UI page and url action commands.

The main loop runs with a 10mS delay so that every time through the loop is roughly that long; that is needed to implement the timeouts in the device class. I could have done this in a more sophisticated manner but what I did is clear and good enough for the requirement.

The Manager and Device classes warrant a bit more discussion. They are use a software pattern called “Chain of Responsibility”; there are basically 5 devices that all look alike, and the manager just passes the action through to all of them and the device that the action belongs to deals with it.

This vastly simplifies the manager class – otherwise it would have to check every string and figure out which device to pass it to – and makes it really easy to implement group devices; the “lights” group refers to all light devices. It also makes it easier to implement the OnIfAnyDevice class, which otherwise would have required special case code.

Backyard controller design #3–Board & construction

In our last installment, we were trying to decide whether to hand-wire the controller or to go with the PC board. The PC board won out handily since it only cost $13.30 for the standard 3 boards from OSHPark.

Here’s a picture of the board with populated with the 3 MOSFETs and 5 resistors. I did the solder paste application by hand since I only need to do one of these. Standard solder-paste since the MOSFETS may switch up to around 8 amps and therefore may get a bit warm.


And here’s a picture after the reflow. Reflow done in my Controleo 3 toaster oven reflow-er. Looks just fine.


One little comment: One problem I had during layout was how to connect the top pin of the MOSFETS to ground in a way that could flow enough current from the front to the back. My first design started with a number of vias, but I didn’t like it. Then I realize I had an easier solution; I just use a single through-hold pad and hand filled it with solder. It will carry far more current than I need.


In my original concept all of this was going to fit inside of a double-gang electrical outlet box, but I realized that a) I’d rather mix as little low voltage and line voltage as possible and b) the box I used was only half-depth, so no room. Which argued to use a box and mount it to the house. Here’s the one I chose:


It’s a good size and has mounting bars. I don’t really need the gasket because I’ll be cutting holes for the wires. $11.60.

The next order of business was to figure out how to connect the big 12-gauge lighting wire to small connections on the board. I am lucky enough to have a good local Electronics store 15 minutes from my house (if you are in the Seattle area, Vetco is worth a trip), and that yielded a couple of terminal strips:

I think I bought two for $4.99 each, plus I bought some 18 gauge wire to go from the board to the strip (the big holes on the board can only support 18 gauge. Which led to this:


Those are all of the connections that take big wire, and the terminal strip color-coded with Sharpies.

Yes, I know I messed up the sequence; the 12V in at the lower right portion of the board really wanted to be there for each connection to the three 12V outputs. And it turns out that the wemos nodemcu layout I used was upside down, so the ESP-12 is hiding underneath the module rather than on top of it. There are female headers soldered to the board and male headers soldered to the nodemcu board. This allows me to easily remove it for reprogramming. Which was already required a time or two.

I used the same technique for the remaining controls I needed but they don’t map 1:1 to the board.


Here’s a few steps at once. I found an MDF cutoff and used that as the back of the board, and the screws that mount it also mount the terminal strips.

On the upper right terminal strip we have 120VAC coming into the box; that connects to a 5V power supply. There is a small 2AMP SSR that I had lying around that will switch on the 200  watt 12V power supply when it is needed. The “Pump on” output will connect to a similar SSR in the remote electrical box.

I did a full test of all the features, and they all worked. Well, except for the switching for the 12V power supply, which was broken by a refactoring I did in the software.

Umbrella lights

We have a shade umbrella with some chair under it, and one of the requirements was to have some light underneath it. I didn’t find any premade ones that I liked, so I bought 5 meters of 12V led strip and made my own. I made 8 strips that were 16” in length, attached wire, shrinkwrapped them, and then hooked them all together to a single supply. I only took one picture during construction:


But I did get this picture of them in operation:


Box installation

The box got installed on the wall and the various wires were hooked up.  This is under my covered kitchen deck so there is no real chance of any water getting in.


The AC comes in from the far right; that is a 15’ extension cord that plugs into a GFI with an in-use cover; directly under that is the 12 volt 16.5 amp power supply which then feeds back into the 12V input for the board. The red/white wire carries a 5V signal to the SSR in the electrical box that controls the fountain. The three main loads are hooked in along the bottom.

There are two things missing in this picture; the 12V line that used to run the stair lights is not hooked in, and the stair lights are not connected into one of the existing lines. It turns out the transformer for the stair lights does not put out 12V with no load; it puts out 17.3V. I did a conservative design on the board that would support 15V without damaging the ESP, but 17.3V was too much. I therefore built a small in-line voltage divider and used that to connect the stair lights in.

As of now, everything works fine delta one bug that I am chasing down.

I’ll write up a post about the software next.

Backyard controller design #2–schematic and board layout

My original plan for the controller was to do all the wiring by hand on a perfboard (“old school”); it’s not that complicated and I wouldn’t need to wait for a board. But I decided to do a pcb board to see how much it would cost and because I wanted an excuse to try out Kicad 5.0.

I started with the schematic:


We have the Wemos D1 mini (clone, actually) in the middle, with 5 outputs (PUMP, 12VPOWER, HOUSE, BED, AND UMBRELLA), and two inputs (STAIR_SENSE and controller). If you haven’t seen labels used in a schematic before, every pin with the same name is logically connected though there is no wire drawn between them.

On the right we have three drivers for the landscape lights using the NPN transisitor/MOSFET circuit I discussed in the last post. All of those outputs connect to the 6-connector header (screw terminal) strip.

On the upper right, the Wired_Controller1 header will be for a (possible) hard-wired controller for the lights and pump. It’s connected into the analog input of the ESP. In the actual handheld controller there will be four switches hooked across a voltage divider so that the switches will give 1V, 0.75V, 0.50V, or 0.25V when pressed. The ESP code will figure out which switch was pressed and therefore which action to take.

In the middle is the AC_Switching1 header. It contains the two outputs to control the remote solid-state relays for the pump and 12V power supply. It also contains the 5V and ground from the 5V power supply that will run the ESP.

On the left we have the parts for the stair light sensor. We have a voltage divider that will convert from the 12 V that will come in to a value that the ESP can tolerate. There was a bit of calculation there. The valid ESP8266 input voltages range from 2.5V (for the lowest guaranteed high value) to 3.6V (the maximum input without damage). We want to choose the voltage divider ratio to work well within that range.

My first choice was to use 330K for the upper resistor and 110K for the lower one; that would give a 4:1 ratio. That would put the lowest guaranteed high value at 2.5*4 = 10V, and the highest tolerable value at 3.6*4=14.4V. I decided I wanted a bit more range on the high side, so I opted from 330K and 100K resistors, giving a 4.3:1 ratio, and a voltage range of 10.75V to 15.5V. I considered overvoltage protection, but given the ampacity of the supply a simple zener likely wouldn’t be enough and I would need an SCR crowbar to handle overvoltage. I decided to skip it in this version as the power supply is a regulated one.

That’s all for the schematic; not really that sophisticated. Oh, the NPNs are really 2N2222; I chose the 2N2219 because it already existed.


Here’s the board layout. It’s a weird mix of through-hole and SMD components as I already had both the MOSFETS and the NPN transistors. I started with the header for the landscape lights because they will be pulling some hefty current; that meant I wanted to keep the traces short, and it also meant that I wanted to put the 12V in nearby in the upper right. The controlled where the MOSFETS ended up, which controlled where the NPN transistors and their resistors ended up. I reordered the output pins on the header so that they matched the order of the output pins on the ESP module; I could have remapped the pins as well but this was a bit simpler. The AC switching header also got re-ordered to make the connections simpler. And then I tightened things up a bit to minimize the size of the board. At that point, it was about $20 to do a board from oshpark, which was pretty much the cheapest I could find.

That’s relatively cheap, but I’m not excited about having to wait for it to make it back to me. The footprints for the screw terminals is not based on a header that I have; I bought some terminal strips before I decided to do a board design, but I need to buy some better ones for this sort of design. I need to get real terminals so I can get real dimensions, and I might see what I can do with all SMD devices; smaller terminals and transistors could cut the size of the board by 25%.

Two more things to mention. You’ll notice that there is not a copper pour for the ground. It’s probably not required for a board operating at these speeds, and I would have to be careful around the ESP8266 antenna because having copper underneath it would mess it up.

I did another layout with through-hole resistors in case I wanted to hand build it:


Back to the problem in hand… If I was willing to wait for a PCB to show up, I could wait for some new MOSFETS and transistors, and that would certainly make things smaller. So, I went MOSFET hunting, and I found the IRLR7821PbF, available in a TO-252AA package at $6 for 5 MOSFETS. Sound good.

I pulled up the datasheet and started reading. It’s pretty similar to the IRLB8721 that I had currently specified, but on Page 2 I found the output characteristics graph:


Looks like the one we saw in the last post, right? Except this this one starts at 2.5V and 2.7V curves. Looking at the 3.0V curve – to be conservative – and we see that with 10V drain to source, we can get a little more than 10 amps of current at a junction temperature of 25 degrees. At 3.3 volts, it’s closer to 12 amps.

What that means is that we can drive this MOSFET directly from the ESP8266. We can lose the NPN transistors to drive the MOSFETs plus one of the resistors.

So, off to do a new design with this MOSFET. I decided that I’m going to mount the board, run wires from the board to some terminal strips that I have, and then hook the real wires to those terminal strips. That will make it easier to hook up and I can make the board smaller so that it will be cheaper.

After a lot of iteration, here’s what I end up with:


It’s about 30% smaller than the original board; part of that is done by letting the ESP board overhang the end of this board, but they will both be in an enclosure (3D printed, I think), so there’s no harm in that. All of the heavy current stuff is contained on the right side of the board.

I first head to OSHPark, which tells me the board is 48mm x 37mm. That’s less than half the size of a credit card, so, tiny. They will make me 3 boards for $13.30, and oshpark does really nice boards, with an ENIG finish, but they take a couple of weeks to show up. I head next to and find nobody cheaper, except I used them for the boards in my dodecahedron and they’ve done good work, and I can get 5 boards in 5 days for $10, shipping included. They must be blackmailing DHL to be able to ship so cheaply.

I’m trending towards OSHPark since I need to order the new MOSFETs in anyway.

Backyard controller design

I’ve done a lot more work on the backyard controller design and things have firmed up.

Here’s what it looks like.

First, I don’t think the 100 watt power supply I bought is going to cut it; I have 36 watts on the ground and 40 watts on the house, and we’ve added tree accent lighting, fountain accent lighting, and I think I’m going to include some existing stair lighting on this. Oh, and some umbrella lighting. That would put me close or slightly over 100 watts, and that doesn’t leave any margin for losses in the wiring or a power supply that doesn’t quite do what I think it’s going to do.

The project is going to be split into two modules.

The first will live in the duplex outlet and will consist of the SSRs to drive the pump and the power supply and a 5V power supply for the NodeMcu. I have some nice thin 2 amp SSRs that will do nicely for those two loads and I’ve verified that they work fine on 3 volts (they worked okay on 2 volts in my tests), and my current plan is to hot glue them to the back of a split duplex outlet. One outlet will be used to plug the 12V power supply into, and the other will be back wired to connect to wiring that goes to the outlet next to the water feature. I *might* go hunting for some beefier SSRS, but the good ones are unfortunately expensive and the cheap ones have a bad reputation.  So, we’ll see. The ones I have are fine for those applications but if somebody plugs something beefier things will not work well.

The 5V power supply will be just enough to run the ESP; an amp will be fine. And yes, I’m going to break code and mix high and low voltage in the same box, but I will do my best to do it sanely.

From that box I’ll run some 4-conductor cable out. It will have:

  • +5V
  • GND
  • 12V ON

That cable will run to the second box mounted up underneath the deck. It has the following inputs:

  • 12V power (from the power supply)
  • 12V power (from the existing stair lights)
  • +5V / GND

And the following outputs:

  • 12V stair lights
  • 12V bed lights
  • 12V house lights
  • 12V ON

Maybe I’ll add in the under-umbrella lights as a separate circuit; the extra components are cheap and it would be nice to have separate control there.

My current stair lights are controlled by a switch in the garage and a power supply there. I originally thought I’d use a 12V relay to either power them from the garage or this controller, but it’s easier to just sense the 12V in the new controller and power all of them from the new power supply.

The MOSFETS I have are IRLB8721PbF, which are reputed to be decent for logic-level switching… Let’s take a look at the data sheet:


What I’m trying to figure out is what sort of current I can expect if I drive them from the ESP8266 pins. My drain to source voltage is 12 volts, so I’m looking at the right side of the curve, and I’ll pick the 3.0 V curve to be conservative. And that shows me that I can get around 10 Amps, which would be 120 watts. With 200 watts planned, I’d only pull 100 watts or so, so it looks like I’m close but okay.

But… Take a look carefully at that graph. See where it says “Tj = 175 C”. Yeah, that’s hot, and it’s the absolute maximum temperature, which means I’d really need some heatsinking or other cooling. The whole point of a nice power MOSFET is that they have low R(DS) resistances and therefore don’t get very hot. Which is not true if you are only driving it with 3V. This is the “if you’re stupid” graph.

There’s another graph in the datasheet:


Notice this one says that it has a junction temperature of 25 degrees centigrade. Which isn’t even body temperature. But, to get that from a 3 volt drive, I can only pull 3 amps.

What that really means is that I could easily build a test circuit and have it work great with my test loads of 30 watts or so, and then install it and hook it up to a 100 watt load and it will melt. Which would be bad.

The graph gives a really simple solution; instead of driving it with 3 volts, I need to drive it with something high. Like – I don’t know – maybe the 12 volts that I already have in the circuit. The graph only goes to 10 but if it went to 12 (insert Spinal Tap reference here), we’d expect that it’s pretty much the same. And it shows that we could do upwards of 100 amps from this device in that situation.

We can’t; the maximum continuous is 62 amps, but we can easily pull the 10 amps that we need. And the datasheet also tells us that at 10V(GS), the R(DS) is 8.7 milliohms. So, at a 10 amp current, that means the voltage across the MOSFET will be 0.087 volts, and it will dissipate 0.87 watts. A bipolar transistor here would drop 0.6 volts and dissipate 6 watts, which you would definitely need a good heatsink for.

MOSFETS do see increases in R(DS) as they get warmer. I am *probably* okay, but I’ll also probably put a small heatsink on the MOSFETS anyway and do a little testing overnight to see how they are pushing that much current. Or I could do the thermal calculations to see how much junction temperature rise I can expect.

Or… I might get lazy, and run two of them in parallel. Another nice thing that you can do with MOSFETS that is problematic with bipolar transistors. Bipolars have positive thermal coefficient, so if one gets hotter it pulls more current and things rapidly go downhill. MOSFETs does the offset, so you can generally put them in parallel with no problems.

So, how do we switch it with 12V? There are numerous MOSFET gate drivers out there that are designed not only to use a higher voltage but push enough current to be able to switch quickly; MOSFETS do not technically draw current but they do have gate capacitance so you need to pull some current to get them to switch quickly. That’s really important if you are building something like a switching power supply that you are switching at a relatively high frequency, but for my application, all I need is on and off and it doesn’t have to switch particularly quickly.

So, I’m going to go old school and use a small signal bipolar transistor to switch the gate.


The schematic comes from here. It’s really simple; when the logic input is low, the transistor won’t be conducting and the pull-up resistor will pull the gate high, turning on the MOSFET. Turn the transistor on by flipping the logic input high, it pulls the gate to ground (well, to 0.6 volts, which is close enough), and the MOSFET will turn off. It does invert the signal, which is a bit inconvenient but not really problematic in this case, as the 12V is only there is the power supply is turned on.

Pretty much any NPN transistor will do; I have some metal cased 2n2222s in my box, so that’s what I will use.

The only remaining part of the hardware is the sensing circuit for the 12V coming from the current stair light power supply. That’s pretty simple; take the 12 volts in, run it through a simple voltage divider, and I’ll get 3 volts to feed to the ESP.

All this is going to get hand-wired on a breadboard; there’s no reason to do a PC board for this application. I think the connections will all be screw-terminal barrier strips as they work well with the beefy 12 gauge wire for the low voltage lights.

I’m also going to build a small remote that you can use inside so you don’t need your phone to do the switching.


The software will be based on the ESP8266WebServer class, with a simple method to query the current state and separate methods to do the switching. I’ll do turn on, turn off, and toggle methods to provide some flexibility.

I recently switched to VS Code and Platform IO; it took some futzing to get it working, but the experience is so much better than the arduino IDE, and it knows how to create an ESP project that works out of the box. I have the bare-bones http server running for this; I don’t expect the full code is more than a day’s work if that. Oh, and I’ll do a web-page interface as long as I’m doing it.

I haven’t done anything on implementing the advanced functions based on sunset times etc., though I will probably implement auto-off for both the fountain and the lights.

Backyard controller requirements…

We’re in the process of doing some new landscaping in our back yard, and that involves a small fountain and some landscape lighting. Which of course brings up the question obvious question:

How are you going to control the fountain and the lighting?

Here are some initial requirements:

  1. There are three separate circuits of control; one for the fountain, one for the landscape lighting in the main beds, and one for the new general purpose lighting that will be mounted under the second floor eaves (the current lighting is big floodlights that provide really harsh illumination.
  2. The fountain is 120VAC; the landscape lighting is going to be low voltage.
  3. We need an easy way to turn each of them on and off.
  4. We would like to be able to have them function automatically on some sort of schedule.
  5. It would be nice if the schedule is tied into our light dark cycle automatically; I am far too lazy to remember to adjust them by hand.

The main controller will be based on a – no surprises here – an ESP8266 NodeMCU controller running a hacked-up variant of my animation software. The landscape lighting is going to be LED, which gives the following control requirements:

  • Two AC circuits – one to control the fountain, and one to control the power supply for the landscape lights.
  • Two DC circuits to control the two landscape light circuits independently.

The AC control will be done with a couple of solid state relays that I salvaged out of earlier holiday light projects. The DC control will be done with some nice power mosfets. I should be able to drive both directly from the controller.

All of this needs to fit in one half of an outlet box. I’m not sure the form factor; I’m thinking that I’m going to 3D print a box for the electronics, but how it fits into the duplex box is tbd. I *might* put override switches on the box so that if you want to you can just press a button to turn the lights on for an hour.

And you can take the underground conduit for the pump outlet and the wire for the landscape beds as “already implemented”.

Here are the parts that have already shown up:

A 100 watt 12V DC power supply. It claims to be IP67 waterproof. The “6” means that it is “Dust Tight – No ingress of dust; complete protection against contact”. The “7” means “immersion up to 1m – ingress of water in harmful quantity shall not be possible when the enclosure is immersed in water under defined conditions of pressure and time (up to 1 m of submersion)”.

IP67 rating is impressively good. If it were true, I could drop this puppy into the fountain reservoir and it would keep running…

Alas, it is unlikely to be true; the ratings for much of the stuff out of China are hit and miss, with a bit more on the “miss” side of things. Which is why it’s going to be mounted up under the kitchen deck where water won’t be able to get to it.

I should call these “ubiquitous 10 watt low voltage LED lights”. I have a bunch of these at my cabin, and they are pretty well made; nice heavy aluminum housings to get rid of the heat, decent mounting options. This go about 18’ up in the eaves to project a nice smooth light down on the yard. I bought 4 of them.

Image result for leonlite pathway garden light

These are the pathway lights. I spent a lot of time trolling the chinese marketplace sites (aliexpress/alibaba etc.) looking for some decent lights that were cheap. What I found is that you can either buy high end lights that are $45 each, or you can buy part of an endless supply of really cheap and crappy solar lights, but nothing in between. So I settled for these from Amazon. The Amazon product is not linked because it has changed underneath to some other lights; suffice it to say that I bought 12 of these for about $13 each. These will be spaced out in the beds to make them look all pretty-like.

Astute readers will note that I’m using 36 watts for the pathway lights and 40 watts for the floods (or only 30 if I only put up three). That leaves me about 25 watts to spare. Some may go to accent lights on the north fence, and others might go for some lighting to help get to the hot tub. If I was smart, I would have gone bigger than 100 watts, but that can be replaced if necessary later on.

This is a nice little power MOSFET that will be switching the landscape light circuits. Why this MOSFET? Well, let’s look at the datasheet.

First off, MOSFETS are far nicer to use to switch loads than bipolar transistors. Bipolar transistors have significant downsides; you need quite a bit of current to switch big loads (the overhead lights will be about 3 amps) or you need darlington transistors, and because of the fixed collector/emitter voltage drop, you lose a lot of energy in the transistors, and they get hot.

This little MOSFET will happily switch 44 amps @ 10 volts and 100 degrees C, which is *way* more than it will ever see. It will switch 3 amps with 3 volts on the gate and 11 amps at 3.5 volts; the ESP runs at 3.3 volts so it will be enough to switch the current I need (if I needed big current, I’d need a bipolar driver in front to push the voltage higher). And – like most power MOSFETS – it has very low resistance between the drain and source (8.7 milliOhms with 10 volts on the gate). What that means is that it dissipates almost no energy as heat when on, and I can run it without a heat sink; it will at most get very slightly warm. And it also means I’ll send a full 12 volts out to the lights.

I guess I could also show the big 200’ roll of landscape cable. In the old world of incandescent lights, I would have needed to power these lights with a loop or maybe multiple wiring runs; in this world, the floods have their own power supplies so the voltage to them isn’t critical and the path lights don’t pull enough power to result in much voltage drop.

For the box connections, I’m thinking I will probably go with some molex connectors; that gives me a fairly safe way to hook up the AC to the power source and that way I can disconnect the whole module.

Easy PCB stencil creation and alignment

I have a product that I’ve just started selling; it’s a LED globe/Soldering challenge kit that looks like this:

It has a PCB that looks like this:


For my first run, I needed to make 10 kits, and each of them has 12 of these boards, so that’s 120 boards.

I’ve been hand-soldering the prototypes, but it takes quite a while and my eyes aren’t as good as they used to be. I just built a reflow oven based on the controleo3 kit so that I can reflow in cases like this.

Which means I need a stencil. I could easily just order one up, but that means I’m going to have to align this tiny stencil with the board 120 times. Doesn’t sound like fun…

What we need is a way to apply solder paste to a set of boards in one shop and make it repeatable. In the woodworking world, that would call for building a “jig”, or perhaps a “fixture”. Which is what this post is all about; we’re going to use a laser cutter to make all of this oh so much easier.

Teaser photo

Here’s a teaser photo of what we’re going to build:


Get your board outline and paste mask in SVG format

Since I’m doing my design in Kicad, this was really easy; just go into your design, click the plot button (like you would to create Gerbers), choose the F.Paste and Edge.Cuts layers, and set the plot format to SVG. That’s it.

Well, actually, you should probably modify your paste cutouts to be a bit smaller than they are by default; see this excellent reference for how to do it in Kicad.

If you are using a different package for your design, search online for how to make stencils from it; it will tell you how to export.

Create a combined image in Inkscape

The export give us two separate files; one has solder pads, and the other has the board outline. The first step is to combine them together.

Open both images in Inkscape. Change the color of the edges to blue and the color of the pads to red. We do this so we can control which ones get cut and which ones don’t in the laser cutter.

You do have access to a laser cutter, right? Because if you don’t you’re wasting your time.

Anyway, that gives us two instances of Inkskape:


We now need to combine those two together in another image.

Create a new document in Inkscape with File->New. Go to the pads Inkscape version, do a Select All, then a copy. Switch to the new document, choose edit->paste in place.

Repeat the operation with the edge cut Inkscape version.

If your are of true character and have a pure heart, you will get the following:


Edit->Select All, then Object->Group. That puts this all together into a single object.

Save the document away with a catchy name like “Combined”. We now have the image for a single board.


We now need to create an array of objects; in my case, it’s going to be an array of 4 wide and 3 high. We’ll start with the four:

  • Select the single object.
  • Paste it three time. Line them up approximately. It doesn’t matter like this.
  • Bring up the align and distribute menu. You will never find the icon to do this, so try CTRL-SHIFT-A. Hover around until you find a icon that says “align top edges”, and pick it.
  • Distribute the empty space using “make horizontal gaps between objects equal”.
  • Mine looked like this:


    Those are way too close together for me. Undo the distribute, move one of the edge ones out, and redo the distribution.


    That’s better. The actual spacing is up to you. Group them together and save.

    We’ll do the same thing for the rows; create two copies, align the left edges, and then distribute:


    Save. Looks like we’re done, right? Not quite, there’s one more thing to add:


    This will work fine, but we would have to hand-align the stencil with the boards, and that’s going to be a bit of a pain to do. What I want is a way to make it repeatable.

    The secret is pins. Pins, I say!

    A trip to my local hardware store yielded two 5mm shelf support pins. They are likely longer than I need and I might cut them in half for my usage. They look like this:


    We are going to use them for alignment, which means we’ll need some 5mm holes.

    Flip back to inkscape, and draw a circle. Pick the selection tool, and up under me menu bar, you’ll see the width and the height. Set both to 5mm:


    Set the fill color to full green, set the stroke color to black, flip over to the stroke style, and set the width to 0.1mm. It should look like this:


    Put this one to the upper left of your objects, copy it, and put the second object to the upper right. It should look something like this:


    Note that it doesn’t look that great. That’s okay, we will fix that now.

    Draw a rectangle from one corner of your objects to a point spaced away; this will be the pin location. Something like this:


    Then drag the circle so that it is at the corner:


    I call this “using a gauge block”. Move the rectangle to the other corner and use it to align the other pin as well, and then delete the rectangle. They don’t have to be symmetrical for the technique to work, but I like things to be regular.

    I ended up with this:


    Why so many items and so many colors? We will use them in the cutting process.

    The jig that we created will be a sandwich of different materials; from bottom to top they are:

  • On the bottom will be a piece with only the peg holes cut into it; we will use the black circle outline for those cuts.
  • Next up we will have a piece with the peg holes and the edge cuts, so we will cut both black and blue.
  • Finally, for the top, we will cut the actual stencil; it will have the circles cut for alignment and the solder pads.
  • There’s a bit more complexity than that; I’ll talk about it when I get to the actual cutting.


    The goal of making the fixture is to make laying down the solder paste easy, so the materials need to be chosen carefully.

    My PCB house says that they material they use is 1.6mm thick. I don’t trust material thicknesses, so let’s check:


    That’s pretty close, just a 0.04 mm thicker than I expected.

    For the main parts of the fixture, I needed something that was fairly rigid, fairly cheap, and the right thickness. I thought about hardboard but decided to go with what is called “chipboard”; I’m not sure why it is called chipboard because it’s just very compressed cardboard, the kind you find at the back of tablets of paper.

    After looking it locally in vain, I ended up heading to Amazon, where I came across this:

    Grafix Medium Weight Chipboard Sheets, 12-Inch by 12-Inch, Natural, 25-Pack

    Grafix Medium Weight Chipboard Sheets, 12-Inch by 12-Inch, Natural, 25-Pack

    25 sheets was more than I needed by about 24 sheets, but it laser cuts well and is decent for prototypes.

    The thickness isn’t listed in the specification, but that was one of the questions asked, so I looked at the answers and found that is was:

  • 1/16th of an inch at most
  • .057” (1.45mm) (from the manufacturer)
  • Almost exactly 1.5mm per board, determined by measuring a stack
  • 2 mm
  • It’s nice to have some many helpful answers. I could probably make most of those work, so I ordered it. It showed up, and what did I find?


    So, the correct answer was “none of the above”. It is notably a full 0.1mm thinner than what the manufacturer says. I’m not sure that just means there is more variance than the manufacturer says or they are just going thinner. Luckily, I can work with that thickness

    For the actual stencil, there were a few choices. You can cut them out of Kapton or out of Mylar. I went looking for Kapton in the common stencil thicknesses of 3 or 5 mil and didn’t find anything that looked good and cheap. So, looking at Mylar led me to Amazon, where I found 4 mil mylar, also in a package of 25.

    What is the mylar thickness?


    A quick bit of conversion shows me that the sheet is just over 3.8 mils thick, which is fine.

    Materials in hand, I headed out to my workroom where the glowforge lives to do some cutting.

    Some cutting remarks

    First up was cutting the mylar. The Glowforge has a significant bit of airflow to pull fumes out, and 4 mil mylar would blow right off the crumb tray, so I used ceramic magnets to hold it in place.

    One of the problems with mylar is that when you heat it up it tends to shrink. Since the holes I want to cut are rectangles, the laser head needs to stop at each corner, and at least on the Glowforge, it doesn’t do anything to the beam, so you will get a lot of power right at the corner. Maybe we could break the rectangles into two cuts and carefully manipulate the laser power, but I’m not that confident it would work. If you want to cut it normally, I would recommend trying low speed and very low power.

    Luckily, there’s another option. We can do a raster engrave of the squares and just ablate away all of the material in the middle. This avoids the “stuck in the corner” issue, and since the power level is fairly low and the start and stop is done by turning the laser on and off, there should be fewer issues.

    The right way to do this is to put a piece of paper under the mylar and figuring out what power and speed settings cut through the mylar cleanly but barely touches the paper. I grabbed some settings from the Glowforge Forums and used those.

    For the mylar, we are engraving the red paste mask part of the design and the green circles. The blue board outlines are disabled


    This is the first row being engraved. You can see that there is a little sloppiness in the outlines, but in general they are pretty much all the right size. Here’s the final sheet:


    The stencils look like what I expected and the 5mm holes look appropriate as well. Maybe this will work after all…

    Next up was cutting the top piece of chipboard with the board outlines. The board outlines are turned on in cut mode, the circles are switched to cut mode, and the paste mask is turned off.


    I previously did a proof of concept on this step, so I knew it was going to work. Nice clean cuts.

    And finally, the base cardboard piece. All it has is the circles, so it looks like the above picture with just the circles.


    Sandwich time!

    We start with the base.


    And then add in the 5mm pins. This posed a bit of a problem; the pins have a nice chamfer on the end so they didn’t stick into the cardboard very well. I solved this by cutting one of the pins in half with a dremel and an abrasive wheel. I should also note that at 4.96mm, they are just slightly undersized.


    So, it turns out that the 5mm holes aren’t quite 5mm in size; they are just a bit smaller so I need to force them in a bit. A friction fit is good, but a forced fit is less good. This is exactly the sort of stuff you learn if you do test cuts. Well, perhaps version #2…

    Adding in the board layer, which aligns quite well with the bottom layer. And the boards fit with just a little bit of movement, which is just about perfect. They are proud (above the surface) by about 0.3mm, which I determined by math. That will probably be okay, but if I want/need it to be closer, I can easily shim it out with some mylar, which at 4 mil is almost exactly 0.1mm thick.


    The moment of truth. Adding on the mylar layer. The mylar holes are also too small, perhaps more too small than the cardboard.


    What sort of result did we get? It mostly looks pretty good. There is a tiny bit of bowing in the mylar, which I think is due to the “too small holes” part, but it’s probably good enough right now. The alignment is offset a bit but it’s certainly usable:


    Revision #2

    The nice part about building a jig this way is that the materials are cheap and doing another set of cuts doesn’t take much time, so it’s easy to do another revision.

    My first goal was to fix the circles so that they better matched the pins. Since I set them to 5mm explicitly, I figured I’d need to make them a little bit bigger. So, I opened up the design in Inkscape, selected the circles, and what did I find?


    Huh? I honestly set them to 5mm, but now they are smaller.

    A bit of experimentation revealed what was going on. I am used to working in Visio where the dimensions are inherent properties of the object, so a circle that is 5mm in size is always 5mm in size.

    Inkscape is different. When you way that a circle is 5mm in size, you are setting the outside diameter, and that includes the line width. So, if you set the size of the circle and then change the line width to be thinner, your circle will no longer be 5mm in size. More like 4.95mm.

    Discovering this made me happy, as it meant that the bad fit was from something I understood, not something I did not understand.

    That was a really quick fix, and I cut the new pieces and put the sandwich together. This worked much better; everything went together much easier, and the alignment was better:


    Looking closely at the entire stencil, the errors look pretty random. It’s by no means as nice as the commercial stencils I’ve had cut, but it seems serviceable enough.

    I did want to deal with the spacing issue so I could get the board thickness a little closer to the fixture thickness. It turns out that 4 mil is almost exactly 0.1mm, so I cut a spacer as part of the previous revision. Here’s a crappy picture of my first attempt (the stencils are really hard to take pictures of):


    That is what happens when you try to cut mylar with high power; the beams stays on at the corners and totally blows it out. I *thought* this would still be usable, but all that melted mylar globs up and is way thicker than 4 mil.

    I cut a second version as part of the revision, using the lowest power that would work.


    That is definitely much better, but when I grabbed my micrometer and measured it, it turns out that the mylar melts a bit where it’s cut and the edges are about 0.2mm thick. Since I was hoping for something like 0.3mm total, just using this spacer should be sufficient.

    First pass with solder paste:


    And the resulting boards. It was mostly good enough; needed a bit of touch-up for a couple.


    LEDs and decoupling capacitor added:


    Into the oven:


    And all done:


    The reflow worked well; 11/12 were fine at the start, and I replace one LED to fix the others.


    Round 2

    Round 2 was more of a production run. I changed my technique so that after putting the paste on, I would peel the stencil up and then separate the layers to let the boards fall out the bottom. This worked pretty well. I did 9 rounds plus 4, or 112 boards total, which used up most of my LEDs. Two rounds in the oven, and I had 111 functional boards.

    I really need to build a new test rig; the current one only tests 3 at a time and it’s a pain to load them.


    I’m quite pleased with the way that the jib turned out; I pretty much works exactly the way I had hoped, and I can apply paste and populate a set of boards in about 10 minutes.

    DLE (Globes of Fire) Part 5 – First Board!

    When a new telescope is completed, one of the big milestones is known as “first light” – the first time that the telescope is used as it is intended.

    Now that I am the proud owner of a reflow oven – a modified Black & Decker toaster oven fitted with Whizoo’s Controleo3 reflow oven kit – and I have a new version of my boards back – it’s time to think about how to build these things in a reasonable way.

    The plan is obviously to switch from hand-soldering to reflow. To do that, the first thing that I need is a stencil that I can use to apply solder paste. Thankfully, kicad makes this really easy; you can modify the solder pad tolerances in the program, and the pcb editor can write out SVG files (thanks to Rheingold Heavy for this post). If I have the pads, I can easily cut a stencil, likely out of mylar because it’s a bit cheaper than Kapton is.

    That would give me a way to do a single board if I could hand-align it closely enough. But each of the globes needs 12 of these boards, and hand-aligning is a pain.

    So… what my real plan to do is to cut holes in a piece of hardboard (or cardboard) that will hold a number of the boards (12 or 24) and then a matching stencil. If I align the stencil one, then I can put solder paste on all of them.


    So, here’s the test. I took the pad svg and the board edge svg, joined them in inkscape and then cut them on the glowforge. As you can see, the boards fit perfectly into the cutouts, and the solder pads cut correctly. Next I will need to do a better version of this, with different colors for the pads and board edge so I can turn them off and off when laser cutting. I’m also probably going to cut holes for some posts that will give me registration between the board with cutouts and the stencil.

    You can also see the first two boards that ran through the reflow oven. I did the solder paste without a stencil and I also skipped baking the LEDs since they showed up in a factory-sealed pack and have been sealed since, and both boards came out fine. And a 10 minute reflow cycle is a lot quicker than hand soldering…

    Provisioning and using the ESP8266 controller

    The ESP8266 controller is preprogrammed with the ability to connect to your local wifi network and be remotely controlled.


    Initially, the controller does not know how to connect to your network, so it sets up its own network. Here is how to set it up:

  • Using your phone/laptop/tablet, connect to the network named something like “EDP_1002170403”. The password is the same as name of the node.
  • One you are connected, open up your browser and navigate to That should enter the provisioning page. Enter the SSID of your wireless network and the password, and click on connect.
  • If everything is working correctly, that will connect to your wireless network. You can find out the IP address by looking for the “EDP_…” name in your browser’s host table, or you can hook the esp board up to your computer and watch what it writes out the serial port when it boots.
  • Controlling via http

    You can control the LEDs via http by sending textual commands to controller. The format looks like this:

    http://[ip address]/message?content=[message]

    Controlling vs UDP

    If you want realtime control of the LEDs, http may have too much latency, which may result in unexpected pauses. The controller also supports communicating through UDP.

    To connect via UDP, use the same IP address and pass commands directly. The internal controller code runs at 100 Hz; if you drive with UDP messages at 60 Hz everything should just work great.

    Supported Messages

    All commands are three letters long, followed by another character (the examples use an underscore (“_”), followed by numeric parameters.

    The following commands are supported:


    Alternate between two colors.


    r1, g1, b1: the rgb values (0,255) for the first color (0-255)
    r2, b2, b2: the rgb values for the second color
    time: the time for each color

    Example: alt_0,100,000,000,000,000,250

    Blend to

    Blend from the current color to a specified color


    r, g, b: the rgb values (0,255) for the new color
    time: the time for the blend

    Example: rgb_255,255,255,1000

    Color rotate

    Rotate through a bunch of different colors.


    speed: the speed of the rotate
    brightness: The brightness of the colors

    Example: col_5000,200

    Flash decay


    decay: the speed of the decay
    min: the minimum pause before the next flash
    max: the maximum pause before the next flash

    Example: fdcx250,10,500

    Full control

    Full control is used to control the color of all the leds directly.


    chunk: the number of leds to apply each set of data to.
    data-bytes: colors express as two digit HEX values in the format RRGGBB

    Example: ind_011,000044440000004400

    Each color in data-bytes will apply to 11 LEDs. The data-bytes contain 3 color values:

    000044 – a blue value
    440000 – a red value
    000044 – a green value


    Save the current animation so that it will use that animation when rebooting.


    Set pixel count

    Set the number of pixels that the controller will use. This will result in a reboot of the controller.


    count: the number of pixels

    Example: n_13

    DLE (Globes of Fire) Part 4

    It’s been very long since my last update, and a fair bit has happened.


    I did a rev 1.2 of the board and sent them off to allpcb for a small run (10 IIRC, so 120 of the LED boards and 15 of the end boards).

    The boards showed up quickly, and didn’t work. Well, two of the LEDs worked sometimes, but the third would not.

    Clever me, I did some led moving and I managed to route the VCC line for LED #2 right across the data out pad when I did some moving. I could break the pad by hand and get them to work, which through trying to be quick led me creating a circuit that would work for all the colors except white because I didn’t break the trace completely. Which led me to think a new real of LEDs was bad and waste a couple of days trying to track down what was going on.

    I took the opportunity to do rev 1.3:


    I bumped the VCC and ground tracks up in size, redid the VCC routing, and just generally cleaned things up to be nicer. I also added (finally) a 100 nF decoupling capacitor to the right of the #1 LED, which should help eliminate glitches in the future.

    I spun a small verification order (3) through OSHPark because it was only $5, and those worked great. After that, I pulled out my little list of material costs, went back to reprice the PCBs, and found that JLCPCB would do my full first order for $83 delivered, which was about 30% less than the $120 I had written down. Given the temporary nature of PCB special deals, I put that order in, and today found this on my doorstep:


    Well, technically they were in a *box* on my front porch. That is 600 of the LED facets in the two bags at the top and 50 of the top facet in the small box. And the two pretty purple boards are the test ones from OSHPark.


    I’ve gotten pretty good at soldering the LEDs on the facets, but my plan all along was to reflow them. Towards that, I picked up a few things:

    That’s a nice little Black & Decker TO1313SBD toaster oven.


    That’s a Controleo3 toaster oven conversion kit. We’re going to hot-rod that oven, adding a full computer control to it (the blue board on the left), add an extra heating element, a lot of insulation, and even a servo to open the door.

    All of this will give me a reflow oven; you can put a board with solder paste and components on it, hit a button, and it will heat the board at a certain rate until the solder melts and then cool them down at an appropriate rate. It’s going to live under the garage near the laser cutter, and my guess is that I’m going to need a bit of ventilation for it.


    I am at what I think is the V1 firmware, for approximately the third time. This took a whole lot of time and effort, with the usual fun of running two different codebases on two microcontrollers connected over USB.


    The first time setup for IoT devices can be a bit of a pain, as they have to get your wireless ssid and password. In playing around, I found that iOS doesn’t let you enumerate wireless networks or change connections programmatically, which meant it might be a real pain to set up multiple nodes by hand.

    Then, I had a small bit of insight, and realized that I already had a device that could easily enumerate all the wireless networks; the ESP can do that an I already had the code because I needed it for testing. It was merely a matter of grafting it onto the existing code.If you connect to the network for any node and give it an SSID and password, it will verify that it works and then pass it off to all of the other nodes so that they can auto-configure. That code is all done, and it’s pretty cool to watch because the current firmware shows the state of the connection by flashing. Okay, maybe that’s only a little cool.


    I wrote a few of the simple animations that I want; some color rotations, a flash and decay animation, and a blend from the current color to a new one.

    I also wanted to be able to go fully to the metal and control every LED remotely and quickly. That led me to a better Http server for the ESP, a brief flirtation with TCP, and finally an implementation based on UDP. The server is fast enough that you could send the data for all 33 leds 500 times a second and it would work; it is currently constrained to 100 Hz because that is the speed the animation loop runs at, and I expect that for real applications sending data at 60 Hz would be fine.

    I am particularly happy with how the command processor worked out; the implementation is nice and clean.

    The wireless information is stored in permanent memory, and it is also possible to store the current animation so that it will resume on startup.

    Software (app)

    I want to have an app to control all of this. It needs to support both Android and iOS, which made Xamarin the logical choice; I can support both and I can write C# code which is a huge plus in my book.

    Like many open-sourcy software, it can be a real pain at times, but I’m able to build an app that deploys to my phone and debugs, and that’s a decent first step. I’m working on network discovery right now; once the provisioning is done, the app needs to enumerate all local ip addresses and see if one of my controllers is hiding there.

    And I’m using Xamarin Forms, which is built on top of XAML, which I guess is an advantage since I did XAML professional for a fair bit, but it’s a bit of a mind-bender as usual.

    I wanted to do something different for discovery, so I wrote a graphical pinger. Here’s a video.

    The app still needs a lot of work; it needs a way to do the initial provisioning, a way to list the different animations it can do, a color picker, etc.

    Givin’ the dog a bone–USB charging station part 2

    One of the realities of doing CAD work is that the real world sometimes intrudes…

    Your laser cutter – for example – is limited to cutting a given size of material, and only in one plane. And it isn’t a perfectly thin cut, there is a little width to the laser beam.

    For router-based machining, one of the problems is that the cutter is round, and often the cuts you would like to make are square. Here’s an example:

    Image result for cnc dog bones

    The part on the left is what you designed, and the part on the right is what you got when you cut it. There are a few approaches to deal with this; you can cut the corners out with a knife or saw, you can just pound the parts together and hope the material yields, or you can change your design so that the corners are cut out. It looks like this:

    Image result for cnc dog bone examples

    Hence the name “dog bone”. With the Shaper, there are a few ways to do this; you can either modify your design to include the dog bones, or you can do them on the tool, one at a time, kind of by hand. Since there are hundreds in this design, doing them on the tool did not seem very exciting.

    There is an add-in for Fusion 360 that does dog bones, so I installed it and tried it on a few designs. Like lots of freeware, it’s a bit challenging; you either have to pick every corner where you want the dog bone, or you can let it pick the corners that need to be modified but this only works if the corners are vertical.

    Oh, and it takes a long time. A *long* time. Like 5 minutes for a panel with just a few cuts if you mark them by hand, or 20+ minutes for one with lots of holes (19) where it figures out which corners to modify. This is made much more annoying because Fusion 360 does something that I thought wasn’t supposed to be allowed under Windows UI guidelines any more; the status bar that it shows brings the window to the foreground and selects it. Since this is happening about every second, you can’t do anything else on your computer while the dog-boneification process is underway. Which kindof gets in the way of making good progress, since you need to go and do something else.

    About this time I needed to get some wood for the shelf, and I needed to know how much and how I would arrange it the cut pieces on the board. I found this tutorial to be very useful in understanding how to do that, and ended up with a nice layout on a 24” x 48” sheet that used a bit more more than half of the space.

    Went to add the dogbones by selecting all 13 pieces in the and kicking off the add-in. An hour later it was still running. Two hours later is was still running, much more slowly. Left it overnight and came back to the autodesk crash dialog.

    About this time I was really thinking of just using the Glowforge and forgetting about dogbones, but the whole point was to use the shaper, so I pressed on.

    Went out for lunch, picked up some stock (birch plywood that was 4.7mm thick), rolled back to my 3-d layout, set the thickness of the stock, and went through and did each of the dogbones by hand-selecting each corner. After that was done, I ran the Fusion 360 plug-in for the Shaper Origin, which generated SVG files that I uploaded to their website (you can use a USB key if you’d rather). I was going to do the bottom part of the design; the last wide shelf and then the pieces that hang the hub underneath that, four pieces in total.


    At some point, Fusion lost the material selection for the one piece, and I was too lazy to fix it.


    Here is the setup. Sitting on the router table portion of my BT3000 table saw, I have an extra ikea shelf (melamine and very flat), a sacrificial piece of MDF on top of that (you need to cut just through the material), and then the birch plywood on top (that piece was about $8). Across the wood you can see the “shaper tape”; this is how the vision system on the router knows where it is. The basic process to cut is:

    1. Move the router around so that it locates all of the domino-shaped shapes on the shaper tape.
    2. Load a design (in this case, from the online pieces I uploaded)
    3. Set the cut parameters (the size of the cutter you have in the router (1/8” in this case), how deep you want to cut on this pass (I did two passes, one at 0.125” and one at 0.2”)
    4. Do a “z – touch” so that the router knows where the top of the material is and can therefore judge depth.
    5. Move the router so that the line you want to cut is inside the circle.
    6. Turn the router on (using the physical switch on the head)
    7. Press the cut button (green button on the right handle), and wait for the bit to plunge into the work.
    8. Navigate the router around the cut.
    9. Press the retract button (orange button on the left handle), and wait for it to retract.

    At that point, you can move to another cut that needs to be made or change parameters and recut the same line (deeper, for example).

    This worked really well, except for two issues. The first was that on my second cut, something went wrong, and on the cut, the router plunged the bit as deep as it could and then the software crashed (you can see the burned hole near the bottom of the workpiece). I had to turn off the router, pull it carefully out, and cycle the power on the shaper to get back. The second was my fault; I cut all the way through an outline before forgetting that the piece I cut had a cutout. Oh, and the software crashed again when it was just sitting there; the image on the display is a static one before I moved it to make the picture nicer.

    And the result is…



    What do we see? Well, the first thing you’ll notice is that there is a lot of fuzziness on some of the cuts. The shaper uses an upcut bit, so that’s pretty common. The fix is to do the first cut at a bit of an offset back from the line and then do the final cut without the offset. Overall, the lines look really straight, which is remarkable given that a human is moving the router around.

    What else do we see? Well, the joints don’t look very good, and there is a distinct lack of dogbones on them.

    It turns out that I outsmarted myself. One of the tricks with dogbones in wood is to set the cutter size slightly smaller than the actual size of the cutter; that makes the dogbone a bit smaller but it still works since the wood has a little give to it. But… the Shaper knows the size of the cut you are asking it to do and the size of the cutter, so it just avoids cutting the dogbone path. I cut them by hand with a utility knife, but I was short of time so this is the result I got.

    Finally, a couple of action shots with the hub in place:



    Up next is to redo the dogbones for the remaining pieces *again*, and the cut them using the offset to see if I can get nicer joints.