Align holes in your project box without measuring – no special tools required.

In a previous post I described how to align holes without measuring. My original alignment tool was laser cut, but due to lockdown I’ve had to devise a simpler way to acheive the same accuracy using readily available materials – this time I use BluTac and an old milk carton.

Holes for the 3.5mm sockets are exactly in the right place.
Circuit board and project box
We can see where holes should be, but only from the inside.
Cut a piece out of an old plastic milk carton, to fit inside the box
Fold the plastic and add a thin layer of BluTac (other colours are available)
Press the plastic strip and BluTac onto the sockets to make an impression
Carefully remove the plastic strip
Position a bradawl in the centre of each hole and push through both layers of plastic
Holes punched through correctly
Re-attach the BluTac in EXACTLY the same impressions you made previously. Accuracy depends upon it.
Carefully insert the circuit board into the project box
Ensure the circuit board is in the correct postion, and press the strip onto outside of the box
Use the bradawl to mark the drill centres

Yes it’s just that simple. This method worked first time for me. If you are unsure, drill the -holes a bit smaller and file them out to be in the correct place. A 4 minute video of this process is here.

Check out my videos for accurately marking other types of hole without measuring –
USB-micro oval cut-out (as described in a previous post here)
Pin-hole (ideal for a recessed reset button)
Pinhole on the lid to show the recessed LED of Wemos D1-mini

Wemos D1 mini GPIO test board

Visualise Active Ports

Sometimes it’s useful to know the activity on the GPIO pins of your microcontroller. This little monitor board is designed specifically for the Wemos D1 mini and has a LED on each GPIO pin to help you visualise what is happening on inputs and outputs.

This monitor is quite useful for checking DC levels and slower pulses such as when controlling servos, relays, etc. For faster pusles it’s best to use a ‘scope or logic analyser.

Microcontroller boards other than the D1 mini can be accommodated by either re-designing the layout for the extra pins, or using extension leads to monitor those pins you are interested in.

LEDs can be disconnected by removing the jumper links, so as not to interfere with other functions. All LED series resistors deliberately have a high value to minimise loading the GPIO pins. The white LEDs drew less than 500 microamps each when used with a 1K series resistor, and they were still quite bright.

General view showing breakout header sockets, header pins, and jumpers.

The monitor can also act as a small breakout board, extending the Wemos header pins to 2 sockets and 2 pins per GPIO line. This can be handy when developing your project, as Dupont extension leads could be used to connect the monitor board to your PCB.

Wemos D1 mini and the breakout test board.

Construction is simple – besides the header pins and sockets, there are just a dozen SMD resistors and LEDs, mounted on a prototyping board. The underside of the board is where the connections were made, linking pins with single strands taken from a length of scrap multistrand wire.

Underside showng the link wires and SMD resistors.

The video shows the board with jumpers installed for all 9 GPIO ports (D0 to D8). Due to high value series resistors, the LEDs do not interfere with program uploading, and if you install the RX and TX jumpers you can watch the LEDs giving a satisfying twinkle with the upload activity.

Perfectly aligned holes without measuring

How to cut a hole to mate up with what’s inside your project box.

THE PROBLEM — You’ve made the electronics part of your project, and now need to cut a hole in your project box so you can plug in the USB cable. But how do you know where to cut? Unless the box is transparent, you can’t see exactly where the USB socket hole should be. There is a short (2:40) video of this post here.

Update: At the bottom of this post, there are links showing how to locate drill centres WITHOUT any tools.

Hole is in exactly the right place. and allows for plug housing
Micro USB plug fits neatly

The usual way is to measure the internal position of the USB socket when the PCB is fully in the box (not always possible) and transfer the measurements to the outside of the box. You have to be able measure and mark accurately.

PCB ready to fit into the project box.

This little tool provides a drilling and cutting guide on the outside of the box, when the USB socket is on the inside of the box (possibly hidden from view). No measuring is required.

Align the two strips

My design is quite simple. Overlay two strips and fix them together at one end – similar to tweezers. The strips staddle the wall of the project box, one strip inside the box, the other outside. The inner strip is fixed into the USB socket, and the outer strip has guide marks for the required opening.

Thin yellow inner strip is clamped in position.

The inner strip — should be reasonably thin so it can fit between the PCB and the box. I cut a 10mm wide strip off an old credit card, narrowed it at one end to make a tab that fits snugly into the USB socket, then bent the tab 90 degrees (warming helps but is not essential).

Line up the outer strip’s tab with the drill holes.

The outer strip — should be stiff transparent material. At one end, mark where the cut-lines and drill holes should be for the USB socket. Align the inner strip’s tab with the outer strip’s markings, then fasten them together at the other end. That’s it!

Fit tab into the USB socket

USAGE — To use the template, insert the tab into the USB socket and slide the circuit board and the inner strip into the box. Ensure the outer strip is flat to the outside of the box and use the cutting guides to mark the box. My original marks were the drill-centres for a couple of 6mm holes. Use a drill press for accuracy, and a small file to smooth and adjust the drilled holes to the final shape.

Slide the PCB and the tool into the project box.
Mark through the drill pilot holes

This technique will work on plastic or metal, and can be adapted for any shape of socket and hole. Draw the marking guide to accept the largest plug you may use.

View of how it looks on the inside.

CONCLUSION — Cutting holes in the right place is something I have always struggled with. I have to admit I was amazed when this worked first time!

Alternative view

Credit goes to Alan Bailey for helping implement this project from concept to completion in just a few hours. Below areYouTube links showing how it’s done, and how to locate holes WITHOUT any tools.

A Model Lighthouse

Designed and built at the Sheffield Hackspace using an arduino and bits and pieces of things that you might find lying around in your own home…

Here’s the setup:

An arduino (pro mini) for controlling the SG-90 servo motor
An ESP8266 for wifi access and neopixel control
A piece of gutter and downpipe for the main body
A plastic dome sourced from a solar powered garden lamp
An Aldi’s peanut butter jam jar lid (crucial)
Other bits and bobs scrounged from various unwanted poundland items

If you think this is cool wait until you see the boats!

Compiling and uploading Arduino sketches from within Notepad++

Notepad++ is my favourite editor for Arduino sketches, but it lacks the facility to compile and upload sketches directly to the Arduino boards. The usual procedure would be to save the sketch in Notepad++, switch to the Arduino IDE then compile/upload.

However, there is a plug-in for Notepad++ which enables you to run external commands – this post describes how to set it up for the Arduino IDE.

Install the plugin

First ensure you have the latest version of Notepad++ (currently version 7.6.6) and select the menu item under ‘Plugins Admin…’.

Then select the ‘NppExec’ plugin and click install.

Set up the commands to execute

After it installs, you’ll be able to select ‘Execute…’ from the new sub-menu (or simply press ‘f6’), which will display the ‘Execute…’ dialog box.

The empty ‘Execute…’ dialog box will display.

Enter the following text into the command(s) window, ensuring the path points to your ‘arduino_debug.exe’.

set arduino_path = "C:\Program Files (x86)\Arduino\arduino_debug"
inputbox "Enter the COM port of your Arduino (e.g., COM1):"
cmd /c $(arduino_path) --port $(input) --upload $(full_current_path)
Commands are remembered in the Execute window

Pressing ‘OK’ will allow you to enter the COM port (this is shown in the Arduino IDE ‘Tools’ menu).

Select a COM port

Press ‘OK’ and the process of compiliation and uploading will begin.

A pane opens in Notepad++ and displays the Arduino compilaition progress

To VERIFY without uploading, the commands in the Execute window will be simpler with only 3 lines –

set arduino_path = "E:\Arduino\arduino-1.8.9-PORTABLE\arduino_debug.exe"
cmd /c $(arduino_path) --verify $(full_current_path) --verbose-build


You can store the commands in the Execute window by using the Save… button. I named my stored command scripts ‘Upload’ and ‘Verify’. Stored commands will then be available in the drop-down box.

Your stored command scripts are selected here


  • Press f6
  • If you have stored commands, select one from the dropdown box
  • Click OK


  • Keep the Arduino IDE open with your sketch (not required, but helpful).
  • Ensure the Board type, COM port, etc. are correctly set in the Arduino IDE.
  • In Arduino IDE select external editor (File -> Preferences -> Settings Use External editor
  • Ensure the serial port monitor is not open.

A wi-fi and touch controlled NeoPixel ring using the Wemos D1 Mini ESP8266 module.

This project describes an easy way to control a strip or ring of WS2812 LEDs via a web page. It was originally based on the Arduino FastLED library.

Although the FastLed library code gives us a great example of how to control NeoPixel rings and strips, it doesn’t provide for user interaction. So it was decided to add the ability to control the device by wi-fi, and also have a touch switch for local control.

Materials required
A Wemos D1 Mini module was used as it consisted of a low-cost ESP8266 wifi chip and antenna, and it can be programmed by the familiar Arduino software. The Wemos module sits in a socket which is soldered to a matrix circuit board. This allows the module to be swapped out if needed, and also makes it easier to connect the touch-switch and neopixel wires.

A touch switch module was chosen rather than a discrete push-switch as it can be hidden behind the acrylic case and should also provide more reliable switching. The 100 x100 x 25mm square case was laser cut from 3mm acrylic, and was designed using the makercase on-line designer. This is the quickest software for making simple boxes. An extra 100mm square piece was cut for the front, with two circular cuts to accommodate the neopixel ring so it can lie flush with the front surface. Later, the touch-switch hole was cut so the sensor sits behind only one thickness of acrylic.

Laser cut acrylic case

The components fitted easily inside the box – it has plenty of room for a battery pack if you wanted to make it totally portable.

The touch switch sits in a rectangular cut-out.
Here is a view before the centre cover is glued on.

Software overview. The project uses websockets so that any web browsers connected can control (and be controlled) by the device. The touch-switch also controls the software and the settings are communicated to all connected browsers via websockets in real time.

User settings are stored in an object, derived from the ‘userDataClass’. This object stores settings for the brightness, colour, active pattern, demo pattern, provides functions for brightness gamma correction, etc.

The touch-switch code decides whether the switch received a tap or long press. A tap changes the pattern and a long press increases/decreases the brightness. Debouncing the switch was achieved by using a 32 bit integer and bit-shifting each switch reading into it. This method has both the advantage of being able to check for a steady switch state, and to discriminate between a short or long press. A future article will explain exactly how this is done.

Here’s a video of it working.

How to download a complete website, including links between pages.

Quite often, you may download sections of a website, only to find downloading separate pages does not maintain the links between them.

There is an easy way to grab whole sections of a site (or even a whole site), such that you can run it locally offline with all the links between pages intact, and you can even upload the whole captured sections to your own website and the relative links will still work!

Copy and paste the index page or a sub page into httrack

It works on Windows 2000 to Win10, and Linux. You can use the portable version which will run from a USB stick, or you can use the installer version.

And it’s FREE.

You can capture (mirror) several websites complete with their data, and they may be accessed from a master web-page; as in the example below.

The REALLY cool bit is that downloadable files such as PDFs and jpg files are saved too. If it’s in a directory and referenced by a regular page link, it will be downloaded.

Error reporting is also good. Use this on your own website to show up a list of any broken links – and other errors.

Let me know if you learn any neat tricks with this software…..

Richard Langner







Using the Boards Manager of the Adruino IDE

By Richard M Langner

In order to program an Arduino device (a board or a stand-alone chip), it needs to be listed in the Arduino IDE. If it isn’t listed, this article should help you list it using the Boards Manager. The basic procedure is –

  1. Locate the Boards Manager URL for your device (search the web).
  2. Add it to the ‘Additional Boards Manager URLs’ list (under File → Preferences).
  3. Install the device in the ‘Boards Manager’ (under Tools).

I am using the Arduino IDE v1.6.7 and the device I want to list is the ATtiny85 stand-alone 8 pin chip. Boards/devices are listed in alphabetical order and you can see below that no ATtinys are listed.
(Click to enlarge the images)


First, we need to find a board manager for our device. A search for ‘ATtiny85 board manager’ brings up a couple of candidates.


Click on the top result and copy the ‘Boards Manager URL’ to the clipboard.


This URL needs to be added to the ‘Additional Boards Manager URLs’ which you will find under File → Preferences.


In Preferences, click on the button to see a list of board managers that are already installed.


In my case there are only two managers installed


Paste the URL (you previously copied) into the list on a new line and click OK. Then close these boxes and return to the IDE main screen.


You have just told the boards manager where to look for the information.

Now you can begin to install the manager for the ATtiny85.  Find your way to the Boards Manager –


and type ‘ATtiny’ into the search-box. You should get something like this –


Click on the appropriate manager item and an Install button appears.


Click on the Install button and after a moment you will see confirmation the manager has been installed.


The ATtiny devices will now show up in the list of boards/devices.


Finally, select the ATtiny85 device and ensure that all the other settings are correct.


You are now ready to program the ATtiny85.

The same procedure may be used to install other boards/devices into the Arduino IDE.

Note: Your screens and menu options may be slightly different to mine, but the general method of listing your device should be the same.

Programming the ATtiny85 using an Arduino UNO

By Richard M Langner

This article describes how you can use an Arduino UNO to program a bare ATtiny85 micro-controller chip. I will show you how to program the ATtiny85 with the ‘Blink’ sketch. These are the steps –

  1. Connect the UNO to the ATtiny breadboard and connect the 10uF capacitor
  2. Configure the Arduino as an In-circuit Serial Programmer (ISP)
  3. Insert the ATtiny85 into the breadboard
  4. Configure the IDE for the ATtiny85
  5. Modify and upload the ‘blink’ sketch to the ATtiny85

1. Connect the UNO to the ATtiny85 breadboard and connect the 10uF capacitor
Connect the UNO to the breadboard as shown below. If you intended to keep the breadboard and UNO solely for programming, I recommend using an 8 pin socket for the ATtiny85 – this will ensure you insert the chip in the correct place each time on the breadboard.
Don’t insert the ATtiny85 in the socket yet – you must first configure the UNO to act as a programmer.

Pin connections:

  • ATtiny Pin 2 to Arduino Pin 13
  • ATtiny Pin 1 to Arduino Pin 12
  • ATtiny Pin 0 to Arduino Pin 11
  • ATtiny Reset Pin to Arduino Pin 10
  • ATtiny Pin 2 to 150Ω resistor, resistor to LED anode, LED cathode to GND (not shown here).
  • 10uF capacitor connects between GND (-) and RESET (+)

(Click on the images to get a clearer image.)

Uno as an ISP

2. Configure the Arduino as an In-circuit Serial Programmer (ISP)

Select the Arduino UNO board

and open the ISP sketch.

Next you should upload the ISP example to the UNO board. Ensure you have selected the correct COM port.

Congratulations! Your UNO is configured as a programmer.

You’re now ready to program the ATtiny85 with the ‘Blink’ sketch. You will need to connect an LED to display the blink. Connect a 150 Ohm resistor to the physical pin2 on the chip. The other end of the resistor should connect to the LED anode (its long leg), and the LED cathode connects to GND.

3. Insert the ATtiny85 into the breadboard

Remove the power by unplugging the USB cable. Taking care, insert the ATtiny chip into the breadboard socket the correct way around. Re-connect the USB cable.

4. Configure the IDE for the ATtiny85

Configure the IDE as follows –

  • Board  =  ATtiny85
  • Processor  =  ATtiny85
  • Clock speed  =  8MHz

2016-10-01_00037 2016-10-01_00038

Set the programmer ‘Arduino as ISP’

If the ATtiny85 is new, it will require the fuses to be set.  Among other things, fuses set the CPU speed. The fuses only need to be set once for each chip. To do this, select the ‘Burn bootloader’ option.


5. Modify and upload the ‘blink’ sketch to the ATtiny85

Open the example sketch ‘Blink’ and change the LED’s digital pin number to 3 on all the sketch lines (this is because the ATtiny85 does not have a pin13. Note that physical pin2 on the chip is digital pin3 on the ATtiny85). The code should look like this –

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 3 as an output.
  pinMode(3, OUTPUT);

// the loop function runs over and over again forever
void loop() {
  digitalWrite(3, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(3, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second

Finally upload the ‘Blink’ sketch to the ATtiny85.

That’s it! The blink program should now flash the LED.

The UNO is now set up as a programmer and so further ATtiny85 chips may be programmed by simply plugging them into the breadboard and uploading your code to them.

Richard Langner
With thanks to OJ for his help in defining the procedure.
This is my first post here, so please let me know if there is anything missing or incorrect.

Hacking De-bounce and Rotary Encoders

Prototype console interface for embedded projects

Prototype console interface for embedded projects

At the UK Makerfair during a brief lul the conversation turned to rotary encoders, simply as I had ordered a paw full from china for one of my many projects that simmer along in the background. The picture here shows the initial prototype that I used for this article. The feedback about rotary encoders that I received was that they were terrible and to be avoided. Principally as the switch contacts were very noisy and produced way too much bounce. I was still interested in using them firstly as having done embedded stuff for years bounce is something I consider trivial and fixable, secondly as they make a really cool, easy and feature full user interface using the minimum of pins.

De-bounce circuits

De-bounce circuits

The circuits I most commonly use for de-bouncing simple switch contacts are shown in the picture here. I ran this up in Kicad for the article. Something worthy of note is that Arduino’s and a number of other micro controllers have internal pull-ups that you could use. Do not use these when de-bouncing your inputs. They vary very widely in effective resistance value and the results will be massively variable when used with the same external components. Indeed a quick search of the internet shows a range of circuits and values mostly with a string of comments along the lines of someone found a different value or combination to work better. What is happening here, and why so much variability of what should be a trivial, bread and butter type, of interface circuit.

No de-bounce

No de-bounce

Time to dig out the Bitscope I bought from Pimoroni a while back and capture some waveforms. It will work as a capable enough DSO for this investigation. On the left is the A output of the rotary encoder from the previous picture set-up as a switch with pull-up as per the schematic above. The value of the pull-up resistor in this case is 10K Ohms a fairly typical pull-up value. The large nice square pulses are the outputs from the encoder and the very narrow horrible pulses are the switch noise and bounce. This looks reasonably what I would have expected although the switch looks to be more noisy than bouncy. I spun the input shaft quickly by hand to get enough pulses into shot and it is noticeable that the rubbish pulses produced are proportional to the speed of spin. The other thing that is noticeable is the duration of the pulse are quite short. With a standard press button you can not move your finger that quick and a de-bounce period in software of around 10mS is not uncommon. In this case though, if you did this it is clear that you would be missing a lot of steps from the encoder. Each one of those noise pulses is a full logic value in height and will trigger an interrupt, giving you a wildly incorrect count and wasting a whole shed full of precious processing cycles. I can see why you might think they were to be avoided if you had not de-bounced them in any way.

100nF De-bounce Capacitor

100nF De-bounce Capacitor

Adding a 100nF capacitor as per the above schematics produces the results below. This produces a very large reduction in the height of the noise pulses but they are still large enough to trigger some interrupts, the amount of processor time we waste though is reduced. The number of incorrect counts is also reduced but there are still some present. Also look at what is happening to the corner of the rising edge of the pulses that we want to work with. They are no longer square and are being rounded off. So a big improvement but still not as good as we would like. In a simple switch this rounding etc is not a problem. We are working with a rotary encoder though and the relative position of the edges in each channel is important to us. Where an edge curves too much it becomes unclear where the micro controllers input will decide it has switched from logic 0 to logic 1. If we got such a big improvement for adding in 100nF, will adding in some more be helpful?

200nF De-bounce capacitor

200nF De-bounce capacitor

So lets add in another 100nF capacitor in parallel across the one we put in last time. Taking the total up to 200nF. Yes the noise is reduced much further and we could probably work with that at a push. But look at the state of the rising edges. As we increase the capacitance we increase the loss of definition of the rising edge and consequently our ability to correctly resolve the direction of the encoder. The faster the encoder is turned the more problematic this becomes as the curve remains the same width but the width of the pulse we are relying on has become narrower. We could have kept the capacitance value the same but increased the resistance to say 20K and we would get exactly the same result. The RC network that is cleaning up our signal has a time constant that is proportional to the ratio of the resistance and capacitance that makes up the circuit. It is this time constant that is low pass filtering the pulses and giving us the effects we can see on the scope. Bearing this in mind if we check out the Atmel AVR data sheet, as this is the most popular micro-controller in the Arduino series, we see that the internal pull-ups have a value of between 20K and 50K. So a massive variation in the pull-up value and consequently a massive variation in the de-bounce action and on our pulse edges is produced by this, hence why de-bounce circuits that use the internal pull ups are to be avoided. We need results that are consistent.

For a simple press button a simple RC network as shown in the above works great as it is a very slow logic signal, but what can we do to recover nice square edges on our fast, encoder signal pulses, and get rid of the noise pulses. The answer is to use a Schmitt Trigger which increases the level at which a rising edge will be consider to have switched from low to high and reduces the level at which a falling edge will have switched from high to low. This circuit will ignore the noise pulses that we have reduced in height leaving us with a clean pulse train and nice square edges from our encoder. Check out the linked wikipedia article, ignore the over complicated mathy explanations and control theory waffle look closely at the wave form diagrams at the top right of their page. What is more this circuit is so useful that it comes already built in to a number of inexpensive logic gates. You don’t need to make one.

Unfortunately I don’t currently have the parts to hand to show the fully processed pulse train but the procedure is to add in a Schmitt Trigger logic gate (ie a 74LVT14 or similar)  as per the diagram above, pick the pull up resistor value for your chosen application 10K is good for most applications, looking at our scope waveforms you may want to go to somewhere conveniently around 20K. Then starting with a small capacitance for the de-bounce capacitor increase it until all your noise pulses on the output of the schmitt gate have gone. Using your scope to see when this happens. Once you have achieved this you know what the correct values are and can pick the nearest off the shelf value to use every time and get repeatable results. What’s more you will not be wasting any precious processor cycles on clever de-bounce code and unnecessary interrupts.

Take away points from this are:-

  • Do not use the internal pull-ups with de-bounce circuits it is a false economy.
  • Simple RC circuits are plenty good enough for simple push buttons and switches.
  • You need a logic gate with a schmitt trigger input to clean up the faster logic pulse trains from rotary encoders.
  • You can do a lot of electronics and get an intuitive grasp of what is happening by laying on a scope and laying off the math.
  • Clean up your signals before trying to code them clean, crap in equals crap out.
  • Rotary encoders are great if you know how to work with them.