Tutorial Raspberry Pi, Controlando Pines GPIO con Python (RPI 3 y anteriores)

hello one all my name is alex and list as robert tutorial in which basically what is easier to do in terms of interface electric with the road barry in my opinion that is to control well in gp I or well it is digital input and output and that basically can be done in many ways in the case that I am going to do I am going to explain how to do it in countries we pass a very simple programming language and that it is also quite powerful that is to say, you can already do many things with countries that if I had done it for example with scratch is a has a graphical environment programming for the raspberry quite simple is quite limited It is rather to learn for children about everything and others with which I have decided to do it in countries it can also be done for example in java for sure that libraries can also be done from the console in any case and the demonstrated how to make a country are because there is a lot of information on the net and I do not know how to program the country you cannot watch on youtube there are many videos about it therefore I will not explain that in this tutorial so nothing first What we need to know is that you have the ripa rapa and that they do camping well here basically we have the pinot of these goods here as well as they are in the same order we have more to we have orders with super their numbers other masses we have for example the s & p y y 12 wards 5 volt supply feeding of 3 with 3 it is important that it is known that the raspberry pi works backwards against which we cannot connect things of 5 volts directly because we can damage it keep in mind that it is very sensitive to the rival branch is not like a microcontroller that can be a little more robust we cannot connect anything directly because we can damage any of the pins like this that it is very important that what is basically the The montage we have is the one in the video on the left that I have here that cannot be seen well try to do it a little more I walk so it looks good basically what we have is to the pin 39 who is the one here we have connected never ok we have connected the mass that is going to connect to this resistor that we have here and show here to this resistor I have to heat the ground you need to connect pin 39 that you see in the diagram the other part of the resistor is connected to the cat that is, the negative of the led then the anode of the led the positive is connected behind the white wire to pin 40 which is the gp io 21 that is to say that is what it is called but It is the number 40 physically although it is the last that the last one is here because it is in the extreme in extreme we have more exterior of the silver on the other hand we also have a button that we have connected between the gp pin and 16 and the ground, that is, 36 and 34, which are this purple and gray wire and basically they are connected directly to the pushbutton as seen in it that it is not counted here and is Here, keep in mind that the button may be backwards, that is to say that the pushbutton if they connect them if for example I connect between this pin and this pin It would be the same because they are short-circuited, that is, it is the same pin although it has two these two on this side are the same and these two this sides the same with which the violet connects here they connect to violet here and the gray here is as if it has always been pressed and thus it will not work well we consider so that in a case to a switch a pushbutton of this type so well basically that is assembly no we need nothing else and now what are we going to do basically is to open the country the steroid minimize we are going to program and we are going to country are three that is already installed as standard in earnest see on the flush well here we give new fai here we have a text editor where We can put our code I don't have it here I have you open in I'm going to open it here that I had put before to leave it already written this is the coin is a country and I will explain it but well I'm going to set it to 1 to make it look like I finished it do and want to be saved in any case basically there is the code is quite simple although it seems complicated it is very simple with in these two pins this first what is in red are my comments is say we can delete them that this will not affect the operation of the program and by the way the code will stay below in the description of the code of this video basically with this we import libraries the library allows us control different things have functions that we can use and here we are importing the raspberry gp yo library that allows us to control the digital input and output pins and one called time that allows us to do delays and things like that ok then in the next line what we do is that we tell the berries well to the program that the numbers that we are going to use 21 and 16 ok they are this that says here I have asked for 21 gp and 16 because because this can also be this is actually a pin that will have another number with respect to which is belongs to the main processor of the processor therefore if we do not put it well because we have the other way and when we put 21 it does not make a pin if we gives the 21 of the processor that can be connected to another site with which it is important to have is ok then in this set tuning what it does is basically take off some edges that would give us what they will give us if not we put but in this case they are irrelevant or warning with which in This case we are going to put it because we know that this will work and that it will not the problem ok then here we declare two valid two variables the one that already has programmed before, you will see that, for example, the country has not yet declared the data type you just put the name and the variable here in this case we are going to put 21 which is the end we have connected and our led did not close the image of 16 that we have it our button I am going to open it again so that they see it the 21 why we are here the reheated and the 16 the button and the other two are more then we have put it but at the final I am not going to do it like that so ignore it in gps is here we configure pin 21 is that order 21 as because it is called let's configure it as an express exit by the gp and gave point out to turn the led on and off jake and here we configure the button the pushbutton we put on pin 21 what We configure it as a job and I have also since it carries a resistance of internal pull up of express I will put resistance except the pintna la activa because otherwise we would have to put a resistance on the pushbutton also ok but of course no, no, we don't need them because the berries are already Well, it has some included, we simply activate it but we have a function called walter more works in the structure than everything that is let's say Tried here I need what is at this point will always run because because man is he says while true is to say now this while be true true as true is always true because it runs infinitely and this runs forever this is that this part of the code then in this part of the code the first thing we do of the gp I point input that we see if the button is pressed one and as the resistance to weld when being pressed the attention that we have at the input pin of the pushbutton the voltage will be zero when the pulses were zero that's why I say if it is false because that is if it is zero that is, it is pressed I print on the console which will be this pushbuttons is expelled and I say that time is worth 0.1, you will see that it is time and if not if it is not pressed I say what time is 1 all the following function falls asleep the micro sleeps here we get the application of micros hormones the application sleeps we say it is on the slip point to be part of the library time wants to use the link and sleep time that is to say the time that I have configured therefore if I am pressing the button it will be 100 milliseconds that is 0.1 seconds and if It will not be a second ok with which we spend so together lift time we wait for it to go out that is, we wait that time we turn on the led ok then we wait again for the same time and then we turn off the ok and then we come back here because why we are at the same height as I told you we recheck the button and do the same again with which what is going to do this is going to be that when we press the lecce to turn on every 100 milliseconds to turn on and off and if we do not press it it will turn on and off every second ok and the last thing we have here is basically a function that what it does is that we say clean remove what has to be removed or left the gp ports the port or gpu or pins you caught so that they can be use our problem at other times without problems but of course this is not going to run on this show because we are always on the walt so nothing good anymore We are for the one that you know how to program in the country even then completely whatever you want connect a server and when you give it a button it sends an email which they feel like it because in civilian clothes you can do a lot of things so now with this, we have the limit is the imagination rather like this that nothing is what we are going to do execute it for it first we have to save otherwise he will tell us that we have to address it we are going to 6 we are going to home the let's say normal directory of my documents or let's say the personal folder in linux we go to the country that is the user that brings raspberry country his serial operating system we can create another but hey we are going to use country that is from which it comes and now for example here we could create a new folder that does not allow me to create it so I would have come here let's create it let's go home and we are going to create for example to put tutorials but I create the folder and it should appear here If it does not appear to me, we simply go back we go forward again and here it comes out I will try the e verify and we are going to call this for example tutorial we are also going to make it save and now we simply give run run die we fight f50i and to him well, let's say he says start and begins to execute the program with which the program is already running and this what he is doing the rush derrick as if to see what is happening and we understand him with a second between off and on what happens if I now press the button button how to return it says the button is pressed and it was starting to locate it will not be seen well in the camera maybe but if I let go then it returns to a state What happens it takes to see if I press the button because it only checks it when is like this it checks it every two seconds because it is doing this and then it Check out these ways to fix it and improve what we have to be the easier way to do it if I press again stays and pulsing faster and looser however when when pressed and I loose it detects it faster because of course the time that I am here sleeping they are zero they are only 0.1 seconds so nothing good after this fairly long tutorial wanted it to be as short as possible but it always lengthens because I like to explain things that are understood will have to be a tutorial in which I see a thing sometime miles we can do the monuc or at least that's my opinion so nothing good I hope you have liked the video in please manito if you like them share if you think you can be of use to someone else and don't forget to subscribe if you want to see more videos of raspberry set off where anything else related to electronics a I greet everyone and even the function

For more info click here

Related posts

Leave a Comment