Tutorial: How to Install Visual Code Studio for working with Circuit Python

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay welcome back uh this video in particular rolls up a whole bunch of things into one continuous long tutorial on installing visual studio code plus all extensions for circuit python fixes a few quirks that are needed to make things work smoothly what we're going to do is we're going to start from pure scratch doing this so i won't assume i have anything installed what i've done is i've created on my system a vm and let me get my cursor to where it belongs and [Music] there we go so and i'm just going to minimize these so we don't need to see them just quite yet so whoops this is a bare bones kde neon install in vmware player as you can see virtual machine up here yada yada i've done some life improvements to it so i will show you what i've done so basically you can see from this note i made sure the full vm sorry vim was installed um some distros only install them tiny which means certain keystrokes don't work blah blah blah i just make sure that whole thing is in there mc is known as midnight commander a norton commander your clone it's great when you have to move directories from point a to point b and stuff like that without worrying about command line and what it is um gui notepad um that remembers its state like in the sense that if you ran kate or you ran some of the others and you lost the note back you could lose the whatever changes you had in the files if you hadn't saved them this doesn't do that this is exactly like notepad plus plus in windows does exactly the same thing because at the command line i want to see old style commands i don't want to do ip address show and stuff like that net tools and of course i wanted a browser that i could get at my profiles or stuff and that is google chrome now i also got rid of the snapd subsystem it can get bent as far as i can concerned um i'm a fan of got a debian package for it just bloody well install the debian package for it i cannot remove flat pack out of kd neon because the tool known as discover won't let you do that because discover depends on flat pack to run properly otherwise i would get rid of it too uh you will need git get is needed to install one of the repos and then use to get another repo okay once i had everything that i wanted i did some checks on certain things first i checked my python 3 you should be able to do this yourself and i will just move this notepad off for a sec so if you do python 3 you can see right here it's 3.810 okay that makes sure that uh while i'm doing this i don't want the the dumb strain saver to go off and the screen locking to go off and all that other crap so i turned all that off um i set up the desktop with a quick launch bar you see it on the left side it's the usual thing i always do on my katy neon layouts um i made sure i have a pico ready for you guys this guy here and the nice thing about vmware players when you plug usb in you can tell to map that particular usb all the time to the vm so it'll automatically do it get rid of this so having all the baseline ready to go we are going to install the visual studio code and all the pieces needed so of course the very first thing you need is visual studio code now some distros if you go to root or you sudo i'm just going to do it by root if you were to do a course apps search code and of course you might want to grab for viz there's no visual code so all these have the two words code and visual and then for visual studio code some distros will have code actually in the repo some won't have code so i'm working from the assumption that you don't have it in the repo so we go off to our browser that we have open and i go to the first tab i have set up here download visual studio code so we get debian good rpm kd neon it's based on ubuntu 2004 so we need the debian package and we need the 64-bit package so code 158.2 amd64 the debian package now one thing you want to do and not screw around with this is leave your home tree alone don't work from it create a place to do your work in this case we know it's going to put it into the downloads directory because that's the default for chrome okay now this is the reason why i didn't get rid of the flat pack for discover is because when i click this here discover comes up an offer is installed this is similar to g debbie which is a gnome debbie installer that can be attached in the os um other ubuntu's so i'm saying here i want to install this of course it gives a password in this case my vm is just has the classical worst password on the planet and if you want to know what it is you have to watch spaceballs the movie and the password for the airshield which is also the same as the password for his luggage yes one two three four five six so it's installed it now one bonus of this packages like this or google chrome or anything like this that once you install it if you go off to etc app sources list.d and have a look we have visual studio code as a repo now now if we do we do an apt update actually first probably ah there you go code see code is now available to you as part of your replay you will get the updates for code uh consistently so now we want to do is make sure as a user we have an area to play in so i create all the time my work directory i leave everything else stock in the home tree i do not try to put files in this directory i put files into subdirectories within this tree so i get pictures i put in the pictures directory i get downloads they usually go in the downloads directly on my work directory depending what i'm downloading right but i try not to contaminate this root trigger there's nothing worse than this directory if you make it cluttered then you won't can't tell stock from what you changed around so i created the work directory oops and in my case i sucked off the host system a couple of things we're going to need to look at this will just prevent me from cut and paste and typing a lot of silly things across the environment which i can do if i wish to now in this area we're going to run visual studio code and get it started now it's in our menus it's under development the first thing i want it on my quick launch bar so i'll add it to the desktop now this is a plasma desktop thingy thingy okay you want to move that icon into this bar you must click on it and hold your mouse until all those dots appear like so now you can go like this and push on to it and let go voila it's moved from the desktop is now in the panel there is an option in the control panel i won't bother showing you but you can turn off that delay for holding the mouse button down meaning that as soon as you click that icon the six dots come up but there is a reason for it okay they don't want the system confused that you are trying to launch it versus you trying to move it so launch visual studio first time you launch it you get some pre-setup stuff so i'm going to go with this i'm going to ignore the corner okay and i'm just going to make it a window because i'm a fan of windows not full screeners okay now i'll make it a little wider okay so let's just go through what you can do yeah yeah yeah uh open your playground no i don't want to do that uh split editor yeah mark done track your code no we're not going to do a repo customize your shortcuts there's only one keyboard shortcut we care about in here and that is file save which they've already done in this version which is nice it used to be this wasn't set but in circuit python as you remember saving the file runs the file basically from the circuit python device so being able to do a hotkey control s just to save things you want to check things out that's important and we're mark done okay so that was actually i believe new is 1.58 this little front tutorial it didn't exist in 157. okay so this is empty now on your left side you've got a bunch of these icons top one is the file bottom one is the extensions okay if we look at extensions we look at installed xero we have nothing now of course you can see that microsoft lists the top three things they think you should be in well maybe down here fourth one python cc plus plus jupiter and c-sharp oh look at that they even offered me to have them within the editor no no i'll keep my vim to my them right but since we're doing circuit python we have to get a base done so first thing the first is python now one thing you can also do on here if you search python notice there's 60 billion python things okay now what happens here is this is the root this is the microsoft uh stuff okay now the last time i did the install of this it was just python but we're going to check what else it might install along with because sometimes these packages you can consider them meta packages they actually contain more than one so for example this python extension pack down here it installs all these things python visual studio intellicode diango ninja magic python right so what we want to do let's go into this one and we're going to install this one and see what happens it should have theory put python in it might put a few extra in so off it goes to the races you can see the little blue scroll up there it's busy working on it it's installed there we go done so we'll take out of our search expression because we want to see install i was correct they've they've changed just a little bit so they've added uh jupiter notebooks they've added pylons they've added python okay now one of the things in here uh we want to make sure we can install this actually just extra to make sure it works so there is a popular thing here and a recommended thing here right i'll just click it off so what we have can do here see there's visual studio intellicode and there is a pythons in here but they already put pylance in here see but i don't see intellicode in here so let's go and tell visual intellicode okay we're gonna put that one in now the other one is sense you get something like that nope it used to be two of them um since no won't worry about it um i remember on my other vm but i did this a while back um i had in visual studio intellisense also but maybe they finally have integrated the intellisense component into the language component okay so now we have those two installed we're not quite done yet with extensions okay let's just go make sure python yeah okay ah itchy nose uh okay so you got all that parts in but we're still not at circuit python's level yet we just want to make sure everything is in and it's running now one thing i do recommend is you do major extension installs like this it's just exit visual studio code count three elephants and start it again sometimes when you do stuff like this it insists on a restart but it doesn't really tell you this and you find you got weird things happening usually the best thing is just to restart visual studio code so we have nothing yet we can do a python file so we can go here and say new file for example okay now i'm going to get rid of the icon i'm going to go here and let us uh open a folder let us open the work directory yes i trust the authors this is new too of course the author is me okay now it just so happens the inside of work i have this this is not the way i would organize my work by the way okay but we're just going to demonstrate that the python works so new file come on give me a new file there we go test dot pi print so you can see oh yes you want to really really help me print so you can see we're got our intellisense we've got our intel code it's out prompting with stuff our classic right and there's a big fat green button over here you could say run python in the terminal hello world blah python's working okay so we want to know we're ready to go next step so we go back to here and we know we have pylance installed because we can see it in our installed stuff jupiter pylons okay pylance is microsoft idea of the language engine it's also a linting program and a bunch of other stuff like that it's also the most pain in the ass thing to work with now there are two main language servers that you can implement with python um jedi or pylance the other thing is once you start doing some python code you can see this down here you're going to have the interpreter where you can pick the interpreter so in this case down here we have python3810 64-bit it knows we're running that no problems okay this will come out here as under the problem window we also have down here tweet feedback and notifications okay you can see right now we're in a python shell basically well a shell running python okay that's what that play button did up there so in our extensions we are going to now install and this should be the correct order circuit python there we go so this is joe devious i hope i say his name wrong but i probably did um his circuit python at now the real function of this extension is to complete some of the code sense inside of circuit python we'll install it it's going to do a number of things for us not only will go and get a copy of the thing i believe he stated in his in his github that he uses um azure cloud and some weird tools over there to actually build this extension for visual studio code but there we go it's installed now as i said major things just exit and come back in again now i'm not going to show the welcome screen anymore so i'm going to turn it off in here and in this case we don't want to see that folder actually anymore either we're going to be a little more proper about this uh close folder so we're empty now we're going to set ourselves up for this picot right here and to do that we go we want to basically work in a subdirectory how's that one so now we have a pico we don't need our test file anymore gone okay so one of the things we're gonna find out right away and hopefully this will be murphy's law won't screw me around on this okay we're going to plug this in so do we have the device or not let's find out in devices removable devices adafruit pico yes it is in here so we should have this device and we're going to just check here our friend d message there is our pico right there raspberry pi pico yada yada now i noticed this slight change in the kd neon prompter normally there's an icon in here usb devices and disks and i'm those noticing lately it wasn't actually popping up and saying offered the mount in whatever what i have noticed though i go down here into the file explorer there's circuit python right there and if i click on it a lot now mounted now i've pre-prepped this picot with circuit python and the classic blink program that's all i've done on it okay now normally when you first take one of these things as virgin there are two subdirectories that are not in there the vs code of course and the pico code workspace they don't exist in here okay now you'll notice there's some other directories in here i wonder if i can zoom yeah i can zoom it a bit some of these other directories in here um this fvsn vent sd um the trashes the metadata never index um some of these deal with environments not linux but mac so apparently if you don't want the mac to do stupid things on the limited space that's on here you create one of these directories um and it stops this from happening i think there's a there yeah this is a dummy folder apparently holding a dummy file and this is telling the mac i think don't do this don't index this drive this guy here is the trashes from the linux side i'm not sure if you're aware um linux trying to be more windows ease and gives you a retrievable junk directory like i mean if you trash something now from the gui it goes into the trashes and you can re restore it again in classical unix if you delete something sorry buddy it's gone that's always been the way for a long time but no people weren't happy with that okay and then there will be an empty code file in here basically with hello world in it okay that is the stock a circuit python install onto the pico that's usually all it contains since i've already loaded this into visual studio code once and i saved it out i have a vs code directory and a pi pico code workspace now to achieve creation of this what you're going to do is you in your file explorer here you're going to open a folder you're going to open the circuit python directory yes i trust this directory that can get tedious now this is new before i wouldn't say anything about this so you can see now it's figured out it's on circuit python the circuit python extension it's gone and get the the code bundle this and it will do this every single time you load up one of these guys the idea being is that it goes and retrieve the most current bundle from adafruit from the circuitpython.org hub make sure you're always up to date on libraries and stuff like this okay now what you want to do in here is when you first open this up these two guys are not here right so you'll want this first of all when you open up you say file save workspace as and give it a name for your workspace i've already done this okay and when you do that this gets created now i'm going to close this folder off and open up the actual workspace folder in there so this time i'm going to open a workspace i'll go to circuit pie i will pick this workspace and i will open it up okay see again mr bundle gets checked okay so let's look at this file that he created now by default this file you will get asked the question in here since i've already done it once in fact let's do something a little special here file close let's close this workspace for a sec i'm going to just get a copy of the contents of this okay so we're gonna go back to home work and we're gonna make a new folder here and we're gonna call it pico bu okay and here ctrl a copy and in here paste eight items doink okay now in here and are we still open nope good we're closed and here we're gonna go and this guy here and this guy here we're just going to delete them okay so i've added to my file explorer and kde dolphin the uh i turned on the option that when i chose to do actually delete it really deletes so these files are all gone okay nothing there okay so this is usually what the stock will look like now let's set and we open this up again well this time we don't have a workspace file to open so we'll open the folder okay should be our check we don't have a board doesn't know what it is doesn't know about anything it's created the vs code directory it's created the initial settings json file but we don't have a workspace file so as i said the first thing you should do before you do anything file save workspace as and give it a name we'll call it pico1 why not right but now we have a pico1 workspace if we open this file up okay it populates some of the stuff in here now one thing i've noticed in here um and i don't know if this has gotten he has fixed this yet in the release version of his extension i'm just going to widen this a little bit more is notice there's a blank path in here the other file had a null yeah not a good idea um so you can see in here some stuff are put in place by default now it used to be uh just a few versions back the default was unchosen for the language server you actually had to go f1 language configure language server something there restart language servers it's in here somewhere right you would you would set the language server um apparently you don't have to do that anymore which is nice um and of course it's defaulting to pylance okay now one other thing in here this is a json file we open the code up in here already we can see a problem notice the board we can figure it out this is the type of things i was having with um pylance i was having with um circuit python as a general is imports were not being found properly okay so we are going to fix this but one of the things that is recommended in here is another extension this is a more cosmetic extension and that is magic python magic python is a syntax highlighter cutting edge python 3 blah blah blah all the usual fun stuff okay so we're going to add this one too that's it just this one i don't think there's any other railings there's some other extensions you could do um a repel but i will get into an issue that i haven't solved yet with debugging and i think this will require um a fix from adafruit themselves i think this is stems from the way things work on circuit python more than anything else now as i said before you do a change like this in this case since we just created the workspace i would politely close the workspace and then restart this to make sure everything's active again as i said certain things middle studio will install it but it won't um come on guys can we not do that there we go so file open workspace again i've never done a duplicate workspace but who knows circuit python code one open okay checks the bundle we haven't chosen a board yet so let's choose a board so we know this is a picot raspberry pi pico okay now you see some line changes in the workspace it's actually added picos and to boot you can see here it's directly referencing the boards directory for the pico it's uh referencing the stubs directory and if i slide this all the way over and the bundle directory let's let's check the code out this time see what happens do we still have our we still have our board issue so i think it's time we fix this and just to make sure we're not interfering with anything over here or this interferes with us and you can also see in here we've got a warning one so we want to see warnings we can click down here the import board cannot be resolved what did i say imports an issue so we're going to fix this now i'm going to close this off we'll get back here but we're going to now work at the command line and fix this okay not the file explorer there command line okay so i'll call my fixing directory fix ah yes very creative so what we need first of all is the code for vision that extension from him and i happen to have it ready right here so this is the github repository this is where we're going to get it from and all we do in here in github you go here to code and i flag it as https now if you flag this if you have the option for ssh that assumes that you have an account over there i'm not signed in here at the moment i do have a github that's why i'm not being offered so i will clone that and in here get clone paste okay so we now have a copy of his extension time for some slurping we go in here and we have a look you see everything's in here except if we look at his installed version of it and we're going to do that right now ls minus la and normally i can do dollar sign home but i'm a long typer that's where all your vs code lies that's all your extensions lie and we are into joe that one so you can see in this chunk we have a whole bunch of other that's what i'm talking about the azure pipeline by the way we have all the stuff and in the installed version we have all the stuff notice that we have a stubs directory in a boards directory here but we don't have it yet here we're going to build those so if we go into scripts and have a look we have some scripts now this extension is designed for both um the mac the linux and the and windows so that's why we have a windows style batch file we also have a unix style shell script i'm pretty sure that this shell script runs also in the mac but it has a problem if we look at this shell script right here let's see if you can spot the error down here if you spotted that they were not backing up a number of subdirectories properly you spotted the problem so what we want to do we know that i've tested this out we know that this works cd circuit python the two gits work the pip3 install requirements works the make stubs works the move works it's everything below this that's broken so this is where our vive vim comes in effect we want to modify this build script a little bit so what i'm going to do in here okay we are going to actually execute some and this that last one this is the real bad command it shouldn't be doing this because when you do this it doesn't work properly in circuit python and we'll talk a little bit the two different files that are called board okay okay now we're left with can't build grips we've remembered out everything up to the point we've after we've moved the stubs directory okay let's see if this works last time i tested it it works at this point so to execute a shell script like this just like that we go off and get the circuit python git repo we do all this okay so we missed something here okay i think i had this error before so if we go into the circuit python directory okay and what should have happened in the script we're going to fix the script it didn't make the sub sub directory properly so by our build script again and after we clone ncd into here we do all these sub modules okay since we're in the circuit python we're going to do a make stubs well they haven't make stubs there so why did it not work okay something actually whoops is happen this is where i had to do this step by step by step and find out what's going on uh q exclamation mark quits without changes um so something it didn't make the stubs why did it not make the stops i don't see it here that's the trick so you did all this correctly unpacking objects from branch sub manual path checked out build stuff that is line seven pip three command not found okay now we know what happened okay we're missing two packages in our distro um where is pip doesn't exist so apt install pip three we don't have a pip3 pip yes i don't understand why if you're going to install python into your thing why on earth you don't put pip in it's like the root of all evil now we need to actually upgrade pip so we're going to just do a quick search here because i don't remember this off by heart all the time updates pip so what we want to do we need to update the pip now self updating pip it can be actually updated pit package and linux so it's basically this right here is where we're actually at so go here and our package name is pit see we updated pip from pip okay now pip is there now the other one we didn't have make and i forgot completely about that so apt install build essentials okay build essentials is in does that mean we have a make oh sorry where is we have a make okay good we've been corrected so uh doing there we go so we'll start this off again in this case our minus rf circuit python we'll just start all over again and try one more time try number two at this i forgot completely about those two tools okay cloning cloning requirements file that was in the script means pip was working dubs doubles is working we now have a stubs directory now this is the part we have to do manually uh cat the build again because we need to look at okay so he would have us back one directory after making the stubs and moving the stubs and then he would have us install another requirements file so pip install minus r okay cd back into scripts again we completed that stage now they would have us run the build stubs python file python 3 except we're not doing that path because technically when we backed out of the circuit python directory we are in the scripts directory so doing this doesn't work in fact doing this doesn't work either we have to actually go back to subdirectories so in our case we need to run so now if we look this is building that boards tree we now have boards we have stubs in fact it's actually up to date because it's based on whatever the current github repo for the whole circuit python system now now that we have these in here if we look at the last line of our thing they would have us remove this and i say no don't do it let's have a look at what they're actually looking at there's a subdirectory here called board that's missing in his if we go ls minus now we won't do an la um home william dot vs code extensions joe and we are looking in thubs board is missing in here not good if we look into that your particular directory and we look into no sorry cd stubs boards we're going to see one of the type two types of file this is in this guy this is known as a stub file for um python it wraps around like my guess is the actual c code and exposes everything to the system you can have a look in it it's not like it's hidden or anything like that what this does is it defines some stuff for dealing with the pins on the board that's really all the board files actually do now in the boards directory do an ls we have this one board.pyi we capped this board api what we have here is a filler file a template in fact it's based on i guess the micro bit v2 but it really is it's it's template for what to do with everything okay and of course [Laughter] there that one and we go and look in boards this case it looks like he's fixed it we can actually have a check at that let's go cat okay it does now what we don't know is what i've built is at the same level what already existed since i'm building based off current stuff for today we need to make sure that we if we drop and place these two directories that we're matching for everything so in this case we are going to go off into the vs code uh extensions joe and we're going to move boards to dot org we're going to move dubs dot org like so so they're out of the way i have a tendency to back things up first not just blindly erase things right so this is where midnight commander comes in effect if you ever or well you have to be old as me to remember dos days and north commander was a very popular utility back in the 80s when you had a copy lots of files on your hard drive it gave you this double paned effect left and right later tools like winscp and stuff like that basically our variants on the norton uh commander theme so we have to go we have our destination and our source at the moment are the same we just tab back and forth so i'm going to back up and i'm going to go into the work directory and i'm going to go into the fix and i'm going to go in here and i'm going to go into scripts and i'm going to go ctrl t pick boards ctrl t pick stubs f5 and i'm going to copy them over yes modern hardware makes it like pinky blink fast ssds make it blinky blink blink fast yes actually two nvmes in here makes a blinky blinky blinky fast you can't tell how fast anyway i've now changed this so if we look here boards and stubs they are replaced with our rebuilt versions of it so let's go back to visual studio code open the workspace oh look no problems we highlight board look at that fixed working correctly digital io working correctly time that's a base system python file now if you choose to add more python modules to your os's python there is now a golden rule about this don't do it globally do it as the user and in fact they highly recommend you go one step finer and you do it as a virtual environment the idea being you create the virtual environment and in the virtual environment when you join it you then add on all the parts you want to work with okay golden rule number two do not screw this up do not install adafruit stuff for the os's version of python they're not the same so yes there's an adafruit blinker and a bunch of adafruit stuff now when you're working with all this stuff your friend is the pie pie repo okay the packaged indexer if you actually search projects here add a fruit there is a ton of added fruit in here in fact everything that you see in the circuit python libraries directory is here now if you want a better understanding of all this and how to load your board up with libraries this is not the way to do it this is intended for people who are on a raspberry pi and are using its gpio pins to control things with circuit python in that case not this picot but let's say a raspberry pi zero or a raspberry pi regular those ones then you would go here because in essence the machine is also the circuit python drive right these guys these little dot boards like this it's a separate isolated little environment on the board it's not technically um like the raspberry pi regular we have all this other stuff that's running the os everything else okay so putting this into your local python stuff can affect the way you code on these little boards because then circuit python gets confused it looks for stuff on the board it also finds stuff in your os and sometimes it'll work and sometimes it will not work and not work in a subtle and nasty way and you can't figure out why the code is not working so this is not for these little boards so instead what we want to do we go visit the libraries page on circuit python and you're going to find here bundle versions now my understanding is 7 is not production yet it's at the tail end of testing but what we're going to do is we're going to download the bundle the mpy files and we're going to talk a little bit about mpys and in this case i'm going to actually put these in my work directory and i'm going to actually create a subfolder here and i'm just going to call it add a fruit okay and we'll save it in here and for the hell of it we'll take the 7x bundle because we're greedy and we want all the files we can get i will also take the pi version and i'll take the examples file so if you're looking at their 2500 plus tutorials on adafruit yeah there's a lot of them these examples are will contain every one of them they might not contain the notes complete about it but they will contain all the code okay this is also a place you can see so for example today is the 25th and you can see on the 25th these things have been done to it so there was updates so this is why the extension goes and checks for that bundle and continuously gets a new fresh version every day or every time you want to load up okay so we've downloaded them and we'll go and look at our cd work and we see we have our added fruit tree see adafruit okay now one one thing when i ever get a tar file or a zip file tar file being tar or compressed tar tgz or tar gsat you want to check did they actually put the subdirectory in there and then the files or did they just put the files in there i've encountered both so one way to test this guy out is minus t and i'm just going to check the mpy bundle file just check it out okay we can see here they created the subdirectory so we can go back up take our t off and since we want i'm not going to unpack the 7 but i am going to unpack this and i am going to unpack the examples so basically we've unpacked three of the four files i'm not going to worry about seven so when you're working for the for in this case the blink program there is nothing to load if you look my library directory is empty now we come upon a case of another import issue and we want to put something in here [Music] let's go look at the examples let's see something where we need to put some libraries in and we'll create some code i'm going to want mr walk and add a vote and now we want the examples there we go so if you look in examples wow whole pile examples okay and some of them are you can see what the names of some of them they're around certain boards and stuff like that this guy here is a lot of led uh can we find something fairly simple in here i don't have a gps on there does this thing have the uh camera number of the pico had the uh um what's it called the three axis um sensor in there what if that's in here actually let's just take um the max 72 simple test i'm going to borrow this file and i'm going to go back to here to circuit python i'm going to paste it in here okay like so and we'll go back to circuit python because we know we're going to need a library out of this okay and i'm going to rename code.pi because in circuit python you can only have one code dot pi it's like lord of the rings you can only have one ring the rule them all so in this case we'd only have one code file rule we'll just call it code 1. pi get it out of the way and we're going to rename this guy here as code of pi okay so we look at this we have to import the max 7219 we need that now there's a good chance this code will not do a damn thing at the moment even though it thinks it's there it probably isn't there you don't have that in the lib directory okay so if we go file exploring we need to put in the code so that was our examples directory and get rid of it and we go to the bundle directory now the reason they give you mpy and they give you pi they're effectively the same thing except mpy is like a compiled bitwise thingy uses less space up on your device the idea is that you don't waste space because space can be precious so if we look in here we just see under the added fruits mmm there's a max right there copy and we go around the circuit pie and we go into lib and we paste one folder okay now to ensure that we're actually doing things correctly we're going to officially close this workspace and open it again close workspace and open workspace again if we look in the lib for um well that's interesting that's a different way of doing it normally i expect a subdirectory and i would open this up but you see here there is really some stuff here compressed and an init file for it and you cannot peek into these these are compressed files if you want to be able to peek into these files um you have to go and install the pi file but in theory if we click on this and we say go to reference i think it is go reference go to the declaration nope see it's a wrapper doesn't work very well if you put the pi version subdirectory in here and you did that you'd actually get the code from mac729 this this file here right i don't think we can get anything out of matrixes either go to declaration nope we can't okay and they're already complaining about this but i wouldn't worry about i think this is a false red herring this is where we need to do another tweak to our workspace we want to add a file in here to tell pyland to stop being an idiot and overdoing things so that's what we're going to do next but as you can see the environment is working really really well we fixed up our import problem basically we have main code.pi working we can drop stuff into the library directly it's finding things correctly um we can look at the settings.json file now this one is a very short one let's go look at the one i created for this i extended this file a little bit i think i've extended this file a little bit so i'm just going to go look at it whenever we saved everything in the backup uh hi you're saying that's a good idea why did i not think of it so i'm just going to open this up and yes you can see this is slightly different okay it's basically over everything else is exactly the same but we have a couple more extra lines in here okay so i'm going to just borrow this code i know we're going to generate an error but i just want to compare the two sets of code basically go away go down here so the original code as you can see the top chunk is basically the same we have analyzes extra paths analyze extra paths right and we only have two paths in here stubs and the bundle in mine i've included stubs um i've included a piece from his global storage is uh 22 107 that and technically this lower one here is not needed um i'm actually going to remove it now this is all json files so if you do something like this you have to remove the last comma like that it lives for the comma okay so we can see i've only i've added boards into here to make sure it finds stuff in the boards directory correctly and otherwise i'm basically identical in fact it looks like uh what's the version up here 114 yeah um i've doubled up on one here normally these things are these that particular line is done auto magically by him but we do know like so so we have stubs we have that line everything else is identical so the only real other line i'll i add in is this one right here so i'm going to borrow that line and we'll just go up here and we'll put a comma on it and then this chunk of code down here which json is bitterly complaining about because i didn't do nesting and stuff like that correctly this is where the control s comes in there we go so that's that one and this is this one okay now we have to deal with uh mr pylance being an idiot so let's deal with pilots being an idiot and i happen to have an idiot control file for pilots whoops that's not what i want wrong file end okay so if we go into my i don't think i have it in here no if we go into my metro m4 express which is i copied over we have a pylint rc file copy and you can get a template of this file a number of places i got mine from i think the pylance get or whatever just to get a sample of the pylance file and oops we need to go back to here we need to jump up back to circuit pi and we need to paste this here pylance rc okay oops of course i keep forgetting in visual studio code f5 is not refresh the screen f5 is run code okay so let's open this pylon strictly so what this really is it's all the parameters and control systems for pilots and really the only thing we really care about in here is this this is controlling the the error codes that pilots will nag the hell out of you poor and basically what i've done is from about here here really dumb ones that we know we're doing this bad white spaces trailing white spaces bad indentation pointless string reporting missing imports lying too long lying too long is a very annoying one right if you come from another language like c you can have a line as my technically c is one big long line once the compiler gets done with it so we do that and then this bottom piece here we can see we're doing a little it's kind of broken at the moment because it doesn't update manually it doesn't really affect the system but you see all those 111s and dates in there they're all wrong at the moment it's not really that important you can go in here and fix it if you want i can make this uh you know 114 fix the boards you know the usual stuff like this right but i'll see that i'm not worried about that if you put that in this bopper block is what you care about it cuts down uh whoops it cuts down on errors showing up in here that are kind of dumb so it's a good idea another thing you'll find in circuit python the order of the imports is important sometimes you'll put demo code in there and it'll complain so what you do is you go here and you sort imports there you go we just sorted the imports it doesn't like board where it was yeah okay okay so now we've solved uh linting issues we've solved import issues and everything is working clean and we promise not to screw it up well i hope i won't screw it up at this point you're ready to go um you should be having a clean working thing now one thing you'll find if you get a bleeding edge new board down here it might not be in here you might click this and get an error message because it can't find it okay i know a bug was submitted about that and there was supposed to be a generic filler that was supposed to be provided to fill that area but all that really does down here is add to the workspace these lines down here so once you've done one of these boards and you've got the vendor id product id you can tweak these two line set lines this one and these two with the correct one now you will notice that um adafruit is always one particular one right and raspberries another particular vendor code that sort of thing so you'll find if you go i think to 239a in the boards directory you'll find a whole whack load of product ids okay but that's all you have to change and after this you rarely go into these files you don't touch anything um one other thing i have found um that'll drive you nuts and that's my job just to make sure you get go nuts is paths you're wondering well what about them now in theory in these extra paths if you put a trailing slash on here it's supposed to be everything under that directory doesn't always work i am 50 50 on this so sometimes i'll have model i have to modify these paths specifically like if i said in here just um for example if i put in this blank path which is not a null luckily if i put in here you know slash media slash willam circuit python slash you would think i wouldn't need anything else to find all the stuff in the circuit python directory it doesn't work i literally have to specify slash lib for example for it to find stuff in the lib directory well great okay so watch out for that and i don't know if that is a um damn pylance problem again or not yeah you think while you're having all these pylance issues you might as well shoot it in the foot and get rid of it and go to jedi well jedi's older pylance is newer it's the one that seems microsoft's actively maintaining now let us open a different workspace i'm going to put a different board on close workspace and i'm going to go to the file explorer here and safely remove oh this is key you want to stop corrupting your device instead unfortunately you have to put the uf2 bias firmware back on all the time don't pull the board without doing a safe remove okay so i've safely shut it down and i will remove it don't do that so i have here the m4 metro plus the led matrix i was working on i'm not going to do really any coding on it but i just want to show you plug it in so it's told us and by the way here's that alien not working quite right timings off but we click on our circuit python down here and it's mounted and we come back in here we'll open that workspace and have a look at it as you should see open workspace circuit python we should see a code check to make sure that we're bundle is up to date there it goes okay we see down here then out of fruit industries metro express m4 serial connector if we click on code there's all the code linter pi lint is not installed okay we missed one i will install it oh i made an error pilent rc is for that tool it's not for pilots but they kind of work together so you can see down here that it's putting it in as a local install for the user not a global install which is what we want okay so we missed one more extension and it's complaining that we have three problems okay so board cannot be resolved bus cannot digital i open up result now this is where um this is the type of issues i was having before now let's just exit this and i'm going to just start it again just to make sure that because of the pylint install we didn't screw it up all the trailing new lines now why would this one not have board i fixed everything well it's possible the vs code settings json is off and it is so that's where our problem is 14 14 and 07 16 no i believe that's 07 25 we can check for that sometimes i find this does not update joe's thing doesn't update things so you have to kind of sometimes make sure it does uh so we'll just look at home and we'll look at vs code extensions joe yeah 14 okay and then we have in this global storage it's somewhere in here um i think it's global storage we want to find oh config code user okay um not in here not in here we want oops i'm missing a directory somewhere where is it dot config okay completely out of this tree dot config and then it is code right there we go down this tree global it's in here somewhere oh user global storage joe bundle what's our bundle yeah 725 okay so we're fine so we correct these subs boards 725 this 716 should be 25 like so ctrl s on that and then we need to also fix the metro file too it's probably wrong yeah that's what i thought 14 and that got updated that's good control oh this is something i had to turn on when i was working on this particular board the ram size in the metro 4 is smaller than the pico for example make sure python linting mpis enabled is false otherwise you'll fill the drive up just like that also this could be six two six two [Music] like so [Music] and control s now i happen to have an extra path in mind i was experimenting that's the stub path parameter for pylance it only accepts one path i just wanted to make sure it was finding the stubs i probably don't need it right the extra pass is probably analysis extra path is probably fine so we get rid of this we get rid of this and we go back to code voila fixed so beware that sometimes if you load an old project up and you're getting this it's just probably this paths and settings are are dated and you might have to update them but in this lib directory for example i have all these ones for messing around on this board with l rgb led things that i was working on and i think on this one i can't remember yeah so this one is correct in the sense that it actually expands it all out but there you go this is the board file that you remember now of course it's complaining about an import here um this is really a case of bootstrapping itself um it's in complaining that you can't do unable to import bus i o but in reality it's incorrect um i wish i wish some of this stuff wasn't recursive so what else we got in here um go to declaration yeah so again you get this sort of stuff in here but everything will work just fine this is i think pylance error more than anything else then they actually mean the code being wrong right so your mileage will vary a little bit but this is how you kind of troubleshoot things i found when i was playing with this um with the max that's not why you see the fonts file down here um i had to put the fonts file in the root i couldn't put leave it in the lib even though technically in the lib i was that's where the fonts files first showed up it didn't like it there um and yeah this is where this trash can might actually have stuff in it well maybe not today i cleaned it out again so watch out for that and why is there a readme down here what that says welcome to circuit python oh okay your metro m4 with circuit python no this is not a metro m4 uh this is a metro m sorry m0 this is an m4 but it is working we have loaded in okay new lines see this trailing new lines who cares i have an extra trailing new line we have trailing white spaces so let's just go here and say trailing new lines come on oh we don't have a lint problem anymore that's how you get rid of the damn things i mean really so what i have two lines down here it's not gonna kill the damn python file right i'm sorry but this is where i think python in a sense gets way too finicky about things yes i understand the need i heard that rust is even finickier you have to do things exactly a certain way yes i understand it's probably going to prevent errors and whatever but i don't think having an extra new line at the bottom of your file is going to cause a security risk and blah blah blah i think they go overboard so and of course in this pylon file as you see basically the same one but i think i've got everything covered and if you have any questions about any of this this is all done from scratch done from square one this should get you circuit python installed build environment working intellisense working a couple of problems fixed errors in the uh not errors more like annoyances in the pilint fixes in the pie lance to solve some stupid pathing issues that it always has and of course fixing the circuit python extension itself so the primary error was board not being imported which is now completely solved now there's one last thing i do not have a solution for what if you want to debug this well at the moment i am forced to do things like this prints um you would think that i can yes i can go to the repo there you go let's see if i can actually stop this code i think i might not be having passing my control c's through that's one problem with a vm let me just check if vm uh yeah i might not be actually passing ctrl c let me just check with the console prompt here for a sec i am passing a control c it's this guy's up ah one other thing we have to talk about and now i remember why see this stupid error message okay in this case i need to go back to my console and i happen to have this virtual machine open in a console window here okay now we need to fix something uh i completely forgot about this is outside of circuit python or anything it has simply to do with when you're dealing with boards like this arduino or anything like this you're not allowed so i am going to in the vm unless you dash route and yes a very secure password if we go into etc udev okay rules we have no rules to handle all these boards if i go over to the host system etc udev rules and this you can't see at the moment because i am not putting the console up but i will now put it up okay not ruse rules we have a bunch of rules so we want these rules uh except for the snap chromium rules actually i do not need those anymore i am srf uh let's get rid of those if you're wondering how i'm doing this okay it's classic unix middle mouse button paste whatever you last highlighted so we don't need those but we want all the other rules okay uh we technically don't need the vmware scuzzy udev rules um that's the one for the host system we'll copy it but we'll remove it because we don't really need it technically the hand tech is for the oscilloscope we don't really need it in the vm but anyway let's move these rules so scp star to root at 192.168.42.213 colon etc udev rules dot d oops that's not going to work are you sure one two three four five six see if that works oh something when you install uh by default into your guest os on the vm let me go back to the vm here and i'll just park this for a sec um ssh doesn't allow for direct route uh access but being nasty people we are get rid of that we're gonna fix that by etc ssh sshd underscore config if we scroll down a little bit into here this guy right here x and then we go over to here get rid of append and make it a yes and then system control roll that's if i spell system correctly system control restart ss hd boink like so now we'll go back to our console over here okay we might have to just redo the connection again so we've now transferred why did we go black [Music] okay console properties now we're going great that was funky okay we've copied everything all those rules now we don't need this guy anymore let's go back to the vm player and we're just going to clean up a little bit on this so ls minus la oops wrong directory okay cd into etc you dev rules there we go all our rules and as i said before i i can get rid of them if i really want to but i don't need the st linker programming devices tty usb controls all the usb ports in fact that's a kind of a cool rule to look at if you want to know it handles all forms of the ttys port usb acm and s whatever and this square bracket stuff here just tells it it could be zero through nine blah blah blah a little wild carding a little bit of symbol linking blah blah blah group mode yes the devil 666 which is read write read write rewrite okay so then we have the lib sig rock for the signal acquisition device stock the flerk is another and the j link is another programmer platform i o that got generated by uh platformer which we haven't done and installing here yet uh well i won't but we will might go i might download another install and talk through of that one okay um the vmware scuzzy udev rules rm minus rf we'd actually don't need this one um actually we'll just leave it in it doesn't hurt it doesn't do anything um at all okay so we don't worry about it now if we go back over here and we just exit and come back in okay and we go down here and we try to open the serial monitor oh we're still denied that's not correct did i put the rules in the right directory let's just close this off forget ifconfig i'm pretty sure i put it in 213. yes oh i almost forgot you dev admin uh dash help for a sec we need to trigger it okay let's try again oh we don't need a second set come on give me a break let us try opening again ha ha this time it works so we are in the repo uh you know you're in python because you do this you do this and you go this and you go this you go this python right and then you go ctrl d and you restart it again and the border starts blinking again now in theory what you should be able to do is run start debugging and it'll ask you current active python file and this is the problem i run into i cannot seem to get around this i mean yes all the stuff comes in doing doing class variables special variables function variables all the beautiful stuff you expect from a good debugger except i have a problem with board now this is the error you you'll get the error from where's the output for this error there's a message behind this um it's not that there's no name board is that it likes to come back and think your board is your my your host system your uh in this case it's actually the vm if i did this on the host system would come back you're on an intel generic linux board i can't figure you out right no i'm not i'm on that metro and this is what i don't understand i would love it if the debugger could just you know jump over this ignore it but instead you get crap and there's nothing much i can do about this at the moment i haven't figured a way around this i really really wish the adafruit would look at the circuit python with allowing the debugger to work properly and i'm apparently not the only one and other people had this so who knows no module found board it which is dumb because board is there we know because it's there and we know where it is exactly but it's not finding it so don is the only thing i cannot give you in this tutorial is the debugger so we're our result is uh let's go run yeah run without debugging no running without debugging uh cut it out um let's go back in this so we are left with um print statements so this is why you see some stuff in here where i print out certain things trying to figure out what's going on so let's see okay i'm going to leave it at this um i think i am going to turn basically this tutorial i'm going to try and see if i can figure out to do it not that i can't figure out too um it probably would be time consuming is to actually screenshot cut and paste sections of this as i do as i go through it and create a pdf so to speak of a tutorial maybe some a web page of it to put somewhere it's showing how to do all this but this should get you started and it should get you programming in circuit python i might do an atom one too i have gotten atom fully working and they have their own version of circuit python extension for it so i might choose to also do an atom layout a lot of the fundamental base stuff for the python that is exactly the same it's just an atom it has a definite different look and feel to what visual studio code does so we'll leave this at this moment i'm just going to of course close my workspace actually do i have anything to save no i don't okay close workspace close that off and that is it i'm gonna go and cut this video at the moment if you like it you know do the stupid youtube thing like dislike complain whatever you want um make comments whatever you want i'm still looking for yes 24 more subscribers maybe i can get to 100 one day yes ten years down the road william finally gets a hundred subscribers on his pity little channel well who knows so bye
Info
Channel: Electronic Enigma Zone
Views: 4,306
Rating: undefined out of 5
Keywords: Hobby, Electronics
Id: byJyYnZy8UM
Channel Id: undefined
Length: 102min 11sec (6131 seconds)
Published: Sun Jul 25 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.