Getting started with MicroPython + micro:bit using VSCode

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone today i'm going to show you a visual studio code extension to program using micro python on the micro bit so you need to have a couple of things ready on your system in order to use this extension first of all you need to have visual studio code installed obviously the second thing is you need to have python installed you can verify if you have python or not by either opening the terminal over here i just open my terminal on my system or you can also use the integrated terminal in visual studio code so this is completely up to you if you're on windows you might want to look at the command line and type python if you see something like this so where basically the system is prompting you to input something to input something then uh python is installed and you're good to go okay so make sure vs3 code is installed and python is installed then head over the extension tab and search for micro bit you will find several extension the one you want is micro bit python you install it you might also install another extension that i've already installed it's called the serial port helper and this will become very useful for debugging your code basically for print out from the micro bit and being able to visualize that on your computer i have already this installed so i'm not going to install it again with this done you're pretty much ready to get started so you want to plug in your micro bit and you should have basically this case this situation you have your micro bit and it's plugged in with a usb cable uh you can see here two different micro bits by the way uh version one and version two version two can be recognized by these little notches down here it has more memory which means you can have larger files basically more code you can upload on this one it also has extra capabilities that version one does not have but this extension will work with any of the two so i'm gonna put aside the version two i'm gonna just keep version one over here you also notice that it is connected to a usb cable this is not only a power cable this is a data cable what does it mean basically means that if you plug it in as you can see my mouse crossover over here as soon as i plug it in the micro bit is mounted on my operating system and i can see it okay so if you don't see this one probably you're not using a data cable in that case it will not work the extension will not work for you okay so once you're done with all of this and the micro bit is plugged in you can simply uh go to view command palat we'll open this embedded window over here or alternatively you can do command shift p which is this command here command shift p or on windows control shift p and then simply type micro bit python and you will find all the commands you actually can use so the first command we want to use just one time it's this one flash micro python environment on micro bit i'm going to click on this one and at the same time i'm going to show you what is actually happening to the device so on the back of the device this led is now blinking that means we are uploading something on the device it's completely removing any code that was here and installing micro python i have a successful message down here micro python successfully installed and i'm good to go okay so this is you have to do it one time but you have to do it okay and if you don't do this no python code will be able to run on your device okay so again if you didn't follow me is command shift p and then flash micro python environment on micro bit once you're done with that what you want to do is to initialize a project to do so i create an empty folder like on my desktop and give it a name project please make sure not to use space in this folder name okay i drag it in and my workspace is project again no space in this name then command shift p and now i search for micro python initialize the workspace so i click on this and you see a short list appearing one it tells you it tells you basically which template project you want to use to start you can use an hello world or you can use empty project an empty project basically will not modify your current folder i'm going to use another word instead i click on this and i see a main.pi file you must have a main.pi file in order to to get your code uploaded so if the extension will not find a main.pi file it will not work out so let me actually increase the size of this a little zoom in okay so now what i'm going to be doing i'm going to upload this command shift p flash but i will choose flash sketch on micro bit before we use flash micro python environment micro bit we already did now we do flash sketch on micro bit and as soon as i do that i see i lower the opinion over here right to show that this is working i'm going to change with say i do that again command shift p flash sketch on my commit and as soon as i do that i will appear okay if it does not appear to you but you see a successful message like here file successfully uploaded you might want to reset the device how you reset it you just click this button here that is that and you do that manually so i found out that on windows uh you can upload the sketch but then you have to manually reset the device so basically you click it where is it and then it will work okay on mac it seems it's resetting automatically after uploading the sketch so let's do a more complex example let's use a maybe uh something like this um while true and i'm gonna simply print something like hello world and then i'm gonna sleep for one second so one thousand milliseconds okay uh you might wonder where this command come from these commands are command of the uh micro bit uh and we are importing them and those are inside of this folder okay so this is actually here just for intellisense it will work even if you don't have this folder but when you initialize the project this folder is going to be made for you over here so intellisense will work okay so let's try to upload this so i flash it but really nothing seems to happen because we are printing out something but where does this go and here is the extension i was mentioning before the serial port helper you click on this one and you see the available serial port you want to select this one make sure that the baud rate is uh 1500 115 200. so this is the baud rate you have and down here you can choose if you're on hex mode or string mode keep string mode then i'm going to select on this become green and i see a hello world printed every second so everything is working perfectly great let's make something a little bit more complex then we continue with this extension so what i'm going to do is i'm going to create another file called maybe help actually help pi and over here what i'm going to do is something something very simple i want to create a helper function called the test so i'm going to have that test and i have a message and this message may be what i want to do is i want to ignore this pop it up by mistake i want to display the message okay again you see these errors because it doesn't know what is display so what you want to do is run micro bit import everything and this will make intellisense working messages msj msg all right so we have this uh very simple test function what i want to do is i'm over here and now before we start i wanna print the message so what i'm gonna do is from uh helper import everything and in this case here i'm gonna have my function test and say welcome all right and now i'm gonna flash it and welcome will appear over here and at the same time you will find that the serial port is still working and we're still printing hello world every second so perfect everything is working and basically with this simple example i was able to show you that you can have multiple files as long as you have the main file called main.pi all the other files are going to be uploaded as well all the files inside of this folder python files or any other file will be uploaded on the micro bit okay so watch out only this current folder all the files are going to be uploaded on a micro bit how can i verify this you can actually try to remove these files from the micro bit so i can remove a single file you will find there is a list of files that i can remove from my micro bit helper.pi remainder pi and if i click for example on help head of pi i'm removing that file and now i try to remove another single file and you will find there is a remainder pi okay you can also remove all of the files remove all the files from the micro bit over here and now basically there is no more file on a micro bit so let me upload this again i flash it i want to show you something interesting so say for example i uploaded everything is working but now i'm gonna delete these two files and i'm gonna trash them or maybe i'm gonna attach one and maybe the other one i'm gonna i don't know i'm gonna simply modify with something silly okay so i have helped a pi that i modified and main completely disappear now what i can do is i can copy a file from the micro bit so i can fetch it back since it's on the micro bit i can fetch it so for example over here let me fetch elbe first and as soon as i wanna fetch it is asking if i want override i want to override it now helper.pi will contain the correct version that i have before now let me fetch also the other one um the main and it will just get it without asking me to override it because there is no other one and here i have back my files and i can modify them and re-upload them and so on uh the last command i want to show you it's this one called fetch fetch examples from online so you can do this once in a while i'm gonna do it now he fetched successfully all the examples and now when i try to initialize again initialize my project you will find there are more projects actually available i still have the yellow world i still have empty which means no modifying my current space but i also have other two buttons and memory stats so say for example i want to get the buttons example all right so this one is gonna modify my main my helper is not gonna be modified i'm gonna simply delete it because i don't need it anymore and now i'm gonna flash this one up on a micro bit and now i have let's see uh [Music] yeah it seems i correctly flashed it i believe no i did not correctly flash it so let me refresh it again i fetch by mistake instead of flash i flush them and now there is a sad face when i click on a according to the code it becomes a little smile okay again if you don't see this happening right away you might want to click the reset button on the back with this this is pretty much it so i hope you enjoyed this tutorial i hope you enjoy the extension as well and if there is any problem please reach out and write an issue on github so that actually can be fixed and that's it thank you very much for listening bye
Info
Channel: Make Lab
Views: 10,755
Rating: undefined out of 5
Keywords:
Id: eSGJLu1kqyg
Channel Id: undefined
Length: 13min 8sec (788 seconds)
Published: Mon Aug 23 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.