Build it step by step
0 of 7 doneTest the display
Run the Adafruit ILI9341 example.
Read the input
Print raw values for a pot voltage.
Capture a buffer
Fill 300 samples quickly.
Draw the trace
Scale 0 to 4095 to the screen height.
Add the trigger
Wait for a rising edge.
Add the timebase
Change the sample spacing with a pot.
Protect the input
Add the resistor, clamp and capacitor.
How do you build a mini scope display on TFT?
An ESP32 samples a signal and draws a live waveform on a TFT with trigger and timebase controls. You need ESP32 DevKit V1, 2.8 inch TFT touch (ILI9341, SPI), Potentiometer 10 kΩ × 2, Resistor 10 kΩ × 2, Ceramic Capacitor 100 nF, Resistor 1 kΩ and Resistor 4.7 kΩ. It takes 7 steps and about 240 minutes.
- Level
- Intermediate
- Time
- About 240 min
- Parts
- 7
Parts list
- Development BoardsBuyESP32 DevKit V1 × 1
- DisplaysBuy
- PassivesBuy
- PassivesBuyResistor 10 kΩ × 2
- PassivesBuy
- PassivesBuyResistor 1 kΩ × 1
- PassivesBuyResistor 4.7 kΩ × 1
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| TFT VCC and GND | ESP32 3V3 and GND | Power |
| TFT CS, RESET, DC | ESP32 GPIO5, GPIO4, GPIO2 | Control |
| TFT SDI (MOSI), SCK | ESP32 GPIO23, GPIO18 | SPI |
| TFT LED | ESP32 3V3 | Backlight |
| Signal in | 1 kΩ resistor to GPIO34 | Input (0 to 3.3 V only) |
| Two diodes or a 3.3 V zener (optional) | GPIO34 to 3V3 and GND | Clamp for safety |
| 100 nF capacitor | GPIO34 to GND | Reduces noise |
| Timebase pot wiper | ESP32 GPIO35 (ends to 3V3 and GND) | Timebase |
| Trigger pot wiper | ESP32 GPIO32 (ends to 3V3 and GND) | Trigger level |
Code
The ESP32's converter can take tens of thousands of readings a second, enough to show audio and slower signals, but it is not a replacement for a real oscilloscope: its input range is 0 to 3.3 V, its response is not perfectly linear near the ends, and the screen redraw limits the refresh rate. The sketch waits for the signal to cross the trigger level while rising, then collects 300 samples at a spacing set by the timebase pot and draws them as a trace with a grid. Never connect mains, a battery above 3.3 V, or anything unknown: a two-diode clamp and a 1 kΩ resistor protect the input from small mistakes but not from real voltages. To measure larger signals, build a resistor divider for known ranges, and for signals that go below zero add a bias network. Good test signals are a potentiometer sweep, an Arduino PWM pin through an RC filter, or a 1 kHz tone from a phone through a 10 kΩ divider with a bias. Arduino IDE with the ESP32 boards package, board "ESP32 Dev Module".
Runs on a virtual ESP32 Dev Module in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// Mini scope: samples GPIO34 and draws it on an ILI9341. Libraries: Adafruit ILI9341, Adafruit GFX. Board: ESP32 Dev Module.
// Input range 0 to 3.3 V DC only. Never connect mains or anything above 3.3 V.
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
Adafruit_ILI9341 tft(5, 2, 4);
const int SIG = 34, TIMEBASE_POT = 35, TRIG_POT = 32;
const int W = 320, H = 240, N = 300;
uint16_t buf[N]; int prevY[N];
void setup() {
analogReadResolution(12);
tft.begin(); tft.setRotation(1); tft.fillScreen(ILI9341_BLACK);
for (int i = 0; i < N; i++) prevY[i] = -1;
}
void grid() {
tft.drawRect(0, 20, N, H - 20, 0x4208);
for (int x = 0; x < N; x += 30) tft.drawFastVLine(x, 20, H - 20, 0x2104);
for (int y = 20; y < H; y += 22) tft.drawFastHLine(0, y, N, 0x2104);
}
void loop() {
int usPerSample = map(analogRead(TIMEBASE_POT), 0, 4095, 5, 500); // sample spacing in microseconds
int trigLevel = analogRead(TRIG_POT);
// wait up to 50 ms for a rising edge through the trigger level
unsigned long t0 = millis(); int a = analogRead(SIG);
while (millis() - t0 < 50) { int b = analogRead(SIG); if (a < trigLevel && b >= trigLevel) break; a = b; }
for (int i = 0; i < N; i++) { buf[i] = analogRead(SIG); if (usPerSample > 15) delayMicroseconds(usPerSample - 15); } // reading takes about 15 us
grid();
for (int i = 1; i < N; i++) {
int y = H - 1 - (buf[i] * (H - 22)) / 4095;
if (prevY[i] >= 0) tft.drawLine(i - 1, prevY[i - 1], i, prevY[i], ILI9341_BLACK); // erase the old trace
prevY[i] = y;
}
prevY[0] = H - 1 - (buf[0] * (H - 22)) / 4095;
for (int i = 1; i < N; i++) tft.drawLine(i - 1, prevY[i - 1], i, prevY[i], ILI9341_GREEN);
tft.fillRect(0, 0, W, 18, ILI9341_BLACK); tft.setTextColor(ILI9341_WHITE); tft.setCursor(2, 2);
tft.print(usPerSample * N / 1000.0, 1); tft.print(" ms/screen trig "); tft.print(trigLevel * 3.3 / 4095.0, 2); tft.print(" V");
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| 3.3 V from the pin | Trace at the top of the screen |
| A PWM test signal | Stable square wave at the right trigger |
| Turn the timebase pot | More or fewer cycles on the screen |
| Unplugged input | Trace floats near the middle |
If it does not work
Trace jumps
Raise or lower the trigger level.
Trace looks jagged
Use a slower timebase or draw fewer points.
Clipping at the top
The signal exceeds 3.3 V; use a divider.
Blank screen
Check the CS, DC and RST pins.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the mini scope display on TFT?
ESP32 DevKit V1, 2.8 inch TFT touch (ILI9341, SPI), Potentiometer 10 kΩ × 2, Resistor 10 kΩ × 2, Ceramic Capacitor 100 nF, Resistor 1 kΩ and Resistor 4.7 kΩ.
How long does the mini scope display on TFT take to build?
About 240 minutes for a intermediate maker, in 7 steps.
How do I know the mini scope display on TFT works?
3.3 V from the pin: Trace at the top of the screen. A PWM test signal: Stable square wave at the right trigger. Turn the timebase pot: More or fewer cycles on the screen.
Trace jumps: what should I check?
Raise or lower the trigger level.
Trace looks jagged: what should I check?
Use a slower timebase or draw fewer points.
Clipping at the top: what should I check?
The signal exceeds 3.3 V; use a divider.
Blank screen: what should I check?
Check the CS, DC and RST pins.
