Feature

Flea Scope

Low Cost PIC-Based Oscilloscope

Rich Testardi

Issue 76, November 2023

Flea scope is a very low-cost, easy-to-use 18 million sample-per-second (Msps) USB oscilloscope and mixed-signal logic analyzer with a built-in waveform generator.

Seeing the waveforms generated by your project can give you a clearer understanding on how the circuit works. Unlike using a multimeter that shows just the voltage of the circuit, an oscilloscope helps you see how components are interacting with each other, and how the voltage signals change over time.

In an endevour to encourage kids to become producers of technology rather than just consumers of it, maker Rich Testardi decided to make an affordable DIY oscilloscope to make it accessible to kids.

Rich’s Flea-scope is a mini single channel USB oscilloscope which you can connect to a computer, tablet or smartphone. It uses a custom designed web app so there’s no software to install.

The project also features nine digital inputs that operate as a logic analyser, and a waveform generator to probe signals into your circuit instead of just measuring them.

We caught up with Rich to learn all about his handy project, and how to build one.

Please introduce yourself to our readers, Rich.

I have worked in software and hardware my whole life, at HP, EMC, Microsoft, and various startups, usually at the lower levels of the software stack, near the hardware, often writing device drivers and kernel code.

I have a wife and 17yo daughter and live in Colorado. I am grateful most of the time and Christian. I love anything outdoors or math/science related. In the future, I hope to be teaching high school students. I live without a cell phone (well, except a sim-less phone for interoperability testing)!

What first got you into electronics?

In 1975, my father brought home an 8080A User's Manual, and I was fascinated by it. One of my older brother's friends was nice enough to walk me through how every single instruction of the microprocessor worked!

My older brother got me a job at the company he worked at, first cleaning and later assembling printed circuit boards, and over the next year I saved enough money to buy an 8080A microprocessor for $29 from Digi-Key along with other parts and wire wrapping supplies, and I built a small computer with 256 bytes of RAM (not even any ROM or EPROM), with binary input switches that could load a program into RAM using DMA, and binary LEDs for output!

I programmed it in machine language for weeks, and found I loved both software and hardware!

What was the motivation to make your Flea-Scope, and how long have you been developing it?

For many years, I have dreamed of taking an advanced USB-capable microcontroller (MCU) and creating a trivial oscilloscope using its A/D Converter(s).

I dreamed of building a tiny piece of hardware with a USB connector on one side and a BNC connector on the other side, which could interface between a host computer and a normal oscilloscope probe. I naïvely dreamed of just hooking this up to a PC or tablet or phone for power and having instant access to probe signals and traces, without the need of any heavy-weight oscilloscope software!

But for many years my dreams were squashed by the thought of creating an “app” for a half-dozen different platforms, involving multiple languages, device drivers, app stores, etc.

Two things happened to finally make this dream a reality... First, WebUSB and Web Serial interfaces were added to Chromium-based web browsers, allowing them to trivially communicate directly with USB gadgets in a platform-independent way, without even the need for any software install -- just open a web-page and you are up and running!!!

And second, Microchip introduced the PIC32MK line of USB-capable microcontrollers which had fast A/D converters (3.75 million-samples-per-second each) that could be interleaved (5x of them!) together to achieve a reasonable sampling rate for an introductory oscilloscope -- they are just ramping up production now!

How it works

Above is a block diagram and board diagram, with the pinout explanation below.

  1. USB connector: supplies 5V power and USB data connectivity to Flea-Scope board
  2. 3.3V regulator: regulates 5V to 3.3V for use by MCU and other components
  3. DC-to-DC converter: converts 5V to -5V for use by dual supply op amp
  4. BNC connector: high impedance input accepts -6.6V/+6.6V at 1MΩ/12 pF
  5. Passive input circuitry: divides -6.6V/+6.6V BNC input to -3.3V/+3.3V op amp input
  6. Dual supply op amp: unity gain op amp to drive MCU op amp from high impedance BNC input
  7. Passive pullup circuitry: divides bipolar -3.3V/+3.3V op amp output to unipolar 0V/+3.3V MCU op amp input
  8. MCU: manages USB interface and MCU timers, op amp, ADCs, comparators, DACs, etc., plus StickOS BASIC
  9. Crystal: provides 12MHz timing for MCU
  10. Passive reset circuitry: resets MCU on power on or button press
  11. ICSP connector: programs MCU at board manufacture time

What limitations does it have compared to commercial devices?

The main limitations compared to a real commercial oscilloscope are:

  • It is limited to 18 million-samples-per-second (real commercial units start closer to 500 million-samples-per-second). It also captures nine digital inputs at the same rate and has a built-in function generator!
  • It only has one analog channel (real commercial units have 2-4 channels), though multiple Flea-Scopes can be ganged together in a pinch by using the "trigger out" of one to trigger the others.
  • It has only one analog input range (-6V to 6V, or -60V to 60V with a 10x probe). If this takes off, though, I have considered adding a few dollars of additional input circuitry to add a second or third range, for better resolution at lower voltages (embarrassingly, I can actually get 2 additional bits of A/D resolution from the existing units at all but the fastest sample rates, but I kept the software simple and have not taken advantage of that, so far -- we left money on the table...).
  • It has no AC coupling on the input but you can just measure thru a 0.1µF capacitor to achieve the same result (and if you're just looking for power supply noise measurements, Flea-Scope will always report a peak-to-peak and rms value of DC signals anyway, which is one of the most common uses of AC coupling).
  • It requires manual calibration. There are no trimmer components, so each board has to be calibrated for the components it receives, as there is variation between components. This calibration process just takes a few seconds and usually does not need to be repeated.
  • It clearly has more noise than a real commercial unit, which is part of the reason I let go of things like multiple analog input ranges. The primary goal was to be cheap and "good enough" for student of hobby work, but if it takes off, the sky's the limit if we can add a few dollars of cost...
  • It has a BoM of roughly $13, and it can form the basis of any other embedded system, by logging in and interactively reprogramming it in StickOS BASIC, with nothing more than a web-page terminal emulator! :-)

Can you elaborate more about the noise and how your scope performs?

I don't pick up noise from electronics nearby that I have noticed (and I have a fluorescent magnifying glass lamp right over my work area most of the time), but there definitely is internal noise. When measuring a clean ground or power supply, the Flea-Scope typically reports 0.02 volts peak-to-peak signal, so all that is noise. It has about a 10mV resolution (0.01 volts).

As for ground loops, my main target for Flea-Scope was tablets and phones, so they won't have that problem because they are ground-isolated already. For an older PC that has a 3-prong cord, though, it probably is a good idea to use a USB isolator which you can get from online stores for $15 or so. This will protect you if you accidentally connect the oscilloscope probe ground to something that is hot in comparison to the PC ground.

Please tell us about the software. Did you design this yourself? How does it work?

There are two parts to the software, the firmware inside the MCU and the software of the webpage. Both are completely my own design.

There is a basic description of how the firmware works, in the link just above to the User's Guide.

The firmware inside the MCU is based on StickOS® BASIC, which I wrote a decade or so ago. StickOS® BASIC is an entirely MCU-resident patented interactive programming environment, which includes an easy-to-use editor, transparent line-by-line compiler, interactive debugger, performance profiler, and flash filesystem, all running entirely within the MCU and controlled thru an interactive command-line user interface.

In StickOS, external MCU pins may be bound to “pin variables” for manipulation or examination, and internal MCU peripherals may be managed by BASIC control statements and interrupt handlers.

A StickOS-capable MCU may be connected to a host computer via a variety of transports and may then be controlled by any terminal emulator program, with no additional software or hardware required on the host computer. Once program development is complete, the MCU may be configured to autorun its BASIC program autonomously.

For Flea-Scope, I simply added two new commands, "scope" and "wave", which allow the webpage user interface to initiate oscilloscope captures, and configure the waveform generator.

The software of the webpage is all JavaScript using WebUSB or Web Serial API to talk to the CDC/ACM serial port exposed by the MCU's USB interface. (This is actually the subject of an already-written article I hope to have published in Circuit Cellar in the next few months, but they require exclusivity to first publish.)

WebUSB or Web Serial API are the technologies that allow us to not have to write an "app" (nor device drivers, etc.!) to talk to our hardware from a web browser. They allow a webpage to get authorization from the user to access a USB device directly, and the rest can be managed by platform-independent JavaScript!

When you log into a Flea-Scope, either using the GUI or using the Deep Dive User Interface to talk to StickOS directly, you are using (only) this JavaScript.

What kind of prototyping was involved? Were there any design challenges you needed to overcome?

I did many, many turns of the board. 27 I believe. I tried a dozen different op amps (from cheapest to most expensive) until I found one that had the linearity and frequency response I wanted.

Even then, as I went from a single supply to dual supplies (so I could measure negative as well as positive voltages), I had more turns, trying to cut costs (I eventually eliminated the voltage regulator on the negative supply, since the op amp I settled on had a power-supply-rejection-ratio PSRR of 120dB).

At one point, I had USB noise showing up in the signal, and to get rid of that required different decoupling as well as a different layout for power supply traces. It all got quite involved!

I even had to switch from auto-routing to manual routing when I shrunk the board width to fit in a solderless breadboard for "deep dive" use!

How did you go about designing and sourcing the PCB? Any advice for our readers who also want to look at designing their own PCB?

I initially used a local PCB house I had used before, but the cost of turns there was so prohibitive (like 10x the cost) that I eventually switched to pcbway.com in China.

Unfortunately, I can say the turnaround time from China is actually faster, as well. (This is part of why we need to turn the tide here, and get our kids designing and building amazing stuff again, and pull the earbuds out of their ears (unless they are designing a sound card! :-).

We read that you hope to see this used in schools. Can you elaborate on that further?

Oh, yes! This is actually a double-approach dream for me. First, I'd like to see kids actually designing and building stuff again, like even using Ohm's Law (!) and analog components, which typically requires an oscilloscope, rather than just assembling prefab components that other people have designed and built.

The high-level robotics and components we teach our kids now is fantastic, but the kids are missing the whole underpinning of how these components are designed and built. They are just plugging things together, doing things that other people have already envisioned!

I want to turn the kids loose into the Wild West again, to design and build their own components that nobody has envisioned before, just like I was doing with the 8080A by giving them enough understanding to work with a blank sheet of paper!

The second part of this dream is that I want to make microcontrollers much more approachable to kids. Real microcontrollers with pins and power supplies and noise, etc. Today, the Reference Manuals of these parts are well over 1000 pages. The barrier to entry is so high, especially with the advent of surface mount technology added on top of everything else! And, while things like Arduino help that immensely, again, the kids miss the underpinning.

Specifically, with any "reset-and-run" model, they miss the interactivity that I believe helps them learn and explore best, and develop the deepest understanding of what they are actually doing.

They also miss the whole experience of "in-circuit emulation", which all professionals benefit immensely from.

For our readers who would like to build one for themselves, are all the details on your Instructables and GitHub pages?

Yes, all the details I am aware of are there. And I have supplied just the big zip file to an assembly house in China to see if they actually work. I should get 50 pieces back in the next month for a quite large amount of money since the run is so small. I hope they work!!!

Is there anything our readers should know about your project that we haven't covered?

I think you covered it all! I have a bunch of documentation out there like the User's Guide and an introduction video and the GitHub repositories.

My main website (overstatement) is just: https://rtestardi.github.io/pages/

And my GitHub repositories are here: https://github.com/rtestardi

Wonderful, thank you. On a side note, can you think of any maker hacks that help you when building projects?

One hack I got from SparkFun that I love is the "offset header pads". There are 0.1" header pads on Flea-Scope, but they zig-zag a tiny bit rather than being a straight line. This allows you to press in a row of header pins and they stay put even without soldering.

They don't wobble and fall out, so you can either solder them without having to keep them straight (they do that by themselves), or you can not even solder them at all and plug in components soldered to header pins instead! You can have the header pins point up or down, or even change your mind!

Finally, where do you go for inspiration or to expand your electronics knowledge?

This is a tough one. For me, usually "necessity is the mother of invention!". It is usually some pain point that gets me motivated.

For the oscilloscope specifically, it was the heavyweight-software that came with a previously purchased oscilloscope I had, which stopped working on OS upgrades and was not maintained, slowly falling more and more out-of-date.

For my microcontroller projects, it was that I wanted a toaster oven temperature controller for doing SMT reflow at home. And I didn't want to have to always deal with MCU programmers or heavyweight development environments for such a simple task...

Thank you for your time. Rich. All the best with getting the Flea-Scope into schools and getting kids hands-on with micros.

The Build:

Parts lists are available on the GitHub or on the Resources section of our website. Alternatively, refer to the BoM on Mouser’s website.

The PIC32MK0512GPK064-I/MR MCU part is brand new. If you have trouble finding it, you can use the "GPK" (general purpose) or "MCM" (motor control) flavor, with identical firmware, and you can also use the "1024" (1024kB) or "0512" (512kB) flash size as well. I find the PIC32MK MCU in its default QFN package with "/MR" suffix (much!) easier to use than the QFP with "/PT" suffix, but the gerbers can also be modified in minutes to use a QFP instead of a QFN. All traces are laid out for the larger part already.

PCB

You will need to build the Flea-Scope printed circuit board (PCB). You can just upload a gerber zip file containing the files https://github.com/rtestardi/StickOS2/blob/main/board/scope_gerber.27.zip to a manufacturer like pcbway.com and have them fabricate empty PCBs for you in a week or so. The board measures 1" x 2.4" (25.4mm x 1mm).

As a side note, I've had great experiences with pcbway.com for both boards and non-framework stencils. When using their website, be sure to click on "Quick-order PCB", so you can upload the zip file containing the gerbers, etc., first, and not have to manually enter any parameters like board dimensions.

PCB Assembly

I usually build the boards with a solder paste stencil (also from pcbway.com) using Chip Quik SMDLTLFP solder paste and a Kester 2331-ZX flux pen and Kester Pocket-Pak lead-free rosin-core solder for any rework; I clean boards after rework with isopropyl alcohol and a toothbrush followed by running water.

Refer to this assembly drawing showing you where each component goes; the PCB silkscreen also locates each component value for easy hand-assembly (unlabeled caps are 0.1µF bypass).

I reflow my boards in a toaster oven that is controlled by another Flea-Scope (see link in resources. I realise this is a chicken-and-egg problem. You have to do the first board by hand, just watch for the solder to melt).

BNC Plug

The last assembly step, if desired, is to solder the BNC connector by hand on the board. This is easier with a high-power soldering iron. I use an old Weller WES51 soldering iron.

Programming the MCU

"pic32.X.27.production.hex" (available on the GitHub or DIYODE resources) contains the firmware to program the Flea-Scope PIC32MK MCU. I use a Microchip PicKit 4 to program the MCU using the 6-pin ICSP header on the Flea-Scope board.

Connecting Flea-Scope

  1. Plug Flea-Scope's micro-USB connector into your computer, tablet, or phone. LED e1 (blue) should blink at 2Hz for 2 blinks, and then settle to a 1Hz blink while Flea-Scope is idle
  2. Open "flea-scope.html" from any Chromium-based web browser on your computer, tablet, or phone
  3. Click or tap the "Connect" button to authorise web browser access to the Flea-Scope USB device
  4. Select the Flea-Scope USB device (or your customised hostname)
  5. Click or tap "Connect" again to confirm

Operation

The Flea-Scope GUI is here: https://rtestardi.github.io/usbte/flea-scope.html

Flea-Scope will warn you if it is missing calibration values. Calibration is easy. Using the default "1m" secs/div and "auto" trigger level, first touch the probe to ground (available on silkscreened pins) and press the "cal_zero" button, then touch the probe to 3.3 volts (also available on silkscreened pins) and press the "cal_3v3" button. Done!

If you are concerned with ground loops (like if you are using an older computer and not a tablet or phone), you can also use a basic USB isolator in full speed mode like this one available from Amazon (https://www.amazon.com/gp/product/B07235PR4V), resulting in a full floating ground.

To learn more, check out the User’s Guide https://rtestardi.github.io/usbte/flea-scope.pdf.

Board Explanation

Controls

  • SWITCH MCLR: resets the Flea-Scope microcontroller (MCU)
  • SWITCH s1: (safemode switch used by StickOS in deep-dive interactive mode)
  • LED e1 (blue): heartbeat LED (blinks 1Hz while Flea-Scope is idle and 2Hz while Flea-Scope is active)
  • LED e2 (green): indicates trigger detected (also can be used by StickOS in deep-dive interactive mode)
  • LED e3 (red): indicates waiting for trigger (also can be used by StickOS in deep-dive interactive mode)

Pins

  • PINS a0-a8 -- (multifunction analog-capable pins used by StickOS in deep-dive interactive mode) GND (square), 3V3, 5V, a0, a1, a2, a3, a4, a5, a6, a7, a8
  • PINS b0-b8 -- 3.3V or 5V digital capture input bits (can also be used by StickOS in deep-dive interactive mode) GND (square), 3V3, 5V, b0, b1, b2, b3, b4, b5, b6, b7, b8
  • SCOPE IN pins: scope trigger output and alternate scope analog input (instead of using BNC) GND (square), TRIGGER OUT, SCOPE IN
  • WAVE OUT pins: 3.3V wave output from waveform generator
  • GND (square), HIGH FREQUENCY SQUARE WAVE OUT, WAVE OUT
  • N.B. use WAVE OUT for all waveform generator outputs except high frequency square waves
  • ICSP pins: (only used for MCU initial system programming)
  • N.B. beware that the square pin is MCLR, not GND!!!

The Flea-Scope Web-Page User Interface

  1. Horizontal scale selection (secs/div): sets sample rate for input capture from 0.5µs to 100ms per division
  2. Trigger mode selection (trigger): sets the trigger mode to one of: auto, level, rise, or fall
  3. Trigger voltage set (green dashed line): displays the analog trigger level voltage against the analog waveform
  4. Digital trigger bits selection (b0 thru b8): set the digital trigger bits and start digital triggering
  5. Clear button (clear): clear all digital trigger bits to "don't care" ("-") and resume analog triggering
  6. Delayed capture seconds input (delay sec): sets the capture delay in milliseconds (#m) or microseconds (#u)
  7. Probe selection (probe): select x1 or x10 probe on BNC input (affects analog display area and volts selection)
  8. Polar selection (polar): selects unipolar voltage display (0 to +volts) or bipolar voltage display (-volts to +volts)
  9. Vertical scale selection (volts): vertical full scale of: 0.5, 1.0, 1.8, 2.5, 3.3, 5.0, or 6.6 volts (or 10x for x10 probe)
  10. Waveform output selection (wave out): sets the waveform type to one of: ekg, sine, square, or triangle
  11. Waveform output frequency input (freq out): sets the waveform frequency in hertz (#) or kilohertz (#k)
  12. Analog display area: displays the captured analog waveform
  13. Digital display area: displays the captured digital waveforms
  14. Calibrate zero volt button (cal_zero): persistently set 0V calibration value for current probe type (x1 or x10)
  15. Calibrate 3.3 volt button (cal_3v3): persistently set 3.3V calibration value for current probe type (x1 or x10)
  16. Pause/resume trigger and capture button (pause/resume): pause or resume triggering, capture, and display
  17. Single trigger and capture button (single): enable a single trigger and capture while paused
  18. Measure button: measure one (absolute) or two (relative) points in the analog or digital display area
  19. Horizontal scrollbar: allows viewing of additional samples beyond those which are initially displayed
  20. Status area: displays measured points time, frequency, and voltage, trigger voltage, or other status
  21. Voltage area: displays average, peak-to-peak, and rms voltage of current analog capture
  22. Hostname area: displays customised Flea-Scope hostname, if set (using "deep-dive interactive mode")

Troubleshooting

If your assembled Flea-Scope does not work, typical troubleshooting includes:

  1. Look for shorts/opens, especially on the QFN or QFP and USB (shorts can be easily reworked with the Kester 2331-ZX flux pen; always clean and dry boards after rework; I use isopropyl alcohol and a toothbrush followed by running water)
  2. Check power supply; measure 5V to ground, 3.3V to ground, -5V to ground
  3. Check clocks; SY testpoint should be 117.2 kHz, UP testpoint should be 46.9 kHz
  4. Check USB pull-ups; D- testpoint should be ~0V, D+ testpoint should be ~3V

Detailed Specs

  • 1 analog input sampled at up to 18 million samples-per-second (18 Msps) using a 10-bit ADC
  • Full-size BNC connector with 1MΩ, 12pF input impedance
    • -6V to +6V input scale (or -60V to +60V input scale when used with x10 oscilloscope probe)
    • Compatible with most x1 and x10 oscilloscope probes with full-size BNC connector
    • Auto, level, rise, and fall analog trigger modes
    • Delayed trigger/capture capability
    • DC coupling
  • 9 digital logic analyzer inputs co-sampled along with the analog input
    • Compatible with 3.3V or 5V logic levels
    • Auto, level, rise, and fall digital trigger modes
  • 2% accuracy goal for voltages and timing
  • "trigger out" pin allows multiple Flea-Scopes to work together simultaneously, like a multi-channel oscilloscope or an even wider logic analyzer!
  • 1 generated test waveform output
    • Up to 40 kHz for DAC-based arbitrary waveforms
    • Up to 4 MHz for square waves
  • 1 micro-USB connector; isolator-compatible
  • Simple web-page user interface
  • When used in "deep-dive interactive mode", Flea-Scope also features:
  • StickOS® BASIC, an entirely MCU-resident interactive programming environment, with built-in:
    • program editor
    • line-by-line compiler
    • interactive debugger, including edit-and-continue
    • performance profiler
    • flash filesystem
  • 18 fully programmable and interactive multi-function I/O pins, configurable for autonomous:
    • digital input/digital output
    • analog input/analog output (PWM)
    • frequency output
    • servo output (PWM)
    • I2C master mode
    • SPI master mode
    • UART input/output
  • 2 user-controlled LEDs and 1 push-button switch
  • Compatible with solderless breadboards!
  • Simple web-page user interface
  • Customised hostname setting (to distinguish multiple Flea-Scopes on the USB and thru the user interface)
  • Firmware upgrade support