Mini Lab Portable Oscilloscope

by HamzaNaveed in Circuits > Tools

1237 Views, 7 Favorites, 0 Comments

Mini Lab Portable Oscilloscope

psu-cover.png

Hello and welcome! In this tutorial we will cover the building of a DIY Portable Dual-Channel Oscilloscope, using a Cheap Yellow Display (CYD).

An oscilloscope is a helpful workbench tool that graphically displays varying electrical voltages as a two-dimensional waveform over time. Unlike a multimeter that only gives a discrete numerical value, it allows you to visualise and measure signal properties such as frequency, amplitude, and distortion.

The one we’re building is on an extremely tight budget using the famous ESP32-powered CYD screen that costs about 10-15$ on sites such as AliExpress. It packages the ESP32 Microcontroller, a 2.8in resistive touch-screen, and other features (that we won’t really need) like audio amp, RGB LED light, speaker pins and microSD slot. The ESP32 samples its GPIO (General Purpose Input Output) pins at 1kHz (1000 times per second) and passes the through its own ADC (Analogue Digital Converter) to create waveforms.

Why I built this?

I’ve been working on electronics for almost 3 years now (I started when I was 13) and STILL haven’t bought an oscilloscope due to the price wall. However, my school’s STEM room recently got one of those cheap mini ones (FNIRSI) and I toyed around with it for a bit and thought it’d be simple enough to construct, so I opted to do so for the workshop!

Since we’re building a really basic tool to remain within the realm of DIY electronics and not 2nd Year ECE, our scope won’t have similar high-end features that expensive ones from Keysight have. For our scope:

What it CAN do

  1. Display voltage lines for 3.3V and 5V through its two input probes, on separate axes
  2. Show the time base scale and the y-gain peak on the axes, each of the two voltage graph lines use a different scale identified on the screen’s side (P stands for peak, which is the highest point on the scale)
  3. Pause the screen, and allow the user to scroll backwards and observe the produced voltage lines

What it (sadly) CANNOT do

  1. Display negative voltages
  2. Display anything above 5V
  3. control and adjust time base
  4. Anything else fancy that you’d expect from expensive lab grade scopes (though we are working on a budget here!)

⚠️ Safety Warning ⚠️

Whilst the project itself is hazard-less (worst case scenario you might fry some components but you’ll be fine), exercise precaution whilst handling soldering irons and tools such as dremels/rotary tools.

Supplies

IMG_4436.jpeg
  1. ESP32 CYD (Comes in many variants, mine is a 2432S028R)
  2. 2x 100nF (104) capacitors
  3. 4x Schottky Diodes (eg. The 1N5817)
  4. 2x 2.2kOhm resistors
  5. 3x 10kOhm resistors
  6. 1x 20kOhm resistors
  7. Rechargeable LiPo battery (the one I pictured isn’t the one I’ve used)
  8. TP4056 Module
  9. Voltage booster module (Anything with a 5V output suffices)
  10. (Optional) 3D printed casing (Any will suffice, this is the one I’ve used)
  11. (Optional) Mini grabber clips
  12. (Optional) Aluminium foil (for cable shielding)
  13. For programming: Arduino IDE

The Theory

IMG_0976.jpeg

This step can be safely skipped, here we explain how the circuit works.

The schematic may look a bit confusing, but to break it down we have three probes for our oscilloscope, one 5V MAX probe and one 3.3V MAX probe (which is of course the maximum voltage we can measure from each one), and one ground (GND) probe. The GND probe simply grounds the scope to whatever you’re measuring giving a return for the signals to ground and enable electron flow for us to measure them.

The 5V probe first and foremost go through a basic voltage divider to scale down the voltage by 2/3 to make it safely readable by the ESP32’s ADC (Analogue-Digital Converter). Since the 3.3V probe doesn’t need to be scaled downwards it doesn’t use a divider, hence it will fry the ESP32 if connected to anything at 5V.

The above schematic is for the 5V probe, the 3.3V probe does NOT require the initial voltage divider and that can and should be omitted.

Both probes pass through a 2.2kOhm resistor which limits the current through them and prevent damage to the GPIO pins on the MCU. The 100nF capacitor acts as a filter to prevent noise from being displayed on the scope.

The circuit also uses a voltage clamping setup to prevent the voltage going above or below 3.3V in any way (see image). In the case of a voltage going above 3.3V the Schottky diode pointing towards the 3.3V pin becomes forward biased (because the voltage at the input end becomes larger than the output end, which previously sat at 3.3V from the ESP32’s own supply) and the voltage is safely dumped into the ESP32’s own power rail. Going below 0V also causes the diode pointing away from GND to become forward biased and allows the voltage to be dumped into the GND.

The 10kOhm resistor that connects the probe to ground is responsible for bringing the probe to 0V once the probe is disconnected. Without it, the filtering capacitor cannot discharge and holds the voltage within itself, keeping the probe set high and accidentally creating a sample-and-hold circuit.

Lastly the circuit is powered by a recycled battery I found in my junk, charged using a standard TP4056 battery protection IC and through a step up module, powers the ESP32.

Programming the CYD

20d90585-3ab5-435a-950f-63b286f62eaf.jpeg

First things first, we’ll upload the oscilloscope code to the ESP32 and then start working on physical circuitry. Ensure you have Arduino IDE installed (On Windows it can be downloaded from the official site or the Microsoft Store). You will also need a data-compatible USB to Micro-USB or USB to Type-C cable (many cheap phone chargers won’t work, they’re power only). Many CYD models come with both ports built in, however they cannot be used at once so do not try that!

Programming the CYD requires installing specific libraries and config files for the screen and touch, namely TFT_eSPI and XPT2046. This tutorial from RandomNerdTutorials covers how to setup a CYD for programming using Arduino IDE. It’s worth checking out their example code to make sure your CYD is working.

Once that’s sorted, download the OscilloScopeFirmware from my GitHub page HERE and flash it to your CYD. Set your board to “ESP32 Dev Module” (as the tutorial above also does) and you may need to use Boards Manager to add ESP32 boards to your IDE settings.

Not all CYDs are created equal. The firmware contains definitions for the GPIO pins used, and I’d suggest changing them to match your own CYD’s pinout.

Breadboard Testing

IMG_4422.jpeg
IMG_4417.jpeg
IMG_4418.jpeg

Before finalising the casing, it’s worthwhile to build the circuit on a breadboard to ensure it works as intended, like I’ve done here. My breadboard is REALLY messy, hence I’d suggest using the schematic above instead of following this diagram. Nevertheless it worked fine for me, so on to the next step!

Soldering Part 1: Probe

IMG_4431.jpeg
IMG_4430.jpeg
IMG_4429.jpeg
IMG_4428.jpeg

Now that we’ve confirmed the circuitry works, we can start soldering it together. Its a good idea to use heat-shrink tubing to cover leads after soldering and prevent short circuits.

If you think my solder joints are bad, it’s best you don’t see my OTHER ones because this is the cleanest I’ve ever done!

Following the schematic can be daunting at first, the way I did it was to simplify it by not soldering ANYTHING to the power rails first, and simply connecting the voltage divider (pic 3) to the capacitor and resistor (pic 2) and adding heat shrink (pic 4). After that was done, I soldered up the power rails. I’m using the ESP32’s GPIO 21 as the 3.3V source, the code writes it to HIGH and thus it provides a stable voltage.

You will also need to snip the wires on the connector that likely came with your board, to solder the wires. Keeping them short gives us two benefits, it makes it easier to fit within casing and also prevents interference, as longer wires not only have higher resistance but are prone to electromagnetic interference.

A single final probe should look like Pic 1. I’ve used mini grabber clips to function as probes, however you can leave them as standard DuPont M/F connectors or even bare wire (although I wouldn’t recommend the latter).


Soldering Part 2: Power

IMG_4433.jpeg
IMG_4432.jpeg

I was initially going to make it USB powered only, but one of my teachers suggested the battery system so I could bring it to school for a lab demo.


The power circuit is really simple, a LiPo battery feeds into a TP4056 board, and the output of the board goes through a voltage booster to provide 5V for the ESP32 to function.

The reason I used a micro-USB power cable instead of direct connections to the board are:

  1. I absolutely suck at SMD soldering and would probably break something
  2. I didn’t have a second connector to link up to the VIN-GND pins on the board
  3. It allowed me to skip over adding a power switch since I could just disconnect the cable to turn it off

It’s a very unglossy solution, but it worked for me. If you have the skillset and parts, obviously don’t do this.

I did make a dumb blunder here and forgot to solder the booster and had to cut the cord (pic 2) to solder it on.

By the way, if you’re curious to know why the booster only has 3 connections, both input and output share a ground terminal so we’ve got V-IN, GND, and V-OUT. There is no specific requirement on which booster module you should use, as long as it gives you 5 volts it’ll suffice.

Once we’re done with this part, we can put away the soldering iron for good! On to the next step, assembling our casing.


One Final Test…

IMG_4434.jpeg

Before putting everything into the never-to-be-opened-again-unless-something-breaks casing, its worth connecting up the probe and the battery and making sure it works.

Point note, if your scope shows a ton of noise (I mean electrical noise in the form of fluctuation, if it makes sound noise that’s a bad sign), thats perfectly normal. Exposed wiring, shaky hands, and your finger on the back of the board is bound to cause some fluctuations (like it did for me in the pic).

Oh and, bad news. I broke my third grabber clip so I unfortunately couldn’t connect up my second probe :( I’m waiting for the delivery to arrive but it might take a month or two, so for now its a single channel oscilloscope I guess, awaiting its probe.

Assembling the Casing

IMG_4437.jpeg
IMG_4438.jpeg
IMG_4443.jpeg
IMG_4439.jpeg

So now we’ve got four parts (hopefully): the CYD, the battery circuit, the probe circuit, and the casing.

My casing is 3D printed (link in the Supplies section of this article) and I superglued some lego pieces on to hold the stylus (that comes with the CYD). Another thing I did was drill holes for the probes and the board’s light sensor (LDR). Whilst the code doesn’t actually use it, I might push some firmware updates in the future for things such as brightness adjustment, and I definitely don’t want to pop the casing open again!

Whilst packing everything into the casing beware, exposed circuitry touching the back of the board is a recipe for disaster. The CYD is a princess of a board and has tons of contact points on the back, one short and you’ve fried a perfectly good microcontroller. I tried to mitigate this by enclosing the circuit in paper (pic 2 and 4). This worked fine for me, and other options include hot glue, epoxy, or a tiny few-layer-thick 3D printed plastic. Obviously don’t use something like aluminium foil for the back or you’ll simply make it worse.

Another obvious issue for me was space, as I couldn’t fit the battery circuit inside the casing. So instead, I hot-glued the battery and its stuff to the BACK of the casing (pic 3). This idea, as silly as it sounds, worked surprisingly well. The only thing that still irked me was the ugly visible wiring from the booster to the micro-USB cord for the CYD, but I guess thats the price of not taking risks. I guess one tiny advantage is that it technically could charge a phone in a pinch!

Done!

IMG_4442.jpeg

And congrats! You’ve built an oscilloscope for a fraction (very small fraction) of the price of a store-bought one. It has way lesser features sure, but hey, at least you learned something!

The above picture shows the displayed sine wave (highly noisy because I used really low quality wires) off a basic Arduino script I wrote. It’s the perfect workshop companion to my previous build, the DIY bench power supply!

If you have any questions regarding any of the steps or components to build your own oscilloscope, drop them in the comments. I'll try to answer them all!

Happy tinkering! 💟