Sharing Debugging Techniques

Composing a post on the forum explaining the project and the problems being encountered is also a good way to suddenly have that "lightbulb" moment

Sometimes it is even the act of clicking "Reply" that triggers it off

Testability

I try to write code in a way that each function can be tested separately just with a small test environment around it.

It's more or less like @embeddedkiddie pointed out: Start small, test small.

How to start

I usually start with the most critical functionality and try to keep the (very first) solution as simple as possible to ease debugging. Making it look "beautiful" is less important and has time after creating a safe solution.

Which takes about an oh-no second to realize.

a7

Oh lord! Mine too!

Many of us oldsters know this, it is more for newcomers.

  • Okay, this isn't really a debugging technique but it adds reference information to a sketch.
    You can add a reference page or wiring image to the sketch so when it is needed in 6 months, you can find it again.

  • In the IDE, a single click takes you to a URL or an image on the internet.



// Click for Arduino Blink documentation:
// https://docs.arduino.cc/built-in-examples/basics/Blink/

// Click to see LED wiring.
// https://images.squarespace-cdn.com/content/v1/62d7afdd0711b76729174013/83ea983b-ac01-4f57-8a8e-15e6bd02a001/led_circuit.png?format=1500w


//The setup function runs once when you press reset or power the board
void setup()
{
 //Initialize digital pin LED_BUILTIN as an output.
 pinMode(13, OUTPUT);
}

//The loop function runs over and over again forever
void loop()
{
 digitalWrite(13, HIGH);   //turn the LED on (HIGH is the voltage level)
 delay(1000);              //wait for a second
 digitalWrite(13, LOW);    //turn the LED off by making the voltage LOW
 delay(1000);              //wait for a second
}

If using Arduino IDE 2.x, it is Ctrl+click (Command+click for macOS users).

  • Thanks for the update.

  • I'm still at 1.8.18

:old_man:

There have been times when writing about an issue I have on here , I’ve realised what the problem is and the fix - then I delete it so as not to appear stupid

  • Well, some days, I feel ignorant. :roll_eyes: