Debugging Without Arduino Hardware

I wrote a complex c++ code for Arduino Uno. It will be hard to deploy, debug, fix process using physical Arduino. Is it possible to test my code logic on Visual Studio Code? I can start debug and breakpoints works. I can use Serial.print to see on VS Code console, but it is slow and I can see Serial.print outputs too late and all messages appear at the same time. Is there any easy way to debug the PlatformIO project on VS Code like I debug a desktop application?

PlatformIO doesn’t officially support debugging real 8-bit AVR hardware, but:

  • Atmega32 debugging with avarice and avr-gdb is a thread about using a ATATMEL-ICE with the avarice software as a GDBserver. The debug probe originally costs ~100€, clones can be built cheaper. Avarice can also work with the cheaper AVRDragon, ~50€.
  • VSCode PIO debugger for AVR is thread about integrating the dwire-debug program into PIO, which also opens up a GDB server. Uses the debugWIRE debugging technology via the (bi-directional) reset line, only needs a serial adapter and a diode as hardware.

Once you have a working debug probe connected to the target and a program which can open a GDB server, PlatformIO can connect to using it’s normal avr-gdb gdbclient and you can debug as normal. Also see options in docs.