#215 Raspberry Pi PICO 2040 - getting started with Thonny IDE & µPython

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
and welcome back yes we have the ubiquitous blinking led on the bench today but it's running on a raspberry pi rp 2040 and i thought we'd start simple so that's what we're starting with a blinking led because if you get this far you'll already have cracked the um well not the problem but the the first step in getting that riser before i connected your computer uploading micropython onto the chip itself and uh no learning how to run sketches either from within the ide or directly from the chip yeah it's all a learning curve in it let's crack on then now quick shout out to my sponsor jlcpcb they're doing a collaboration with easy eda as you know it's my preferred pcb cad program it's simple but powerful it's intuitive to use let's just have a quick look at a design i made recently so here's a fairly recent design of mine my esp32 web radio designed it in easy eda because i had all the features that i needed and don't forget the teardrop feature that allows the tracks to be slightly bigger at the ends where they join pins and things to give them a bit more stability and then you just click the gerber button at the top here so that one there and it says great you can either generate your gerber files directly or order them at jlcpcb and if you click that it will go straight to the gel cpcb site upload the gerber files as it's generating them in the background automatically and show you what you can do there and let's not forget they got a facebook group here it is and as you can see they're joining forces here a bit more transparently so we understand that the two are connected easy eda to design your pcb and jlc pcp to actually manufacture it sounds good to me now if you join the group there's all sorts of good things on the way so have a look at that as well jlc pcb go and have a look so what's all the fuss about the raspberry pi 2040 so what raspberry pi have launched many many boards haven't they yes but this one of course is not a traditional raspberry pi in the sense that it does not have an operating system running this this is trading very heavily on the toes of the arduino world embedded microcontrollers that have access to gpio pins and no operating system to help you you must program it either in cc plus or micro python which is what we're going to do today but i certainly want to look at the c c plus way of doing things in the future because after all that's the way we do it on the arduino now as you can see it's a nano sized board um and let's just whiz through the specs yeah for just for the sheer hell of it and if you have in the back of your mind what the nano specs are the arduino nano specs are you'll be well quite amazed really so first of all this is this is an arm cortex m0 right so at the heart of the chip it's an arm chip it's got two cores how we use both cores i have no idea yet but i'm sure i'll find out in weeks to come it runs at 133 megahertz now you might be going wow the poor little nano only runs at 16 but let's temper that little bit the nano runs native machine code doesn't it yeah hex a decimal bites it does them one by one and it can do one one calculation or one step per clock cycle whereas on here basically we've got a little interpreter built in here so it's it's reading the line of python that you've written and interpreting that and all that of course takes time and effort so although we have 133 megahertz i suspect the performance is going to be that of a much lower clocked chip but we'll we'll see sram how much has it got 264 kb now that's in six banks whether that's important or not to us as developers programmers i've no idea we'll come on to that how much flash has the chip actually got inside it none but i think that little black chip there that's the one with two megabytes of chip and it can support up to 16 if you really want to expand it now as you can see there's lots of pins along the outside and it's actually got 26 gpios four of which are analog to digital so that's that's you know along the lines of what we'd expect from a nano type machine wouldn't we um it also has usb 1.1 support for host and a device which is something i'll be looking at very closely do you remember a long time ago i wanted to get um a keyboard that allowed me to press an alt key and a number because my keyboard does not have the numeric pad on it right because it's too i find it too long and although i have a working solution with an arduino it'd be nice to get it working on this as well so that's something to look forward to the adc channels analog to digital conversion channels are 12 bits not 10 so that makes it a little bit more accurate and there are five adc channels right five that includes a temperature sensor which is somehow built into this it's got two spi's that's one more than the arduino it's got two uarts one more than the uh the unit it's got two i squared c channels yeah that's one more as well and 16 pwm pulse width module modulation channels right for dimming lights or motor speeds or whatever it is you're going to do that okay and it's only got one timer though one 64-bit timer is that going to be a problem well i doubt it but we'll see and uh oh yeah it's got a real time clock on here somewhere i haven't found that bit yet but we're not we're not at the stage where we need that just right now and one unique feature it's got that i've been reading up on slightly and i think hmm this is this is this is interesting to say the least it's got programmable io state machine pins right and i'm thinking how is that going to work well i think that's some time for the future let's get flashing leds working probably first um fine now so that's that's the specs right and they're all they're all quite nice specs yeah i mean this is certainly more powerful i suspect than any nano we've got but is it more powerful than say an stm32 or an esp32 um probably not but we're not in the game of saying well this one's better than that it's not a race is it it's horses for courses we'll choose the microcontroller for the job that needs doing yeah so one of the reasons i'm looking into this particular chip it's developed by raspberry pi and you cannot ignore them right it's going to be successful whether we as arduinites think ah rubbish we don't need another one no matter what we say this is really going to be successful already there is so much documentation out there it is very very easy to get started and once you've got started and you've gone beyond this sort of blinking led stage i suspect that's when we can go this is better than that one but not as good as that one and i'll see which controller i want for my next project right let's um let's get this up and running then this board this rp2040 board without the headers soldered on you can probably just make out of soldiers and headers on there is about three pounds 50 right plus delivery now i bought mine from pimmeroni because i bought stuff from them before but of course there is the the pie hut this is in the uk by the way but you can buy it absolutely everywhere just don't buy it from the far east because although they're undoubtedly selling the genuine product is about 10 times more than you'd expect it to cost quite frankly um now if you're buying this abroad i in europe you probably wouldn't want to buy from a uk business right at this very minute what with brexit and the customs things it takes forever to send stuff abroad now you could buy it from somewhere like um elector which i think is about five euros just to shadow under five euros for the board and if you want the pins already pre-soldered i think it's an extra three or four euros and if you can't solder them or don't want to solve them that's the way to go at least you have a board then you can do stuff with but you have a look just type in raspberry pi pico and just see where you can get it from and it is it's a cheap board not only that just i think it was yesterday the other day before the the chip on here the rp 2040 chip has now been released and you can buy those and that they cost an absolute absolute fortune they're about a dollar a piece yeah i know a dollar so if you wanted to make your own board for a project then it's a viable entity isn't it for a dollar yeah it's certainly up there with you know all the 18 mega three to eight ps and things and this is as i say quite a fast chip especially once we get c plus plus running on it okay that's that's all well and good how do we actually get this running well first of all i've got to assume you've bought one of these right and you've soldered or had soldered for you the the header pins on you've plugged it into a breadboard like this okay now when you've done that we need to install the ide that's been specifically developed i guess for this board and it's called funny let's have a look and this is it now as you can see it's a very nice clean website that shows you a lot of things about funny but what we're actually interested in is this bit at the top where we can download the version 3.3.10 at the moment and it's available for windows mac and linux okay so we're all sort of catered for so download that now you could go through this it does tell you some features and all that but there's a an easy way to get started and let me show you that so this website from a raspberry pi organization is you know a model in clarity frankly and it enabled me to get up and running very very quickly and i'm sure it will you too you can read this through about adding micropython firmware and uh how to load things up but i'm just going to let you look at that in your own time i'm just going to demo stuff so you can probably do both things in one go because when you've seen something work it all makes a little bit more sense doesn't it so let me just walk you through what you have to do now assuming you've got your board set up on a little breadboard like this when you first plug it in watch what happens over here in the ports it's pretty much like what happens when you plug in an arduino forget the two there there already that's my video switching thing and that's my esp32 radio so would expect something else to appear there once i've plugged it in and you'll hear the windows sound of course as it comes in and it refreshes and there is so this is now on com7 okay now that needs to be there however if you press reset and then that boot switch and then release preset it goes into a mass storage state where you can drag programs into the actual chip itself we're not going to do that right now i'll leave that for a later date but it's you can try it i'll show you what happens so this is windows explorer window there this this one over here with the um all this right now you can see all the drives and things that my pc has identified fine but if i press the reset button do you remember i told you last time that pimeroni have created this tiny tiny little um pcb that you solder onto the top here to create a reset button that raspberry pi organization for reasons best known to them did not include so if you haven't got that reset button you're literally going to have to disconnect the cable every time you want to program it and then press that boot button there and then reconnect which is yeah as you can imagine it's a bit of a faff isn't it so because um i bought that only cost something like one pound 50 and they donated then a pound to the raspberry pi organization too so i thought that was a pretty good deal really so if i press that reset button first then the boot button then release the reset button you should see something come up on that windows explorer let's try it so hold that one down press that one let go that one let go of that and as if by magic he said desperately hoping something would happen oh oh it's happened so quick i don't even see it as you can see over here we now have this h drive up here raspberry pi rp2 does that mean does that mean this is version two of the raspberry pi pico or nobody's saying anyway so if i double click that this is now effectively looking at the contents of the drive you know what they've classed as a drive on there that index file there if you double click that that will actually redirect you to the actual internet right and this one just contains some information oh there it is look so that's what that file contains um i don't know how useful that is to us now or in the future uh we'll come on to all those sort of things as we go through not today though okay so that's that's how the raspberry pi gets set into that um drive like a usb stick drive mode right which you don't need if you're going to use thoni and upload your programs to it so let's reset everything back and see what thony's going to say so once you've installed thoni and got it looking pretty much like that you'll have an untitled tab at the the top there um a few icons at the top which to us arduinites are going to be pretty self-explanatory yeah the save the open the run not the um what would that be in in arduino that would be like check the code wouldn't it compile it basically we do have a stop button that's quite uh important and if you try and do anything you'll probably get an error like this down here because this isn't set up yet for the pico down in the bottom right hand corner down here we must click that and look at the pop-up window let me get that on screen so by clicking in the bottom right hand corner it does say python 3.7.9 but that's not what we need for the raspberry peak at so if we click that you'll see this little pop-up window now the the one that's selected at the moment is the same interpreter which runs thoni which is not what we need we need micro python raspberry pi pico as soon as you click that you'll get a pop-up window that looks something like that and basically what it's saying is we need to download the micro python code into the raspberry pi pico so just just click install if you notice by the way it says there that the the target is drive h and that's what came up in windows explorer when we configured the raspberry pi pico as a sort of an external drive okay so you just click install and it copies it across and you can do this multiple times if you want if anything ever goes wrong with your raspberry pi pico you can download it again click close right there we are in the bottom right hand corner it says raspberry pi pico micro python hurrah so at least we now know that there's there's the right interpreter down on that picot oh another reminder right so let's um let's type in that blink sketch from last week that doesn't flash the external led it's going to flash that internal one the one that's flashing now you see that so let's uh let's get the code for that so this is the code that you need to type in if you're gonna flash that led okay now we can go through the code but what i want you to just bear in mind here you see on my machine that led already flashing that's because i've done something to embed that code into the actual raspberry pi pico itself which we'll come on to in just a minute all right but the way you'd run that normally and let's make it really slow so you can tell it's a different bear code if i move that down to say 1.5 that will make that that flashing led that's flashing quite quickly at the moment isn't it that will run that much much slower so if we now press the run button this this arrow run current script if we press that they are now you saw that led down there suddenly run at a much slower rate okay so what it's done it's overridden if you like the the embedded code that i've put there while i was playing it out and that's running this script you think okay great so we're running it and if we want to stop it we simply press the stop or restart the back end button that's this one here stop and that's it and it's you get some messages down here and if there were any errors in your syntax here that also appear down here so that's it it's stopped now as you can see nothing flashing at all if i were to press the reset button again then it would run that inbuilt program all right let's let's let's cover that then joey if you were writing this program you go i want this program now permanently on here so that every time i plug in this usb port it just runs that program what do you do well as you can see at the top here i've called this blinkpico dot py well change that name do a file save as main dot py that's all lower case m a i n and you save that and it will go then down onto the picot let's let's try that let's um let's change this code so we know it's going to be that one running so that and do that shall we okay right the first thing we need to do is change the pin number from 25 which is the inbuilt led to a 16 that one that i was flashing previously on the breadboard i've chosen gpio16 simply because it's at the end of the board as you can see down there and i'll put a 100 ohm resistor in series with that blue led i chose the blue led because it's got a much higher forward current drop and therefore unlikely to burn out that pin so now just to prove that just by changing that code and then running it it's going to work let's click the old run button there we are off it goes flash flash flash flash i know it looks white to you but it is a blue led as you can tell okay but as soon as i disconnect this usb power and if i were to reconnect it it's not going to be that blue led that runs no look we're back to this one at the top here that built-in one on gpio25 so how do we get that program permanently fixed on there right first of all i'm going to save this blink picot as the new name main dot py now when you click the save as and type in the main dot py it'll go well where do you want this to be saved do you want it saved on the windows machine or linux machine whatever it is you're using just as another program or do you actually now want to download this to the raspberry pi pico in other words embed it on that chip as you would say with an arduino nano remember there's no actual compilation involved is just downloading the program and the interpreter on here will sort all that out at runtime so we're going to say yes i want it down on my raspberry pi pico please you then get this other window come up that says okay what's the name and you say yes i want it to be main dot p y because we're overwriting that one that i put there previously so main dot p y ok it is actually prompting me to say do you want to overwrite it you can't see that as i say yes and it says okay i've done it so theoretically if i now press the reset button it should start blinking that that led shouldn't it oh it does a little bit slowly but it's blinking it but how does that does it actually prove it's running it on here and not my computer well let's power off [Music] so we've powered off power back up again and there it goes running the main dot py okay so long as you download it onto the actual micropython board itself so if for example we were now to increase this frequency to 5.5 um so much faster flash than what you see there we'll stop the back end by pressing that so that's stopped okay in fact the led's now sort of stuck on that just happened to be the state it was when it got stopped and we'll press the run again and look there we are much faster but we're running this now effectively from my pc aren't we we're just sending it all the way down there it gets interpreted but it won't it won't remain on here forever unless we save it as main dot py okay right okay that's some the first steps if you get this far i think we're all going to be well on the way to actually doing something a bit more useful than just flashing led we got pwm of course we could fade this led in and out and of course there's a million and one other things we can do because we've got i squared c we've got spi yeah all that for a future video okay cool don't forget to to look at pimroni then or raspberry pi organization where you can buy this or wherever it is in your particular country and you can follow me on this route as well and because it's embedded sort of code we'll treat it a bit like an arduino nano and see how far we get i think cool right quick update on the bin lid situation from last week's video i said yeah bin lid but it could be anything that you can you know bring to xero i made multiple schematics all of which are crossed through because they're a lot of rubbish i'm not doing it like that anymore but yeah multiple gone wrong basically i was i had to make a decision whether to use surface mount components or through-hole and i know that surface mount are still a challenge for a lot of people so i think well if anybody did want to play with this and if i have some spare pcbs i'm not saying i'm going to have but you know chances are putting surface mount components on they're going to put quite a few people off so i thought right let's stick to through whole components and then stupidly because just i was in cruise control i stuck a surface mount at mega three to eight p on there and i got right to the end i thought hang on a minute this doesn't make sense who's gonna be at a solder a 32 pin quad flat pack 18 mega three to eight p if they can't solder a simple 0805 component or something yeah so i've done it all again this is what i've ended up with right that's um i know i know it's small but this is now a dip at 328p like you find on the original arduino uno right so that'd be nice and simple and i've split it out to all these different things and i've almost almost got the pcb let's have a look at that i think this is like first draft of my pcb as my chunky 18650 battery however i only sort of got this into this state yesterday i haven't checked it yet and there might be some amendments and i've got ground plane so there's lots of things i haven't done yet but it's coming along so if anybody is following this great don't think i'm i've forgotten about it because i most certainly haven't i've got to build it quickly before the rain gets into my bins especially during the winter okay i think we're i think we're done for this week thanks for watching don't forget please go and visit uh my sponsor jlcpcb not least because they're monitoring how many referrals i get and things like that so it'd be nice if you did go and see them but they do obviously i'm using easy eda for this as you can see this is easy eda the pcb we made from jlc pcb if i'm doing this i think this is really nice i like this i think you will too so go and have a look at jls pcb's website even if you've got no intention of buying at the moment go and have a look to see what they can do yeah and please use the link in my video description so they know it's me sending you that direction great thanks very much for watching comments down below please thumbs up if you liked it and 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: 7,148
Rating: undefined out of 5
Keywords: Arduino, Beginners, electronics, C++, microcontrollers, programming, gadgets, ardiuno, PICO, Raspberry Pi, RP2040
Id: 7MnpnpL4Qw8
Channel Id: undefined
Length: 25min 10sec (1510 seconds)
Published: Fri Jun 11 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.