Raspberry Pi Pico W LESSON 53: Animating NeoPixel Strips Using MicroPython

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys this is Paul mcarter with toptechboy do.com and we're here today with episode number 53 in our incredible nude tutorial Series where you are unleashing the power of your Raspberry p Pico W I will need you to pour yourself a nice tall glass of ice cold coffee that would be straight up black coffee poured over ice no sugar no sweeteners none needed and as you're pouring your coffee as always I want to give a shout out to our friends over at sunfounder sunfounder is actually sponsoring this most excellent series of video lessons and in this class we will be using the Kepler kit for Raspberry Pi Pico W now most of you guys probably already have your gear but if you don't look down in the description there is a link over to Amazon you can hop on over there and pick your kid up and believe me your life and my life are going to be a whole lot easier if we are working on identical Hardware but enough of this Shameless self-promotion let's jump in and talk about what I am going to teach you today this is a follow on to the lesson that I taught last week which where we learned how to do nominal basic functions on a neopixel array controlling a neopixel array from the Raspberry Pi Pico W using micropython and then I gave you a homework assignment to try to go in and kind of animate it where you have one pixel color that's sort of running back and forth so that you get comfortable with not just controlling the color but controlling the position and making your neopixel array a little bit Dynamic now if you need more instructions on how to hook it up and how to get started go back to the last lesson but I can give give you a very quick overview or just kind of catch you up basically I am using the 8 LED strip that comes in the sunfounder kit and you have three wires the red goes to 5 volts which I have down here which is physical pin uh what is that physical pin 40 down here in the corner and then on physical pin 38 I have the ground which is the black wire and then the center wire the yellow wire is data and it comes over to physical pin one which is GPI pin zero now I explained how these things worked last week but I must remind you that you must not try to hook more than an8 pixel strip to the Raspberry Pi picw power now from the picw you can control an arbitrarily large uh neopixel strip but you must have a separate power supply so if you you go more than eight don't try to power it off of the 5 volts you need to snag the 5 volts from a more high power power supply talked about that a lot last week now what the assignment was the assignment was to create a field of red pixels and then have a green pixel run back and forth how many of you guys were successful if you were successful leave a comment down below I Am Legend double chest bump and if you are not successful leave a comment down below I folded up like a cheap Walmart lawn chair okay so hopefully you guys uh hopefully you guys got it it was just to get you to go in and kind of be familiar with what I uh what I taught last week and so I'll go in and I'll show you my solution and I hope some of you guys were able to do it so let's switch over here to this view let's get myself out of your way and let's jump in a lot of this you ought to be pretty uh a lot of this you should be pretty uh pretty uh comfortable with because we went over it last week but the first thing is you're going to in need to import neopixel that's the library that allows you to kind of does the bookkeeping and some of the leg work for you and working with that neopixel array we're also going to be using a gpio pin so we're going to need to say from machine import pin and then it's always good to import time because it seems like we usually want to put some sort of delay here now we got to set things up how we have it hooked up you remember my pix pin the control pin to the pixel was GPO pin 0o physical pin one GPO pin zero and then how big is my strip well I'll call that pix size and we have eight pixels on this particular one now I need to create the neopixel object I'm going to call mine pix you could call yours kitty litter box if you wanted to I think pix is a little more descriptive so I will call it that and that is equal to neopixel the library we just imported neopixel the method and we've got to tell it which pin we're using pin is that method that we just imported which which pin are we using we are using pix pin that we just set up and then how big is our strip it is pix size like that okay now we have our neopixel object that we can write to we can write data to it and now really I think we need two colors because we're going to have uh we're going to have a Green Dot running on a red background and so I'm going to say uh I'm going to say red I'm going to set up the color red and that is a tupal well it's RGB so red is 255 full string comma 0 for the green comma 0 for the blue and then the color green I'm going to Define as I'm going to Define as what I'm going to Define that as I'm going to Define that as 0 comma 255 comma 0 kind of had a brain glitch there because I was thinking about something eight steps ahead and I kind of lost Focus sorry about that but those are my two colors that is what we are going to do and now the first thing that I want to do is I want to just see if I can just make it run one way and so I'm going to say while true when is true true true is always true I am creating an infinite Loop and now what I'm going to do is I am going to come in and now I need to write to I need to write to each individual pixel so I need to step for I in range okay I'm going to start at pixel zero and then I'm going to go up to pix size now you think pix size is eight but I'm starting to count at zero but the range function always stops one before the second variable so it's going to stop at pick size minus one which is seven so it's going to go from 0o to S which is eight numbers so it's a we've gone over this over and over it's kind of a crazy thing but it will work and we want to step one each time now what I want what do I want to do I want to say pix do fill I want to make them all red okay I want to make them all red so pix Phill red so I don't want to have to go through and do them all at once so I'm going to say pix Fill Red okay and then what I'm going to do is I am going to pix Fill Red and now I'm going to pix uh of I I'm going to turn the specific i1 I'm going to turn that equal to Green like that okay now I'm going to do a PIX do write to write all those and then I'm going to do a time do sleep of 0.1 okay now you might say well you turn them all red and then you turn one green is it going to be blinking no it won't blink because I'm setting the data up with these two and then I write it here so it's going to cleanly very cleanly put in the pattern that I put in now this one should be red this one should be Green Dot running against a background of red and so let's see if that is going to work could it really be that easy could it really be that easy I don't know I do need you guys to hold your breath and let's see what happens ah denied denied what is this I need to find pix size what is this nonsense ah case is important my friend case is important the real problem is one of of you guys out there one of you guys thought hold your breath business I don't have to hold my breath I think you know who it was you know who you are the one that didn't hold your breath and I will need you to hold your breath this time along with everyone else boom look at that so I'm going right to left and you can see that the green is going and then wrapping around and coming back and that is actually very very wonderful okay so guys thank you for holding your breath now what I said though was I wanted it to go back and forth and so really what I want to do now is I want to come in and I want to go backwards so I want to go forward and then I want to go backwards so now I'm going to say for I in range you might hear a dog downstairs yeah I got a new dog I'll tell you about that dog someday uh in fact I should have a live stream with my d new dog it's a it's a pretty fantastic dog it's a pretty fantastic dog okay so now I've gone forward I want to go backward so now I'm going to say for I in range and this time I want to go from pick size okay but you see I can't start at pix size because it would start at pix size which would be eight which is too big so I want to start at seven because the seventh position is the eighth one right as we talked about so I say pix size minus one which would be I start at s okay and now I need to go to zero and then I need to step in minus one like that and then I think this other stuff I think would be the same don't you I think it would be the same so let's go like that okay and so let's see if this will bounce back and forth bounce back and forth okay wow look at that boom Okay now what's the one thing that I don't like the one thing that I don't like is when it gets all the way over here it pauses because I'm writing that one twice because in this first for loop I go all the way up to pick size which means it's going to write the seventh position which is this number eight here okay it's going to write that one and then here where do I start I start at the seventh position okay I start at the seventh position so it writes the seventh one and it writes the seventh one it's so confusing when you start at zero so this is 0 1 2 3 4 five 6 7 which is the eighth physical one okay but I'm writing it twice and I don't want to write it twice because you see how it goes and then it pauses and that kind of annoys me so what I want to do is I want to I could adjust it in either one of these positions but it's the seventh one so what I want to do is I want to stop at pix size minus one which would really stop at pix size minus 2 because it's already stopping one before now it's going to stop one before minus one which would be minus two and now this time I think it should run smoothly so let's give that a look boom look at that so you see the thing is freewheeling now very very naturally very very naturally and so that looks really good you know what I think I would rather do though is I think I want a running red I want a running red on a green background and so I'm going to set everything to green and then I'm going to run it red now this might be interesting if I just did this because it's going to flip once it hits the end yeah you see it hits and it flips that's kind of neat I kind of like that okay but let's do it the way I really wanted to do it so I'm going to have the green back BR and then my pixel my running pixel is going to be a red pixel so let's see how that looks YY up I've got the runin red the runin red pixel I really like that some of you guys that used to watch The Night Rider I don't know that has a movie and you know he had those lights on his car that did things you could try to do some night rider type of stuff on here but I think I've shown you what you need to really go in and do some neat animations and if you want to get a long string of them in a separate power supply you could really really do some pretty cool and some pretty impressive things okay I want to give you one more homework I want to give you a couple more homeworks because these pixels you got to start taking all that stuff we've already learned you know how to do data structures how to animate things all that and I want you to be exercising those skills that we learned in earlier lessons on a new component which is the neopixel and so this is what I want you to do and so I'm going to come in and I am going to see if I can stop this okay give me just a second so I'm going to show you what the homework assignment is and the homework assignment is going to be the homework assignment is going to be let's see okay here you go boom what you can see is I am running the pixels all together through the colors of the rainbow very smoothly through the colors of the rainbow and I will kind of give you a hint on this you don't want to go in and just start making up a bunch of numbers and so I'm going to give you a little bit of a hint you know sometimes I think I give too much of a hint sometimes I think I give too much of a hint give me a second here okay sometimes I think I give you too much of a hint but what I am doing is if you look at that rainbow and man I wish you could see it in person because it's just so brilliant and Vivid and up here maybe if you just look at the little stars that are being formed in the camera you can see the colors more clearly but it is really a very very impressive and very uh brilliant thing that we are doing but what uh to give you just a hint here what I am doing is I am just running it around the HSV color wheel so I'm running it I'm running those pixels around the HSV color wheel and so now it is your assignment your homework assignment to go in and just run these pixels through the HSV color wheel okay guys I hope that you are having as much fun taking these classes as I am making them I am really really enjoying these uh these neopixel arrays I'm really kind of tempted to just deck my house out with like thousands and thousands of these uh of these LEDs and really uh really animate my house but I kind of live in an area that that might frighten people so I probably won't be uh I probably won't be be doing that but there's just all types of stuff you can think of some really really cool Christmas uh Christmas lights you might even kind of get started on getting your pixels and and and maybe Start program Pro programming them up for next Christmas also guys I want to really uh thank you guys who are standing with me on patreon you guys are the ones that are keeping me in the game and I appreciate your support want to thank you every week for that you can also help me by giving me a thumbs up on this video leaving a comment down below will also help you can also make sure that you subscribe to the channel when you do ring that Bell to make sure that you get notifications When Future lessons drop and most importantly make sure you share this video with other people because the world needs more people doing coding and fewer people sitting around watching silly cat videos poll morder with toptechboy do.com I will talk to you guys later
Info
Channel: Paul McWhorter
Views: 3,094
Rating: undefined out of 5
Keywords: STEM, LiveStream, TopTechBoy
Id: 7IvAQJfU908
Channel Id: undefined
Length: 17min 24sec (1044 seconds)
Published: Tue Jan 23 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.