Projects / Mini scope display on TFT

Mini scope display on TFT

Intermediate4 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. ESP32ILI9341ILI9341

    Test the display

    Run the Adafruit ILI9341 example.

  2. ESP32

    Read the input

    Print raw values for a pot voltage.

  3. ESP32

    Capture a buffer

    Fill 300 samples quickly.

  4. ESP32

    Draw the trace

    Scale 0 to 4095 to the screen height.

  5. ESP32

    Add the trigger

    Wait for a rising edge.

  6. ESP32

    Add the timebase

    Change the sample spacing with a pot.

  7. ESP32

    Protect the input

    Add the resistor, clamp and capacitor.

In short

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

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
TFT VCC and GNDESP32 3V3 and GNDPower
TFT CS, RESET, DCESP32 GPIO5, GPIO4, GPIO2Control
TFT SDI (MOSI), SCKESP32 GPIO23, GPIO18SPI
TFT LEDESP32 3V3Backlight
Signal in1 kΩ resistor to GPIO34Input (0 to 3.3 V only)
Two diodes or a 3.3 V zener (optional)GPIO34 to 3V3 and GNDClamp for safety
100 nF capacitorGPIO34 to GNDReduces noise
Timebase pot wiperESP32 GPIO35 (ends to 3V3 and GND)Timebase
Trigger pot wiperESP32 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.

CheckExpected
3.3 V from the pinTrace at the top of the screen
A PWM test signalStable square wave at the right trigger
Turn the timebase potMore or fewer cycles on the screen
Unplugged inputTrace 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 →

Ask Lark AI

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.