The featured image of this post is based on a picture by Florian-if published at Wikipedia under CC-BY-SA-3.0

Is it possible to build a hardware debugger for debugWIRE for less than 10 €? As it turns out, it is. You just have to make a few compromises and also do a little bit of soldering and gluing.

Hardware debuggers for cheapskates

After I had finished the implementation of dw-link, an Arduino sketch that can turn your Uno into a debugWIRE hardware debugger, somebody asked me whether it would be possible to run the sketch on an USBASP ISP-programmer, something you can get for a few € on eBay, Aliexpress, or Amazon. Indeed, that would be very attractive. You could buy the system dirt cheap, it already has everything on board including an ISP cable, and one would only need to reflash the firmware. Unfortunately, it does not work since these programmers have only an ATmega8 on board, but dw-link needs an ATmega328. And then there are other reasons why it wouldn’t work such as that the SingleWireSerial library does not go together with interrupts needed by the USB subsystem.

The question, however, started me thinking how far we are away from this situation. Doing a little search, it turns out the USBASP programmers are only dirt cheap when you buy them directly in Far East, which means it takes a couple of weeks before they arrive. Then you can get them for 3-4 € including postage. In Germany, you have to pay at least 7 € (incl. postage). So, what is the situation with Unos and Nanos? Turns out that you get a Nano in the Far East for 3 €, in Germany you get them for around 7 € and an Uno for 8.50 € (including postage). So, the price of the basic system is almost the same. The question is, how much do you have to add to it and how convenient the resulting system is.

Opening a can of wires

My initial example in the dw-link manual shows how to connect an Uno turned hardware debugger to a target chip using 6 wires. These are the usual ISP wires, of which the SPI lines are only used to set/reset the DWEN fuse and may be some other fuses as well. Nevertheless, you want to have all of them.

Putting myself into the shoes of an Arduino hobbyist (well, I am one), I would use a debugging tool only if applying it is relatively painless. If I need to make six connections, need to double check that the connections are right, and then in the end get the message “Cannot connect: Check wiring,” the initial enthusiasm of using a debugging tool would quickly vanish.

There is an obvious solution to this problem, namely, using an ISP programming cable as you would use it when you turn your Uno into an ISP programmer. It can be plugged into the ISP connectors on the debugger/programmer board and on the target board. Only the RESET line is broken out on the debugger/programmer side.

djmlambert describes in an instructable in a very detailed way how to build such a cable. He adds even a cap between RESET and GND on the programmer side, in order to disable the auto-reset feature of the Uno. This is helpful, but optional for the hardware debugger.

I myself built such a cable, where I also broke out the Vcc wire, so that for targets that are not so power hungry, I can use the automatic power-cycle feature of the debugger.

In addition to the cable, you can insert a cap of 10 µF between RESET and GND and you probably want to add the system LED. In the first design, I used the builtin LED on pin 13 of the Uno as the system LED. However, that meant that one could not use an ISP cable as above, since the builtin LED is on the SCK line of the SPI bus, which we need for ISP programming. So now we need a separate system LED that can be plugged into the Arduino Uno connectors.

Both the cap and the LED are optional, but they both make life much easier. The cap prohibits a reset, when the host connects to the debugger, which makes the startup two seconds faster. The LED shows the internal state of the debugger, e.g., when power-cycling is required or when a restart because of an internal error is necessary.

I had to change the pin assignments a bit in dw-link and adjust the manual and the examples. All in all, it is probably worthwhile, because now it is much easier to have a system that can be set up in half a minute in order to start a debugging session.

The bottom line

Let us have a look on what is required.

So, that is all that is needed. Let us add up the cost.

ItemPrice
Arduino Uno8.50
6 Dupont wires0.30
1 jumper wire0.05
Heat shrink tube (2 pcs.)0.50
Capacitor 10 µF0.07
LED 5mm0.13
Resistor 330 Ω0.03
Sum9.58

This meets our budget limit of 10 €. But honestly, all of the above ingredients will be in the spare part box of an Arduino aficionado. So, the actual cost is closer to 0 €. And how does it look like when it is assembled?

With this setup, you can apply the hardware debugger probably in 90% of the situations that come up. However, what about the remaining 10%? When you want to debug 3.3 V systems? When there should not be any load on the SCK line? When you want automatic power-cycling for a power-hungry target?

Beyond the simple hardware debugger

One important requirement is an interface to 3.3 volt systems. There is actually an easy solution to it: Make your debugger a 3.3 volt system. There exist a few Uno compatible boards that allow switching between 3.3 and 5 volt: Seeeduino 4.2 and the Keyestudio PLUS Board. Both boards cost 11-12 € in Germany. When they are switched to 3.3 volt, they work beyond the specified maximum frequency. However, at room temperature there should not be a problem.

Another option is to use level-shifting hardware such as the level-shifter breakout board with four BSS138 N-channel MOSFETs. As described in the manual, that works quite well, but you have pull-up resistors on the SPI lines of the target, which changes the electrical characteristics significantly.

My most preferred solution is therefore dw-probe, a printed circuit board, I have developed. It requires, however, production of a PCB (which can be done at Chinese fabs for 0 €!) and SMD soldering, which is probably not for everybody.