Transcript for:
Basics of Embedded Systems and Applications

Welcome back. In this lesson we are going to have a look at the introduction to embedded systems. Although this is the introduction we will be looking at the overview of the entire embedded system but these are the most fundamental things that you need to be aware of. As a student to this course I am offering you this presentation for free on my website. I have left a link in the description for you to navigate freely. If you want to say thanks then you can comment below this video so that I know. now this lesson is entirely theory based but i promise you guys that i won't bore you so i've added enough graphics for the entertainment as well so the first thing that we are going to have a look is at the definition so by definition what is an embedded system as the name suggests you it is embedded it means that you Few components are put together in this case. It will be hardware of the software for some dedicated activity I have highlighted a word dedicated because it is for one specific activity for better understanding Let us look at the examples. I have taken the example of the ATM We all are aware that we go to the ATM. We insert our card add type in our pin and cash out right but we cannot go to the atm and ask for a soda that would be nuts so the second example is a calculator and the third one is a washing machine we can use the washing machine for laundry but we cannot use the washing machine as a dishwasher right so there is a lot of emphasis on the word dedicated make sure you keep it on mind whenever someone asks for this definition the next thing is the system on chip by definition it means it is a microchip with all the necessary electronic circuits in parts for a given system on a single chip this is the architecture of system on chip this is a small chip like intel or qualcomm etc you may be aware what this chip is but you are unable to recognize it as you don't know the internal parts of it so this is what is the system on chip consists of now there are other two types which is system in package is packed and your third one is a system on board so your system is built entirely on this board There are three types of system on chip. The first one is the microcontroller, the second one is the microprocessor and the third one is the programmable system on chip. And the chip that we are going to use out of these three is the programmable system on chip because we are going to program the chip for some specific activity only. So few things which you can find on the chip are the digital analog mix signals or the radio frequency functions that will be sorted on a single substrate. The very fundamental thing that i want you guys to understand is that soc does not necessarily contain built-in memory so the memory can be internal as well as external here is a representation of the chip which you might be aware of already and this is the exact thing that we are talking about now where can you find these chips in your smartphones laptops computers or any other system because that is the core of every system present in this world our next topic is chips on board this is the representation of the chip that you might be aware of the most famous companies that design these shapes are arm atmel intel and microchip now arm is just the designer but it does not manufacture its own chips whereas atmel intel and microchip design as well as manufacture their own chips. But a very interesting part is that this microchip is brought by Atmel and the Atmel is brought by ARM. So ultimately ARM has all the licenses to almost all the boards. So out of this, which board are we going to exactly use is definitely the most famous one ARM. So the ARM stands for Asynchronous Risk Machine. ARM itself means the Cortex-A. Cortex-R and Cortex-M. So ARM is the ARM. So Cortex-A stands for the application which gives out good performance for the power supply that is the medium power. It can be of 32 bit or 64 bits and it is most widely used in rich operating systems. Now the most useful of this is the Cortex-R which is the real time. Now the example I have taken for this is the airbags. Let's say you crashed into something and there is a delay of milliseconds. for the airbags to pop out so there is no guarantee of the damage that has taken place so the real-time system should have the least error margin by least i mean it should be negligible the response should be so spontaneous that there is no room for error so this cortex r is most widely used in optimization for real-time systems another famous use is of the cortex m series which is the microcontroller This Cortex-M series has 6 different versions. We will have a look at it soon. But this microcontroller can be of 32 bits and it is most widely used for microcontroller applications that is in our embedded system the board that we are going to use will definitely have this cortex m0 plus series this is a pyramid that I developed for you guys it has all the six versions of the cortex m-series which is the m0 plus m2 m3 m4 m5 and m7 there is no m1 and m6 and the cortex m0 plus is the most famous out of this our next topic is components on and off chip I want you guys to pay attention at this topic because this is really important for you guys to understand what goes on the chip and what doesn't go on the chip. Now the things that does not go on the chip is input, output and the power supply. And the things that go on chip are interface ICs, your clock, memory. now the memory can be internal or external but by default it is internal so i have added it on chip so when it comes to exam point of view you can write it as memory can be on chip or off chip and then there is your microprocessor and microcontroller I know I have listed down things here but what you do understand by interface ICs, clocks, memory, what is a microprocessor, microcontroller or what goes into the input output or power supply right so I've listed down few things for you to gain some knowledge so interface ices are your a2d converter or d2a converter usb uart spi your wi-fi or bluetooth low energy and what goes into the clock and what do i mean when i say clock clock means your oscillators your face lock loops and so on and by memory i mean ram rom flash memory and so on we all know that we use memory just for the purpose of storing data and programs moral comes under input is the switch buttons keyboard etc output is the display your load printers speakers etc and then power supply which is bit obvious that you need to give supply to the board in order for it to function in the first place so till now we have talked about all the fundamental things and the design and what all goes into that board but how exactly are we going to control the board that is through programming So how do we program the board? There are two ways which I have listed. The first one is the offline compiler and the second one is the online compiler. Coming to the offline compiler, I would not recommend it at all because this scale software needs different other files for it to function. The first one is the dependencies. Then you need a terra term or the external terminal for it to function. And there is a lot of errors which can occur. on the system side i've explained it in my compiler tutorial on why you should go for the online compiler now the board that we are going to use is the freedom kl25c and that board is um enabled by embed what do I mean by the term enabled now any board designed by this arm does not necessarily have to be enabled by the embed embed gives out licenses so make sure that your board is enabled by the embed that means it should have given out licenses to that specific board in order for it to function The online compiler that we are going to use is the ARM embed. The ARM is in collaboration with embed hence the following. So that's it for this tutorial. I hope you guys enjoyed it and grabbed all the necessary points that you need. I'll see you guys in the next one. hello guys welcome to another tutorial I'm Alex and if you're new here make sure you subscribe today we are going to learn a new parameter called pulse width modulation by using that we are going to control the intensity of our led so let's hop into the program Open your compiler the first header file is there. So for the pulse width modulation the new API comes into the picture which is PWM OUT. Make sure P is capital and OUT is capital. Then you can name any of the object with your favorite name or whatever. Then goes in the pin number. This statement right over here means this is an API PWM OUT. which controls the intensity of an LED. This is your object and this is the pin number for your red LED. I'm going to use the red LED because I think it's fascinating as well as that's my favorite color. Next step is the same one which we always do. As we know we always write our program in the int main and always in the while loop which is an infinite loop Having said that today we are going to learn two things first one is the PWM What exactly do I mean by pulse width modulation is that it is basically a series of pulses with different duty cycle time in a fixed time and What exactly exactly is duty cycle as you see from this picture this is one pulse which has a width of this corresponding size as indicated and while learning pulse width modulation the next thing that comes into picture is the duty cycle you should turn your phone down while recording duty cycle is t on upon t on plus t off t on plus u of together is called the total time period and again what is t on and t off so going back to the width the pulse that is on during that moment is the t on and the pulse that is off a flat as you see in this representation this is off area this is the on the area this complete cycle together is the total time period that I am talking about and this is the t on so duty cycle is t on plus this both value the whole value of this one cycle a complete cycle consists of t on plus c off do remember that this is just a representation of 25 percent duty cycle and if you want to take it in person all you have to do is after getting the t on by total time you just multiply it into 100 the way you always do it with a percentage so that's about the pulse width modulation the second thing that we're going to learn is the for loop and what's the specialty of the for loop is that you can use three criterias and for a condition and if that condition falls true then you can go ahead and print out the value and as well as you can use the for loop as many times as you want and for doing that first of all we need to define a variable which i would say float i is equal to zero okay so why did i take float instead of integer because because we already know that zero is on and one is off because in emulator system led is active high so if i take 1 and 0 that would be a whole number which is actually an integer but if I take integer that is int then we won't be able to see the intensity of the light so for doing that we need to take float what does float do is you can use values such as 0.1 0.2 0.3 2.2 5.5 so you can use numbers in point that aren't a whole number so that is a float one now open your condition for for loop in here goes our three conditions first of all i is equal to one that is off then i will be definitely greater or equal to zero right because if it's already one that is off it should be moving towards zero which is on state and then our condition as I is equal to I minus 0.1 which means that it increases the intensity of the LED by 0.1 you can keep it as 0.2 as well but I think that will be not so noticeable so make sure you keep it something that you can quickly notice and there shouldn't be a jump in the intensity definitely you can use it go ahead but i prefer this so what happens if this condition is satisfied you can say my led is equal to i now we already defined i is equal to zero but we get the value of i from over here so that value goes into this line of code and the intensity of the led varies so next step is to automatically add a delay of 0.5 seconds that's our one loop Now we open another loop. This loop was for making the LED to go from low to high. That is the intensity. Okay. now we have another loop which is i is equal to 0 which is on state and i here should be less than or equal to 1 and then our condition goes in as i is equal to i plus 0.1 which means that the led intensity goes from high to low this condition right over here decreases the intensity of the led and if this condition is true then myled is equal to i that is the water there is whatever value is at that point i'm using myled because i already defined my variable as myled in here if you use abc then you definitely need to keep it as abc is equal to i then the delay goes in 0.5 seconds with semicolon this is a code that that said nothing too intense save compile you Open it in your folder, copy the file and paste it in the drive that has been connected and this is the following output that you can see. so I hope that this tutorial was really simple for you guys and using this PWM we will do other experiments as well this was just our introduction to the PWM so that you guys can clearly understand and make sure you give it a big thumbs up and I hope that you enjoyed this tutorial thoroughly I'll see you in the next one Hello guys, welcome to another tutorial. I'm Alex and if you haven't subscribed make sure you subscribe. In this program we are going to make use of sensor but in a very different way by using three LEDs with the user input. In the last tutorial I forgot to In the last tutorial I forgot to tell you guys about the definition of the sensor. Basically a sensor is an electronic component or you can say a module or a subsystem. Like we see in the embedded system it is a subsystem in that it is used to detect events or changes in the environment. And it is used to send the information to other electronics. Having said that what exactly is this tutorial? So we have to write a program where red LED glows. When the value on the sensor is 0 to 0.4 as I told you guys and introduced you to the concept of sensors I told you that 0 to 100 percentage is considered and if you eliminate the percentage you will be left with 0 to 1 Which satisfies this condition then we have to Glow the green LED if the value of the sensor is 0.4 to 0.6 and the third condition is to glow the blue LED if it is between 0.6 to 1 that is the rest before getting started with the code this time we will import the library first and then we will write the code for doing so the instructions are same as the previous one it's very important that you go and watch the previous tutorial the link is in the description if you want to navigate freely you have to follow all the steps again and land on this page click on Import into compiler. You wait for it to initialize then a dialog box will pop up Everything will be same. You just need to select the target path Which I set it as tutorial by Alex. I've already created the file. You guys can create it and then import the file Click on import close the last compiler tab in here go to main.cpp in the tree i forgot to save the program question so i'm going to type it again the library is imported everything is as it is as the last program till the input is given so include embed dot h include tsi sensor serial PC USB TX USB RX semicolon TSI sensor TSI semicolon The changes to the pins will be made because we want to use all the LEDs you can use bus out and if you use bus out you will have to use the hexadecimal values but to just make it simpler I'm going to use the digital out this capital always capital I will use led one where led LED1 will represent the red LED and the pin number will go here that is PTB18 is for red LED. Similarly digital out for green LED I will name it as LED2. PTB19 is for green. Digital out LED 3 is for blue. That is I'm naming it as LED 3. You can name it as blue as well. PTD 1 is for blue. Next is Intmin. Open your round brackets, curly brackets. let's define float t is equal to zero while loop even the next one is same that is tsi this is tsi is equal to t read percentage with empty round brackets and the same semicolon will get the input value from the sensor that is when the user will touch the sensor it will get the value and store it in the value t we can use the next step the pc dot print f to print it on the terminal if we want to see the value of t so it will be t we can we can say value is equal to percent f that is the float value and for sophistication we use the next line and the point of the cursor will go to the first and t is where we get the value and ends with a semicolon i'll quickly comment out till here the program is kind of similar except that we included the digital out LEDs now the condition starts for the red let's start with if loop that is the value of T which we get from the user if it is less than or equal to 0.4 then do the following LED 1 will glow embedded system is active low so 0 is equal to high but how do the other LEDs know that they have to be off or on so we have to define them as LED 2 is equal to LED 3 is equal to 1 which means rest of LEDs are off that's one condition for if the second one condition was to get the green LED glow for doing so we will use the else if loop else if if T is less than or equal to 0.6 that is if this condition is satisfied then LED 2 will glow that is green will glow the rest of the LEDs will be off so LED 1 is equal to LED 3 is equal to 1 which means off close the bracket the last condition is else you don't have to give any conditions if if condition is not satisfied else if condition is not satisfied then automatically your third condition will be satisfied else LED 3 will glow which means blue LED will glow and the rest of the LEDs will be off indent them properly Some of you might have a confusion or doubt that if LED value is 0.4 and If the input touches somewhere where the value is 0.5, then won't this operation will get executed? No, because if condition is satisfied then the rest of the conditions will be false, they won't be executed. If the value is 0.5 that means it doesn't satisfy if condition. It will eliminate this condition and jump over to the else if condition to see if this condition is getting satisfied. So, if condition 0.5 falls into this condition. condition so it will eliminate the next condition and this one was already eliminated and how does it know that if the value is 0.7 or 0.8 or 1 it has to glow the blue LED so if this condition doesn't get satisfied it automatically means that this condition is not getting satisfied as well the only thing left for it to do is to execute this step no matter what. So we don't have to define any condition with the edge, we just have to tell it what to do. Simply save your program, compile it, see if there is any error, open the file in the folder, copy it and paste it in the drive of the hardware. And this is the following output that you should see. have fun while you learn I hope this tutorial was helpful and give it a big thumbs up I'll see in the next one hey guys welcome to another tutorial today we are going to look at the compilers that we can use along with the embedded C program there are two ways which you can use a compiler which is obviously the online and the offline compiler would highly recommend you guys to use the online compiler why I don't want you to use the offline compiler is because there are a lot of complications in it so let's say you have a program file what should you do is you just compile and get the file when you're using an online compiler but when you're using an offline compiler what you need to do is you need to have a lot of dependency files first of all downloaded to your computer then there are more than 9 to 12 steps that you need to do to get each file every single time that you have to do between the compilation and to get the end result file okay to put this in a very simple way if you're using an offline compiler and there is some error that pops up now you do not know that if it's an error from the system side or the user side but if it is an online compiler there will be zero error that means that there is some mistake that has occurred from the user side so you just have to check the program instead of checking out all the settings if it was an offline compiler so I will show you guys how to use an online compiler with its interface we will be using only the online compiler throughout our tutorial unless required to use an offline compiler okay so it's very simple you don't have it's just like signing up for any other website so this is a free online compiler that I know of and I'm not in any way related to it I'm not even an affiliate to that but I just want to tell you you guys just has to share because it makes a lot of tasks simpler so it will be easy for you to focus on the program rather than all the other different complications that might pop up so if you want to thank me you can leave a like to me on this video or leave a comment below so that i know if it was useful for you guys but if you know of any other compiler which is compatible with our board that is a freedom board that we are using then do let me know so there are two ways in which you can use it You can reach the compiler is the first one is embed.org on this home screen you just have to click on the developer resources it takes you to this page which says arm ember and in the url it says developer.embed.org the other way is to just go to developer.embed.org directly Every programmer might do this, so it's efficient to know which site you're using. So since this is a site ultimately that you have to reach in your NCEP, click on login or sign up. it's a bit obvious that i already have a login id but just to walk you through the signup process you need to enter your email id choose a username password make sure you remember both your username and the password and then enter your first name last name your country and fill in the captcha that's all you just agree on both of this and then click on sign up going back to the login page you need to go on to your email and click on the confirmation only after that you will be able to log into this site so come back to this login page and then click on enter your username and your password as you can notice this is your profile there are several options to look at your dashboard profile or you can log out if you want to follow me on any social site this is what you can reach me out to I'm Alex O'Connor Instagram Facebook Twitter whatever you can always catch me up here or check out my website so as we're done with the self promotion over here you can leave out all these steps we don't need them you just need to click on the compiler a new window will open for you guys it's loading wait for a minute or two it doesn't take much long either so this is the workspace which you will be greeted with let me quickly walk you through but you will be greeted with an empty screen so this is the workspace details this is i'm alex o'connor the board i am using is freedom fl25c the total programs i have is 41 i last modified it 17 minutes ago for recording this tutorial it shows the recently modified tab definitely you can adjust the length and all by dragging it okay that's what the right column coming to the left column so these are the list of the programs that you have if you click on the plus sign it will expand and you can see all your files in it so the main file that we need is the main dot CPP you will write your program in main dot CPP whatsoever in that file this work page management is similar to it but once you have selected the file let's say take an example main.cpp you just double click on it so this is the white space that will pop up this is where you write your program all you need to do is save and then you click on compile as soon as i click on compile it will compile within a second or two and this is the output description so if there is any error it will indicate you over here with a message and if it is success then it will show success as well as there is a file right over here which you can use to show in folder and this dot bin extension file is your output file all you need to do is copy this file and paste it in your embedded board drive which you have connected as simple as using a usb but if it was about an offline compiler then there would be about 10 steps between this save and the compile and the next thing i'll show you guys how to create a new program you need to go to new new file i'll definitely walk you through on our first programming but still you need to look keep the platform as it is unless you are using a different board okay let the template be as it is and this is where you can name your program this is a new program okay it says creating program please wait okay this is how your file will look there will be a already imported library of embed apart from that you need to click on make This is the template which we requested for. You can delete it and you can freshly write your program. So how do you select your board? If you want to select a different board, click on the board on the right which says Freedom KL25Z. You can use definitely any board that is compatible with it. I'm using the Freedom KL25Z as I discussed. What you can say is add platform. It will show you number of boards. So whatever board you pick, there is a Freedom KL46Z. Great. so there are n number of boats which you can choose from okay I'm using the freedom kl25z of the cortex m0 series click on it this is what you will see and from here you need to open embed compiler you will be back into your compiler and it will ask for if you want to create a new program you can say yes no whatever right now I'm cancelling it so you can see the freedom KL25 board is set now if it was another board it will indicate you right now over here so as I said before if you're using a compiler make sure you're not using several compiler tabs altogether so this is one compiler and this is another tab that we have already opened so just close it and you can also close this page because you don't have to do this every time so next time you log in you will have this board selected by default so you don't have to worry about setting the boat again and again this compiler is like a github so you can definitely share and do a lot of stuff you can import and export so once you're done with the program if you want to log out just close out this compiler and you will be left with the tab that we came through hover over your profile and click on log out it's gone okay i hope that was informative see you in the next one Hello guys welcome to the new tutorial. So I'm thinking that since this is a series of tutorials I don't need to really welcome you guys every single tutorial that will be really a pain and as well as it will be really boring for you to hear all the intros again and again. So maybe this will be the last time so welcome to your next tutorial in this tutorial We are going to do a color circle What does that mean is we are going to blink the LED first with the red green blue? Using these three primary colors we are going to glue out Secondary colors which is yellow cyan magenta or you can say purple and white also we will make sure that all the LEDs are off as an operation as well so open your online compiler to start a new project go to new new program leave everything as it is except the program name I'm going to name it as color circle tut by Alex okay click on main.cpp wipe out this program we are all set to get started the first step is to include embed.h The second step is a new operation which is Bursout. Make sure B is capital and O is capital. Now, we will see how to make a new Bursout. one does this ring any bells to you we did it in our last tutorial these are the pin names so what does this statement mean is here bus out is a new operation that I am going to introduce today it actually comes under group control what is a group control it is a flexible control of multiple pins so what does bus out do in that it writes a single value to multiple pins so as we know that in our last tutorial what we did was we did digital out and then we named every single LED if we wanted to use all three at once so that would be like this These are three lines of steps that we have to write in order to use all three LEDs. Also, we have to assign LED1, LED2 and LED3 as a sensible variable that is the object. So instead of doing all these tedious stuff what we can do is we can type bus out as a class and rgb is the object which you can change to anything and these are the fixed pins that we have already discussed so it is a class object and pins then goes the int main then comes in the while Open curly brackets, intent properly. So here we write our program. Our first step is to glow red LED. Next step is to add little delay. so that we can actually differentiate between the colors then we want our green led to glow then we add some delay then blue delay i want yellow which is a mixture of red plus green then a delay then i want sign which is a mixture of green plus blue delay then I want magenta or you can say purple as well which is R plus B delay and then white these are called color codes so white is a mixture of r plus g plus b and then we will add some delay and the last step is to turn off all the leds then add some delay that's it so for this it looks like a pretty big program but no so first of all let's fill the space which needs the delay because we are aware of that operation which is weight 0.5 in round brackets with a semicolon at the end i'm going to copy paste but you guys type it out if you want Every alternate line has a delay okay. All you need to understand for this program is binary to hexadecimal conversion. Binary numbers is made up of ones and zeros. Hex numbers are made up of 0 to 9 and 10 is denoted as A, 11 is denoted as B, 12 is denoted as A, is denoted as C, 13th is denoted as D, 14 E and 15th F. This all cumulates to 16 values in total. Our object is RGB. and as a first step we just want red to glow for doing that since these leds are active low which means 0 is considered on and 1 is considered off so so basically it would mean that if i want red to be switched on then it should be 0 green should be switched off so it would be 1 blue is off it would be 1 so this should be my red value but that's not the case since it is active low there is a reverse polarity that comes into picture there is something called as reverse polarity which means you instead of starting out and adding a zero right over here and then converting into hex form what we have to do is instead of adding the zero on your left hand side we have to add a zero on the right hand side if it is a three digit because for converting into hex we need four bits this value would be 6 and instead of simply adding 6 we want the computer to understand that it is a hexadecimal value so we would simply add 0 into 6 which makes it comfortable for the machine to understand quickly similarly for green it would be 101 which means red is off green is on and blue is off which would equal out to 5 so instead of 5 it will be X into 5 In case of RGB, it will be 110 which means 0 into 3. which is a green i will just comment it out for your betterment blue so these three colors are the primary colors using these three primary colors we can get three more secondary colors those are yellow which means red plus green but we don't have to add red plus green value here we just have to use r plus g and that means it is 0 into 4 for sign it is green plus blue which is 0 into 1 then the magenta which is red plus blue that is equal to 0 into 2 and then using all the three primary colors we can obtain white which is r plus g plus b 0 into 0 also we have to have a state where all the leds are off so that would be 0 into 7. there you go these are the codes that you have to just enter right above in your code i will comment it out so that you guys can see the values properly now in order to write the code we have to use the object that is rgb is equal to just put out the value 0 into 6 and make sure you add a semicolon for green it would be rgb is equal to 0 into 5 semicolon then there is a weight operation which you are already given then it would be rgb is equal to 0 into 3 semicolon space it out then is rgb is equal to 0 into 4 semicolon then is rgb is equal to 0 into 1 semicolon rgb is equal to 0 into 2 rgb is equal to 0 into 0 RGB is equal to 0 into 7 so this is your code right over here save the project then click on compile it shows the error oops I have roads main right well I'm glad that it popped up error so that I can show you guys Save the project and compile it again. If there are errors, the file won't be downloaded. Now it says success and the file has been downloaded. Then open it in the folder. Select that file. Copy the file and paste it in a drive which popped up when you connected your board. The output is as shown. That's it for this tutorial, see you in the next one. hello guys I'm Alex and welcome to you another tutorial of embedded systems programming today we are going to do a basic program of blinking and LED first of all open your browser then go on to developer.embed.org it is a best practice to use the direct URL instead of going on to the main site and then going on to the developer account then go in and login I've showed you guys how to use this online compiler in my last tutorial if you guys missed it the link will be in the description or you can navigate yourself through the playlist so fill in your username and your password I'm logged in as you guys can see click on the compiler a new tab pops up let it load now we have to make a new project for doing so click on the new tab on your left top corner click new program the platform that we are going to use is frdm kl25c which is a freedom board let the template be as it is you don't need to select a new one you can name your program I'm going to name this program as LED blinking tutorial by Alex click OK it says creating program please wait it doesn't take much time if you have a good system now click on the main dot CPP you will be welcomed with the screen you can delete it out this is the program actually which we are going to do but to be a good programmer you guys need to practice every single step so make sure that you type out every single step instead of copy pasting now that we are in our main.cpp you can say this is a c program but we are going to import in different libraries for the different ports and purposes so first of all as we used to do include htdio but we are not going to do that we are going to use an embed system so the first and the foremost thing that we will include in all our project henceforth is include quotation marks embed.h which is the header file, head stands for header. Move on to the next line. Now we need to use an interface between our software and the hardware. And the main hardware that we are going to use as our output is the LED. So in order to blink... out your led you need to interface using the function digital out which configures your digital ports now here digital out is a class give a space and the next thing can be a variable which can be anything in the world it can be rat it can be mango that's now how it's spelt okay it can be mango or it can be apple as well but make sure as a programmer we have to give out some sensible names so that the person who approaches your code or has a look at it should be able to understand although he will be able to definitely identify it later but make sure it is sensible so that it is easy for us to decode or debug later on so i'm going to use my led or simply led also make sure whenever you're giving out led it is not in caps because the capital led is already assigned to some other function in this program so tap out a small led and then open round brackets so In that you need to insert your pin numbers which are the ports. So please do not type with me We do not need this code. This is just for your understanding. So hence on we will denote R is red which has the port number ptb18 you don't have to remember these pin numbers as you can go through the datasheet g is equal to green which has the port number ptb19 b is equal to blue which is ptd1 i don't know why they haven't kept ptb20 which would be really easy but as you know they screw it with all the different things so having said that we will use a blue led so as i said for the blue led you will use the port number ptd1 and make sure you end this with a semicolon now i'm going to comment it out so that you guys can understand really well so the digital output is a class which doesn't change you have to define it in order to interface then the word led is a object which you can change but make sure that you name it really sensible if not it's fine this program is going to work 100 percent and in the round brackets there is a port number or you can say pin number of that led the developer board usually has three leds which is now been optimized to one led so the board we are using has just one led but which gives out three primary colors which is rgb which is red green and blue and it gives several secondary colors using those three primary colors so one led is sufficient we start our program by int main which is the same in the C program and it is a good habit to indent and comment. It is a good practice for any programmer to type in both the open and the close brackets together and then you can space out. Also it is a time saver because you don't have to do match the following at the end of the program right. The first step is to write while. What does this code mean is it is infinite loop that means see we want our LEDs to blink as on off on off on and off we don't want our LED to just blink once and turn off right So this while one operation lets the program run in infinite loop as we wanted After the while one make sure you open the curly brackets as I told you guys make sure it is properly intended Now that you have spaced it out the real program comes in over here It is a very simple program. You just have to assign when to switch on and when to switch off so how do you do that first of all you take your object led is equal to one now here i have to really tell you guys to focus on what i'm saying in next one minute please don't type out what i'm going to type out this is just for your understanding as we know that one is equal to high which means on in electronics right and zero is equal to low which means off But that's not the case when it comes to embedded system LED. Here it's opposite which means 1 is low which is off and 0 is high which means on. So can you guess what this function might do? LED is equal to 1. What it will do is it will turn the LED off. off. Okay, I'm going to remove this. The next step is to enter a delay of 0.5 seconds by using the wait operation. Our next step is to turn on the LED which is LED is equal to 0 semicolon. What does this function do is it will turn on your LED. Our next step is to give out 0.5 seconds delay again. Please know that this time delay is in seconds itself. The next step is to click on save. The next step is to compile and download. Give it few seconds to compile. If there is any error, it will throw out in this compiler output for program dialog box with a description. But right now it says success. So that means there is no error. error whatsoever. Open your file in the folder. You don't have to open this file on your computer. All you have to do is select this file, copy it, then connect your device to your desktop or your laptop. It will show a drive that pops up. up just as when you connect your USB so go into that and just paste your code right over there as soon as the code is pasted you can see the following output on your embedded system right away you can achieve the same with the red and the green all you need to do is just change the port numbers to PTB 1 8 for grid red and PTB 1 9 for green and then make sure you save it compile it open the file in the folder copy that file and paste it in the device drive folder that's it I forgot to tell you guys that why we inserted a delete as well as the off operation right see what happens is when you just have the LED on it will stay on in an infinite loop In order for the LED to blink, you need a OFF operation which is LED is equal to 1. So this operation turns ON, this operation turns OFF and this ON and OFF operation will go ON and ON in an infinite loop due to the wild one. The reason we inserted a delay of 0.5 seconds is because you want to see the difference when the LED is switching OFF and ON. You don't want the LED to just switch ON, switch OFF, switch OFF. what happens when you don't add a delay is due to the persistence of the vision you won't be able to see when your led is on and when your led is off if you guys have any queries or if you guys need the code then there is a link in the description to a blog post you can click on it and get all the tutorials and the posts update if you find any other difficulties comments below this is for now see you guys in next tutorial hey guys welcome to another tutorial today we're going to do reverse LED blinking if you're new here then we are doing a embedded system course and possibly extended to Internet of Things this would be our third programming section where we are going to learn the reverse LED blinking in last section we did a color circle now we are going to do exactly the opposite of what we did in our last tutorial but with the addition of delay so that we can really differentiate between the color flow okay so head over to your online compiler create a new project i would name this as reverse led blinking by alex this kind of routine you know so click ok as you can see a message which says a new id section has been opened with your account actually i missed my class for recording these videos because i didn't feel it was useful to attend those classes anymore anyway so one of my groupmate must be using this compiler i'm going to refresh this tree it means that my compiler will work so go to main.cpp this is where we write our program delete this out basic step is to include embed.h Don't wait for me to tell you that. Next line is defining our pins because we want our hardware to work with our software. So we will use the bus out which we did in our last section as well. B is capital and O is capital. Then give a variable which you want. then give a variable which you want we can go with RGB but for the namesake, let's go with ABC it will still work okay open round brackets and in there you need to define your pin name so it would be PTB18 which is for red PTB19 for blue pt d1 for green i remember it i have been using the embedded both then a semicolon next line int main round brackets open curly brackets i always do it from the start so that you guys will do it from the start instead of copy pasting because what it happens is it kinds of give you the practice and after repeating it so many times you usually get hanged to it that you won't even forget the steps anymore next is to include wild one which is an infinite loop the thing i'm writing is called comments you can do it with a double slash and after a while we need to open our curly brackets again and we write our program in it right over here our first operation should be off then the led should wait and then it should go to white then it should wait then it should go to magenta wait sign wait yellow wait blue wait green wait red there would be the sequence which is of white magenta cyan blue green and red and in between them there should be a a wait operation so that we can actually see the blinking of the led a quick revision from the last section that the computer understands the hexadecimal values which is zero where whenever our number starts with zero into some number it is a hexadecimal form although it understand binary ones and zeros but we need to use hexadecimal for this it would be easy for us to do so and in hexadecimal over here it is in the reverse polarity so instead of adding your zero to the msb you need to add it to the lsb and you have to follow the binary to hexadecimal conversion to get these values as we already did it in our last section i'm not going to repeat it you can definitely go and follow that meanwhile our first operation is to be off so it will be instead of rgb it will be abc because that's what we gave the name okay so it will be abc a will be red b will be blue oh coincidence right and c will be green okay so for off the value is zero into 7 for into if you still haven't figured out then it is a x there is no into sign on the keyboard so you can use the x okay so what this will do is it will turn it will turn all leds off next operation is to wait for one whole second instead of 0.5 second as we did it in the last because what was happening is the led kept blinking to the next girl without waiting so there was not actually a blinking it was it's just a sequence of colors hence the name color circle right over here we are going to blink so we have to put in a weight of delay our next step is to next step is actually to make the led off again even though this is an operation of off but that is the first step to do right so after that we need the led to be off even though it is off you would understand right now what i'm trying to say but as we go ahead you can already guess from what it is so then wait for 1 our next color is white for white, abc is equal to 0 into 0 then it waits this would be your default idea of how to do now you see now you will understand what i was trying to tell you guys that now that we have given out white right over here we want our led to glow off so that it looks like it is blinking so now the operation of off will come again now you can see why we included two offs even though this was an off operation already but this was the step that we required and then we needed to off by default anyhow so this is the white and here it should be a default value of white next color is magenta which is 0 into 2 wait one then the off operation then wait for one second then sign which is zero into one wait off wait then is yellow which is 0 into 4 wait off instead of copy wasting and typing because it will give me a good practice even though it seems silly but practice makes a man perfect next one is blue which is 0 into 3 then wait for one second then the led goes off which is 0.7 by doing this i already understand all the values by heart because that's how many times i've already done it so wait and then abc is equal to 0 into 5 for oh abc 0 into 5 which is the value for green LED and then wait for 1 second and then ABC goes to OFF which is 0.7 and then wait 1 and then ABC goes into 0 into 6 which is red LED and then it waits for one second goes to off again into 0.7 and then waits for one second again that's it what else save so this would be the entire program just a quick recap this is the include header file which you already know bus out is an API which uses a combination of all the inputs so that we don't have to give a single input to each pin namely abc is a variable you can call it as an object which you can name it out anything instead of rgb i gave it the name abc just to make you understand that you can name it anything but you need to use that in your program then these are the pin steps ptb18 stands for red ptb19 stands for blue ptd one stands for green in embedded freedom board kl25c okay then we start our int main we start our curly brackets where we write the program while one loop is used so that it is an infinite loop what this while one loop does is all the program runs and it doesn't stop it will start again from the start to the end it will go in a loop from start to end start to end start to end our next step is to open our curly brackets again for writing the program in the wild one loop then comes the first operation which is to turn off the led then comes an operation to off the led even though this is off we are blinking it out next thing was to glow the white led and then we include an off the led will switch off and then it will go to magenta and then it will switch off it will go to cyan and then it will switch off it will go to oh our i haven't wrote here it should be yellow okay and then it will go off wait one number one actually indicates literally the number of seconds for writing in milliseconds there is another operation which i will tell you guys later so this is literally an off operation this means the pin goes off this means it waits for one second before showing the other output then we go to blue off green off red led it goes off and then again because of the while operation that we gave right over here this loop will start again this is off this will be off this will go to white and the loop goes on and on because of this while infinite loop okay now that you understood the program asked you guys to save do that and do the compile the compile output for program in reverse led shows success show in folder copy this and paste it in the drive that pops up when you attach your embedded system hardware paste and this is the final output that you can see it is off off white off magenta off cyan off yellow off blue off green off red off you can now if you want to go in a straight line that is red green blue yellow sign magenta white and then off you can just reverse out the values that is you need to just first place in the red value then off then the green value then the blue yellow sign magenta white in that way that's it for this tutorial if you guys have any queries the links are in the description you can reach out to me if you are new here make sure you subscribe i'll see you guys in the next tutorial that's it for now welcome to a new tutorial I'm Alex and if you're new here make sure you subscribe today we are going to learn a couple of new things as well as we are going to do some fascinating project all the projects we did so far are based on LED this is based on LED but it will be some interactive so so what exactly is the project the project is that we are going to use the sensor that is present on the embedded board and using that sensor we will try to vary the intensity of the LED in our last tutorial we saw saw that we could vary the intensity of the led using the pulse width modulation api we will use that api that this time we will take the input from the user that is the one with the embedded board so before i go ahead into the lesson i will show you where exactly is the sensor on the embedded board as you see on this image this white piece is not a space for you to touch because this exactly right over here between these two poles is a sensor and when you hold your board in such a way that your SDA connector is facing downwards and your board is held towards you in this way this area which is the sensor starts from zero on this level that is the sensitivity is zero from here and as we go above it goes from zero to hundred please note that this is the percentage that is zero to hundred percentage and not the value now that you know that this is a sensor to use a sensor we have to import a library that is the second thing that we are going to learn but as of now i'm not going to import the library let's just write the code as of now and we will try to import the library when the error pops up after saving okay the only thing i'm going to tell you for the sake of writing this code is we are going to include a new library called tsi sensor tsi is capital and s is capital in sensor dot h h is a file definitely so for doing this project we know that we are going to vary the intensity of the LED and to vary the intensity we know that we need to use PWM out API which we did in our last tutorial and this is LED which we use as object and we will use the blue LED whose pin number is PTD1. ESS sensor is just a library. You have the library but you need to get the book from the library in order to get the knowledge that you need so we have the library but we haven't issued a book yet so that book would be our api here tss sensor and tsi is an object right over here and usually we have something in brackets because that is the standard line of code what we did till now but for sensors we need not define the pin numbers because it already knows that the place of the sensor is fixed so do not put any brackets or anything just define an object instead of tsi you can write XYZ, ABC or your name. I'm going to go with a sensible name TSS sensor. I will comment so that you don't make any mistakes. Till now in all our projects we use just the LEDs. So we didn't have the requirement of using or knowing what type of communication that we are using. But now that we want the input of the user we need to know what type of communication we are using. that's when the concept of serial communication comes into picture UART you must have heard about it UART stands for universal asynchronous receiver and transmitter since this is a serial transmission it also has to be defined the computer and the embedded board does not understand what you are trying to do so you need to make them understand using these codes we try to vary the intensity using the PWM we are using the sensor using the sensor but how do we take the input so we need to define that with the following code serial PC USB TX is capital and USB RX is also capital and then semicolon you cannot change the standard default code method anyhow you have to write USB TX and then you have to write USB RX if you write USB RX first and USB TX later on it won't work at all we'll start the ink main here we know that we are going to take an input from a user so we need to define a variable we will do it as float is equal to t why float because we need to make sure the intensity is between 0 and 1 and that can be only achieved if you are using float if you are using a whole number integer then it's either 0 or it's either 1. the first line of code would be to take the feedback from the sensor and in order to do so we define t is equal to tsi.read and semicolon this line of code will say the input from users and it will store it in T now we have two options either we can print the value on the screen or slash and we can see the output using the LED We will try to do the both but we won't use stera term for looking at the values. Still if you want to use stera term you will get the values perfectly. I will write the code for it but we won't see it. So it is pc.printf and then goes in your bracket where your line of code will be there with ends with a semicolon. In this quotation marks. if you say t is equal to percent f percent f is the value of float which is t this t is just a sentence or a word for your understanding you can say this is my value you is equal to percent f you can't write t because t is not considered okay and just to make things little sophisticated we will use slash n which means next line and slash r which means the first point of the cursor to the start instead of float if we had used integer then we would write percent d we know we are going to print a float value but which float value because you might add hundred of float values So this is where your variable goes in which is C. We want to play with the LED. So definitely we are going to write LED is equal to watt it is 0 or 1 and we are varying the intensity so as per our condition it must be 1 minus T so whatever value is T the intensity will change according to the input then we add a delay of 0. If you touch the sensor, it will take 5 seconds for it to react and that's not really feasible nor recommended in real-time operating systems, especially when you're using feedback networks. This is the code. Save and when you try to compile it, it will pop up an error because we didn't import a library. look right here it says no library found so now we are going to search for this library copy your file name go on to the developer dot embed dot or on the top right corner there is a search bar go and paste whichever library you're trying to find you can simply type as TSS answer or sensor it will definitely pop and there are various libraries that you can import for this file but a really good library that I recommend you guys is from the user emilmon which is under a mercury repository click on it a new tab pops up the details will be listed down below you can check it out click on import into compiler another new tab pops up wait for it to initialize this tab will pop up do not change the source url and make sure your library is checked in no need to mess with the import name all you need to do is select the target that is the program that you already wrote by alex So this is the program that I want this library to be imported in. I click on import. These are the files that I got from this library. And on the left hand side if I see the tree of my libraries I can see that I have imported TSI. So I just click on the main.cpp so that I can go into my library. program and compile it. We have successfully imported the TSS sensor library. All we have to do is just click on the compiler to compile it and make sure once this new compiler tab pops up just close the old one. or else it will show that multiple sections are detected. Now try to compile. You will get the file open it in the folder copy it and paste it in the drive of the hardware and this is the following output that you will get you can touch the sensor wherever you want and you can see the intensity of the blue LED is changing depending on where I touch it. You can also use red and green LED by the pin numbers. So that's it for this tutorial, I'll see you in the next one. But before you leave, make sure you smash that like button. Thanks!