I was wondering if someone figured out a way to step thru a sketch or other way to do this while it's running. Of course I know it's not running from the sketch as it was uploaded to the Arduino.
For someone who is used to programming in Visual basic and having a whole host of breakpoints and variable watching, it's a bit tough for me to switch over, especially since I really don't know much about C++ (but am learning.)
The easiest, most convenient way, is to sprinkle Serial.print() calls around your code.
These can be removed or commented out once that piece of code works as expected.
If you need the serial port for your code, don’t be afraid to create an extra serial port just for your debug output. It doesn’t have to be fast or ‘special’ just enough to tell you what’s going on.
If you mean programming with the Arduino IDE with the less sophisticated processors, serial prints are the most valuable trouble shooting tool. Use them to trace execution (after an if to see if it fell through or not), monitor values of variables and outcomes of calculations, etc.
Another tool might be using LEDs, buzzer or some other indicator.
Thanks for the reply. I actually did try serial.*() but I was unable to get good output in the serial monitor (if it didn't give me an error.)
One project is working with 4 servos being turned with 4 pots. I want to see the value of the pots because even tho the wiring and individual variables for each servo have been verified what seems like a million times, when one pot is changed, the others would start jittering.
When I tried each of the types of serial.*() commands, I really wanted one that was like:
None of them worked. if I could get the variable for each of the 4 servos, I could track it better. Is there a way to do that? The examples I looked up didn't show anything about using a 'text' before a variable.
Thanks for the reply. Maybe someday there will be an option to trace through a sketch. I don' have the knowledge to do anything other than suggest the idea. I'm sure others have too.
Good idea on the LEDs, etc.! Might have to try that.
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.
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?
@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.
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
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.
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!
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!