Transcripts

1. Welcome to Class: - welcome to unleash the raspberry pi through physical computing. - First of all, - I want to tell you how much I truly appreciate you enrolling in this class. - If it any point during this class, - you don't understand something or need some help. - The best place to go is the community tab on the class page. - You're also welcome to email me or reach out on Twitter. - I'm happy to help. - So first of all, - what is physical computing Wikipedia describes. - It is building physical systems by the use of software and hardware that consents and - respond to the analog world. - In the last five years, - there's been an explosion in the hardware hacking space. - Some amazing low cost tools have been created that have allowed hobbyists to start creating - serious hardware projects. - That, - combined with the fact that writing a blob with the latest shiny software tool just isn't - cutting it anymore for the basement hackers out there. - There's a huge desire to write software that leaves the room of our PC and the Internet and - actually starts interacting with the physical world around this, - making your toaster tweet, - getting feedback from your car sensors locking your house from the Beach. - These are all examples of physical computing. - There are a lot of hardware tools available for physical computing, - but the raspberry pi has gained a lot of traction not only because of the price but also - because it can run software that many people already have experience with. - Unlike microcontrollers, - which predominantly require you to write in C or assembly the raspberry pilots, - you create hardware projects using things like python or even know J s. - So what exactly will we cover in this class? - We'll start by setting up and configuring the raspberry pi. - We'll cover in detail the basic digital input output capabilities it provides. - Next, - we'll introduce you to the purple capabilities exposed to be the Pies GP I Ho header and - cover each one in detail. - We'll do this by building a simple home monitoring device. - We'll wrap things up by connecting our device to the Internet so we can check the status - remotely. - We'll throw in some tips and tricks along the way and also cover some electron ICS - principles to help you in your own projects. - There are some things that won't be covered in this class, - however, - while we will cover some basic electron ICS knowledge along the way. - This class isn't meant to teach electron ICS in depth. - I wouldn't even consider it an intro to electron ICS, - as we will gloss over some topics who also be using python to write the code for our device - but won't be covering python in depth. - Most of the code, - however, - will be very simple and will not require deep knowledge of the python language. - Even so, - I've included some links for learning python in the resource section. - Going through some of those first will definitely help but isn't required. - It's not required that you follow the class project exactly, - but it would help to ensure that you are reaching the learning milestones. - List of materials needed to follow along can be found on the info tab for this class. - It can also be found in the resource section for this unit. - I tried to keep the Costas lowest possible. - The most important objective of this class is for you to have fun. - As we go through the various units. - I hope that your imagination will take over as you think of ideas to try and projects to - create. - I encourage you to act on those desires and share them with the class by creating your own - student project. - All right, - let's get started. 2. Prepare the SD Card (Steps 1-3): - Welcome back in this unit will go over setting up our raspberry pie with an operating - system and getting it ready to start a project. - As always. - If you have any questions, - feel free to submit them on the skill share class page, - where you can send me an email or try and find me on Twitter. - So before we can boot up our raspberry pi need to give it some sort of base operating - system. - Unlike a conventional computer, - the pie doesn't have a traditional hard drive. - It's hard drive is the SD card we put in it. - But just like a normal computer, - the pie needs something to boot up. - Traditionally, - that would be something like Windows OS 10 or a form of Lennox. - But even if the hardware were compatible, - the pie would have no hope of running something like Windows or OS 10. - But it turned down version of Lennox will do just fine, - and that's exactly what we're going to install. - The pilot doesn't use a normal CPU like an Intel I seven, - so we can't just throw a bun two or red at Lenox on it. - We need a special distribution of clinics. - Unfortunately, - for us, - there are plenty to choose from. - Lots of smart people have modified various Lennix distributions to make them work on the - raspberry pi. - An exploration of all the available distributions is beyond the scope of this class, - but you can read more about them on the downloads page at raspberry pi dot board. - For our purposes, - we're going to stick with the recommended starter distribution known as Raz B in. - So let's go ahead and walk through it. - We'll start by going to the raspberry pi dot org's homepage Well appear to downloads Now. - In the early days of the raspberry pi, - you had to follow special steps just to get Raz b in onto your SD card. - News has changed all that and made it extremely easy to get started. - As you can see here, - we simply have to for madness D card and copy of the unzip nubes image onto it. - Let's go ahead and download that well. - That's downloading. - You'll notice that they recommend that we four matter SD card using the SD card - associations formatting tool. - So let's go ahead and get that tool now. - The downloads air over here on the left hand side, - and we'll just choose the SD four matter for dot over windows. - As usual, - we have to go through a license agreement. - So we'll go ahead and accept that and the down little start. - I'll go ahead and fast for the download is it takes just a minute. - Okay, - once that finishes downloading, - just go ahead out to that location where just downloaded on windows will unblock it before - we extract it. - We'll just extracted here. - Okay, - great. - Now let's go ahead into that folder and we will launch the set up the Senate for this tools - . - Really easy. - We're basically just gonna go ahead through and accept off defaults, - so I'll sort of fast forward and let it play through a little faster so you can see what's - going on. - Start by going to next. - Just accept the defaults here and hit Install. - Okay, - which this finches up. - We'll go ahead and click finish, - and that's all there is to sitting up that tool. - And you can see we have a little bit left to go on our nubes download so we'll go ahead and - fast forward. - That hasn't finishes. - No way we watch this formatting tool. - You'll see here that we have a drive dropped down. - This will be the drive that you have us that represent your SD card. - In my case, - that's G. - Now you want to make sure you verify this because if you select the wrong Dr here, - you could end up formatting your local hard drive or another are drive that as things like - pictures and things like that. - So, - as you can see here, - my ruble disk is my G drive. - You can also see the size is correct will come into the options you could just leave. - The format type is quick, - but you'll want to turn the format size adjustment toe on and then click. - OK, - Once we've done that, - we are already to format this drive, - so we will go ahead and we'll click format. - Once RST card is formatted, - we're ready to put the image on toe. - So it's come back to this image that we downloaded. - Go ahead and unblock it like we did before, - and we will extract it here. - Oh, - this will only take a minute. - All we need We don't want to copy the folder. - We want to copy the contents of the folder. - So let's go ahead and select all of this will, - right Click and we'll do a copy and then we want to put that onto our SD cards will come - over here to this window. - If you remember, - SD card is the G Dr will open that and we'll just paste our files here. - Now it's a lot of files, - so this will take a second. - So we'll go ahead and use the magic of video to speed this up. - I only take a few seconds. - All right, - that's it. - This SD card is now ready to be placed into our pie so that we can boot it up for the first - time, - which will allow us to install raspy in. - So let's go ahead and do that next. 3. Install Raspbian and Update (Steps 4-9): - Okay, - so now that we have our card here with nubes on it, - we're ready to hook everything up. - So I've got the raspberry pi out here. - You can install it in a case if you want to. - Just make sure that you leave access to these header pins because we'll need those later, - and all we're gonna do is hook all of this stuff up. - So first thing we're gonna do is insert the SD card. - Make sure it's nice and snug will go ahead in hook up our monitor. - I'm gonna start with wired Internet, - So go ahead and look that up. - And the last thing that will need is a keyboard, - so we'll go ahead and that it the U. - S B port. - Now, - I would wait to connect your power toe last. - That's just the way I normally do it. - Um, - another thing that you wanna be aware of is you don't want to lay this on a surface that - can conduct electricity, - so don't put it on anything metal. - You can actually leave it without a case. - It's fine if you don't want to use one. - Just make sure that it's sitting on something sturdy so that won't fall off. - And that won't connect electricity. - So the last thing will do is will connect our power. - And now we are ready to boot up for the first time. - I'd like to make just a quick note on the video quality in this unit. - It's really bad. - As I'm trying to record directly from another screen, - I promised. - The whole course won't be like this. - As soon as we get our pie installed, - I'll start to ssh in and screen record so everything will look much nicer than the first - time that you boot up your pie. - Now that you've got Nubes on your SD card, - this is a screen that it's going to boot to. - It is going to give you the choice to install bunch of distributions. - We want to stick with Raz B in, - which is the one that's highlighted by Deep all. - So if you just push space bar on your keyboard, - it'll put an X on that, - saying that it's highlighted. - And then, - if you notice you might not be able to see on the screen in the top left, - there's it, - says Install, - and there's an I in parentheses, - so If we just push I on our keyboard, - it's gonna give you a warning that it's going Teoh race everything on the SD card and be - overridden, - and so then we'll just hit. - Enter to say continue, - and it will start the installation. - This is a great time to grab a snack or a drink, - as this will take a while. - While Raz B is installing you, - compress L to set your language will bring up a drop down. - You can select the one that you want. - You can also choose your keyboard layout by pressing nine. - If you do it now, - while it's installing, - you won't have to worry about it later. - Once the install finishes, - you'll get this message box that says OS is installed successfully. - Just it entered to say OK, - that'll trigger a reboot of your pie. - And after the pie loads everything up, - you'll see this blue screen with the white dialog box on it. - This gives you some options to configure your raspberry pi. - The only thing I would recommend doing here is making sure that ssh is enabled. - To do that will go down the Option eight Advanced options hit, - enter and scroll down to ssh and hit Enter should be enabled by default. - But just check it and make sure and hit. - Enter. - It'll say ssh server enabled Had entered for Okay. - Once you've done that, - if you hit the right arrow key, - it will take you down to the bottom and highlight the select. - If you do one more right arrow, - it will take you to finish and hit. - Enter. - It's off screen here, - but that will bring you up to your first prompt. - What you want to do from this command line here, - the very first test you want to do is an Internet connectivity test. - I recommend just doing ping space google dot com, - and you can see that I'm getting responses, - which means my Internet is up and running. - Just that control. - See, - to cancel out of that. - Now that your raspberry pi has raz being installed and is connected to the Internet, - we're ready to move on. - One thing I like to do right after getting Raz being installed is to configure it for ssh. - I just want to clarify that this is not required for the class. - If you want to continue using the keyboard and monitor. - That's just fine. - Ssh stands for secure show and will allow us to log into our pie from another machine on - our network. - In my case for my desktop computer, - this allows me to get rid of the monitor and keyboard connected to the pie. - The way I like to do this is to have my router reserve a static i p address for my - raspberry pi based on its Mac address. - Is there so many possible network configurations and router types? - I won't cover how to do this, - but there are plenty of resource is online. - If you do a little searching on Google, - all we really need for ssh is the I. - P address of rpai. - If you're using Lennix, - you can simply open a terminal window in type ssh, - followed by a space and then the i P address on windows. - I like to use putty. - So for my desktop, - I will launch putty and you'll see that I need to fill in some information the port in - connection type default. - Ssh. - So all I need to enter is the I. - P. - Address of my pie, - which I've configured in my router to be 10.0 dot 0.17. - Once I've entered that, - I'll come down here and click open, - and it will launch a terminal window from here. - I will just log in with the default credentials that come with our Raz B and distribution. - The user name is pi P. - I in the password is raspberry all lower case, - and that will bring me to a terminal problem, - just as if I were right in front of the pie. - Just as a test, - I'll do an LS command, - which lists the directory contents, - and you can see that it works just fine. - I really like using ssh because it allows me to be on my desktop computer, - where I can easily look things up on the Internet while I'm working on my projects. - Another thing I like to do at this point is to install a USB WiFi adapter so I can unhook - my Ethernet cable again. - This is not something that I'll cover and is definitely not required for the class. - But if you intend to use WiFi, - I'd suggest that you set it up. - Now. - Make sure any WiFi adapter you purchase specifically list that it's compatible with the - raspberry Pi as many will not work with our pie booted up and razz being installed almost - ready to start working on our class project. - The last step of setting up our pie is making sure Raz being is up to date. - We do that with two commands pseudo after get update and sudo apt get upgrade. - The pseudo part of these commands is something we will use frequently throughout this class - . - Sudo is a program on Lennox that allows you to run commands his route. - If you're a Windows user, - think of it as allowing you to run commands with administrator privileges. - So in this case will run apt, - get update and after get upgrade with administrator privileges, - you will need Internet access for these two. - Run. - We'll do the update first, - followed by the upgrade. - These commands do take a while to run, - so it's a good time for another snack run with our pie updated. - We're ready to move on in the next unit. - I'll introduce you to the GP Io header on the raspberry pi 4. The GPIO Header: - in this unit were going to introduce you to the general purpose input output header on the - raspberry pi. - We'll talk about the capabilities it provides and cover a few do's and dont's having - followed the raspberry pi for a while now, - I've seen a lot of cool projects, - but many of them use the raspberry pi only is a very cheap Lennix machine, - things like print servers and file servers, - Minecraft, - consuls and beginning programming environments. - Those things are really cool. - Don't get me wrong. - But for me, - the real power of the raspberry pi comes when we start connecting hardware to it. - We do that through the GP Io header through the header. - We can achieve quite a bit because it gives us access to things like the S P I and I two c - protocol as well as general input and output. - Don't worry about what all that means right now, - because we're gonna cover all of it during this class. - What's important to know is that these things were we used to connect to the outside world - . - So instead of thinking of the SP I protocol, - we can think of a display and for general input and output. - We can connect things like motion sensors, - buttons, - switches. - And then when we talk about the eye to see protocol, - we can connect things like sensors and other components, - the concepts we're gonna cover in this class or general enough that you can use them to - connect almost anything to your raspberry pi. - So the first thing we need to do is locate the header. - Well, - it's pretty hard to miss, - as you can see whether you have a model A or model be raspberry pi the headers in the same - place. - It's just in the upper right hand corner if you're looking at it from this perspective, - so let's take a closer look. - To be able to correctly identify the pins, - we need to know how they're numbered. - We start by locating Pin One Now. - From this image, - it may seem like the P one label at the top left of the header is identifying Pin one, - but that's only a coincidence. - P one is just the name of this header. - As of the second revision of the Raspberry Pi board there, - six headers on the pie labeled P one through P six. - Now just to the right of that, - P one label was a little white box, - which is the actual indicator that this is indeed pin one. - The numbering then continues, - similar to how you would read a book left to right top to bottom with pin to here, - followed by pins three and four. - And then, - if you count all the way down, - you'll get to the bottom where there's pins 25 26. - So what do all of these pins do they provide us with? - All of the functionality will need to connect our pride external hardware. - We have power in the form of both 3.3 and five volts. - That's important to know that there's some limitations to how we can use power from the - header and we'll talk about those as we get further along. - For now, - I just know that we can only pull a limited amount of power from those pins and we have the - ground pins to complete the powers. - Then we have pins for the various protocols will be using as our project progresses, - things like S, - P, - I and I to see one aspect of the header. - We won't be covering this class is the you are. - As you can see, - the pins for that are located here. - Finally, - we have quite a few pens available for the basic digital input output. - Now, - unless you have a photographic memory, - there's no way you're going to remember what each of the pins is just by looking at the - header. - I mean, - I guess you could memorize them, - but I like to take an easier approach. - And there are a few ways to simplify working with the header and remembering what functions - the pins provide here. - Just a few. - The simplest and cheapest ways to just print out a pin diagram for your board revision. - There are different revisions of the header pin map, - and in just a minute we'll show you how to figure out what yours is in the middle. - Here is an ingenious concept called the raspberry leaf. - It was created by Simon Monk and is meant to be printed out and then installed on your pie - . - Just like this, - this is a really nice way to mark your header. - If you'll be using jumper wires to make your connections, - it takes a little bit of effort to create because you need to pre perforate the leaf before - sliding it onto the header, - but makes it so you don't have to constantly refer to a print out and count pins. - Finally, - there's the high end solution known as the pie cobbler from Ate a fruit. - You simply connect a ribbon cable to your header, - and the cobbler board has all of the pens marks. - This makes it really easy to connect to a bread board, - and it's what I'll be using for our project just to keep things clean. - Now, - if you don't want to spring for the pie cobbler, - don't worry about it. - Just haven't pronoun handy and use jumper wires. - And that worked just great. - So now that we know that there's different versions of the header, - we need to figure out what version we have on our pie, - and that's a really simple thing to do. - All we have to do is Buddha Bar pie to a command prompt. - Here we're gonna type in cat C A T space, - and then we'll do forward slash Prock ford slash CPU info. - Now, - if you're not familiar with Lennox operating system Cat is just a built in utility that - will allow us to display the contents of a file. - And in this case, - we're gonna display the contents of the CPU info file inside the Proctor folder. - So we hit. - Enter here. - It's gonna tell us a bunch of information and the one that we care about right now is this - revision down near the bottom 000 e. - In my case. - So what we do is we take that revision and we come over to this page here on the Lennix dot - org's. - And there's a hardware history table, - and what we'll do is just look up our revision number in this table, - As you can see for mine tells me that this model be already knew that. - But the important column is the PCB revision. - Here it's version two point. - Oh, - we can also get some other information like this. - Particular one was manufactured by Sony. - Now that's important because most sites that give you information about the pin out of the - header will have both versions available. - For instance, - we have this simple table here. - There's both versions, - and even the raspberry leaf has both versions that you can print out and install in your - pie. - Now that you've identified your vision and chosen a way to identify your pins. - Go ahead and set that up. - Now you go ahead and pause the video and do that. - Whether you're just printing out a sheet, - installing a raspberry leaf or using the pie cobbler, - now's a good time to set that up. - It's also a good time to get your bread board out, - because we're gonna be using that shortly. - If you are using the pie cobbler, - go ahead and hook it up. - Now, - if you plan to use jumper wires to follow along, - that's okay to just make sure bread board is nearby because we're gonna start filling it up - . - So here's what my set up looks like so far. - Before we go any farther, - I want to cover a few items regarding header safety, - otherwise known as how to not ruin your raspberry pi first. - If you plan to use jumper wires to make your connections, - do not use alligator clips. - It may look OK, - but they're likely to big and can cause a short. - The power and ground pins are right next to each other, - so if you inadvertently short them together, - you'll break your raspberry pi. - Instead, - I recommend using isolated jumper wires. - As you can see, - these create a much cleaner connection, - and there's no risk of shorting pins together. - Another way you can accidentally short pins together is by touching the header while the - pie is powered on as a general rule, - never touch or try to make any connections on the header. - While the raspberry pi has turned on. - Electrostatic discharge can also be a problem in touching the header, - even when the pie has turned off. - So be sure to ground yourself before touching anything or making connections. - So let's review never make connections, - while the pious powered on it only takes a minute to turn it off, - make the connections and booted back up. - It's not worth ruining a pie to save a minute, - even though there's a five vote pin on the header. - The peripheral pins on the pyre, - not five vote tolerant. - That means that if you connect a five volt source toe one of the input output pins, - you can ruin your pie. - If for some reason you need to interface with the system that delivers five bolts, - you'll need to use some sort of level shifting technique. - If you're going to use jumper wires, - use isolated female jumper wires to make connections to the header. - Or use a ribbon cable like you saw in my set up with pie cobbler. - Make sure you always verify which board revision you are working with to make sure your - connections air correct. - Chances are you have border vision to, - but it's best not to risk it, - especially since it's easy to figure out. - As we showed along that same note, - you probably heard the phrase measure twice. - Cut once. - When you're dealing with making connections, - verify the pin twice and connect once. - This is especially important when connecting jumper wires directly to the header. - Always double check the pin you're connecting. - Finally, - never, - ever touched the header while the unit is powered on. - That goes for other parts of the pie as well. - While it's on hands off and while it's off, - be sure to ground yourself before touching anything. - Well, - that's enough of theory and scary warnings. - Now it's time to start working on our project. - In the next unit will introduce you to the general input and output capabilities of the pie - and talk about how we will use them to start piecing together our class project as always. - If you need help or have questions, - the best place to go is on the Skill share website for this class under the community tab, - you can also reach him via email or find me on Twitter. 5. Setup Basic Input/Output: - welcome to Unit four of the class. - This unit will be covering the set up of the basic digital input output that a raspberry pi - header provides us. - So let's remind ourselves of a few things before we get started. - When dealing with the Iot header, - we need to remember that 3.3 volts is considered a digital one or the high state. - It actually needs to be greater than 1.3 bolts, - but we'll just say 3.3 bolts and ground or less than or equal 2.8 volts, - is considered a digital zero. - Our GP I opens can be configured to be an input or output, - but they can only do one job at a time. - It can't be an input and an output at the same time. - And finally, - we need to remember that while there is a five volt pin on the header, - the input out pins are only 3.3 vote tolerant. - So if we connect five votes to those, - we're gonna end up ruining our pie. - Now it's set up our pies that we can have access to this functionality, - the pipe on script. - Okay, - so we have our pie booted up here and we're ready to start working with the input and - output capabilities provided by the header. - Now, - as I stated in the introduction to the course, - we're gonna be using Python to do all of the code that we're going to need to write for our - monitoring device. - Raspberry by default, - comes with python installed, - and you can see that if you from your command line here just you python dash dash version. - You see, - the python 2.7 dot three is installed. - But for what we're gonna do, - we're gonna need a little bit more than just the basic python. - We're gonna need the developer tools and we're also gonna need something called the rpai - dot g p a library. - And so let's go ahead and install those. - We'll just do a pseudo after get install, - which is just if you're not familiar with Lennox, - that's just saying that this is a standard command. - To install new packages, - you will need to be connected to the Internet for this store. - That's what Do sudo Apt get install hi Thon Dev and we'll let that go ahead and install it - says it's gonna take up 42.2 megabytes of additional dicks space. - Is that okay? - Yes, - This might take a minute, - so we'll go ahead and skip ahead. - Okay, - Now that that's installed, - let's go ahead and install the, - uh, - raspberry pi GPO Python module will do that. - Very similar to how we did the python Dev modules do sudo after get install. - It's python Bashar pied a g p i o. - And when this model is going to do for us is that it's gonna make it really easy to access - the general purpose input output pins on the raspberry pi. - And as you can see, - the latest version of the Rpai GPO library is already included with the RAZ B and - distribution. - So if you remember from before when we needed to find out our border vision, - we did this we did cat slash Prock slash CPU info and we use this revision number to go - look up in a table. - What border vision we have. - Well, - now that we have the GPO library, - let's go ahead and launch a python environment. - We do need to use pseudo here because of the way that the GP I module access is the low - level hardware. - So you need to make sure you run. - This is ah, - administrator here and from the prompt here. - We're gonna go ahead and import our pied a g p i o as g p A. - That's just says that we're gonna import that module and we're gonna reference it as GP io - . - So go ahead and do that. - They will do GP ioo dot rpai underscore revision and you could see we get a to here, - which is correct. - We found out before from my specific raspberry pi that my board revision was too. - So this is another easy way you can tell after you've installed libraries to get your - border vision instead of having to look it up in a table. - This also tells us that everything looks like it's installed properly, - So we are ready to start trying to access the input and output and seeing what we could do - with it. - As always, - if you need help or have questions, - the best place to go is on the Skill share website For this class under the community tab, - you can also reach him via email or find me on Twitter 6. How to Hook up an LED (Step 1): - Now that we have our GP i o module working on our pie, - it's time to start connecting things to it. - Now, - a few of the things we're gonna cover involve electron ICS principles. - If you don't understand them, - try to look something's up online to get help. - If that doesn't work, - feel free to submit questions to the skill share class page. - I'd be happy to answer those there. - So when we talked about our header on rpai and the GP I opens, - we talked about how they could be configured as either an input or output. - We're gonna tackle the output side first. - So if you remember from our header section you have a pin here. - Multiple pins, - actually that connect to ground will destroy one of them. - And we also have a pin appear that connects to 3.3 volts. - And we'll draw our I open like this. - No. - So the first thing to understand is when you configure a pin to be an output, - what happens when we toggle? - It's setting in our python scripts, - so there's two ways to set this. - We can either set this to a one or two a zero high or low. - And when we set an output pin when a pince configure doesn't output to a one or high, - it's gonna try and drive it to 3.3 volts. - If we send it to a zero or connected low, - it's gonna connect it ground. - And so what we want to do first is we want to see how we can connect an led to turn the led - on and off. - That's sort of the hello World project in hardware. - So let's see. - How we might do this we're gonna do is if we could do this like this, - we could come out of our Iot pin come down. - We need to go through resistor now, - the resisters to limit the current to our led. - That's the symbol for it. - And this is the symbol for our led, - and we'll connect it back down to our ground pin here. - So what's gonna happen is when we drive this pin high, - we set it to 3.3 volts. - Current flows from a high potential to low potential, - so it will try and flow from 3.3 volts down through here into ground. - The resistor limits the amount of current. - But when that current flows to our led, - that's what's going to turn it on. - So that's one way to get our led to turn on. - Now we can also hook this up another way. - Strong other. - I open here. - This time we're gonna draw the line out of our 3.3 volts, - go through the resistor through our led and come down to our pin. - So remember, - there's two states to the pin, - 3.3 volts and zero volts. - Now, - if we set this high or to 3.3 volts, - no current is gonna flow from 3.3 volts to 3.3 boats so are led Will not turn on. - However, - if we set this toe low or connected to ground, - that's when the current will flow. - So it's the exact opposite. - In this case, - if we set our, - um, - are pinned to be high, - that turns the led on. - We set our pinned to be high in this case, - it turns it off. - Just something to remember when we're writing our scripts for it. - Um, - we can hook this up either way. - The way I prefer to do it is this way and I don't want to get too much into the details of - how the raspberry pi handles this, - but something to know when we hook it up this way, - the Penis said to source the current. - In other words, - when it turns to 3.3 volts, - it's trying to provide the current to flow to ground to turn the led on. - In this case, - the pin is sinking the current, - the current actually being supplied from the 3.3 supply on the pie down through the - resistor and into the output pin. - Um, - it's called sinking current. - Now the raspberry pi can Onley source so much current based on the drivers that air in it - when I mean when I say drivers, - I don't mean software drivers. - I'm talking about hardware drivers that drive the current, - um, - for how these input output pins work. - So you can hook this up either way for our purposes, - we're gonna be using this one. - We're gonna be setting it up so that the 3.3 supplies is driving the current through our - led. - And so we just need to remember that in our Python script later, - zero is going to be on one is gonna be off. - So now that we've seen how this looks on our white board and how we might draw this up, - let's move to our bread board and see how we might connect this up to get it working. 7. Intro to Fritzing and LED Hookup (Step 2-3): - all right. - Now that we've seen how our circuit will look on our white board, - it's time to put it on to our bread board. - And I just want to take a minute to show you a tool that I like to use when I'm planning - out circuits for different projects that I work on. - And it's called Fritz Ing. - The website, - for it is just fritz in dot org's and I'll put a link to it in the show notes here. - But this is what it looks like here. - And what we're gonna do is we're gonna download. - This will come to the download page and you can see that I am running windows. - But you can download it for Windows, - Mac or Lennox. - So I'm just gonna download the windows version of it here. - Well, - that's downloading. - What this is is a good way to visualize on a bread board your circuit before you actually - put the components on your bread board. - It's great for more complicated circuits to visualize how you're gonna connect things also - , - to see how you're doing on real estate on your bread board, - things like that, - we're gonna use it in our project to show the different phases. - As we connect things up, - I'll do these all inference sing, - and I will show you what they look like in that before we put him on the bread board. - Now that's finished. - I'll just pull this window over here. - That's just in a Zippo here. - Soldiers to extract all once that's extracted will just come into the folder here, - and we'll just double click on it to launch it and let me just go ahead and slide this over - here are screen resize it here. - Okay, - so it comes up to this nice welcome screen, - but we're gonna come right over here. - This is where we're gonna work most of our times in this bread board. - You and you could see this looks just like a real bread board. - This is one of the things I really like about spritzing is it has a very real life. - Look to it. - You just use the scroll wheel on your mouse to zoom in and zoom out, - and then all you do is you grab parts over here, - there's different libraries and you can download additional libraries and you just drag him - over onto your bread board, - example resistor. - And down here you can change the values. - You know, - just the color bands. - Just how it would look in a real resistor. - You can add things like switches that will get into later and and buttons things like that - now fit in there. - They're all the right size. - And when you want to connect things up, - you can just come down here. - There is a wire part, - and we can just, - ah, - click from here. - So we have to drag them on here. - Tatchell wire. - From here to here, - you can even use the control A control click that will kind of give you this curve. - Look to the wire seeking bend, - Um, - and kind of make it, - you know, - look a little more rial, - which is nice. - The other thing it has Ah, - that will be doing next. - Things like this weaken dragon led on and connect that up will show you how to do that in a - minute. - And even if you come to the microcontrollers, - I believe is the name of section here we can even drag on a raspberry pi the mountain You - could see you could move things around. - You can If you get down in the corner here, - you can You can rotate him and moving like that. - Anyway, - I just want to give you a brief introduction. - This is a tool that will be using you don't have to. - I just like it. - Like I said to plan my layouts on my bread board, - see what space is gonna be taken up and how I want a route wires and things like that. - So just something to be aware of. - I'll be showing you the fritz seeing images as we go along as we connect different parts - and it's a great tool. - If you want to download it and play with it, - check it out. - Okay, - so here is what are led circuit? - Looks like when we hooked it up to our bread board. - Inference sing. - This is just like we drew it up on the white board. - We come out of the 3.3 volts header pin through a resistor. - In this case, - it's 330 OEMs into our led and then are led. - Connects back to an input output pin. - In our case, - it's gonna be pinned 12. - Now, - in this diagram, - it's labeled 18. - That is the BCM reference number, - and we're gonna talk about it a little bit. - The difference between the board pin number, - which is this, - is literally pin 12 if you remember how he counted it in Unit three. - But it's also referred to has been 18 to the broad common chip. - We'll talk about that a little bit later, - but for now, - this is how we have it set up. - A couple things to note. - If you are not familiar with how bread boards work, - it's really easy along the top and bottom. - The pins connect horizontally. - If we're looking at it like this and then in the middle, - the pens connect vertically. - They do not cross the middle of the bread board. - So the pens on this side on the top side here are not connected to the pins on the bottom - side, - and the other thing to remember is your led has to be hooked up the right way. - You can hook it up backwards, - which will burn it out, - so make sure you're paying close attention to how you hook that up. - So this is how I intend to lay it out on our actual bread board. - Let's see what that would look like. - And that's what it looks like when I have hooked it up to my actual bread board. - Now, - for those that aren't using the pie cobbler, - that's okay. - I have the Fritzi image here, - uh, - connecting it straight to the raspberry pi. - You're also welcome to do that. - It will work just fine. 8. Use Python to Control an LED (Step 4-5): - with our led connected to our bread board. - We're ready to test it To do that, - we're gonna come back to our terminal here and we're going to launch a python show. - We're going to do that with pseudo python. - We need the pseudo because of how a library works. - The rpai g p a library works. - And so we're going to import that library just like we did in the last section. - Import rpai dot gp io as g p i. - O. - And then the very first thing that we're gonna need to do when we're using this library is - we need to set the mode. - When that does, - is sets the mode of how we're going to reference the pins through other various functions - that will use and their two options. - There's GP ioo dot board and GP ioo dot bcm board means we're going to refer to the pins by - their physical number. - When looking at the header, - we went over that, - um, - in section three, - where we talked about the GPO header how the pins are numbered. - The BCM mode means that we're gonna need to refer to the pin numbers based on how they're - numbered. - on the Broadcom chip that the raspberry pi runs on. - And so you can do this either way. - However, - if we use the board were guaranteed, - that are python code will work between revisions because the library is smart enough to - know what revision were using. - So I'm gonna recommend that we use the board mode. - Okay, - Now that we have that set, - we need to set up our pin whether as an input or is an output. - In the case of the led, - we're gonna set it up as an output. - So for that, - all we have to do is GPO dot set up reference the pin number. - We're connecting to pin 12. - If you remember from our bread board, - and we're going to set this to gp ioo dot out that sets it up is an output. - Soon as we hit, - enter on this, - you'll notice that the led will turn on. - That's because the default state of the output zero if you remember from when we drew this - up on our white board, - when we set the output pin to zero, - that's what's going to turn out. - Led on. - That's what happens here. - So to turn it off. - You remember. - All we have to do is set it high. - So we do that by saying, - gp ioo dot output Reference the pin number again, - and one when we hit Enter here, - you'll see that it turns off and we could just play around with this. - We can turn the led, - um, - back on. - We can turn it back off. - That's all there is to it. - We have successfully connected in led. - Now, - when we're done using this library before we exit, - you want to do a GP Io dock cleanup that just cleans up how the pins were set up. - If we don't do this next time we try to run a script, - it's gonna tell us that the pain is already configured and give us a warning. - It's not a huge deal, - but it's just a good idea to clean up when we're done, - and that's it. - We've got our led working. - Now that we've talked about how toe configure pin is an output, - let's move on to the input functionality in connecting are switching button as always, - if you need help or have questions, - the best place to go is on the Skill share website For this class under the community tab, - you can also reach him via email or find me on Twitter 9. Safety Reminder: - before we go connecting things, - start bread board. - There's just a couple of things I want to mention the first I already mentioned in the - header unit, - and that's whenever you're making connections to your raspberry pi. - Always unplug it. - Some of them you can make safely, - but it's best not to risk it. - Just unplug it. - It takes two seconds. - Make your connections. - The pie boots up very quickly. - It's not worth risking burning out your pie. - The second thing along the same lines is depending on where you live. - You might build up a lot of static electricity when you're moving around. - Right now, - we're just putting things on a bread board that are out in the open. - You can touch resistor legs and other things, - so you need to be careful when you're getting in there and pushing the button and moving - the switch. - And before you do that, - it's best to discharge the static electricity that builds up on you. - Touch something that's grounded to get that spark out of you. - That way we won't ruin anything. - This stuff is really pretty safe. - People get scared that don't know Ah lot about electricity. - They think I'm an electrocute myself. - I'm gonna burn my house down. - We're dealing with low voltages and low currents. - I'm not saying don't be safe. - I'm just saying Don't worry too much. - You might get a shock. - You might burn out your pyre, - your components. - That's really probably all that will happen. - So I want you to have fun, - but be safe when you're doing it. 10. Theory and Switch Hookup (Steps 1-2): - All right, - so now we've covered how to hook up and input output pin to be an output to driving led. - Now let's talk about how we can configure it to be an input to read this state of things - like switches and buttons. - So when a penance configured as an output, - it's actually driving the state. - It's saying be 3.3 bolts or be tied to ground when it's configured as an input pin. - It's going to read this state of the pin and decide. - Are you closer to 3.3 bolts? - Are you closer to zero volts now? - It's not so simple. - Listing which one's closer. - There's certain limits that determine what's high and what's low. - But that's the general idea. - And so we want took a circuit up to this so that when we, - uh, - flip a switch, - it'll give us one state. - And when we put the switch back in its original position, - it will give us another state. - So let's see how that how we might do that. - So we're gonna come off of the 3.3 vote pin up here. - We're gonna come down, - and we're gonna just leave this open and we'll pretend that this is our switch like this. - Come down and well connected ground. - And so this point, - the switches open, - and then we're gonna put our Iot pin out there. - Now, - this might look fine to start with. - So in this state that we have here, - if we sample this pin, - it's going to read ground, - cause this is open up here. - If we close this switch, - it's going to connect us up to 3.3 volts. - That might seem like an easy way to get a different state when the switch is in one - position, - as opposed to the other position. - However, - this would be a terrible idea because as soon as we flip this switch, - we're gonna connect are 3.3 volts to ground, - and that's when you kill your pie. - So how can we make this circuit a little better? - Well, - we can't have a short circuit. - So what we can dio is we can just put a resistor in here. - So now when we flip our switch, - the 3.3 volts isn't gonna be tied straight to ground. - It's gonna go through resistor first, - which will prevent that short circuit situation and so will read still ground when the - switches disconnected, - even though the resisters there that'll still read ground. - And then when we flip our switch, - it's gonna read 3.3 volts. - So this is pretty good. - We could connect this up and this would work just fine. - However, - there is one thing that we might want to consider. - What if we accidentally configure this pin to be an output? - Well, - in that case, - it's gonna try again to drive the state to 3.3 volts or ground. - Now, - if it's set to 3.3 volts and the switches closed, - nothing's gonna happen. - No currents gonna flow from 3.3 volts to 3.3 bolts. - But what happens if it's configured as an output and we try to drive it to ground? - So we set it to a zero. - If we do that and we flipped the switch, - we're back to the state where 3.3 volts is gonna connect straight through the ground and - we're gonna have a short circuit. - So now we could just be really careful and not miss configure our pin, - but nobody's perfect. - And we might make a mistake and so we can prevent a problem here by again using a resistor - so we'll have a resistor here. - Now again. - When the switch is open, - we're still going to read ground. - And when we close the switch, - we're still going to read. - 3.3 volts will have to choose the values of these so we don't drop. - Um, - too much voltage here. - But this will work just fine to read the two different states 3.3 volts when the switch is - closed and ground when the switch is open. - Now that's all there is to it. - So that's how we would do a switch. - Now let's take just a second to talk about a button. - Well, - turns out are we have to do is take out that symbol and replace it with our symbol for a - button. - We'll use that as our button because really, - a button is nothing more than a momentary switch. - When you press it, - it closes the circuit. - When you let go, - it opens the circuit back up. - Just how when you flip a switch, - it closes a circuit. - When you flip it back the other way, - it opens it back up so there's really nothing we need to do differently for a button than - we already did for a switch. - So we'll actually use the exact same layout for our button that we're gonna install that - we're going to use for our switch. - Let's take a look at how I've mocked this up in print. - Sing Now. - I changed a few things since the last view of just the led being connected. - You'll notice that I've taken the 3.3 bolt and ground connections off of the cobbler and - attached him up across the top. - And if you remember from the previous explanation, - the pins on the top of the bread board connect horizontally. - So by connecting the black and green wires here, - I get 3.3 bolts in ground all the way across and Aiken Branch off of those wherever I need - now, - a convention that I'll be using here, - and it helps me to stay organized and keep my connections right is that I'll use green - wires to represent ground, - and I use black wires to represent 3.3 bolts. - For me, - it's easy to remember Green and ground both start with G, - and it just helps me keep myself organized. - So now let's take a look at this switch connection here. - Well, - the very first thing that we need to know is, - how do we connect our switch? - It's got three pins on it, - but what did those pins mean? - And a common theme that you'll see as we go through this is that the data sheet will tell - you everything that you need to know when working with things from switches and buttons all - the way up to our display in temperature sensor. - So let's take a look at a section of the data sheet for the switch. - We can see that the switches three pins labeled 12 and three with to being in the middle - that if we look here on the left, - we can see the little circuit drawing, - which shows that, - too, - is the common in connects toe one in three, - depending on which position the switches in. - So if we switch the pin to the left when looking at it at this view, - it connects pins one in two. - If we switch it to the right, - it'll connect pins two and three. - Now we only need two of the pens, - so we'll leave Pin three unused for now. - So with the switch in the position to the right pins, - one and two will be disconnected. - And when we switch it left pins, - one and two will be connected, - and that's all we'll need to hook it up to our input pin. - So if we look at this connection, - we can see that we have 3.3 bolts coming down to pin one and then pin, - too. - If you remember, - we talked about having to protections one to protect the input output pin if we - accidentally configured it as an output and to prevent the short circuit to ground. - Now the values that we chose for these resistors Air one K in 10-K see the show notes for a - link that has a good explanation of how to hook switches up toward input output pins and a - deeper explanation of how he came up with those resistor values. - Another conventional use here is yellow wires to indicate a connection to an input or - output pin. - In this case, - we've connected our switch to pin 16 so we'll need to remember that when we start writing - our scripts now that we've mocked this up. - Inference sing. - Let's see what it looks like when we actually hook it up on our bread board. - Here's what mine looks like before starting the next video, - go ahead and take a minute to hook yours up a swell so you can follow along in the next - lesson again. - If you're not using the pie cobbler, - here's what it would look like if you're connecting it straight to your pie. 11. Switch Integration (Steps 3-5): - with our switch hooked up to our bread board, - we're ready to start testing it. - So we'll launch a python shell just like we've done before using pseudo, - and we'll follow the same pattern like we did when we set up our pin is an output we need - to import the rpai that GPO library. - And remember, - the very first thing that we need to do is a set mode, - and we'll continue to use the GPO dot board mode. - And this time, - when we do our set up, - we're gonna choose pin 16 because that's what we've connected to honor Header. - And instead of doing gp ioo dot out, - we're gonna do GPO dot in because we're configuring this pin to be an input. - And all we need to do to test this state of Arpin is G p i o dot input and pass the pin - number again. - 16 and you see here we have zero, - and that's because our switches in the right position so pins one and two on our switch or - not connected. - Now, - if we come over and move our switch to the left and try it again, - you'll see that we get a one this time and we could just test that again. - I still get a one. - Let's go ahead and switch it back and we get a zero again. - So this is working perfect, - just as we expected. - When the switch is in one position, - we get a zero. - When we flip it, - we get a one. - So far in the class, - we've been doing all of our python testing from the show. - I think it's a good time now to move into a file so we can start running this and not have - to re type in everything every time. - So to do that, - let's just from our command line here. - Let's make a directory using the Make dir command. - I'll just call mine skill share again. - We'll be using the Nano program to edit our file, - and I'll just call it monitor dot pie. - So in here we're gonna do the same thing that we did from the show. - We're gonna import rpai dot GPO as g p I. - O. - And then, - of course, - we have to set our mode, - which is board that we've been using, - And so to test our move to a file, - let's just do something with our led. - So I'm gonna put a comment in here to set up the only deep in. - And if you remember, - just like we did in the show, - we'll do gpu dot set up 12 is what are led is connected to and will do. - GP ioo dot out Now, - if you remember before when we did this set up the default state is zero, - which in our case, - turns are led on. - But what if we don't want the led to turn on when we configure our pin? - Well, - there's a nice little argument that we can add on to the end here called Initial, - and if we say initial equals g p i o dot high. - When it sets up the pin, - it will make the initial state high, - which in our case, - will turn the led off. - Then we'll just do a simple test. - Here will do GP ioo dot output 12 and then set the pin low, - which will turn are led on. - And then we'll just wait for a second and try to turn the led back on just a simple flash - test to make sure that our script is working as we expect and so toe weight that second, - we're going to need to import another python module. - So we'll come up here and we'll do from time import sleep. - And all that does is gives us access to this sleep function in the time module so that we - can call it here right after we turn our led on. - So just to asleep one which will hold us up for one second, - and I will do GPO dot output 12 and said it to gp ioo dot high, - which will turn are led back off. - And of course, - when we're done, - we want to do the cleanup like we talked about not exit out of Nano. - All you want to do is hit control X, - and it'll ask you save modified buffer. - And if you say yes to this since we already gave it a name, - it will follow up with the question file name to write monitored up I If you just hit enter - here, - it will save our file. - And if we do a directory listing, - you'll see. - Now we have this monitor dot pie file. - I forgot to change directories into the Skill share directory before I created this. - So let's go ahead and do a move monitor dot pi into the skill share boulder, - and you'll see that it's missing now. - So let's CD into the skill shareholder, - and you can see our files right there. - Justus we needed to use pseudo to launch. - The Python show will also need to use pseudo when we run our scripts. - So to run that monitored up I fall that we created. - We'll just do pseudo python and then give it the file name monitor dot pie and we'll go - ahead and hit. - Enter here and perfect There's are led. - It gave us one flash. - That's all it was supposed to do. - So we've successfully created the base for our script that we're gonna right. - So all the code that we write in the future now other than doing maybe quick tests will be - in this monitored up I and we'll just build this file up until we get all the functionality - that we're looking for. - Now that we've shown that we can write our code in our Python file, - we don't want it to flash our led. - That's not the functionality that we're looking for. - So let's write something a little bit more meaningful, - so we'll go back into our file here. - Well, - just come down here and follow the same pattern that we did with the led. - Penn will put in a little comment that we're setting up the switch pin well. - The gp ioo dot set up. - Remember, - it's been 16 this time is what are switches connected to. - We're configuring it as an input. - So the gp ioo dot in and let's go ahead and get rid of this code that we wrote to flash the - led Ah, - quick tip in Nano is if you get on a line that you want to delete the entire line. - If you just hit control K, - that will cut our entire line out. - So we'll just do that. - Get rid of those lines. - One thing that I found very handy when working with the raspberry pi in Python scripts is - to wrap on my code in a try except block. - Basically, - what that does is everything you put under the try. - It will run normally, - and then when it reaches an exception, - it will go into your except handling. - And the reason I do this is because when we run these from this show, - they will just run forever. - And the way you cancel those is by hitting control, - See which exits out and brings you back to the shell. - Prompt. - Well, - when you do that, - it could be anywhere within your main try block. - And so we want to make sure that things get cleaned up. - Remember, - we need to call that gp ioo dot cleanup. - So the handle that I do in except keyboard interrupt what that'll do is it'll hit that - except block when we do control. - See? - So let's come in here to our try. - And what we want this to do is just run forever. - Like I said, - until we hit control c So we'll just wrap everything in a wild, - true loop and we'll just test our switch. - So we'll say if GPO dot input 16 is high, - so they have flipped the switch to the left. - Then we want to go ahead and do GPO dot output 12 is our led will set it too low, - so we'll turn it on. - So what we're gonna do is we're going to set this up so that when we flip our switch are - led turns on. - And then when we flip it back to the right, - the led will turn off. - So this will come in here and sample if it's high turn are led off and we'll do else. - So the switches in the low reading or to the right We just want to do GPO dot output 12 and - then said it high, - which turns it off. - And then down here in the except Block, - is where we want to do the cleanup. - So put that here. - Then we'll clean up our line down there and then finally will just want to exit gracefully - . - So we'll do assist dot exit and given a code of one now to be able to use this system exit - , - we need to go ahead and import the module for that. - So we'll come back up to the top here. - We're just doing import cysts that way it won't throw an error when the script runs. - All right, - that's it. - Let's just give this a quick look. - And you see that I have a typo there. - I didn't put the tea on inter evidence where I like to give Dakota quick once overlooked - before I close it and save it. - So let's fix that and we will save an exit. - Okay, - let's run this again using pseudo, - and we'll come over here and flip our switch and you can see it turns are led on Perfect. - Just like we wanted. - Now that switches working as we want it to, - Let's move on and see how we're gonna hook up our button. 12. Button Integration (Steps 6-7): - remembering back to the first video in this unit, - we explain how a button is nothing more than a momentary switch. - So this is how I have it constructed, - influencing. - Now It may look different because I have the resisters oriented a little differently, - but if you look at the connections, - it's all the same. - In the case of our switch, - our 10-K resistor goes through the green wire up to ground, - where, - in the case of our button, - I've just attached it straight to ground without using the wire. - And then are 3.3. - Bolt connection comes down to the other side of the button, - and the one K resistor goes out to the GPO wire, - which is again yellow. - You'll notice that my button straddles the middle of the bread board. - Oftentimes you'll do this if it would be a problem to connect pins in the same row - vertically. - In our case, - our button doesn't have that problem. - I just felt like installing it this way for real estate purposes, - and the reason I know that it's not a problem is by looking at the data sheet again. - If you look at the dimensional drawing here in the lower right hand corner. - We have the terminal arrangement. - We can see that pins that share a side of the button aren't connected to each other. - In fact, - the connection goes from pins 2 to 4 and 123 Now you could arrange this anyway so you could - set it up. - So pin one and pin four connected when you push the switch or pins two and three. - But it's important to note that pins one and two are connected together and pins three and - four connected together again. - This is where the data sheet is so critical it shows the internal connections. - The only other way that you'd be able to figure this out would be to hook up a meter and - keep pressing the button to try and figure out which pins were connected when the button - was pushed in when it wasn't pushed. - This is how we haven't laid out. - Let's see what it looks like in my set up. - And for those not using the pie cobbler, - this is what we have so far. - So go ahead and take a minute and hook your button up so that we can test it. - Okay, - So now that we have our button installed, - let's go ahead and write some code to test it. - So it's open apart, - monitor Paul again and we'll do just the same thing that we've done before. - We'll go ahead and we will put comment in here about setting up the button pin. - And we'll set that up just a lot like the switch been if your call from when we talked - about the theory on this ah button is nothing more than a momentary switch. - So we'll set it up as an input. - And now all we need to dio is we're not going to interact with the led A to this point with - our button. - What we're gonna dio is going to come down here in our loop this while that just - continuously runs and we're gonna do some logic around the buttons, - so we'll see if gp iota input 18. - I remember that's the pin number that are Button is connected to the pool's. - Did she pay a high? - And for now, - we're just going to print something to the screen just like that. - So now we've set up our button isn't input. - We've We're gonna check in on while loop. - And if we press it, - we're just gonna print something out to the console to make sure that are set up is working - correctly. - So let's go ahead and give this shop. - We're gonna go ahead and exit. - We want to save our changes. - Okay, - so let's go ahead and run this pseudo python monitoring up. - I I should just be running there and then let's come over here and touch her button and see - what happens. - Okay? - We got a ton of pronounce here of you pressed me. - So what is going on? - Let's go ahead and cancel this hour. - It's obviously isn't working the way that we wanted to. - Let's go back in to our file here. - Now, - this while live this while true, - right down here is gonna be executing so fast, - and it's gonna be testing that input so fast that just the little bit of time that you have - that held down the button how down? - Even though it's a fraction of a second, - that logic is being executed. - Testing If it's high and it is high for those, - you know, - whatever. - 102 100 milliseconds. - And so it's gonna print that just as many times as it can in that amount of time. - So an easy way we can fix this the simplest way this just come down here and will say sleep - for a second. - So after you've printed out the message, - just hang out for a second before you do anything else, - and that gives us enough time to release the button and see if that changes things. - Let's go ahead with that. - CLECs it out will save. - And now let's go ahead and run this. - All right, - let's come back over to our set up here and push a button and see what happens. - Okay, - pressed it a couple times there and we only got one print out, - so that's working pretty good. - It's good and close this again. - So now what might be an issue with this? - We come back in here if you notice when this sleep executes here. - It's holding up our entire program, - so it's not checking this switch. - That's not doing anything else. - It is literally just staying right there until the one second is up, - and then the program will continue to execute. - Now there are ways to get around this the GP I O module has some things for event detection - , - and I played around with this quite a bit, - where you can create callback functions where the hardware will detect a change and call a - function that you write any time there's a rising edge, - which is what we're doing. - When we press the button that we're going from zero volts to 3.3 volts, - it will detect that rising edge and call your function. - However, - when I was missing around with that, - it was very sensitive to static electricity, - to the point where if I moved around in my chair, - it would set off interrupts, - as in it noticed that there was a change on the pin. - Now we can eliminate that. - We could do some things to D bounce our switch, - and we could shield the pie to make sure it's not picking up anything like that. - But it was really interesting to see how sensitive that was when we set up the edge, - detect. - So to keep things simple for now, - this sleep, - even though it is holding up our program some it's not really gonna hurt us in this - application, - so we're not gonna get much more complicated in this. - I'll put a link down below, - too. - Some of the resource is on the event detection, - so you can look at that If you'd like Teoh, - it is an option. - But for now, - we're just gonna keep it simple and just use this sleep. - We've covered a ton during this unit. - We have are switching our button connected and working and integrated into our python - script. - And that's great. - If you've made it this far, - you're doing an awesome job. - Now we're gonna get into the two communication protocols SP I and I two c But before we do - that, - we need to take care of a little bit of sauntering and that's up next in unit seven. - As always, - if you need help or have questions, - the best place to go is on the skill share website For this class under the community tab, - you can also reach him via email or find me on Twitter 13. Soldering Headers: - before we move on to talk about SP I and I, - two c, - we need to get our boards ready to attach to our bread board. - As you can see here, - we've got the display on the left and temperature sensor on the right. - Now these air on what are called breakout boards, - which means the pins are broken out to these little holes that you can see. - But there's no way for us to connect it to our bread board. - So we need to fix that by sauntering on some headers or wires. - Now, - the best way to do this is to take some header pins like you see here and use a pair of - pliers to break them down into the sizes that will need on the display. - Will need one of seven to cover the ground pin to the select been and then, - as you can see on the temperature sensor, - we're just gonna need four on the top two on the bottom. - So this is what they look like broken out. - This is what the header would look like if we held it in place on the display module. - Now, - one of the tricks that I used to make this easy to sauder. - Is it? - Just use a bread board as a jig. - And so we'll put our header in with the long portion actually installed in the board. - So the short ends air sticking up in such a way that we can layer module on top. - And it's just easy to Sauder. - So this is what it would look like for the display. - Now, - the two pin header you see here is just to keep our board level during sauntering. - We're not actually gonna sort of that. - In fact, - that would be a disaster because, - as you can see on the board here, - that's the negative and the positive. - So we would essentially be shorting it together when we tried to power it up. - And this is what the full jig looks like with the display and the temperature sensor - headers plugged in. - So we're gonna do is set our modules or a breakout boards on top of those header pins like - you can see here to get ready for soldering. - I wanted to make a video to show you how to sauder this. - Unfortunately, - my camera wasn't good enough to get a real tight shot. - There's lots of tutorials on the Internet for how to Sauder. - And this is probably one of the simplest things to Sauder. - So don't worry about this. - You can do this, - not a problem. - So here's a close up of our temperature sensor sitting on the jig. - So what we're gonna do when we saw her, - as you can see in this picture, - is you want to have your sauder on one side and your iron, - your hot iron on the other, - and what you'll do is you'll touch the iron to the pin and the pad on the breakout board - and then bring the sauder in from the opposite side. - So this is a pin after I've sorted it, - and here's the entire temperature sensor sauntered, - and we're just gonna repeat and do the same thing on the display. - This is what it will look like when it's done. - So now we've got our to breakout boards, - Stoddard, - and we're ready to install them on her bread board for a project again. - Don't let the sauntering freak you out, - even if you've never saw her before. - This is something that you can handle, - I promise. - If you don't have hitters. - That's all right, - too. - You can use just why you could just saw her wires directly in here. - It's a little harder because you have to hold the wire and, - um, - started at the same time, - but not impossible. - In fact, - here's a module that I've used before where I've done just that. - I didn't have headers, - and so I used regular wires that I had stripped. - I said, - It's a little hard to do but doable. - If you don't have headers, - I recommend headers. - If you can get a hold of some. - All right, - that's it. - Now that our boards air sodded, - we're ready to move on to the next unit. 14. Intro to SPI (Step 1): - Okay, - so the first protocol that we're gonna cover when connecting to our pie is the S P I - protocol. - Now, - with any communication protocol, - the goal is to connect two things together. - So in our case, - we've got a raspberry pi. - We want to connect that to our display an SP isa protocol that we can use to do that. - So when we're connecting anything together, - the first thing we need to take care of is the power. - Now, - the pie, - if you remember, - has 3.3 volts and five volts, - and it also has a ground. - Now it's important to remember when you're working with S P I or any protocol for that - matter where you're connecting to devices together, - that you're consistent with your power. - So you don't want to be sending five volts down to a device that can only handle 3.3 bolts - . - That's how you're gonna start breaking Things now are display is able to handle 3.3 volts. - So we're okay to share the power from the pie to power. - Now we do have to worry about doesn't have enough power, - cannot supply enough current, - and we'll look at that a little bit later, - but for right now, - let's just assume we can share it so we'll connect the power there in the ground here. - Now, - even if you have a scenario where the display is gonna have its own power, - you have to connect the grounds together. - That way, - when the lines are talking the signal wines, - they are referencing the same thing as ground. - Because if this has a different idea of what ground is than this, - when you start sending data across it, - it could get very confusing. - The data is gonna get jumbled. - It probably isn't gonna work out really well for you, - so make sure you connect the grounds. - So the next thing we need is how do they communicate together? - Well, - an SP I It's known as the three wire or four wire protocol, - and that's because it uses generally three or four lines and we'll draw each of those here - . - Now, - an important concept in S P. - I is an idea of master and slave that always has to be a master device, - which in this case is gonna be a raspberry pi and a slave device. - All communication in this protocol is driven by the master. - And just as a side note, - the raspberry pi actually can't be a slave. - So you couldn't hook to raspberry PiS together. - One is a master and was a slave because the only mode this can operate in is a master role - in the SP I protocol. - It's our first line is what's called Master Out slave in and this is always referenced from - the perspective of the master. - So on the display, - it's also gonna be called Mos Side because it's still master out Slavin because the display - is the sleeve. - And that's where data goes from our master towards our slave. - The next one is master in slave out, - which, - as you can guess, - it's just data coming back this way. - No, - the state is sent only when a clock is running. - A clock is what keeps the two devices in sync to make sure that they're sampling and - reading the data at the same time. - So that's the next line. - This is our clock line, - and it's gonna look something like this. - And remember, - this is always driven by the masters so the master will supply this clock, - so the display knows what speed to run out, - and then the final line is what's called Chip Select. - Now you'll see this sometimes with a bar over it like this. - That just means that it's active low. - Typically, - we think of Ah zero as being zero bolter ground and then hire one being 3.3 volts or five - volts, - or what's known as the supply voltage. - In this case, - the chip select is the exact opposite. - When it's pulled low or its pulled the ground, - that means it's enabled or it's turned on. - So these are the four lines that we need to communicate with now. - One of the unique parts about S P I is that data is transferred at the same time, - meaning as the master is sending data down to the slave. - The slave is always sending data back Now, - it may not be actually putting data on this line, - but the masters going to read it. - So on every clock edge that the master is sending data down this line. - It's also sampling this line to see if data is coming back. - So SP is not really a good protocol to send a bunch of data and then wait for a slave to - process it and then the slave decide to send it back because, - remember, - it's always driven by the master. - So to get data back from the display, - the pie has to be sending data. - And so the way this will happen sometimes is if the master needs to read from the slave. - It'll just send dummy data down. - That's the same length is the data that it needs to read back. - So one of the cons of this is it's a little tricky sometimes to get communication going - both ways. - It's really meant to be driven by the master. - Now, - one of the pros of this is that we can share these lines so you can see we have the display - here. - We could also have another module, - maybe something like a sensor down here that can share all of these lines. - So it's gonna take the master out slave in the master and slave out in the clock all shared - with these lines here. - So when you hook it up on a bread board, - they can all share those three lines, - and then it's gonna have its own chip select right here. - That can come up and connect to the pie and so it can share these three lines just with the - display and only needs one additional line. - So for each additional device, - you only need one additional pin on your raspberry pi. - So it's important to remember one of the great things about SP I is. - It's a standard meaning as long as the display or the sensor or whatever other module you - want to connect is SP I compliant, - meaning it knows how toe work on this protocol, - you can connect it in the exact same way that we've connected display in the center here. - You don't have to figure out or right special code to create a communication protocol. - It's just that is it s p I is the standard and they know how to talk to each other Now that - we understand how to connect to devices that are going to communicate with S P I. - Let's talk about the different modes. - You hear people talk about SPE mode zero or one, - there's actually four mode 012 and three. - Let's talk about what that means. - So I remember when I said that the data is driven by oclock line in a clock line is gonna - look something like this when it's transmitting data. - And if we think of this is zero bolts and this is 3.3 volts. - In our case with the pie, - this is what's known as clock polarity zero or C pole zero. - Now, - just like the Chip select line can be active low, - the clock can be active low as well, - so it might also look like this going from 3.3 volts down to zero. - So again, - this is 3.3 volts. - This is zero. - This is what's known as clock polarity one. - So those are the two different ways that you can drive the clock line. - Now data is going to be put on that master out and master in line during certain windows of - time while this clock line is running. - And so if we think about this, - if we think of the windows where the data can come in where maybe it's zero here or this is - a one and this is a one. - What's known as the clock phase determines when the master and slave or going to sample the - data lines to determine whether it's a one or a zero and so we can either sample on the - leading clock issue of the clock starts here on the left. - If we sample on the leading edge, - this is known as clock phase or C p h Not C p A c p h a of zero and so you'll see the data - will be sent in such a way that whether the clock is active, - higher, - active, - low, - the phase of the data is gonna sample so that it's sampled right in the middle of the data - on the leading edge. - Now, - clock phase one is the exact opposite. - It's gonna sample on this falling edge. - So if he's sample right here, - you can see that's gonna sample right in between the windows. - But on clock phase one, - the windows are actually gonna shift the phase of its gonna shift. - So look, - just something like this. - Where again, - this is a zero. - This is a one. - And if we did one more, - this would be a one that would be clock phase one. - So we've got CPJ zero cph a one. - Now The combination of these two things are what determine the mode and so if we look at it - clock polarity, - Clark fees and then mode. - This is a simple table. - We've got four options you've got 0001 10 and 11 of these Corp respond to the different - modes. - So if clock polarity is zero again like this and the phases zero So the data looks like - this. - That's mode zero. - Now we just got on the table, - would one to and three Now, - by default, - the pie operates in mode zero, - and so does our display, - so we're not gonna need to do anything special. - But it's good to know, - because you may have a slave device that says I use mode to and so you need to calibrate - the master so that it speaks that same language as it were so that the clock is in sync in - the day doesn't sink. - If all of this still seems a little confusing, - don't worry about it. - For now, - we're gonna connect things up. - You'll see how it works. - There's lots of resource is online that you can learn more about this. - You don't have to have a deep understanding of the different modes of SP I when the - polarity and the phase are to be able to connect devices and talk over this protocol. - I just wanted to give you a heads up so you could have a general idea of what we're talking - about when we refer to things like SP I mode zero or clock polarity and things like that. - So now that we've talked about the theory, - let's get in there and hook something's up. 15. Enable and Test SPI Protocol (Steps 2-6): - So now that we've talked about the theory of SP, - I let's get it working on our pie. - So we're gonna come to L A next out organ and there's a page dedicated to SP I on the by. - It's got a lot of different information here. - We're not gonna cover it. - All right? - Now, - we're gonna come down to this link for the loop back test because what we want to do is see - if RSP I module is working. - It says this could be used to test SP. - I send and receive. - Put a wire between Master Out Slavin and Master and slave out. - Okay, - so we're gonna come over to our set up here, - and you can see this blue wire just right here is connecting our master out slaving in our - master and slave out on our pie cobbler There. - So we have that connected just like it says in the directions in the next part. - Says we need to download a file here. - So I've got my terminal here where I'm ssh into my raspberry pi and were literally just - going to copy exactly what they've written there before. - We do that, - though, - I want to make a little directory here that we can work out of. - So we'll do. - Make sure S p I Then we'll CD into that and we'll just do this command. - Now, - don't worry about what w get is. - It's just a utility that's gonna allow us to download a file in this case, - the SP I Dev underscore test dot c file. - So let's just go ahead and do that. - Okay, - So that's gonna download if we just do an ls will see that it's there. - The next part of this is a GCC line. - Now, - if you don't know much about compiling files, - that's okay, - that's all we're gonna do here. - We need to compile this source file. - So we're going to GCC desh Oh sp I underscore test in the file that we're gonna compile is - the one that we just downloaded. - So this is going to do is it's gonna create an output file called SP I Devin or score test - . - Let's go ahead and hit Enter. - That only takes a second. - If we list the directory again, - you'll see we now have this SP I Devonish court test and we're just gonna run that just - like it says in the instructions. - Okay, - Now it says can't open device. - No such file or directory. - So what's going on here is that by default SP I is not enabled on our raspberry pi raz B - and distribution. - And we can see that by looking at a special file. - We'll just use this cat command again. - We've used it before. - We're gonna look in e t c mon proved dot de raspy blacklist dot com We had intern that - we'll see It says blacklist SP I and I two c by default. - Many users don't need them and then it hasn't blacklisted. - Well, - we do need them, - so we need to turn that off. - So we're gonna go pseudo nano. - Don't forget the pseudo because we need elevated privileges to change this file, - and we're just gonna go to that same file, - okay? - And in here, - all we're gonna dio is we're gonna put a pound symbol in front of the S P I line, - which basically turns that into a comment. - We'll save our changes now, - After we do that, - we need to reboot for the changes to take effect, - so we'll just go ahead and do a pseudo reboot and we'll wait for that to come back up. - Okay? - Our pies booted back up. - And now we're ready to try our test again. - So let's change directories back into that s p I directory that we created. - And if you remember, - we compiled that file. - So we're just going to run it again dot slash sp i dev Test Dash d. - Okay, - now we get this SP I mode bits per word, - Max Speed. - The important part is this block of characters this f f f the 40 line that tells us that - data is making it out of the master output pin and onto the master input pin. - Now, - we've confirmed that the ESPN module is actually working on our raspberry pi. - That means we're ready to connect our display, - and that's what will take care of next 16. Basic Setup and Test (Steps 1-4): - remembering back when we talked about SP I there were some things that we needed to know to - be able to use the protocol, - things like the clock mode, - how fast we could run it and what wines that we were going to use. - And so, - before we can hook up our display, - we need to know those pieces of information. - So for that, - we're gonna turn to the data sheet. - Now, - remember, - we've said this before the data. - She is your friend for these projects. - It will tell you the answer to most of the questions that you have. - Some data sheets are better than others. - And so we're gonna go ahead and look at the seven segment display data sheet that sparked - point is put together as far as data sheets go. - This is right there up at the top. - They have done a really nice job of laying it out, - making things very clear and easy to understand. - And the information is very accessible. - Let's come down here to the data sheet links section. - We're gonna go into this interface specifications link. - As you can see, - it's gonna tell us about the U. - R S P I and I two c communication protocols. - As you can guess, - since we've been talking about the SP I protocol, - that's the protocol that we're gonna use to talk to our display. - So if we come to this section here, - we can find all the information that we need to talk to our display. - We can see that we're going to use the slave data in also known as the master Out slave in - the slaves select, - or sometimes we call that the Chip Select and the clock line noticed that we're not gonna - use the master in slave out, - which would be the SD open on the display because we don't need to get any information back - from the display. - Were simply gonna be sending commands down to it. - The other thing that's important here is down here in bold. - It says the maximum speed of the SP I clock input is 250 killer herds. - That's gonna be important when we start talking to it from the pie to make sure that we're - not sending too fast of a clock signal that the display can understand. - And then finally it lists that the display is configured toe work with SP I mode zero and - you'll recall what that means from when we talked about the theory of SP I The nice thing - about this is SP I mode zero is what the pie operates in by default, - so we won't need to do anything special there. - All right, - that's all we need to know about the SP I protocol. - But there's one other thing I want to look at. - So let's go back to this main page here and I want to go into hardware specifications. - Every module that you connect to your raspberry pi should have information about the - electrical characteristics. - So if we scroll down here, - we'll have things like the physical dimensions. - But what we're really looking for are these operating characteristics. - If you recall when we talked about the header, - we can only draw so much power from the 3.3 volts power supply and the raspberry pi. - We need to make sure that as we're connecting modules that we're not over doing it on power - . - If we are, - we need to find an external power source. - As you can see from the table here, - it gives the supply current for different voltages. - We're gonna be using the one right here in the middle of 3.3 volts so you can see that the - minimum current draw will be 3.8 million amps and the maximum will be 7.9. - So right around eight milligrams. - So if we take the worst case scenario, - our display can dropped eight mil amps of current from our raspberry pi 3.3 volts power - supply. - So we just need to make a note of that to make sure that as we're connecting things, - we're not pulling too much power. - Eight mil amps is well below the 50 mil amp. - Limit. - So we're okay to use our raspberry pi to power the display. - Now, - before we actually connect our display to the board, - let's use Fritz seem to see what it'll look like. - So the first thing library didn't have an exact match on the display that we're gonna be - using. - But this was close enough in had the right number of pens across the top. - Let's go over each of the connections. - First and foremost, - we have to have power, - says you can see here we have our ground in our 3.3 bolt connection. - The display can run from his low as 2.4 bolts all the way up to five volts. - So 3.3 puts us right there in the middle. - We're sticking door conventions, - as we have before green, - representing ground in black, - representing 3.3 bolts. - Aside from that, - all we need to do is make the connections for the SP I protocol. - We have the clock line, - the master out, - which is how we're gonna send data down to the display in the chip Select line. - Last. - This is what's gonna tell the display that the raspberry pi is ready to send data to it. - And that's all there is to hooking up RSP. - I display toe a raspberry pi at this time you want to pause the video and make the - connections on your own bread board? - This is what my bread board looks like after I've connected my display. - It's not that we haven't hooked up. - We can go ahead and boot rpai back up and see if we can get this thing to point out some - characters To do that, - we're gonna go back to the data sheet. - We're gonna go back to the main page here and we're gonna go to this basic usage section. - This will describe to us how we can display numbers. - So the first thing they do is they give us an example. - Display one to a B and the data she describes. - How weaken send actual binary values to print out zero through nine and a through F, - or we can use the asking code for it. - So, - as it says right here, - we can send 01 0 to 0 a zero B, - or we can send them as 31 32 41 42 which the asking codes for all of those so we have to do - is send that data down the wire to our display module, - and it should show up on Scream Well, - a neat way that we contest this. - If we come back, - T Olynyk stud, - or go over here, - we can see that there's a way to test the SP I interface through this show, - and that's just by echoing straight to the device. - Let's go ahead and try this. - You bring my show window back over here. - My prize booted back up as I was trying to film the display. - I noticed that with lights on it in the camera on, - I was getting a refresh problem that was easily fixed by turning off the lights. - So the next few shots of video that you're going to see our with the lights turned off. - It's hard to see everything else on the bread board, - but the most important part, - which is the display, - is nice and easy to see. - We're gonna type it just exactly how it says it here at Go Dash any backslash x one x last - exit to back slash x 03 Now the backslash exorcist says we're passing a Hexi decimal value - here and then we're gonna pipe this out to Deb SP I 0.0 when we hit. - Enter. - Let's see what we get. - Awesome. - Get 123 right there on the display. - Okay, - so now that we have 12 300 display, - how do we get rid of it? - Well, - if we go back to the data sheet here, - we scroll down a little bit more, - says clearing. - The display says the clear display command bite is hex 76. - So go ahead and bring our consul back here and we'll dio echo, - dash any x 76 and we'll pipe it out just like we did before we hit Enter and we get a clear - display. - So this shows that our display is working. - We can send commands to it. - We get it to print out digits. - We can clear it. - Everything's ready to go so that we can start integrating this into our python script - pretty good. 17. Controlling the Display (Steps 5-11): - we obviously don't want to use the Terminal two controller display, - and we do need to integrate it into our python script. - And to do that, - we're gonna need a python module. - There are several available, - but the one that we're going to use is this one that we confined on Get hub called Pie Dash - S P I Dev, - this few files that we're gonna need our this sp i dev module dot c and set up dot pie, - which is how will install the module for python to use. - We can get this a couple of way if you want to install, - get and pull the repository down. - You can do that, - but this class isn't meant to go over getting detail. - So instead of using that, - we're just going to use w get again. - Get my terminal here and to get these two files. - First of all, - let's make a directory form. - Call it Python Dash s P I little CD into that can to get these were just gonna do w get - https and then raw, - get hub dot com and then we follow the rest of the path as we see it up in the address bar - . - That's how we get the set up dot pie. - And if you just use your up arrow key, - get the path back, - we'll just take off, - set up it up pie in the U. - S. - P i. - Deb, - underscore Montreuil dot c and you'll notice it's not quite like the URL, - as we have to add the branch in there. - The master part of the link and I include these links in the show notes so that you can - just copy him. - Okay, - so let's do a directory listing and you can see that we have both of them there. - And now to install this for python to use are we have to do is to a pseudo python the name - of the Python file and then doing install. - This will install the module so that will have access to it from our pipe on script. - Now, - before we added into our script, - let's test it. - Using the python show again, - I needed to turn the lights off so that the display was nice and clear. - So let's go ahead and do Sudo Python to bring up our python show, - and then we need to import S P I dead. - That's the module that we just installed. - So let's go ahead and do that. - Then we'll set a variable sp i equal to SPF dev dot s p I Deb like that. - Then we're gonna do SP I open and then the arguments to this. - If you remember when we were using this show, - we're piping it out to SP I Deb 0.0 There's also a 0.1 which will use the other chip select - pin on a raspberry pi And so the arguments are just that. - So for 0.0 will do zero zero like this to open it up just like that Now to write data. - All we do is we say sp I done expert to or transfer to And then we can send the data here - as a array of bytes. - If you remember before we sent, - we can do Hexi decimal in python like this As we sent 01 zero to 03 I think that's right, - Syntex. - Okay, - Perfect. - We got 123 on their display so that's working notice. - We had to put the zero before the X is where as in the show, - we just did. - The exit is that's just syntax difference between Python and Shell. - So if you also recall the way to clear the display was sending 76. - Let's see if that's working. - All right. - Perfect. - Okay, - so that means that we have successfully downloaded the Python module and we can use it now - we just need to add it to our scripts. - So let's exit from here. - Actually, - before we do that, - I want to do an SP. - I close just to clean that up, - and now it will have an exit. - You'll notice When we did these transfer commands, - we got an array of bytes back. - So we sent 12 and three. - We got back a list in Python of 000 when we sent the 76 We got bags. - Eras. - Well, - remember in the SP I protocol, - you have to send a bite to get a bite. - So what the library is doing is when it sends those bites, - even though we're not connected to the display to get information back, - it's still trying to read the master in slave out pin on the pie and telling you I read - back in this case all zeros and that would be the case because we don't have our display - talking back to the pie. - But just so you know, - when you're using this library when you do the transfer, - that return value that you see underneath is what it's reading back from the slave device. - All right, - this is going really well. - Now let's see d back into our skill share folder and will go back into our file our monitor - , - Dr Pie, - and we need to add our SP I Deb module. - So let's right here at the top. - The first thing that we needed to do, - if you remember, - is import SP i, - Dev, - and now we need to open it up so we'll do that just here the top. - Now this isn't right now. - Our Python script is very script e. - It's it's not. - If anybody's watching that has some experience of programming, - it's not object oriented. - All we're doing is we're taking baby steps here to get all of the functionality that we - need. - We can always come back later and re factor this, - but the purpose of the class isn't too right. - Perfect pipe on. - It's too. - Show you how we can use python to interact with that raspberry pi. - So let's come down here to another comment right here will open things up like we did, - so C s p I equals SP I Deb, - uh, - sp I dead. - Okay. - And we'll open it up just like we did in the shell. - If you're called from the data sheet, - there is a max speed on our display of 250 kilohertz, - so we can set that here. - You noticed we didn't have a problem when we used it in the show, - but it's still good practice to set the max speed. - If we know it, - we could just say Max speed hurts equals 250,000. - Just to make sure that we're not going too fast for display. - Okay, - so that opens it up. - Now it's ready to transfer. - Before we do that. - I want to come up here and I want to write a couple of functions, - and the 1st 1 is gonna be for sending data so we'll just call this SP. - I sinned. - I apologize for that blue font, - and I know it's kind of hard to read And what we're gonna pass it is the bus that we're - using and then the data that we want to send and we have to send an array to it. - So we call this the transfer list, - just create a list there, - and now we might want to send different things to this function. - We may want to pass it Hexi decimal value, - l