Intro to Raspberry Pi Pico and RP2040 - MicroPython Part 1: Blink | Digi-Key Electronics

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
raspberry pi has been a renowned name when it comes to single board computers in january raspberry pi created quite the stir by releasing its own microcontroller the rp2040 along with a development board known as the raspberry pi pico the rp2040 is a fascinating little chip and i'd like to show you how to get started there are plenty of ways to interact with this chip but let's start with micro python since it should be the easiest in some future episodes i'll show you c and c plus plus for those of you who want to work a little closer to the bare metal finally i'd like to show you how to lay out your own board for the rp2040 using of course keycad let's jump in [Music] head to raspberrypi.org and click on hardware then click on pico and get started here you can find all of the data sheets and getting started guides the rp2040 is an impressive chip but what i find even more impressive is the quality of the raspberry pi documentation all of the docs are easy to navigate and read so definitely check these out if you want to learn more about the chip and the pico board head to the micro python section note that while the pico is capable of running other languages like circuit python and rust the raspberry pi foundation officially supports micro python and c c plus to run micropython on the picot we need to first install special firmware click to download the uf2 file to upload the firmware we need to put the pico into bootloader mode press and hold the boot select button while plugging in the usb cable that's connected to your computer you should see the pico enumerate as a rpi dash rp2 drive on your computer copy the uf2 file that you downloaded and paste it into the top level of that drive after a moment the pico should automatically reboot it's now running the firmware that lets you use the micro python programming language don't worry you only have to do this once at the beginning or if you need to update the firmware whenever a new version gets released here's the interesting part the raspberry pi was originally intended to be used as a low-cost desktop replacement running linux as such new versions of raspbian are now being shipped with all of the tools to program the pico out of the box this can give you a ready-made single board computer and microcontroller experience but for those of you who want to program the pico from your own computer i'm going to show you how to do it on windows i'm sure the process is very similar on mac os and linux right now raspberry pi officially recommends thony as the ide of choice for getting started with micro python on the pico so let's head to thawne.org and download the installer for our operating system run it and accept all the defaults when it's done installing open thawney you'll notice that it's a very simple editor it's meant to be much like the arduino ide but for micro python it's very easy for beginners to navigate and use at the bottom right you should see the target listed i have python installed on my computer so it shows up here if i click the button you'll get a list of the available target platforms make sure your pico is plugged in otherwise you won't see these listed click micropython for raspberry pi pico this should cause a new interactive environment to start in the shell tab at the bottom of the ide this is a very simple command shell known as repl or read evaluate print loop that runs on the pico when we install the micro python uf2 firmware we can interact with this the replica port via usb let's try a simple python command type print open parentheses double quotation mark hello double quotation mark and close parentheses and then press enter you should see hello echoed back to you micro python uses many of the same commands as python 3. some of the standard python libraries won't run on such a small device so micro python does not support everything you can use rebel to try out various commands before you create your program now let's make a simple hello world program that will execute on our pico in the top part of thoni enter import you time u time or potentially mu time or microtime is similar to the time module in big python but it's been paired down to work with microcontrollers next enter while true colon this is our main while loop that will run forever on the pico press enter and thawni will automatically indent the next line if you haven't worked with python before note that indentation matters we don't have curly braces to enclose sections of code under loops and if statements so we rely on indentation everything at this one tab level of indentation is considered to be part of the while loop now enter print open parentheses double quotation mark hello comma world exclamation point if you wish double quotation mark close parentheses which is just like the print statement we saw earlier this will print out hello world over the serial connection under that type utime dot sleep open parentheses 1.0 close parentheses this calls the sleep function in the u time module which will delay the processor for the given amount of time in seconds it works with floating point numbers so we can enter 1.0 to mean one second click the run button and you'll be asked where you would like to save the file we want to run it on our pico so let's click that button the pico has a small file system that allows us to save python programs and modules to use as libraries you can name the file anything and still run it from thoni however if you name the file main.py in the top level directory it will automatically run every time the pico is rebooted so i'll name it that click ok and the program should start running printing hello world to the console once per second note that right now the program is only saved to the pico board i highly recommend clicking file save as and saving a copy of your work to your computer in case you accidentally overwrite it on your pico i'll name it hello.py as the name does not need to match the file name on the pico at the moment the pico is looping in our program to do anything else with the pico we need to stop the program you can either click the stop button or press ctrl c to end the program and return to the reply now i can click on file open pico to view the files in my pico note that this is a very simple file browser i can right click on files to delete them or i can right click to create a new folder this will be important later for creating libraries back in main.py let's blink an led we'll import the machine library at the top machine is a standard module that's found in most micro python applications you don't need to explicitly import it on the pico but i like to do so here as a reminder that we're using it note that i can create comments with the hash mark anything after that symbol on the line is a comment before our while loop let's create an led variable which will be a handle to our pin object we call pin from the machine module and tell it which pin we want to use and that we want to configure it as an output the raspberry pi pico datasheet has a great pin out of the board on page five the onboard led is attached to gp25 which is why we use 25 for our pin number back in our code let's change the while loop to flash the led we'll remove the print statement and add led dot value open parenthesis 1 close parentheses this calls the value method function in our led object which is a digital write 1 means turn on or change the pin voltage to 3.3 volts we then sleep for 1 second and call led.value again this time we pass it zero which means turn the pin off or set the voltage to ground finally we sleep for another one second let's run this on our pico you probably will not be asked to save it again as it's already saved as main.py on the board however you're welcome to save it to your computer with a different file name like blinky.py you should see the green led on the pico board happily flashing on and off each second i hope this has helped you get started running micro python programs on your raspberry pi pico remember that at this time it's still a fairly new board so it may not work with some of the random micro python examples you find out there on the internet but on the next episode i'll show you how to grab some random code in this case a module load it into your program and use it to read temperature data from a sensor over i squared c stay tuned [Music] you
Info
Channel: Digi-Key
Views: 7,113
Rating: undefined out of 5
Keywords:
Id: JCk9QaCH5QU
Channel Id: undefined
Length: 9min 25sec (565 seconds)
Published: Mon Apr 12 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.