#261 ESP32 Line-by-line Debugging - works with many ESP32 modules

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
and welcome back yes today we're going to be talking about debugging your esp32 using platform i o running on Visual Studio code if making a PCB is a bit of a puzzle to you let jlc PCB help you pull all the pieces in the right place easy Eda is an intuitive electronic design tool just as I'm showing you here and when you've done that you can convert it into a PCB like this one here and you can view it in 3D and see exactly how it's going to look before you order it it's easy to order from jlc PCB directly from within easy Eda with fast reliable deliveries and now two dollars for five pieces including aluminum boards they can even assemble them for you at no extra charge why don't you see what the jlc PCB can offer you today yes indeed now yeah what's that you're you're not using visual studio code and platform Mayo well I'm afraid I've got some bad news for you Arduino that is Arduino IDE 2.0 point something um says no I'm not going to debug an esp32 it will debug some of the Arduino boards but well frankly nobody uses the ones that it can debug let's look here so this is the official Arduino documentation it says okay debugging with Arduino IDE 2.0 oh yeah it doesn't work with a 1.8 at all but anyway 2.0 it goes yep we got this wonderful new debugger so you really should use it and it goes these are all the boards that it works with you think um just a minute I don't know I've got any of these boards now obviously it's never ever gonna work with an Arduino Uno or something like that it just hasn't got the hardware built into it nor has it got the capability you know the space the memory whatever to to ever run any kind of debugger we accept that but that's all the Arduino IDE is currently supporting now there's one on here that caught my eye I thought ah the zero now I've got a zero somewhere I'm not sure where it is but anyway I had a zero and I did some debugging with it oh 18 months ago and it was so flaky I think I showed you briefly and I said we'll come back to that in a future video um well I guess this is the future video 18 months later let's just have a look at this the zero that I've never looked um what sort of bored it is oh there it is what what 38 Euros and 90 cents you've got to be kidding me that's about well it's about the equivalent in dollars 38 dollars for that and I think I don't think people are going to spend that sort of money just so they can debug their code no I think cereal.print statements are more likely to stay than anybody getting one of those well there are there is talk there is talk on the internet about maybe Arduino the company arduino.cc in other words they they may bring esp32s into the debugging fold as far as the Arduino IDE is concerned but given that the Arduino IDE is really primarily aimed at Arduino boards don't hold your breath and in the meantime we can use platform i o running on Visual Studio code so yeah if you're not running on it yet I would strongly recommend that you go to the platform i o download page and download it and we'll get it running because it's a huge step up even from the Arduino IDE 2.0 so out of all those bits of Hardware then what do you actually need just to get started with debugging well the first thing you need is one of these the ESP prog it's pretty cheap something like 12 you can pay more I mean I bought two thinking they're going to be different but they're not 12.18 in a plus a bit of shipping and tax if you live in live in the UK but they're all much of a muchness and I think they all conform to the expressive design so yeah us that's what you need there we are there it is on screen to say where I bought mine from and uh yeah they're all much information is and they come with they come with these little cables so you might well think about getting some 2.54 cables as well or at least one watch the voltage jumper on here the voltage jumper on both sides but we're only using this one JTAG side not the serial side at the moment it's five volts one side three volts the other that's actually set to five volts at the moment because my board this one here uses only five volts as it goes into the five volt pin but you might want to use the three volt or power itself from a USB especially if you're using Wi-Fi of course because that does suck the power out doesn't it a little bit right everything's connected up on the workbench we have the ESP prog here connected via the 1.27 that's the little tiny cable down to this little adapter thing a few dew point cables back to the TT go V 1.71 one of the boards that works very nicely so let's have a look now what happens we'll just leave that as is what happens in the actual code window this is now Visual Studio code and platform i o okay let's have a look at that now I've just been editing this video and I've chopped out about 20 minutes of waffle I'll say waffle it was technical information about how to set up the board and download drivers very simple to do and all that but it takes time so what I'm actually going to do is Link in to Pages like this right all the details are in the video description and in my GitHub so you'll see Pages like this one and this one all about the ESP prog and the driver substitution that you have to do on that ESP prog piece of Hardware takes about five seconds once you've downloaded this actual utility you've got another one here how to use the esp32 debugger there's all sorts of things going on there right and I'm thinking what's the point of me regurgitating all that when you just go away and read it you've got to read it line by line anyway if you're going to start installing drivers right so I'm gonna call that bit out that's on The Cutting Room floor now and I'll leave you with a whole series of links down in the video description that you can just read at your leisure but the rest of the video is definitely worth watching okay okay just thought I'd sneak this bit in quick so this is a very simple blink program the blinking effect is done with a little function that I've written so we can see what happens when how we can get into that function but apart from that it's pretty standard so what we need to do is make sure you press this icon here to get into the debug bit there we are that one there and then say well it's waiting now to say well what do you want what sort of debugging you want to do we can either do it with the uploading or skipping the pre-bug I don't quite know what that middle one does actually but this one here the bottom one says look I've already uploaded the code I don't need to upload it again so let's just get on with the debugging which is what we're going to do just to speed things up otherwise it takes a little bit of time okay so we're going to click that one and now I'm going to press F5 and with any luck it will stop at the very first statement within setup so F5 you can see there's lots of messages on the debug console a lot of them in red which does not mean an error necessarily okay because a lot of them are info messages certainly doesn't mean an error it's fairly slowly debugging overall because it's got a lot of work to do there we are and it stopped now by that little yellow triangle arrow thing up there to say yeah right I've stopped here now what now we can set some break points by clicking in this margin here and saying well I want a breakpoint here on counter plus plus all right just to see what happens now you can either press F5 which means continue running until you hit that breakpoint or F10 which means just do that statement you're on and then move to the next line wherever that is or f11 which means go into the function that's being called and you know work your way through the code that way I'm certainly not going to do that on pin mode because pin mode is a function written by espressive and it goes into all sorts of you know deep code and assembler eventually so we'll just say run F5 and it should come back down to here here we are now counter is 10 because it shows you what we can watch here I've I've clicked the plus button that says I want to watch counter because there's something wrong with counter for example okay well okay so it should increment it by one if I now press F10 just to go to the next line F10 let's go on to the next line and counter as you can see there it's gone to 11. great and at this point everything stopped core zero stopped core one is stopped it's just just paused now I'm not quite sure what that means for like Wi-Fi and Bluetooth and stuff like that if you've got those switched on whilst you're doing this debugging obviously Wi-Fi can't just suddenly stop as far as I know I don't know we'll have to experiment a bit more with this in future videos perhaps anyway now I'm just going to show you one thing off we're going to take that one off there and put it on here you can have multiple breakpoints but don't go mad um because I've read lots and lots of things on the internet and it says if you have too many break points it gets confused and refuses to do anything ever again so we're going to press F5 and it'll run until the next break point which is on This Blink LED function so F5 there we are so it's now down here now if I were to press F5 again it would just run until it reached the same break point the next time round but we want to say go into this function because you know maybe we're trying to debug something within this function for that we do f11 so f11 and there we are the first statement of blink LED which basically just reads the state of the pin and switches it on if it's often off if it's on okay simple as that and then delays for a second over here fine nothing special happening here if we look at the actual board at the moment so here we are you can probably just make out that green LEDs on at the minute so we'd expect that to go off Would we not if I press F5 so F5 so it should have gone through that a bit of code let's go back to the code window oh hasn't gone off yet what's he doing oh no we're still there that's because my cursor Focus has moved because I changed Windows right F5 and go back to the main main board and there is it's now gone off right so we can see it is actually doing something well doing what it's supposed to do right back to code and it's gone back to Blink LED now at this point as I say if you don't press f11 to go into you can press F10 which will just go to the next statement let me put the cursor back where it should be over here right F10 and it's the next statement and so on F10 next statement and so on F5 will just run until the next breakpoint which is wherever we are great so that's basically it you've got F5 which just means continue until the next breakpoint F10 which means single step f11 which means dive into the function that you're currently on shift f11 means step out of the function you're currently on and um yeah that's basically about it I mean there's not a lot to it in that sense it is a little bit well slow as you saw how long it takes to get to the next break point if I press F5 now and there we are see that took what nearly a second half a second where in reality that'd take about you know a millisecond wouldn't it so you have to be a little bit patient with it apart from that it's all working great and you can look at all these um variables here look if I hover over counter you see the 13 popped up there see that 13 because that's what the value of it is you can also see it over here in the watch window um and well that's about it really once you've got it working like this you can delve into the bit of code you think is not working why does this funny formally that you've written not come up with the magic answer of 42 yeah this is the debugging method for you okay I think as as a sort of an intro in what you can do there is enough because anything else you can you can delve on the internet and I'm sure you'll find other examples of what you can and can't do but as a as a simple debugging step-by-step this works very well and I've spent probably 20 years of my life on big systems like dotnet microsoft.net c-sharp where we spent all our life in debugging mode wondering why our code didn't do exactly what we wanted obviously the programs were quite complex and I don't think we would ever have debugged it without having this facility so it's an absolute godsend and Miles better than doing lots of cereal.print type statements believe me okay the debugging system as a whole works very well when it works some boards it just does not want to play with at all and it throws all its toys out the pram and you can just spend hours don't ask me how I know this but you can spend hours on the internet trying to figure out why some boards work and some boards don't now I don't know the reason why they don't work but I have established some sort of pattern and I'm actually having a different board delivered today just to tell me whether or not my theory is correct or not but in the meantime I can show you that I had this board created by jlc PCB for the dev kit 4 esp32 which is very common this is the 38 pin version we'll have a chat about the 38 pin and the 30 pin in a future video but I've got lots and lots of these boards so I thought well a board like this where I can just put the esp32 on and um use one of the JTAG sockets at the top there would be absolutely ideal so here is one where I've populated it yeah so I've got my esp32 on there just plugs in and of course you can take that thing out again there we are so it's very simple hardly any components on there at all just a resistor and a capacitor and an LED over there to show you if you want to see something blinking a bit like that one down there which incidentally I've just noticed is stuck in debug mode if you notice we've never actually finished that session so it's still waiting for me so let me just clear that I'm going to say stop debugging in that led should start blinking and well it went off okay we're just we're just quietly uh forget about that for the timing I don't know what's going on right so this is the um the board then that I created on the back I've just got a few bits of information on it I'll put the design for this board up in my GitHub so if you want to either copy this or indeed adapt it for a different type of board you can do that and in fact my idea for this came from this one here now this one here was created by Brian luff there he is [Music] he was in Ireland and his he had two boards this one here for the mini 32 of which I had once I thought well I'll try that out and I think he had another one for another type of board that I haven't got I think it might have been a feather or something like that but this one works very well the only downside to this board apart from using this type of um actual module is that you can't connect any peripherals to it once you've got your actual device in there which would help if I got it the right way around that way so you plug that in that's that's fine put your JTAG Cable in at the top you see the big cable they would match up yeah so a simple cable between the two would be fine but the trouble with this is that you cannot connect any further peripherals to this once this is correctly inserted so when that's like that you can't connect anything else up to it so if you've got a problem with one of your peripherals that's causing issues in the code it'll be difficult to debug which is why I created this one so that you can have an extra row of pins or something down the side to connect up any peripherals you want so that's probably in brief where I've got to so far when The Other Board turns up later on today I'll continue recording if my theory holds true who knows we'll wait and find out okay I've tested out many more boards now as you can see there's a there's a quite a variety here and not all boards work what I can say is that out of all the boards I've got here all the ones with these sort of pre-built expressive modules with the actual device inside they do not work which is unfortunate because I've got loads and loads and loads of them all the ones that I've tested like this one here with the X on it with the bare sort of Chip and then the other bit all just built around it exactly the same you would think as what's under one of these if you de-lid one of these it's pretty much the same underneath but these work these don't and I have absolutely no idea why but uh I mean it's not the end of the world a they might fix it in fact I might raise a bug to say why doesn't that work and why do these other ones work but even if your esp32 is not supported using JTAG you could of course you know get one of these specifically couldn't you that you know does work upload new code on that find out what's wrong and then put it back into the the module format of your choice because at the end of the day the esp32 underlying all this is exactly the same okay I think um we'll leave this little intermission as it is uh I can't say which boards work and which boards don't of the ones that I've found that do work I'll put a list underneath but it's a very short list because I don't have you know that many boards and there's dozens and dozens and dozens out there well I hope that's wetted your appetite if nothing else um you've got to use Visual Studio code with platform io on top and you can debug some of those esp32 boards and they're probably many others out there that work as well who knows um but it really is a case of you know chalk and cheese really when using cereal.print statements to find out what's wrong versus actually line by line debugging of the bit of code that you think is suspect makes a huge difference there's nothing to add nothing to remove afterwards it's just works it's really good it's a Pity about some of those boards not deciding to play nice who knows why perhaps they'll be fixed in a future release who knows anyway if you've got any comments about how you debug stuff please put your comments down below I love a hearing from you and I reply to them all and if you liked this and found it moderately entertaining or perhaps I should say edutaining um yeah give me uh give me a like up there that's it up there because I like the hey yay that's the one yes very good and if you like these sort of videos generally talking about Arduino and esp32s and all sorts of things like that don't forget subscribe and click the Bell you gotta take that Bell as you won't hear from me ever again that'd be disaster okay and I'll see you in the next video I hope you're finding these videos useful and interesting there are plenty more videos to choose and a couple are shown below and if you'd like to subscribe to this channel just click on my picture below and enjoy the rest of the videos thanks for watching
Info
Channel: Ralph S Bacon
Views: 13,399
Rating: undefined out of 5
Keywords: Arduino, Beginners, electronics, C++, microcontrollers, programming, gadgets, ardiuno
Id: lOG8-mQHZTw
Channel Id: undefined
Length: 21min 20sec (1280 seconds)
Published: Fri Mar 10 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.