Pierwsze kroki z mikrokontrolerami na przykładzie PicoBricks (film, 21m)
Jeff Geerling w swoim najnowszym filmie zabiera widzów w fascynującą podróż do świata mikrokontrolerów, podkreślając, jak te małe chipy zarządzają naszą elektroniką, od zabawek po kompleksowe projekty. Geerling dzieli się swoimi doświadczeniami z dzieciństwa, które zapoczątkowały jego zainteresowanie technologią, porównując swoje pierwsze zestawy do nauki elektroniki z nowoczesnymi płytkami rozwojowymi, jak Raspberry Pi. Jednym z jego celów jest zainspirowanie młodych ludzi do eksperymentowania z elektroniką, a jednym z jego głównych punktów jest to, że nie trzeba być inżynierem elektrykiem, aby zacząć. Kluczowe jest, aby chcieć się uczyć i gotowym podejmować bezpieczne ryzyko.
W filmie widzimy Geerlinga w Dolinie Krzemowej, gdzie opowiada o swoim doświadczeniu w Muzeum Historii Komputerów, które omawia znaczenie przekaźników w historii technologii komputerowej. Zaznacza, że mimo iż przekaźniki są mniej wydajne w porównaniu do nowoczesnych tranzystorów, wciąż znajdują zastosowanie w inteligentnych przełącznikach i innych urządzeniach. Przechodząc do Micro Center, Geerling podkreśla różnorodność dostępnych tam zestawów do nauki elektroniki, takich jak Pico Bricks, Microbit i Adafruit Circuit Playground. Obiecuje, że zaczęcie programuowanie mikrokontrolerów jest prostsze niż kiedykolwiek, a wystarczy tylko chęć zabawy.
Geerling podaje szczegółowy przewodnik, jak skonfigurować Pico Bricks, korzystając z różnych modułów i komponentów. Pokazuje, jak tworzyć proste projekty, na przykład jak zaprogramować urządzenie, aby LED migał lub wyświetlał tekst na ekranie OLED. Zwraca również uwagę na ważność debugowania oraz nauki na własnych błędach, co jest kluczem do efektywnego programowania. Poprzez zabawę z kodowaniem i montażem, czuć rosnącą ekscytację, gdy zaczynają pojawiać się pierwsze odpowiedzi i reakcje na dane wejściowe z czujników.
Jednak nie wszystko jest takie proste – Geerling demonstruje bardziej zaawansowaną zabawę z kapacytorami, które po odpowiednim zaprogramowaniu można wykorzystać do eksplozji. Przyznaje, że dodał mechanizmy zabezpieczające w swoim kodzie, aby zapewnić bezpieczeństwo podczas eksperymentów. Opisując proces podłączania zasilania oraz uruchamiania programu, pokazuje krok po kroku, jak uzyskać pożądany efekt i jednocześnie przypomina, że tinkering w elektronice wiąże się z ryzykiem, ale również z ogromną satysfakcją, gdy wszystko działa jak należy.
Na zakończenie, Geerling podsumowuje statystyki wideo, które w momencie pisania tego artykułu ma 152139 wyświetleń i 6994 polubienia. To pokazuje, jak jego pasja do elektroniki inspiruje nie tylko dzieci, ale również dorosłych do rewizji swoich umiejętności i ponownego odkrycia radości z nauki przez zabawę. Geerling dodaje, że eksploracja mikrokontrolerów nie tylko rozwija umiejętności, ale również wzbogaca życie o nowe doświadczenia. Zachęca widzów do angażowania się w projekty, które mogą wydawać się skomplikowane na początku, ale przynoszą wiele radości i satysfakcji, gdy tylko zaczynamy się w nie zagłębiać.
Toggle timeline summary
-
Wprowadzenie do zdalnego sterowania zdolnego do wybuchów.
-
Wyjaśnienie mikrokontrolerów i ich powszechnych zastosowań.
-
Dyskusja na temat historycznych komputerów i przekaźników w Muzeum Historii Komputerów.
-
Wizyta w Micro Center w celu zakupu komponentów elektronicznych i mikrokontrolerów.
-
Przegląd zestawu projektowego PicoBricks i jego komponentów.
-
Demonstracja programu Hello World używając diody LED na PicoBricks.
-
Rozwój oświetlenia od zmierzchu do świtu przy użyciu czujnika światła.
-
Wyjaśnienie logiki kodowania do kontrolowania oświetlenia w zależności od poziomu światła otoczenia.
-
Wprowadzenie do projektu polegającego na przygotowaniu do wybuchu kondensatora.
-
Środki bezpieczeństwa i kodowanie do kontroli wybuchów kondensatorów.
-
Wgląd w mechanikę wybuchających kondensatorów.
-
Ostateczne przemyślenia na temat ciągłego kształcenia w zakresie majsterkowania i elektroniki.
Transcription
I made a remote control that explodes things. How? It's not magic. It's microcontrollers. These little chips run everything from toys to lightbulbs to robots. Even the most accurate clock I own, flip it over, there's a microcontroller. Two, actually. When I was a kid, it wasn't computers like the Raspberry Pi that got me into tech. It was this thing. Well, not exactly this one, but one just like it. It has 24 different electrical components. Then this book shows you how to build 50 different circuits. And this wasn't the only project board I had. This digital board has a logic chip at its heart, but it's millions of times less powerful than this modern chip. And this modern project board is like my old project kit, but on steroids. And programming these things is easier than ever. A lot of kids don't get the same exposure to electronics that I did. A lot of grownups don't either. So in this video, I'm going to help you get started with microcontrollers. And what's best, we can build a lot of projects without even touching a soldering iron. At least, not yet. Now, I was thinking, what better place to get inspired about microcontrollers than Silicon Valley? At the Computer History Museum, I checked out some of the earliest computers, like this relay switch? Steve Wozniak explained how even a simple switch like this was critical to the computing revolution. The simplest computer logic circuit is a light switch. You turn it on, the light goes on. You turn it off. Very similar to that are these devices down here called relays. You're not seeing very many real electronic parts. You're basically seeing batteries, relays, and a couple lights. And take that, and you multiply it, put it side by side ten times, you can add and subtract numbers up to a thousand. And that's basically the heart of computers. This was before vacuum tubes, before transistors, before chips. I'll link to that whole video below, but relays are still in use all over the world today. And I'm even using one each time I press this button. For computers, though, relays are pretty inefficient. Transistors can switch on and off like a zillion times faster. And you can cram in millions of them in a modern chip like this one. But relays are still useful, like they're in all the smart switches I installed in this studio. That's the click you hear when you turn one on through your phone. But there's another reason I came to Silicon Valley, and that's because Micro Center just opened their newest store here in Santa Clara. Some people think Micro Center's for, like, graphics cards and PC builds. And, yeah, I mean, just coincide, and it's pretty obvious that's a big part of it. But when I come to Micro Center, I head to this aisle. This is where they keep all the good stuff, like microcontrollers and electronics. Now, just to be clear, I've worked with companies behind a lot of the products you'll find in this aisle, so I'm definitely a bit biased towards, well, all of them. And I'm going to pick up Pico Bricks today, because that's the closest thing to that project board I had when I was a kid. But this isn't the only option for learning at Micro Center. I'd also recommend the Microbit or Adafruit Circuit Playground. The key is to pick something and start tinkering. All these boards require a separate computer to program them, and we'll get to that. But before I leave this area, I should pick out a few components for bonus experiments, like blowing up capacitors with this massive power supply. And I guess I should grab some safety glasses. But back to the computer. Micro Center has just a few of those to choose from. I'm going to grab a Chromebook because it's cheap and it works. But if you already have a computer, just use what you got. Now, I never studied electrical engineering, and to be good at this stuff, you probably should. But you don't have to be good. You just have to want to learn and be willing to take risks, safe risks. If you're with me on that, let's get started. So this is the base kit for PicoBricks. And in the box, it comes with a little instruction manual. And it comes in a nice little tray that keeps it off your desk and makes sure you don't short things out. But this is a Raspberry Pi PicoW, which has Wi-Fi built in and Bluetooth so that you can remotely configure it as well. But then there's a ton of modules around the outsides. The cool thing about this board is, after you're finished tinkering with it and learning how it works, you can actually take this all out and snap all of the PCBs apart. And you can take this Raspberry Pi in the middle and plug it in using little Grove connector cables. So you can just use the modules that you want for your project. You don't have to keep it all like this. It comes with a bunch of accessories like a USB cable to connect it to your computer, a little wireless remote control, some cables and a breadboard, and even a battery pack so you can run it remotely. And then it also has this nice little wooden stand that you can pop out and put together. So the first thing that you need to do is plug it into a computer or even any power supply. And this uses a micro USB port, and you plug it into your computer like so. Always flip it over because it's USB. And when it comes on, it comes into a demo mode from the factory. And the demo mode demonstrates all the different modules. It shows, and you can see the repeating pattern that's from the refresh rate on this OLED display. It shows some of the different sensors like the potentiometer, which you can turn up and down. This is a variable resistor down here. And then it has the light sensor right here, which if you cover it up, that light value goes down. And if you let go, it goes up. And then there's also the temperature and humidity on this little sensor down here. It comes with a remote that does different things depending on what buttons you press. It has an IR sensor here that takes the infrared signal from the remote and translates it through the processor into different things that can happen on here. So you can explore that if you buy one of these yourself, all the different functions. But we're going to get right into this. The first thing you do with any kind of hardware or software programming is a Hello World program. Just to make sure you have things plugged in correctly, you do something really simple like printing the words Hello World. In this case, I want to make sure I can make this red LED blink using my own software. And to do that, I'm going to use this online blocks-based IDE called Bricks IDE. But you could use something like MicroBlocks, too. The main thing is we want to make sure that everything's working and we can program the board. So the PicoBricks editor will let you do a little tutorial, but we're going to skip that and just get right into it. This is a block-based programming editor. So instead of writing code, which is hard, but we'll get there, instead of doing that, you can drag things over from here and build your own little application. Now, everything that we want to start on PicoBricks starts with basic, and then you drag PicoBricks at the top just to start your little project. This is saying, like, we have a PicoBricks board and I want to do something on it. The best way to get started with programming is just to do things and fail. And what I'm going to do right now is I'm going to see if there's a way I can turn on the LED. So it looks like there's a little thing here called Set LED On. I'm going to take that over here, and when you drag it around, you can just set it anywhere. But we want to put it on our PicoBricks because that's going to tell it to set it on. And if I click Run, it's going to tell me I'm not connected to a board. So it doesn't know that there's a board connected yet. You actually have to tell your browser, and I'm using Chrome right now, you have to tell the browser where the board is. So I'm going to click this button to connect, and then the board is connected in FS mode. You don't have to know what any of this means. It's just this is what you click to connect. And now it's connected to the board. And now if I click Run, it will send the code over to the board, and we have the LED on. That's great. So we know that this is all working, which is good, but we want to be able to do some other things. Like, for instance, I want to make the LED blink. I want to have it turn on and off, on and off. And I could go over to Bricks and just set this to Off. And then I could do it again and set it to On. But that's going to get really hard if we want to have it blink forever. So if we want to have it blink forever, there's actually a special thing in here for that inside of loops. And most programs that you make for microcontroller will have a loop, the main program loop, and most of the time it's forever. You just want something to happen forever, like it reads sensors and reacts when something happens. So I'm going to drag that up here and put it in underneath PicoBricks, and I'm going to have it set LED on, but I also want to have it turn off and then turn back on. So I'm going to take another thing under loops. It's the wait. So this is going to tell it to wait for a certain period of time, one second in this case. And you could put in one second. You could put in .5 seconds, or you could put in 10 seconds, whatever you want. I'm going to do one second, so wait one second. And then I'm going to set the LED off. And if I run that, the LED stays on. What happened here? Well, this is the joy of programming, is debugging what you expected to happen from what's actually happening. What's happening is it's turning on the LED, it's waiting a second, it's turning off the LED, and then it goes right back to turning on the LED. But microcontrollers are very fast, so it's actually doing that in like a microsecond. To our eyeballs, we just see the LED staying on. We want to have it turn off for a second. So I need to add another wait. So I'll grab it out of here, put it in there, wait one second. And now, if we click run, it will blink the LED on for a second and off for a second. So that's all well and good, but I also want to make the screen say hello world. If you look around in this menu, you'll find display. And these are the controls for displaying things on the screen. And if I just grab this write text to screen right here at the beginning before the loop starts, and if I put hello world, and if I click run, it's not actually going to display it. And that's because there's a little weird thing about OLED screens like this where you have to say, I want to write this text, and then I also want to flush that out to the screen. There's a lot of things in programming that you learn after doing it a bunch of times that you have to do to make sure that something works correctly. So if I do this, show the screen buffer, and then click run, now it says hello world. It's also a good idea if you're going to show something on the screen to clear the screen buffer before you start showing it, because if you don't do that, sometimes the things just kind of pile up on the screen. So whenever I'm writing to the screen, I usually put clear screen buffer, the thing that I'm writing, and then show screen buffer. And now we have our first hello world with a blinking LED. Hello world projects are just for getting started. Sometimes if you have problems setting things up, just getting an LED blinking can feel like a pretty big achievement. But I want to do something more practical, now that I know I can get this thing programmed using my own logic. This board comes with all kinds of modules, including a light sensor and an RGB LED. I think it would be fun to make my own dusk to dawn light, so I'll show you one way to do that right here. Starting off the same way, I'm going to drag PicoBricks out here, and this time I need to get the light sensor value. And before I can do anything with it, I need to know what that value is. When I don't know what something is, I like to debug it. So I'm going to get the value and print it somewhere so I can see what it is, so we can react to it and do things with it. So if I go over to bricks, I can go down here and there's read light sensor. So that's going to give me the information. But if I drag this around, I can't really do anything with it right now. I need to be able to get this information and print it somewhere. And there's a cool little thing down here called a serial monitor that monitors data coming back from the Raspberry Pi Pico, and will print it on the screen here for me to see. So I'm going to try to get this data and print it on the serial monitor. And if I go to basic, there's a thing down here called serial print. And if I drag that up here and drag this read light sensor into the little box here, now I can click run, and it's going to print the data from that sensor. But it only prints it one time. I want to get the data over time so I can see what happens when I hold my hand over the sensor. So again, I'm going to go to loops forever and drag it in here. And now if I click run, it'll be printing all this data. Now an interesting thing is that if you do this without any kind of pausing, sometimes the data gets a little confused. And that's what you're seeing here, all these random numbers. So I'm going to go into loops and add in a wait. And I'm going to have it read the data, we'll say every half second, so 0.5 seconds. And if I click run now, every half second it's going to print out the value of the light sensor. And you'll see as I hold my hand over it, the value goes up. If I let go, the value comes back down. So now we know when it's bright, it's in the 900 range. And when I cover it up, it goes over 2,000 to 3,000. So we can use that value in our code to say when it's over 2,000, it needs to turn on the light because it's dark. And if it's under 2,000, it can leave the light off because it's bright. So I'm going to hide the serial monitor for now because we don't need to see that data. But I'm going to leave this in here so that we can do things with it if we want. To be able to react to different conditions, I'm going to use some logic and say, if one thing happens, then do this. If something else happens, then do that. So I'm going to take this if else conditional and put it in right here underneath the serial print. And I'm going to say if the light sensor is above 2,000, then turn on the LED. And if it's not that, then turn it off. And to do a comparison, that's also under logic. And we can say if something is something, so I'm going to drag this here. I'm going to grab another light sensor reading right here and put it in here. So if the light sensor is greater than, greater than, and then I'm going to grab a number from math and put it here. And we'll just say if it's greater than 2,000, then we want to turn on the RGB LED. And that's under this section, RGB LED. We'll just set the color to white. And then if it's not over 2,000, so if it's bright already, we want to turn it off. And we want to explicitly make sure to turn it off. Otherwise, it's just going to stay on white all the time. So again, go to RGB LED. And then we'll set the color to black so that it turns it off. You could also clear the color if you want. There's usually multiple ways to do the thing that you want to do. And I'm going to make this loop run a little faster. So instead of every half second, we'll have it every tenth of a second. So every 0.1 seconds. And if I click Run, and I can monitor with the serial monitor. So right now it's bright enough that the LED doesn't turn on. But if I hold my hand over the light sensor, the light turns on. So we just made our own little dust to dawn light using this board. The way this thing works is there's an LDR, or light-dependent resistor. You might be wondering why the value goes down when there's more light, and it goes up when there's less. Well, with more energy in the resistor from extra light photons hitting it, the resistance goes down. When you remove some of the light by, like, covering it up, there's less energy in it, and the resistance goes up. That's how we can get a numerical value in our code to react to for how much light there is. If you want to get fancy, you can start adding in functions, and play with some math like I did here. That way we can print the light level on the screen and make the project a little easier to use. But going from this working prototype to production takes a lot longer because if you go buy an off-the-shelf dust to dawn light, it usually doesn't just pop on and off a bunch at dusk, or if someone, like, shines a flashlight on it at night. The world is never perfect, especially with analog circuits like this, so you have to program around it. And sometimes you get things wrong. That's okay. I spent some time making this project better and redoing it all in MicroPython, so let me know if you want to see how that works in a follow-up. But I want to get back to the remote control explody thing I showed at the start of this video. Like I said, it's not magic, but to show you how I did it, I'm going to build the setup here at the store. I need to set up the power supply, which is a little big and bulky, but it'll give us enough power for a satisfying pop. Then I'll hook it up to the breadboard and the relay on the Pico bricks. Oh, did I mention MicroCenter sells the whole lineup of iFixit tools, too? It's great for these projects. And then, of course, safety first. We're working on our eye and ear protection. So what are we working on here? Oh, I'm going to blow up this capacitor. You can't do that here. I'm sorry. Okay, so I'm back in St. Louis, and I'll show you how it works here, starting with this little itty-bitty guy. First of all, make sure you turn off power before you insert the capacitor. And second of all, let's code something in the microcontroller to make sure this thing's a little bit safer. So this turned out a little more complicated than the other examples, but basically there's the main forever loop over here. I broke out the two most important parts into these two functions. First, until I press the button, it runs the arm message function. This kind of sets the board up by giving instructions on the screen. Press the button to arm. Once you press the button, it sets a variable named armed to 1. And then, over in the main program loop, if that variable is 1 or true, it does all this stuff, and it waits for the asterisk button to be pressed on the remote. Why that button? Because it looks like a tiny explosion, and I thought that was funny. But now if I press that button and point the remote at the board, it will run the popcap function. And that, well, it pops the cap. But for this function, I actually spent some time debugging how long I should leave the relay on. If I leave it on too short, some of the capacitors weren't popping. And if I leave it on too long, some capacitors might short out and maybe cause other problems like fire. So first, don't try this at home. But second, an important part of coding is debugging and fixing things. The first 10 or maybe sometimes even 100 times you try something, it's going to have problems. And even this code will run into problems. That's just how things are. But you only fail if you don't learn something every time you get it wrong. And what I learned is I need a couple safety mechanisms on this board to make sure I can control when it explodes. Okay, now when I plug this thing in, it won't blow right away. I have to press the button to arm it. And then, and only then, I can press this little button. Ah! Always stand a safe distance away. And don't breathe in that smoke. Now, why do I have this giant power supply? Well, to get enough current, I can't rely on the USB port coming from the computer. USB might only give me like 600 milliamps, and that's not enough to make those things pop. So we have the power supply plugged into the relay, the relay into the capacitor, and then the other part of the power supply into the other leg of the capacitor. And not all capacitors explode. Some of them don't even budge. Other ones just vent gases through the top. That's what these little creases are for. Oh, and the gas that explodes? That's hydrogen. So in essence, I've just made the world's smallest hydrogen bomb. Not really, but you know the most exciting thing about exploding stuff is you get to see what's inside. The can that holds everything together, it actually went somewhere in here. I don't know exactly where. And these little flat bits of metal are just little strips of aluminum foil. The foil pieces get wrapped around each other with a kind of fabric between them to keep them from shorting out. Here, I have what one looks like before you explode it in this open circuits book. But on mine, the fabric is missing. It's all over the pico bricks, it looks like, and hopefully not too much in my lungs. So hydrogen gas, explosive fabric, and a tiny little metal cap going off like a bullet. Yeah, maybe it's a good thing I didn't do this back at Microcenter. But what if we go bigger? Now, I'm not going to blow this thing. At least not today. Those little capacitors are rated for like 16 or 25 volts. This one? This thing's used to tune RF signals, and it can take 30,000 volts. If you like the look of this thing, check out Gearling Engineering, where we explore high-power RF. And if you want to see some caps blows that are smaller than this, but a lot more dangerous than the little guys, check out this video by Seaskirt. And if you want to learn more about how capacitors work, check out this video by Electroboom. And finally, if you want to see capacitors blowing up in slow motion, check out this video by the Slow Mo Guys. One of the most important things I learned from all my tinkering, always be learning. I'll leave a few other links for YouTubers to follow if you want to dive deeper into microcontrollers and electronics. If you live near a microcenter, come check out the Maker Owl. Until next time, I'm Jeff Gearling. I may have been using one each time I pressed this button. Well, that was a dud. Ooh, it still smells.