A little correction/notice: The debugger shown here is not a "true" hardware debugger, but an instance of GDB in combination with a little mediation program on your Arduino called a "stub". This means that a small portion of your uploaded firmware is only there to establish a connection between your internal program states and the serial terminal. This explains why starting the debugger is part of your code (see debug_init()) whereas a "true" debugger would manage all attachments to your chip from its own peripherals. You could say, the firmware is "aware" of the debugging when using a stub. This also means that a bit of memory will be inaccessible to you, because the stub needs it. If you were to upload a program that uses every byte of memory, you wouldn't be able to debug your program anymore, so keep that in mind. And even more so, since the stub uses serial, any printing won't be available. Happy debugging!
I've been programing microcontrollers with arduino and platformIO for YEARS, but I wasn't even aware this could be posible to do. Also, great video, keep up!
Such a great channel providing simple and useful knowledge... Feeling good to be your 23rd subscriber. You have my support ❤️, Please keep making videos like this. 🔥
As much as I hate RU-vid algorithms as well as this platform, this time I was absolutely blessed with coming across this video. Thank you my dude! For quite some time I was thinking about using some normal IDE for Arduino projects, but was too lazy to actually look it up.
A minute into your first video and I hit the subscribe button. Love your comunication skills, just the right amount of humor and explaination speed. Some of these you-who-tube creators talk sooooo slow... I guess they don't think I can hear very fast. You're awesome and thanks for posting!!
I am astonished that I did not know this is possible, OK it's not a true debugger but it does the one thing that helps debug code i.e. it stops at breakpoints. I rarely need to know the value of the Program Counter and Registers when debugging and if I do I can turn to an STM32 product plus CubeIDE, the only true debugger I have found to be trouble-free. Great video and yes the presentation is very watchable. A bonus was that after actioning all the steps in the video, it actually worked! I have just subscribed - thank you J. PS Just upgraded to the latest version of Jan Dolinay's software i.e. v1.5 and when hitting a breakpoint I can see the values of all 32 registers and the Program Counter and Stack Pointer, I can also add variables to the Watch list and see them change as the code is stepped and finally view memory after setting a start point e.g. 0x8000 and the number of bytes to display e.g. 10.
As mentioned this is not real debug but software emulation of debug. Arduino cpu doesn't stop on breakpoints, and timers continue to count and no sence to try to watch timers. You can not debug your code that depends on timers count in this way. The solution could be, e.g you can mock millis() function in a way that it returns variable that is incremented each time when loop() function returns. So you can debug your code that call millis() function
Personality plus Mr. J's. Interesting programming direction using Visual Studio Code and Platform IO. You have my attention J. I might just try it. Thanks.
I'm glad it wasn't just me. I recreated exactly the start of this video just scrolling through google results trying to find some sane guide on how to debug and getting nowhere...
I wasn't aware of this, I'm not using the nano much lately because for a similar price there are far more capable alternatives but it is definitely a nice tool to have.
@@ArtOfTheProblem don't touch ESP8266. Of course you can use it if you know his big disadvantages... If you wan cheper option try Esp32-s2 in D1 style or esp32-c3 Mh-tiny. But for very beginig Esp32 NodeMcu compatibile board is best. BTW: WROWER version (with PSRAM) allows you use different programming languages (python, PHP, ...)
While I do own an hardware debugger aka the atmel-ice with J-Link on backorder for a year now. This an easy way to debug for smaller projects. For a very complicated I wouldn't chose avr stub.
Great! I've developed a whole project without knowing this was possible. As I got my UART port busy -which was my board main communication channel with other HW modules- I had to use a separate arduino as SPI-UART gateway, and sending those kind of "enter function 1!!!" "enter if" "enter else" texts over the console. Having known this, probably i'd have chosen another way of communication, freeing the UART for debugging. I also wonder why this is not ~basic primitive~ stuff along Arduino community! How can a novice learn without debugging? Thanks again for sharing this information.
Hi! So.. i have a question. In the first step you said to take arduino ide and throw it out of the window. How can i do that? i mean, i guess i can take apart my ssd and find where arduino files are, but i dont think that is the best idea.
That is remarkably simple. I thought you'd need to get one of those extra serial debugger modules to do this. I had no idea it would work out of the box. I wonder how many other devices you can do something similar with?
avr-stub is a software debugger, in most serious situations you would need a debugger like j-link. This is shown in the video in the arduino ide 2.0 features.
good presentation. sure, it works great with simple projects, standard libraries and standard cores but using it with complex projects fails more often than not and the configuration settings are a mesh.
That is true. As far as i understand this debugger is a bunch of bitbanging over the serial connection, which is very error prone, especially if the clock speed is high and the usb cable is long. Nevertheless, if you are planning on building a large project, you should consider moving away from Arduino anyways. STM for example has a great debugger. Works with the Arduino Framework as well.
@@jse-shack825 10Q for the response. I have used STM products; their documentation is cryptic and their tools non intuitive. I have resulted in 'adopting' raspberry pi pico for my needs (i develop rpn programmable calculators) 'cause it is cheap and well documented. i love it. keep it up :-)
Great thing. The debugger is especially important for beginners who are struggling with trying to understand the internal intricacies of how Aduino works.
Hi, a breakpoint is usually used to read out the content of some variables, to understand where a mismatch in our coding is coming from. Can we monitor the value of variables with this "debugger-like" tool? I guess not..
There's one hidden problem with this approach: is that it uses serial. Yes, the same serial many use to print out stuff or for communication with PC. So in case you need to debug and print to serial you will need a second arduino in passthrough mode (reset shorted to ground) and a bit of config definitions in platformiotxt.
@@cbs1710 Its relatively easy - you get the board you want to debug connected normally to PC via usb, then you take a regular uno and short reset pin to ground (effectively bypassing any sketch and processor it has), then connect it to the first board by pins 0 -> 0 and 1->1 (mine has them labeled rx to rx and tx to tx) and connect it to PC too via its respective USB port. In the end both boards should be connected to pc. After that you tell PIO to use first USB port to upload and second to debug. I think there are step-by-step guides you can google for it.
@@emaayan on silicon mini and don't get any errors, but nothing happening (blink merrily continues blinking despite having a red dot next to "delay(1000);" . I'm new to VS Code and PlatmorIO but good with embedded systems in general. Is there anyone willing to work with me on replicating on MacOS?"
@@emaayan There are two reasons (maybe more) for this error message. 1) Ensure the COM port you specified in platformio.ini specifies the correct COM port that your Arduino is connected to. 2) If you happen to be using the ELEGOO version of the Arduino NANO, then this debugger won't work on this device. The ELEGOO version of the NANO uses a CH340 serial communication chip instead of the official Arduino FT232 chip. It does work on the ELEGOO version of the Arduino UNO.
thx, looks like cool. But does default debugger so bad? *find answer* it is strange, but it is not default feature of MC, you need or external debugger device, or MC with built in. Really strange, because there are all capabilities for communication. Anyway, that arduinos that has ESP32 has this ability in WIP, so I hope it will be able soon.
Thanks for the amazingly simple tutorial and the bits of comedy =P. If anyone is looking at this tutorial trying to use the same process to debug a Seeduino Nano device, you have to change the "env:" and "board =" fields to "nanoatmega328new" Also, if you are getting some issues with entering debug mode concerning "libncurses.so.5", just run this on your terminal: "sudo apt-get install libncurses5"
Hello , very interresting and simple. But it's Ok for your UNO or NANO. Do you have an example idem For ESP32-S3 witch include Board JTAG ? Thank You Very Much
Such an excellent explanation. Maybe you could guide me on this problem: Error: Could not find the package with 'jdolinay/avr-debbuger @ ~1.4' requirements for your system 'windows_amd64' .... and so #include's #include #include fail . Thanks anyway ! Greetings from Buenos Aires.
This looks great. but I haven't been able to make it work. It compiles well. Uloads well and the it says .pioinit:13: Error in sourced command file: COM9: No such file or directory. Can you help me? Thank you
Very nice but a couple HUGE catches - serial port conflict mentioned previously AND breaks in SETUP are INGNORED. Inching closer to Atmel Studio every day
Quite cool, but it is still some kind of BS but not that big as Arduino IDE. Solution to this is to buy Pickit4 or Snap or ICD4 and import arduino project to MPLABX. Works very well on ANY atmega. Of course compiled program doesn't have bootloader anymore, unless you specify proper memory offset for compiled binary, to preserve that bootloader area and load bootloader binary during flashing as well. That way you can go back to Arduino IDE if needed. Or you can wipe bootloader and then restore it with programmer.
The only time that i have needed debugging like this was on an arduino mega (about 3 years ago). I have adopted putting serial prints into #ifdef debug with a #define debug to make it easy to disbale and enable anything used for development by commenting out the #define. the other nice thing about this, is it allows you to have multiple types of things sent if you have mulitple #define for various things. So you need data for calibration #define calibrate - then put the serial prints inside of an #ifdef...#endif. Need debuging type stuff, uncomment #define debug. Neeed calibration, uncoment that. need both - you know what to do.
Such a shame, this does not work, gives error "Could not find the specified task." Are you really doing nothing else behind the scenes as have checked your vid slowly through to make sure all the syntax I have taken from your info is correct and still the same error, and yet your demo works, how can this be ????????.
...."Nobody is talking about it"... Because adults in the room use J-link (J-tag) instead which affords a boundary scanner as well. Once you use it you will never want to go back.
"Adults in the room" probably won't even use Arduino, let alone watch this video. The brackets in the title are there for a reason. Many novices get a classic Arduino model and find out about debugging sooner or later and then get let down by the fact that their device is not debug-ready out of the box without additional hardware. This video tells people about a free and easy to use debugger for exactly these 2 beginner models. As flawed and slow as this debugger is, it is far more approachable for novices than a +500$ J-link probe they a) know nothing about yet and b) most likely can't afford.
@@jse-shack825 This "adult" is very amused by your videos. You can get a J-Link EDU for around $60 (current pricing). For ARM based chips there is also DAPLink debuggers available, even cheaper. This method is much better in terms of upfront cost. @eglintonflats Wat on this earth will a entry level want with a boundary scan.
It is software stub debugging, which is technically not debugging, but a) still more debugging than having to use Serial.print() and b) it might as well be debugging for somebody who only uses it for simple programs like many beginners do. And if you're not a beginner, then you probably know how to debug Arduinos with other methods. This video is aimed at somebody who has been fiddling around with Arduino for some time and still might be overwhelmed by the complexity of external debugging devices. Having less potent debugging but omitting extra hardware is a good trade-off for beginners.
First of all, never code in arduino terms, only use anscci C, because in time critical applications you will have a large issue, Second, you will never have accesses to registers view, whitch is fundemental for debugging professional, so dont use this method, bye an Atmel Ice, get rid of the arduione bootloader, and code in Ansci C, the only way to do this right