Arduino blog

Arduino blog

Arduino thinkering

This blog is about things I come by related to Arduino which I feel are inspiring/important/funny enough to write about.

Debugging and unit testing Arduino (Part 3) Setting it up and debugging

eclipse pluginPosted by Jan Thu, July 02, 2015 00:00:38
EDIT for this to work you need to have a gcc compiler in your path capable of making local executables.

(This post assumes you know how to setup and use the arduino eclipse plugin)
For the sake of this post we will now create a new project based on the uno.
Use the create new sketch wizard to create a new sketch called debugDemo as follows:
Make sure you have selected the correct boards file!!
Lets take a blank ino file
click finisch

open debugDemo.ino and paste following code in the ino file.

#include "Arduino.h"
void setup() {
// Add your initialization code here

void loop() {
static uint8_t ledState=LOW;
ledState = calcLedState(millis(), ledState);
digitalWrite(LED_BUILTIN, ledState);
#define INTERVAL 500
uint8_t calcLedState(uint32_t currentMillis, uint8_t ledState) {
static uint32_t previousMillis = 0;
if (currentMillis - previousMillis > INTERVAL) {
previousMillis = currentMillis;

if (ledState == LOW)
return HIGH;
return LOW;
return ledState;

Compile and upload to a uno to verify it is working. (you should get a blinking led on pin 13)
Untill now we have done nothing new. We have just uploaded a blink without delay sketch to the uno.

Now we'll create a debug configuration for our debugDemo project using the "jantje hardware".
To do so you first need to install the hardware found at my github repository.
Once the hardware is on your system right click the project in the project explorer and select project properties->arduino.
Press the button called "manage configurations"

Press the button new to create a new configuration called "Debug" based on "Release" as shown on the image below.

Press ok 2 times to get back to the arduino properties.
Select "Debug" in the configuration in the combo box.
In the boards.txt file select the one that ends with "/hardware/jantje/avr_local/boards.txt"
In debug or unit test fill in "debug"

Make sure you do not have selected "use alternative size command" in compile options.

Compile the project in the debug configuration (this is not strictly needed but it makes it easier to fill in the following forms)
Right click the project->build configurations->build all.
If the build fails probably something went wrong when setting up the environment (but try to build again before looking for the root cause).

Now we have our sketch build for running on arduino and build for debugging on our local machine. What needs to be done now is
Setting up a debug configuration.
Right click the project and select "debug as"->debug configurations.
Select C/C++ application and new.
Here you will have to experiment a bit with the settings. On my system I have to use the "legacy create process launcher". I use the settings as shown below.

!!Note that forgetting to set the build configuration to Debug is a perfect way to increase your frustration level!!!!
Now click apply and then debug.
If all is well you should see eclipse compiling your project and eclipse may ask you to switch to debug perspective (click yes if he does).

The debugger breaks in the main function. Set a breakpoint where you want it and have a happy debugging session.
Best regards

  • Comments(9)//