Raspberry Pi GPIO Tutorial: The Basics Explained

by: Pi My Life Up

Download this transcript

Transcript:

[0.03]
everyone today we're taking a brief look into the Raspberry Pi GPIO pins firstly GPIO stands for general purpose input and output pins these pins allow us to communicate with other circuitry such as extension boards sensors custom circuits and much more you can do some pretty amazing stuff with these pins now there is a few things you should know about using the GPIO pins if you use these pins incorrectly it can result in breaking your PI just make sure whatever you're hooking up to the pins at the Raspberry Pi can support it if you're an owner of the Raspberry Pi and a B+ or PI 2 then you'll notice that the later models have more pins now here we have a diagram of the pins you can get this diagram over at pi my life up comm /r as root - pie - GPIO these numbers refer to the physical numbering of the pins these are easier to understand as they are in order we'll use this method of identification later the GPIO numbers are all over the place in a bit harder to remember them by you'll probably need a reference board or something else to remind you what their number is now as you can see on the diagram there are more than just your standard GPIO pins there are also some called I to see SPI and you are I briefly mentioned what these all mean now now GPIO are you standing pins and can simply be used to turn devices on and off for example an LED eye to see or inter integrated circuit pins allow you to connect and talk to hardware modules that support this protocol the i2c protocol devices connecting to this would typically take up two pins SPI or serial peripheral interface bus pins can be used to connect in talk to SPI devices pretty much the same as i2c but makes use of a different protocol you are or universal a synchronous receiver transmitter other serial pins used to communicate with other devices DN C stands for do not connect this is pretty explanatory do not connect anything to these pins the power pins pull power directly from a Raspberry Pi G and D are the pins are used to ground your devices it doesn't matter which pin you use as these are all connected to the same line now all this might be daunting at first but really it's pretty easy once you get going a lot of the abbreviations and technical jargon turn-off people straight away but once you get past this it's not that complicated now we'll briefly touch on how to set up a pin so you can use them on bars reapply it in this example in future projects we will be using raspbian if you haven't got that installed then you can find out how to install it right here if you're on the latest version of raspbian then you can start programming and using the GPIO pins straight away without needing to do any extra configuration however if you're going to use the SPI or I to see pins we need to activate the modules for them first I'll show you how to do this in a bit however it is recommended that you update your PI to the latest packages to do this you just simply enter sudo apt-get update and now once that's done sudo apt-get upgrade once that is done we can now activate the modules now setting up vit C is super easy firstly go to raspberry config tool by entering the following command sudo razz be confit in here go to Advanced Options and then go to I to see turn it on the PI should now lo you've an eye to see will be enabled after reboot it will then ask you if you'd like it to be loaded by default select yes if you plan on using it every time the pie boots up once that is done go back to Advanced Options and then to spi they'll enable it in like I to see it will say it will be enabled after reboot after that I would ask if you want it to be loaded by default select yes again if you plan on using it every time the PI boots up now reboot apply now we want to make sure it has successfully enabled for modules do this enter the following command LS mod G rep I to see underscore this command will return any modules that start with I to see it should sweet earn something like this I to see underscore BCM to 7:08 so yep that's working correctly and now let's do it for spi LS mod G Rap SBI underscore this command again will return any modules that starts with SBI you should return something like this SBI underscore BCM 2 8 3 5 now you might want to know more about a breakout kit a breakout kit allows you to take all the pins via a ribbon cable and connect them to a breadboard this is a lot easier and safer than working in and around the Raspberry Pi there are quite a few different types of breakout kits you're able to buy a 4 garage repo I personally prefer the T type as they are easier to read and use it is really easy to connect up and once done you can switch your PI on and you're good to start programming and using the GPIO pins let's quickly do a small example using a simple circuit alongside a simple Python script - is the default programming language when it comes to working with the GPIO pins so let's first set up our simple circuit now connect a ground pin to the negative rail on the side of the breadboard of a wire come from pin 7 down to a node further down the breadboard and now connect an LED with a positive end facing the wire and the negative end facing away now connect a 100 ohm resistor from the LED to the negative rail and we're all good to go now let's create a script to make our LED flash so on the Raspberry Pi in to the following command sudo nano LED underscore blink dot P white now let's write out a little program it's really important to remember - is white space sensitive for example if you've got a space somewhere that it shouldn't be - will not like it it will throw a syntaxerror now let's write out for code though firstly write import RPI GPIO as GPIO in bought time now gpio dot set mode bracket GPIO board bracket this sets the mode so the pins we are referring to other physical pins GPIO dot setup bracket 7gp I dot out this sets pin 7 to act as an output and now we're going to make a for loop so firstly you write for I in range bracket 50 bracket colon this will loop through 50 times then exit now for anything inside our loop we need to enter 4 spaces before typing our command so in this case it's space space space space GPIO output bracket 7 comma true bracket and we continue to do this for the rest our output tree means V that GPIO pin is turned on output false means that pin is turned off time dot sleep is pausing our script for one second before moving on to the next command and then finally at the end we've got GPIO cleanup this allows our script to exit cleanly and prevent any unusual behavior that might happen later on so now exit and save by pressing ctrl + X and then Y now running a little script and the circuit should come to life to do this enter sudo python led underscore blink py and there we have it now I hope this tutorial has helped introduce you to the basics of the GPIO pins we will start to go more into depth in the future using these pins will do some pretty cool projects if you have any feedback projects you like to see done or anything else feel free to drop us a comment below or over at Palmolive calm until next time have a good one looking for more pi projects to do check out these 21 awesome pi projects that anyone can do don't forget to subscribe so you can stay up to date with the latest and greatest projects guides and much more



Description:
More from this creator:
This Raspberry Pi GIO tutorial takes you through a lot of the basics of the GPIO pins and what you can do with them Full Guide: http://pimylifeup.com/raspberry-pi-gpio/

As you may know the general purpose input and output pins (GPIO) are used to communicate with other circuity. This includes thing such as extension boars, circuits, and much more. You can do some pretty cool stuff with them. You should beware that playing around with the Raspberry Pi GPIO pins wrongly can result in destroying the Pi. The best way to avoid this is to double check that whatever you’re plugging in will be supported by the Pi. In the little small circuit, I use in the Raspberry Pi GPIO tutorial I use the following equipment. • 1 100-ohm resistor • 1x Red LED • GPIO Breakout Kit Assembled • Breadboard • Breadboard Wire/Jumper Cables There is quite a bit of terminology around these pins but be sure to not let this turn you off from using them. We go into the terminology a little in the video but if you need more information be sure to look up some of the terms I used. In the video we display a Raspberry Pi GPIO pinout diagram. If you would like this to use for future reference, then be sure head over the guide. You can find the link above. We will be looking at doing many projects using the GPIO pins in the future. This includes stuff such as home automation! This is something I know a lot of people have been asking about. I hope you have enjoyed this video on the Raspberry Pi GPIO pins. If you have any questions, feedback or anything else feel free to drop us a comment below. Also be sure to subscribe so you can stay up to date with all our latest Raspberry Pi projects, guides and much more.
Disclaimer:
TranscriptionTube is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to amazon.com
Contact:
You may contact the administrative operations team of TranscriptionTube with any inquiries here: Contact
Policy:
You may read and review our privacy policy and terms of conditions here: Policy