Being able to track errors in a large amount of source code is a skill in itself, a skill that is difficult to learn from books or online tutorials. In addition to constantly learning while debugging your own projects, the next best thing is to observe the processes of others. [Uri Shaked] As he showed, this gives us a great opportunity to improve our debugging skills How to track and eliminate errors in the Wokwi Arduino simulator.
A user kindly reported this error and included the problematic Arduino sketch. [Uri]The first step is to reduce the sketch to the smallest possible program that still produces errors.
Once a minimal program is generated, it is time to check whether the problem is in one of the Arduino libraries or in the Wokwi simulator. [Uri] Compile the sketch, load it on ATtiny85, and compare the behavior of the simulator with real things. It turns out that the code runs very well on the physical ATtiny, so the problem must lie in the Arduino simulator itself.
To track errors in the simulator, [Uri] Decided to shoot a big shot-GDB. Below is an excellent demonstration of how to use GDB to isolate the problem by examining the source code and using breakpoints and print statements. in the end, [Uri] Try to isolate the problem to a misplaced bit in the simulation of the timer/counter interrupt flag register.
If you want to see more [Uri]For debugging ability, please check his in-depth understanding of ATtiny write protection and configuration fuses. If you are amazed by the power of GDB and want to learn more, please check out this quick tutorial!