Introduction: Make a Component Tester With Adafruit CLUE and Kitronik Inventor's Kit

This article shows how to make a simple, graphical component tester in CircuitPython with the Adafruit CLUE and a few extra components. A current vs. voltage graph is continuously drawn producing distinctive patterns for different types of component. This replicates the "octopus circuit" which was found on some old oscilloscopes or can be added to one with an x-y input.

The Kitronik Inventor's Kit is a useful basis for this with its micro:bit edge connector, breadboard, wires and components. Two extra 10nF capacitors (not included in the kit) are required to complete the circuit.

The tester can also identify components using a list of coded rules. This project looks at the accuracy that can be achieved within the limitations of an interpreted language and the use of a minimal set of components. There are more accurate testers using compiled code and commercial products using a different technique mentioned at the end of the article.

The code makes use of the powerful ulab library, a shrunk down version of Python's numpy library.

This was inspired by the component tester on a Hameg HM203-6 oscilloscope originally borrowed and used for Adafruit Learn: Making oscilloscope images with DACs.

Supplies

  • Adafruit CLUE: Adafruit | Kitronik
  • Kitronik Inventor's Kit for the micro:bit: Adafruit | Kitronik - for breadboard, edge connector, five wires and two 2k2 resistors
  • Two 10nF capacitors: Various places including Kitronik
  • Optional:
    • Test hooks with a male connector: Pimoroni - crocodile (alligator) clip leads would also work well

Step 1: Installing CircuitPython and the Component Tester Program

If you are not familiar with CircuitPython then it's worth reading the Welcome to CircuitPython guide first before following the installation steps below.

  1. Install the latest version of CircuitPython (6.2.0 in May 2021) from https://circuitpython.org/ - this process is described in CircuitPython for Adafruit CLUE.
  2. Verify the installation by connecting to the serial console over USB. The REPL prompt shows the version. The version can also be checked by inspecting the boot_out.txt file on the CIRCUITPY drive.
  3. Install these libraries from a bundle from https://circuitpython.org/libraries into the lib directory on CIRCUITPY:
    1. adafruit_display_text
  4. Download the component tester program to CIRCUITPY by clicking Save link as... on clue-component-tester.py
  5. Rename or delete any existing code.py file on CIRCUITPY, then rename the clue-component-tester.py to code.py. This file is run when the CircuitPython interpreter starts or reloads.

The versions used for this guide were:

  • CircuitPython 6.2.0
  • CircuitPython library bundle adafruit-circuitpython-bundle-6.x-mpy-20210528.zip

Step 2: Setting Up the Circuit on a Breadboard

The breadboard and edge connector are shown in the diagram above with a matching photograph. The connections from the Adafruit CLUE are:

  • pin 3 - yellow wire to row 1,
  • pin 4 - white wire to row 5,
  • pin 10 - grey wire to row 26,
  • pin 12 - orange wire to row 30,
  • 0V - black wire to the negative (column) rail.

The black and red test hooks are placed in b5 and b26, respectively. Crocodile clip leads could also be used - the right legs of the capacitors in column a are a convenient place to clip the other end.

Moving the components closer together would allow the breadboard to be used on its own to test components which have breadboard-compatible leads.

The program can be made slightly more accurate by including the exact values of the resistors. If you have a multimeter then measure these before they are placed in the circuit and change the values near the top of the program.

r_neg = 2200   ### Set these to your resistor values
r_pos = 2200   ### Set these to your resistor values

The r_neg value is the top resistor in row 1/5 and the r_pos value is the bottom resistor in row 26/30.

Step 3: Testing Various Components

The video above shows a wide range of components being tested. The left button collects multiple samples and then analyses the data to identify the component. The right button can be used to change the graph to two plots against time with current in blue and voltage in green.

The running order is as follows for each "device under test", components marked ** are from the Kitronik Inventor's Kit.

  • 00:06 Nothing
  • 00:21 Solid core conductor
  • 00:36 1k resistor (979 ohms on multimeter)
  • 01:02 10k resistor ** (9.89k)
  • 01:17 47 resistor ** - 54 shown, 56 on colour bands, slightly wrong on nearest match
  • 01:32 300 resistor - 302 shown , 330 on colour bands due to E12 matching
  • 01:45 IN5408 silicon power diode
  • 01:58 Germanium diode
  • 02:13 Schottky diode
  • 02:27 Zener diode 3.3V
  • 02:42 Red LED **
  • 02:57 Orange LED **
  • 03:12 Yellow LED **
  • 03:27 Green LED **
  • 03:42 Blue from RGB LED **
  • 03:56 PN junction from a BC337 NPN transistor **
  • 04:11 NPN across collector emitter **
  • 04:26 Ceramic capacitor 100nF
  • 04:40 Mullard "tropical fish" polyester capacitor 220nF
  • 04:55 Electrolytic capacitor 10uF - salvaged from an old, broken PC power supply
  • 05:09 Electrolytic capacitor 470uF ** - has very low impedance at test frequency
  • 05:22 Small DC motor ** (9.98mH on cheap LCR tester) - inductance too low
  • 05:54 Relay coil 230 ohm (520mH)
  • 06:19 One primary from a 20VA mains transformer
  • 06:35 Both primaries
  • 06:48 Small piezo speaker (Inventor's Kit has a different one with rather different characteristics)
  • 07:02 10k potentiometer (Inventor's Kit has a small 100k potentiometer)

If you are testing capacitors you must ensure they are discharged first if they have been used recently.

The component tester can identify and measure the following within the approximate stated ranges:

  • resistors between 82 and 82k ohms with the nearest E12 value shown on screen,
  • capacitors (with some correction) between 22nF and 22uF,
  • inductors above ~ 220mH and
  • diodes up to 3.3V.

The accuracy of resistors is good, capacitors reasonable and inductors very poor with significant over-reading. The forward voltage (Vf) of a diode will be approximate for two reasons: the value is based on a current the manufacturer selects and the tester only goes up to 750uA, a tiny current for an LED. The program crudely extrapolates the curve to 10mA to provide the Vf value shown at the top of screen.

The equivalent series resistance (ESR) for inductors is shown at the bottom of the screen. For capacitors this is not measured as the phase difference calculations are not accurate enough to calculate the low values associated with capacitors.

The frequency of the sine wave used for testing is also shown. This will be around 30-40Hz on the Adafruit CLUE running CircuitPython 6.2.0.

Step 4: Comparison With Hameg Component Tester

The Hameg 203-7 oscilloscope manual describes its built-in component tester as:

  • Test voltage: approximately 8.5 V rms (open circuit).
  • Test current: approximately 8 mA rms (shorted).
  • Test frequency: line (mains) frequency (50Hz or 60Hz).

The images above are for:

  1. red LED,
  2. 2.2uF electrolytic capacitor and
  3. collector-emitter for BC337 bipolar NPN transistor.

Compared to the CLUE component tester the LED is brighter due to the higher current, 8mA vs. 750uA. The capacitor's ellipse looks a tad distorted, this could be due to effects from the voltage source, a transformer. The higher voltage, 8.5V vs. 2.33V, is large enough to show the characteristic pattern of an NPN transistor's C-E pins.

Step 5: Variation of Capacitance

An ideal capacitor would have a constant value for its capacitance. A real capacitor is more complicated due to parasitic resistance and inductance, leakage current and the variation of capacitance with frequency, temperature, AC voltage, voltage bias, aging and even air pressure and humidity. The stated value will also be different to the actual value due to the tolerance, often wide for capacitors, e.g. +/- 20%.

TDK cite the multi-layer ceramic capacitor industry measuring standards as:

  • Class 1
    • <= 1000pF: 1MHz 1.0V
    • > 1000pF: 1kHz 1.0V
  • Class 2
    • <= 10uF: 1kHz 1.0V
    • > 10uF: 120Hz 0.5V

TDK: TDK Tech Tube: Measuring Capacitance accurately in an MLCC V2 (YouTube) shows the measurement of a capacitor using the Agilent (Keysight) E4980A Precision LCR Meter. A 100uF +/-10% tolerance capacitor is first measured as 66uF with a handheld meter. The precision meter at 120Hz shows 73uF at 0.089V and 93uF at the specified 0.5V. The 93uF is the correctly measured value and within the tolerance range. All of these (rms) voltages are across the capacitor which may differ significantly from the tester's source voltage for a low impedance device under test. The automatic level control (ALC) feature can correct for this.

The photographs above show the same capacitor measured at:

  • 205.2nF by digital multimeter using a 20kHz 0.7V triangle-like waveform;
  • 325uF adjusted to 217uF by CLUE component tester with 38Hz sine wave;
  • 210.5nF with ESR 0.45 ohms and no measurable leakage by Multi-Function Tester T7.

The adjustment mentioned above isn't based on theory, it's from a simple model (AKA fudge factor) to get closer to the multimeter value as the measured values tend to over-read at lower capacitances.

def capacitorCorrection(m_cap):
    """Apply a correction to the measured capacitance value
       to get a value closer to the real value."""
    poly2_cor = -6.168148e-08 + 8.508691e-01 * m_cap + 2.556320e+04 * m_cap * m_cap
    return poly2_cor if poly2_cor > 30e-9 else m_cap * 0.2

Step 6: PWM As a Substitute for DAC

The CLUE's Nordic nRF52840 processor only has digital outputs which can be set to low or high values, 0V or 3.3V, respectively. This presents a conundrum as this type of component tester needs a voltage which varies continuously between -3.3V and 3.3V to produce the required sine wave.

PWM as a substitute for DAC

The Arduino function analogwrite sometimes causes confusion with its naming. Like the nRF52840, the Arduino Uno's ATmega328 processor does not have any digital to analogue converters (DACs) and cannot output an analogue voltage. The documentation does mention that pulse-width modulation (PWM) is used. PWM output can be seen above with a 50% duty cycle - this is the percentage of the time the output stays high. These digital, low-high-low-high signals can work well for some applications like varying the brightness of LEDs but 50% output is clearly not a constant 1.65V level.

A simple way to make a PWM output more like an analogue output is to add a capacitor to smooth the output in the form of an low-pass RC filter circuit. The (unloaded) output of the circuit for one output pin is shown in the second image above. There are two scans on top of each other but the lines can discerned. The value is now much closer to a constant 1.65V but varies as the capacitor charges and discharges producing a slight ripple. A larger capacitor appears tempting but this can limit the slew rate of the output from this filter.

Another ripple factor is the trade-off between PWM frequency and duty cycle resolution. The PWM system in a microcontroller is controlled by timers running at a clock speed which determines how often the output can transition between low and high. A frequency of 250kHz was chosen as a compromise between low-ripple and resolution. This gives 65 steps between 0% and 100% inclusive, about 52mV per step.

A sine wave created with 120 samples can be seen above from one output only. The resolution is limited and the ripple can be seen but it's a decent approximation of a sine wave. There are some clear pauses in the output where the output value is held. These must be caused by background tasks running in the interpreter - a downside of using an interpreted language on a microcontroller for this particular task.

The RC values of 2.2k and 10nF were chosen based on commonly available components and some experimental testing.

Negative Voltages

The CLUE's nRF52840 cannot produce a negative voltage on an output pin. These output voltages are relative to the 0V pin. However, if two output pins are used and they are set to (0V, 3.3V) or (3.3V, 0V) then the potential difference between them will be 3.3V or -3.3V. This works because the pins in output mode can both source and sink current.

This approach works best in this application if both pins are varied for each voltage change to produce the sine wave.

PDM vs PWM

Pulse-density modulation (PDM) is a slightly different way of encoding the output signal digitally. This would produce less ripple on a smoothed/filtered output but the functionality is not available in the nRF52840 or CircuitPython.

Oscilloscope Inputs and Common Ground/Earth

The images shown above are the output from one pin. It might be tempting to try to measure the output of the component tester but a typical mains-powered oscilloscope has a true ground/earth and this would ground one side showing only half the signal. This feature of oscilloscopes is riskier at higher voltages and a trap for young players.

Step 7: E12 Values

Manufacturers make components with certain values and these look irregularly spaced at first glance. The E12 series values are plotted above with two different y scales which show how and why these "preferred" values are not evenly spaced between 100 and 1000. The next value in the series is obtained by multiplication rather than addition, making this a geometric series. For the E12 series the values are multiplied by approximately 1.21, the example below rounds them to two significant figures:

  1. 100
  2. 120
  3. 150
  4. 180
  5. 220
  6. 270
  7. 330
  8. 390
  9. 470
  10. 560
  11. 680
  12. 820
  13. 1000
  14. 1200
  15. 1500
  16. ...etc...

The E24 series (and E12 subset of that series) do deviate occasionally from the calculated values. Those are shown on the second graph with arrows indicating the deviations. Electrical Engineering Stack Exchange: How to figure out what resistors are in the E12 and E24 series? discusses the likely reasons for these deviations.

Step 8: E12 Values on a Calculator

The E12 values can be shown on a calculator. In the example above, 1 is multiplied by 1.211527658628588(4) repeatedly, eventually reaching 10.

Step 9: E12 Values and Tolerances

The E12 values are shown above with a range of accompanying tolerance values shown over time in the animation. It's rare now for resistors to have a tolerance wider than +/- 5% (gold) but other components like capacitors often have wider tolerances. The tolerances are shown as violin plots to give a suggestion of the distribution but this will vary mostly based on the manufacturing process. A close look reveals the component values from the E12 series overlap slightly in places with a tolerance of +/- 10% and clearly overlap with +/- 20%.

Step 10: Component Tolerances

Electronic components are sold and often marked with the tolerance specified as a maximum deviation below and above the nominal value. This variation stems from the manufacturing process which may also include a selection process. The images above are measurements of real resistors from:

The left plot shows what appears to be an approximate normal distribution with the tails discarded but one that is more like 99k +/- 1%.

The right plot shows a normal distribution with a surprise - the central section is missing. This suggests the manufacturer has filtered out the values close to the nominal value and sold them as resistors with a tighter tolerance. For this project they decided to use +/- 1% resistors instead.

Step 11: Going Further

Once you've built the tester you can test your own components with it. Here's some other ideas to explore:

  • Explore multiple components together. The images above are from the Hameg manual where the authors have combined components, sometimes for artistic effect!
  • Experiment with different resistor and capacitor values in the circuit. It's unwise to go below around 220 ohms for each resistor as the higher currents will stress the microcontroller's outputs. If the resistor values are changed these need to be set in the program for the measurement calculation to be correct.
  • Look at using CircuitPython's (stereo) audio system to drive the two voltage pins. This will provide excellent jitter-free waveforms but the PWM frequency may be lower causing more ripple and phase measurement may not be straightforward.
  • Port the program to the SAMD51-based PyBadge/PyGamer. These have feather connectors on the back and the SAMD51 is faster and has two DACs.
  • Convert the program to C to enable faster waveforms and more accurate timing.

Related projects:

Further reading: