Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Breakpoints are a great way to see how the compiler runs to your code. Now my question is, is there a possibility to use breakpoints when you debug your code?

share|improve this question
    
You could try this; github.com/mikaelpatel/Arduino-Debug – Mikael Patel 8 hours ago
up vote 3 down vote accepted

Not in the Arduino IDE.

You need to:

  1. Install and use a real IDE, such as Atmel Studio, and
  2. Use a full hardware debugger

There is no provision for debugging through the UART/USB interface using the bootloader.

share|improve this answer

As noted in Majenko's answer, the Arduino IDE doesn't provide a breakpoint mechanism but Atmel Studio does support breakpoints.[*]

However, if you have a switch and an LED, you can track the progress of your program in a way that provides some of the benefits of breakpoints. You would add a subroutine, say BPReport(), that via serial output or an LCD reports values of critical variables, then lights the LED and waits until the switch has been pressed and released, with debounce. Call your BPReport() routine whereever you want an unconditional breakpoint. For conditional breakpoints, you can have a routine BPReportIf(cond) which calls BPReport() if cond is true. If you don't want to output via serial, you might use several LEDs or an LCD, and you might use several switches if you want external break controls (for example, cond could be a test of one of the extra switches).

[*] Some hardware debuggers modify downloaded code each time breakpoints are added, changed, or removed. That usage will wear out flash memory more rapidly than just occasionally downloading to it. If a chip has been heavily used for such debugging, don't use that chip in a production system.

share|improve this answer

Though Majenko his answer is correct there are some other options.

As to the real hardware debugging as stated by majenko I would say:
1) Install and use a real IDE, such as Atmel Studio or the arduino eclipse plugin called sloeber (I'm author), and
2) Use a full hardware debugger or hardware that has it on board like the Arduio zero or hardware using other debugging technology like the ESP8266 that allows USB debugging

An other debugging option from a completely different category is to organize your code so that decision logic (hardware independent) and action (hardware dependent ) are completely separated.
Then compile your sketch as a local program and debug the "decision logic" on your local machine*. This method does not allow for "hardware debugging". This method also enables unit testing.

*Note that your local machine is probably a 32 or 64 bitter and most arduino's are 8 bitters which will result in differences in data types which is an extra attention point when using this method.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.