## Saturday, 7 August 2021

### ESP32 auto program fix

Out of the box my ESP32 dev board required me to hold down the BOOT button at the start of programming to get it to program from the Arduino IDE. The board has a pair of transistors to connect the DTR and RTS lines to EN and GPIO0. This is intended to enter programming mode automatically but seems to have timing problems. If I don't hold the button I get:

Fatal Error Occurred: “Failed to connect to ESP32: Timed out waiting for packet header”

Looking around the internet I found a recommendation to add a 10uF electrolytic capacitor between EN and ground. While this did work for programming it seemed to inhibit the board reset at the end of programming. I found 1uF worked better, which let me use a small ceramic SMT cap, which is a lot neater.

The nearest ground is the top right pin of the module and I could have angled it to reach that but I found it easier to just link it to the metal can.

Investigating why it doesn't work I found the setup and hold times for the strapping pins in the ESP32 datasheet:

To enter programming mode GPIO0 needs to be low as EN transitions to high and stay low for 1ms after that.

This is the two transistor circuit on my board which is labelled ESP32 DEV KIT V1, which implements the truth table shown.

The truth table shows that EN and IO0 can't go low at the same time, so the zero setup time cannot be achieved unless both lines change together. Here is what it looks like on a scope after I added the capacitor.

During reset RTS is low and DTR is high, which makes EN low and IO0 high. At the end of reset DTR goes low and then about 1ms later RTS goes high. This would work without the transistors but with them EN starts to go high 1ms before IO0 goes low, so it violates both the setup and hold time. Adding the capacitor delays EN long enough for IO0 to be low as the chip comes out of reset.

My best guess is the transistor circuit is there to ensure random serial monitors don't put the board into programming mode if they assert both DTR and RTS. To work without a capacitor RTS and DTR would need to change state simultaneously. There is a long discussion about it here: https://github.com/espressif/esptool/issues/136.

## Friday, 16 July 2021

### Third Hand

A problem I often face hand soldering surface mount components is keeping them in the correct position while soldering the first end. The surface tension of the solder invariably moves the component.  When using paste and an oven the surface tension is the same on both ends and pulls the component into position. Solder paste and hot air works similarly but it is easy to blow the component away.

One solution is to tin the pad and the end of the component first and then use tweezers to hold the component on the pad while applying the soldering iron to the tinned end. However that requires a steady hand and today, after having two strong cups of coffee, my hands are far from steady!

Some time ago I bought a PCBite probing kit from Elektor. This consists of a steel base, four magnetic clamping posts to hold a PCB and four sharp tip probes with magnetic bases and flexible swan necks intended for making measurements. It works well for its intended purpose although I think the flexible necks would be better if they were stiffer.

I found they make an excellent third hand for holding SMT components in place while soldering.

Here it is holding an 0805 resistor, they are the smallest parts I am comfortable soldering by hand.

## Saturday, 12 December 2020

### Sinkholes

Continuing my series of adventures in 3D printing holes the correct size, I turned my attention to countersink holes.

I don't normally use countersunk screws in 3D printed parts because they create lateral stress, whereas other forms of screw exert a purely compressive force, which can be spread by a washer. However, I am currently designing a part that needs flush screws in its base that is only 4mm thick, so there is no room for a counter-bore to bury a flat head.

First I had to improve my countersunk screw model because I previously just used a 45° cone with a sharp edge. In practice the edge has a nominal thickness of 1/10th of the screw diameter. That means if you countersink the hole with a normal conical countersink drill bit it has to be oversized to sink the head flush, and then leaves a gap around the circumference.

So the ideal shape for a 3D printed hole is an improvement because it can have a straight section at the top.

The complications are that, like horizontal holes, we have to take into account the rounded staircase produced by the filament layers and also, like vertical holes, we need to use polyholes to get the correct diameter when printed.

The cone makes contact with the rounded filament edge above, rather than the centre of the extrusion, where the slicer samples the model, as shown below:

In order for the extrusion to not overlap the cone it has to be offset outwards by a distance $x$, which is simply $(\sqrt2-1) r$ where $r$ is half the layer height. Applying that to the line equation of the cone and limiting the result to be in the range between the screw clearance radius and the screw head radius gives the correct placement for the rings of filament that just touch the cone without overlapping.

To make each of the rings print the correct size I make a stack of polyholes to subtract from the model.

These are double sided so they can be subtracted from the either the top or the bottom of a hole. As the slope is 45° they should be printable either way up.

This is what it looks like subtracted from a part:

I have added an OpenSCAD module called screw_polysink() to NopSCADlib to make printed countersinks. I haven't tried printing it yet but it should certainly work on a top surface. It might get a bit scrappy printed as an overhang without support.