Is there a way to debug or set breakpoints while it's running?

The new IDE (IDE version 2.0) has debugging for the more sophisticated processors.

As of today, the debugger supports all the Arduino boards based on the SAMD and Mbed platforms (MKR family, Nano 33 IoT, Nano 33 BLE, Portenta, Zero). Maintainers of Arduino cores for third-party boards can add support for debugging by adding the relevant configuration parameters; a technical guide for this is coming. You’ll need to connect a debugging probe such as the Segger J-link to the JTAG pins on the board and you’ll be ready to go.

The version 1.x Arduino ide does not support debugging at the hardware level. Using Serial print commands is by the fastest and easiest way to debug. It may take a bit of time to learn as it is a different concept but it can and does work.

You have to start with the proper syntax. Have a look at this example that prints an analog input, exactly what you’re trying to do.

https://www.arduino.cc/reference/en/language/functions/communication/serial/println/

1 Like

Thanks for the advice. I have a half dozen or so UNO R3's. Maybe it's time to upgrade!

1 Like

Thanks for that - i actually did see that one, but what I kinda need to do is get the value of 4 different potentiometers but I need to know which is which, since it's all flies by so fast. So the

serial.println()

Kinda needs to have the name of the variable preceding the value. is there a way to do that?

Thanks

Mike

Read thru this:

@spielbergrules, I agree with @WattsThat. Learn how to use the Serial functions first.
You need to output lots of information to the Serial Monitor to learn to use the Arduino.

If you really want, then there are two online simulators that can also debug a sketch for a Arduino Uno: Tinkercad and Wokwi.
I made a comparison here: Virtual Online Arduino Simulator - Wokwi Arduino Simulator - #3 by Koepel

I'm used to print information to the Serial Monitor now. Using a debugger is rarely needed, because there are often several timing things going on with a combination of hardware and software.
Finding a problem with a pointer or array and writing to wrong memory is also hard to find with a debugger. With such problems you can show us the sketch and we find them :wink:

Hello Mike.

I like using Bluetooth to get info on what the sketch is up to. This is easier than it might at first seem.

I use an HC-05 BT module connected to a software serial port on the Arduino. The sketch then communicates with a phone/tablet app via the BT which can be viewed as serial without wires.

On the phone side, there are several serial BT terminal apps available. This setup provides an equivalent to the IDE monitor and requires no programming effort on the phone side.

If you want to retain data on the screen instead of having it rapidly scroll off the screen, then a simple custom app will do the job. Not hard to learn how to build such a simple app with MIT App Inventor.

There's a good chance that once you master this you'll find many ways to incorporate a phone app in your projects for data display and even controlling your sketches.

John.

See "pert" response here:https://forum.arduino.cc/t/debug-version-of-serial-print/560360/2

1 Like
Serial.print("sensor 1 value = ");
Serial.print(sensor_1_value);

prints

sensor_1_value = 861

Install Streaming.h using library manager
https://www.arduino.cc/reference/en/libraries/streaming/

Then things get so much easier. Example:
https://platformio.org/lib/show/560/Streaming

So...

Serial.print("sensor 1 value = ");
Serial.print(sensor_1_value);

Becomes:

Serial << "sensor 1 value = " << sensor_1_value << endl;

Be sure to add #include <Streaming.h> at top of your sketch

Thanks for those! I will check them out! There's some good info in there. I couldn't seem to find the one I was looking for but maybe can finagle one of those!

Thanks for that reply. All of you folks have given such great info - it's hard to keep up (and that's a good thing!) I will reply to all...

Thanks for that info - I did check out pert's reply. Maybe something can be done with that.

Well crap. I think that's the way to do it! Obviously I didn't think to split it on 2 lines. Again, considering I come from a VB background. Thank you!

Another great reply! So much great help from all you guys! Thank you!

And just for fun, another way using sprintf().

int sensor_1_value = 77;

void setup()
{
    Serial.begin(115200);
    char buffer[25];
    sprintf(buffer, "sensor 1 value = %d", sensor_1_value);
    Serial.println(buffer);
}

void loop()
{
}

Prints:

sensor 1 value = 77

Great point with sprintf, just don’t expect the %f floating point formatting to function. For that you need dtostrf().

Why stop at sprintf? I found here some years ago a way to use printf, which I missed.

# include <stdio.h>

int serial_putc(char c, FILE *) 
{
  Serial.write(c);

  return c;
} 

void printf_begin(void)
{
  fdevopen(&serial_putc, 0);
}

void setup() {
  Serial.begin(115200);

  printf_begin();
    
  Serial.println("W T F");
  
  int anInt = 32456;
  float aFloat = 3.141593;
  char *myChars = "OK, that's a wrapper.";
  
  printf("good old. %d %f %s\n'K?", anInt, aFloat, myChars);
}

void loop() {
  // put your main code here, to run repeatedly:

}

I have no idea what the implications are, but it works. I have placed the key elements off in my own library, never mind about that. I am sure you will all do whatever it is you do or don't with this.

Yes there is yet no floating point, as the demo, er, demonstrates. Too bad.

a7

If you're willing to invest money in a proper hardware debugger and import your sketch into Microchip Studio, then you can do stepping and variable inspection.

Importing works really well if you're targeting an official Arduino core, but third party core support can be a bit flaky.

I doubt that it's gonna have any negative effects. It's sort of the defacto way of defining the standard input/output using avr libc. The neat thing is that you can output to what ever you want, serial/display/carrier pigeons.