Getting started with AVR and platformio

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello since many of you are not using windows and thus cannot use admiral studio for programming the microcontroller unless admiral studio works in a virtual environment under mac macos which i'm not sure whether it does or not then we have to look for different options so admit studio by itself is a windows application and you can find it on microchip's page here are the two options for windows installer either complete installer or a installer which will load everything afterwards in other option which has been established during the past years in order to program different families of microcontrollers is platform io which is an open source initiative and it is a plug-in for the microsoft visual studio code platform or editor and this one is available for both mac and linux as well so if you have installed visual studio code which you can find on the visualstudio.com homepage or you just google for vs code for example then you can start the program if you find it we have it here visual studio code visual studio code and it will look like this um it's still doing something okay it's done doing something and you have let me take it away here you have this icon here which is extensions if we click here then you can actually enter up here platform io and if you spell it correctly not like me platform io then you will actually find a couple of options here but it's actually the first one here the platform i o ide which we want so you can either click install directly here or you click here to get more information and then we choose install and this might take a while so don't be impatient as i was before um just wait until it says that everything is done on here obviously it downloads first its own python interpreter and then it's it installs a lot of core utilities which it needs to compile for different embedded platforms and actually here you have a list of different platforms which it actually supports um it is mostly based around ready-made embedded boards like the arduino or the nucleo from stm but this can be simply ignored for us because we have just in the simple microcontroller which we want to program um and it also yeah it supports cnc plus plus as its programming languages for for the task and if i see a screenshot like this i'm just get frightened because i don't know why you want to see everything like this on one single page and so don't be frightened yourself and it's still not done down here i will also try to find out how i actually can increase the font size later on because i want to stream this out as well to you later so platform io has been successfully installed please reload window actually i tried this one before and i will try something completely different this time i will just restart the whole visual studio code it seems to be to me a much more safe option so let's restart everything here and while it's starting up it gives us a new icon down here on the left toolbar and this is actually the icon of platform io it also starts automatically up with the pio home page and here we can now choose a new project and let's try that and it will tell you that there are what 909 different boards available let's first call this something let's pour this project to test and select a board and the the problem here is that it is many boards and of course our microcontroller board is not here but what you can find is the spark phone no not this one this spark fun pro micro 3.3 volts 8 megahertz this is the closest we can get and we choose this one for now and it gives you an arduino framework as a preferred framework for programming and so we say finish and now it also has to do something it will load a lot of stuff um in the background i'm not sure how much that it says please wait here so we wait okay it restarted itself somehow i'm not sure complete why but um it has now actually if you would have a look in your home directory under windows now then you will actually see users uvc uh platform io that it has created a structure platform io here which it contains i don't know how many how much 400 megabytes of files um on my computer here which is all the definitions of different platforms and and yeah so what we can do now is actually create a new project and let's do this we create a new project which we oh we created a new project we already created a new project test of course that's how we got here in the first place and this is what you see here in the explorer bar on the left hand side where you can see different hidden sub directories and some include lip source test and something down here we have something which is called the platform io.ini if you click on this you actually see the any the initialization file of our project and what we will do here is actually we remove the framework arduino line from it i am currently trying to investigate how we can actually make something where we don't get this line in the first hand but for now you have to remove it and then we go to source and it actually under source src created for you already a main file which will be the file which it compiles and this is actually an arduino sketch essentially so we will also delete all of this what we will instead do is create a simple c c plus plus file we will i will not change the ending from cpp to c now it doesn't matter but i want to include and here you see the syntax highlighting of the editor which is really nice we include we just choose what it suggests and we want from the from the avr block of libraries we want to include the io.h library so you see that it it just suggests what what it's reasonable choices for us and so we can adjust to choose from there i want to include a different library as well i want to include a library which is called which is called util delay.h which allows us to use time delays in our code and then we start by writing our code we want to have a main function as we have seen in the third lecture in the course and it accepts no arguments so the parentheses here is filled with void which means empty and it will return an int value an integer value but it will never do because our int main will never end and so i start by making the two parentheses here and now i can do some commands for our microcontroller and just to test if anything is working we will look into the details what these do later on ddre i will set so ddre it seems to be a variable it is a variable but it's a very which is already defined by the compiler actually by the library io.h for us and it's something in the hardware of the microcontroller so i will choose to set it to 0b01000 and then i will make a while loop i just type wh and it just suggests a couple of continuations for that and if we just click then we get a ready-made while loop with all the parentheses and indentation and everything but we want our condition should be one because it should never end and then i want to blink the led on the pin pe6 i can do this by actually saying port e which is another variable should be the same 0b01000 then i wait and the command for this is underscore delay milliseconds so i press an underscore and a small d and we have four suggestions which fit we take the delay milliseconds and it takes an argument which is actually the time in milliseconds as you can see by the help here which plots up automatically so let's say we blink it for 200 milliseconds then we say port e should be zero b one two three four five six seven eight i also could have written it in hex or decimal and then i want to wait for let's say 800 milliseconds so this is code which is uh correct code we will not you don't need to understand right now what it does in detail but now we want to compile this code and here i'm really not completely satisfied but perhaps i will get used to this as well the compile is done through buttons on the bottom row on the screen here so we have this one here this check mark which is platform i o build then we have platform i o upload which also not really works for me right now and we have clean and we have serial monitor which we will later use and we can open the terminal but once what we want to do now is to build our code and i press build here and it's building and we can actually see and this is good this is unlike arduino for example you get detailed information during the build process here and you get a summary at the end it says that of the flesh memory 0.9 percent or 246 bytes will be used for our program which is quite little and [Music] actually i can i will try to upload this code now and for this i will use if you do this so first we have to find our code and on windows again now um the we can have a look where it is it actually is under your documents folder in a folder platform io projects test the name of the project and then we have the same structure that we actually see here in the explorer window in visual studio code so under dot pyo you will find build the result of a build process and then you fill the will find the name of our platform and in here you will find a hex file which is actually the file which we want to upload let me just show you how this file looks uh more apps here i'll open it in just notepad and so this is how this file looks it's a lot of hexadecimal numbers that's why it's called a hex file so this is a file we want to upload and i will be using my trusted avia dudes uploader here but i will also show you other options later on how to do this on a different platform like just from the command line i have to find the file we go to project we go to test we go to dot po build sparkfun here it is and now i actually have to put the microcontroller [Music] into into upload mode i would have to disk 2 here oh it's completely out of focus well it tries to focus let's go there clean clean up the working area a bit it's completely out of focus i hope that it will focus in a second so what i have to do now in order to upload the code there is already something blinking this led right now i'll have to put the bootloader into reset mode so it actually accepts a new program and i do this by double clicking on the button which we have on the breaker board here double click now we have a fading led um switching back here i can now say program and it said it didn't manage because actually it timed out before i managed to switch over so i will do it again i press i double click on the platform and do a program here and now it says something like it's burning and it has programmed 246 bytes of flash which is actually the same number that should program and if i go over here now we have it blinking again and we have it blinking according to the new sketch 200 milliseconds the led is on and then for 800 milliseconds it's off on off on off on off so just to show you that this is really the code or the thing which happened i can go back and change the times and let's say i blink it for two seconds on and two seconds off just to make a clear difference here i will compile the code and it's still 246 bytes all we changed is the length of the delay i will bring up if you do this here i will now transition and show you my desk here permanently so i will put the chip into reset mode now it is and now we can actually program the new code and when it's done you will see that it actually now blinks at a much slower pace two seconds on and two seconds off so we managed to write code in platform io to compile it and to then upload it into the microcontroller using the usb cable so that's it for now how to get started in platform io
Info
Channel: Uwe Zimmermann
Views: 4,954
Rating: undefined out of 5
Keywords:
Id: IqJRLvPsin8
Channel Id: undefined
Length: 18min 9sec (1089 seconds)
Published: Sun Nov 01 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.