🌈 ESP32-S3 Rainbow: ZX Spectrum Emulator Board! Get it on Crowd Supply →
View All Posts
read
Want to keep up to date with the latest posts and videos? Subscribe to the newsletter
HELP SUPPORT MY WORK: If you're feeling flush then please stop by Patreon Or you can make a one off donation via ko-fi

The Six Stages of Debugging (and How to Escape Printf Hell)

Every developer knows this journey.

  • A bug is reported.
  • You’re confident it’s impossible.
  • A few hours later you’re staring at the code wondering how it ever worked at all.

Here are the six stages of debugging - which we’re all going to go through at some point in our lives:

  1. That can’t happen
  2. That doesn’t happen on my machine
  3. That shouldn’t happen
  4. Why does that happen?
  5. Oh, I see
  6. How did that ever work?

Stage 1: That can’t happen

The first stage tends to be denial.

We get a bug report in and our response is immediate: “That can’t happen.” What’s being reported is simply impossible — our software does not behave in that way.

Stage 2: That doesn’t happen on my machine

The second stage is more denial, just slightly more polite.

There’s a grudging acceptance that the user may be experiencing some kind of problem… but we can’t recreate it.

It’s the classic: “Works on my machine.”

Stage 3: That shouldn’t happen

Now things are starting to get interesting.

We’ve managed to recreate the bug, but we know in our heart that it should not be happening. The code is not supposed to behave like this.

There is clearly something wrong with the universe.

Stage 4: Why does that happen?

This is where we’re finally getting into the fun part of debugging.

We’ve accepted reality, and now we’re asking the right question: What is our code actually doing?

This is the most important stage — and also the one where we can easily get stuck.

Stage 5: Oh, I see

If you’re lucky, your debugging leads you to the solution.

Suddenly the problem is obvious. The code is wrong — and now you know exactly why.

This is the moment every developer is chasing.

Stage 6: How did that ever work?

The final stage is an existential crisis.

The code is definitely broken. You’re left scratching your head, wondering how this thing ever worked in the first place.

The real challenge

The real trick is getting from stage 4 — “Why does that happen?” — to stage 5 — “Oh, I see” — as quickly as possible.

On this blog and YouTube channel, we’re often dealing with embedded devices - particularly the ESP32 range of MCUs.

What are our debugging options?

Printf debugging

For anyone familiar with the Arduino framework, these two functions will be very familiar:

Serial.printf("...");
Serial.println("...");

We litter our code with lines such as:

Serial.println("Here 1");
Serial.println("Here 2");

And eventually end up with things like:

Serial.println("Should not be here");
Serial.println("Really should not be here");
Serial.println("Why the **** are we here!?");

Printf debugging works — up to a point.

It’s quick. It’s easy. And it’s often the only tool we reach for.

But it’s also slow, messy, and gives us very limited visibility into what’s actually going on.

Wiggling GPIO pins

Another option with embedded systems is outputting values on GPIO pins.

We can hook up some LEDs to make this more visible, or if we’re very lucky, connect a logic analyser and really dig into what’s happening. These tools are powerful and can do all sorts of clever things, like decoding protocols.

But even then, we’re still inferring behaviour rather than observing it directly.

There is another way

If you’re debugging an ESP32 project, you might think these two options are all you have:

  • Printf debugging
  • Wiggling LEDs

But there is another option.

Recent ESP32 modules have built-in USB peripherals — and more interestingly, built-in JTAG debugging support.

That means you can add breakpoints to your code and simply hit “Start Debugging” in the Arduino IDE.

It really can be that simple.

With a real debugger, you can:

  • Set breakpoints
  • Use conditional breakpoints
  • Inspect variables
  • Modify values while the code is running

It’s just like debugging code on your desktop — but on an embedded device.

See it in action

Here’s a short video showing what’s possible when you use the ESP32’s built-in USB debugging support, including breakpoints, variable watches, and conditional logic.

If you’re tired of being stuck in stage 4, this might be the quickest route to stage 5.

Related Posts

Web Serial Plotter - I've created a web-based serial plotter for easy data visualization from Arduino and ESP32 projects. It boasts real-time plotting, interactive controls, data analysis, and a serial console—all within your browser with no extra installations needed. Give it a try and streamline your microcontroller data analysis!
This number does nothing - Ever wondered about the ubiquitous 'Serial.begin(115200);' in your Arduino projects? It turns out, with boards like the ESP32-S3 offering native USB support, this baud rate doesn't really matter when streaming data. My tests even showed surprising results with different speeds using Arduino and ESP-IDF, highlighting potential in USB full-speed capabilities. I dove into raw performance testing, and saw deviations from expected UART limits. Check out the full video and explore the results if you're curious about maximizing your data transfer speeds!
How do we debug? - Today, we dissected a classic programmer joke about the stages of debugging and why we find it funny while it reflects a dire situation. We pondered why our first instinct is to dismiss a bug, dug into invalid claims about machines, and appreciated the shift from denial and blame to accepting responsibility and finding solutions. After deconstructing the old stages of debugging, we reconstructed healthier, proactive stages with prime focus on problem-solving. Next, we explored different types of bugs from easy user interface bugs to the complex Heisenbugs. Lastly, I highlighted logging, debuggers, and good old human brainpower as instrumental tools for debugging. Be patient, be a detective.
ESP32-S3 Dev Board Assembly - I finally assembled our ESP32-S3 dev boards—used a stencil for easy SMD work, fixed a few tiny USB solder bridges with flux, and even hand-built one for fun. The EPAD isn’t required (per the datasheet), power LEDs look good, and on macOS you can spot it under /dev before flashing. A quick boot-button dance and the blink sketch runs great—full build and walkthrough in the video.
ESP-IDF v6 in VS Code: Blink (and debug) on the ESP32-S3 - I finally crawled out of the v5.x cave, installed ESP-IDF v6.0.1 with the VS Code extension, spun up the Blink example on an ESP32-S3, fixed a finicky flash by switching to UART, then used menuconfig to set the LED pin, bump the CPU to 240 MHz, use the full 16 MB flash, and enable 8 MB PSRAM. Wrapped it up with proper USB JTAG debugging in VS Code. If you’ve been putting off the IDF, v6 in VS Code is a super-smooth on-ramp.

Related Videos

Stop Using printf() - Debug ESP32 the Right Way - Right, let’s give this a go. Instead of drowning in printf()s and blinking LEDs, I show how the ESP32-S3’s built‑in USB JTAG lets you hit Debug in the Arduino IDE (or PlatformIO) and actually step through code. We set breakpoints, add watch expressions, use conditional breakpoints, and even edit variables live with a simple FizzBuzz/LED demo. It’s quick, it works, and it beats “works on my machine”—just mind real‑time code and ISRs. Works on ESP32s with native USB.
I Asked AI to Design 12 ESP32 Dev Boards. It Said No. - I got bored of making one ESP32 dev board at a time, so I scripted the whole lot. After my favourite AI monkey told me to automate the repetitive bits, I built a pipeline that generates fully laid-out USB-native ESP32 dev boards for a dozen modules—schematics, placement, routing, silkscreen, and Gerbers—automatically. It uses a module database to choose safe pins, LED and boot pins, lays everything out in a standard USB-C two-layer format with differential USB pairs and ground pours, and publishes releases via GitHub Actions. You can fab them right away (thanks PCBWay), but treat them like open hardware: trust, verify, and tell me which ones to build.
I Built My Own ESP32-S3 Board… And It Actually Works! - I finally assembled my super simple ESP32‑S3 dev board—voltage regulator, reset button, three status LEDs (5V, 3.3V, and a GPIO blinker), and all pins broken out. I showed two build methods: stencil + hot-plate reflow (quick, with a few USB bridges to clean up) and full hand-solder under the microscope, complete with the rigorous ‘solid’ test. Soldered the ESP32‑S3 module (skipping the center thermal pad unless you need it), plugged in, got power LEDs, confirmed USB enumeration, flashed a blink sketch, and we’ve got a blinking LED. Next up: turning this basic dev board into something more professional for production.
Live GPIO Viewer - In my latest discovery, I found an incredibly efficient visualization tool from the last outpost workshop that upgrades how I check the status of the GPIO pins on my ESP32. It's super simple to use and allows me to monitor pin activities directly. I set up a couple of LEDs and a button on various GPIO pins to demonstrate its effectiveness and the results were fantastic. Although it currently supports only digital input and output and PWM, I'm optimistic it will expand with time. Thanks to the open-source community, you can find the setup instructions in a GitHub repo. This tool is a revelation and I highly recommend it.
ESP-IDF 6 Setup in VS Code: Blink & Debug an ESP32-S3 - Time to get with the program and jump to ESP-IDF v6.0.1 in VS Code. I show you how to install the prerequisites (I’m on a Mac with Homebrew), run the ESP-IDF Installation Manager, spin up a Blink example for an ESP32-S3, tweak menuconfig (GPIO21, 500 ms), then build and flash—switching from stubborn USB JTAG to trusty UART when things fail. We check the monitor, bump CPU to 240 MHz, fix flash to 16 MB, peek at PSRAM, and give PCBWay a quick shout-out.
HELP SUPPORT MY WORK: If you're feeling flush then please stop by Patreon Or you can make a one off donation via ko-fi
Want to keep up to date with the latest posts and videos? Subscribe to the newsletter
Blog Logo

Chris Greening


Published

> Image

atomic14

A collection of slightly mad projects, instructive/educational videos, and generally interesting stuff. Building projects around the Arduino and ESP32 platforms - we'll be exploring AI, Computer Vision, Audio, 3D Printing - it may get a bit eclectic...

View All Posts