⚠️ CRITICAL SAFETY WARNING: Protecting Your ESP32
The ESP32's ADC pins are strictly 3.3V tolerant. Applying voltages higher than 3.3V (or negative voltages) will permanently destroy the chip. This guide includes a mandatory voltage divider and clamping diode protection circuit. Never measure mains voltage (110V/220V) directly with this device. Use it only for low-voltage DC electronics (e.g., Arduino, 5V/3.3V logic, sensors).
Welcome to TechFix Hub! Every electronics enthusiast eventually faces a common problem: "Why isn't my circuit working?" A multimeter tells you the average voltage, but it can't show you noise, PWM signals, or timing issues. That’s where an oscilloscope comes in.
Commercial oscilloscopes are expensive. But what if you could build a highly capable, portable 2-Channel Oscilloscope and 4-Channel Logic Analyzer for under $25 using an ESP32? In this comprehensive guide, we will design the protection circuitry, wire the components, and write optimized code to visualize real-time signals on a TFT display.
📊 1. Project Specifications & Capabilities
- Max Sampling Rate: ~1 MSPS (Mega Samples Per Second) using direct register access.
- Input Voltage Range: 0V to 25V DC (scaled down to 0-3.3V via voltage divider).
- Display: 2.8" or 3.2" ILI9341 TFT Color Screen.
- Logic Analyzer: 4 additional GPIO pins for digital signal timing analysis.
- Controls: Rotary encoder for adjusting timebase (ms/div) and voltage scale (V/div).
🛠️ 2. Bill of Materials (BOM)
🔌 3. The Protection Circuit (Do Not Skip!)
To safely measure up to 25V, we must scale the voltage down. A voltage divider made of a 100kΩ resistor (R1) and a 33kΩ resistor (R2) creates a division ratio of roughly 8:1.
Additionally, two 1N4148 diodes are placed between the ADC pin and 3.3V/GND. If the voltage accidentally exceeds 3.3V (or drops below 0V), the diodes conduct, shunting the excess current to the power rails and saving the ESP32's delicate ADC pin.
Probe Input (0-25V)
│
[R1: 100kΩ]
│
├─── To ESP32 ADC Pin (e.g., GPIO 34)
│ │
│ [D1: 1N4148] ──> To 3.3V (Anode to ADC, Cathode to 3.3V)
│ [D2: 1N4148] ──> To GND (Cathode to ADC, Anode to GND)
│
[R2: 33kΩ]
│
GND
💻 4. Optimized Arduino Code
Standard analogRead() is too slow for an oscilloscope. We will use the TFT_eSPI library for fast display rendering and direct ADC register reading for maximum sampling speed.
#include <TFT_eSPI.h>
TFT_eSPI tft = TFT_eSPI();
#define ADC_PIN 34 // GPIO 34 is ADC1_CH6 (Input only, safe)
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240
uint16_t adcBuffer[SCREEN_WIDTH];
void setup() {
tft.init();
tft.setRotation(1); // Landscape
tft.fillScreen(TFT_BLACK);
// Configure ADC for maximum speed (11dB attenuation = ~3.3V range)
analogSetAttenuation(ADC_11db);
analogSetClockDiv(1);
tft.setTextColor(TFT_GREEN, TFT_BLACK);
tft.drawString("TechFix Hub Oscilloscope", 10, 10);
}
void loop() {
// Fast sampling loop
for (int i = 0; i < SCREEN_WIDTH; i++) {
adcBuffer[i] = analogRead(ADC_PIN);
}
// Render waveform
tft.fillScreen(TFT_BLACK);
tft.drawGrid(); // (Assume a custom grid function is defined)
int lastY = SCREEN_HEIGHT - (adcBuffer[0] * SCREEN_HEIGHT / 4095);
for (int i = 1; i < SCREEN_WIDTH; i++) {
int y = SCREEN_HEIGHT - (adcBuffer[i] * SCREEN_HEIGHT / 4095);
tft.drawLine(i - 1, lastY, i, y, TFT_GREEN);
lastY = y;
}
}
Note: For a full-featured version with triggering, timebase adjustment, and logic analyzer channels, check the complete GitHub repository linked in our resources section.
🚀 5. The "TechFix Hub" Upgrade: SD Card & WiFi Sniffer
Why stop at a basic display? Elevate your build with these advanced features:
- SD Card Waveform Saving: Add a MicroSD module to save captured waveforms as CSV files. You can then import them into Excel or Python for deep analysis.
- WiFi Packet Sniffer Mode: Utilize the ESP32's promiscuous mode to switch the device from an oscilloscope to a 2.4 GHz WiFi packet sniffer, displaying RSSI signal strength of nearby networks in real-time.
- 3D Printed Enclosure: Design a rugged, handheld case with BNC connectors (using a simple BNC-to-probe adapter) for a truly professional, lab-grade feel.
🔗 Explore More on TechFix Hub
Master test equipment and ESP32 capabilities with our complementary guides:
✅ Conclusion
Building your own oscilloscope is one of the most rewarding projects in electronics. It demystifies how test equipment works, sharpens your debugging skills, and results in a highly practical tool for your workbench. By combining the ESP32's processing power with proper input protection, you get 80% of the functionality of a benchtop scope for a fraction of the cost.
🛠️ Building your own test equipment?
Have questions about the ADC sampling rate, voltage divider calculations, or TFT library optimization? Drop your questions in the comments below, and the TechFix Hub community will be happy to help!
