For most projects, you will want the Pico to be able to run without the need to be plugged into a computer. In this video, we go over how to do exactly that by uploading code to the Pico (and using the magical main.py), and learning how to power the Pico from other sources of power.

Transcript

So far, we've been running our Pico off of our PC, both by powering the Pico off of it, and by running code stored on the computer, but running it on the Pico. And this is fine when you're developing code, but most of the time your projects will need to run without a computer.

In Thonny, if your Pico is connected and the right COM port is selected, you're able to hit View, and then click Files. And you'll be able to see, on this top tab here, you'll be able to see your computer's files, and on this bottom tab, you'll be able to see the files stored on the Pico itself.

Now your Pico might be rather empty. Mine here is a bit chockers full of files from some previous projects. And all of these.py files are actually MicroPython code which we can open, exactly like if they were on a PC, except we're just kind of storing the files on the Pico like a USB stick. And as you can see, we can open up a file, we can edit it, work on it, save it, and put it back on the Pico.

Now if you see here, I have a file called main.py. And this is a very special name, as it's the file that the Pico will run automatically whenever it is powered on. For example, this USB is not plugged into a computer, just a phone battery bank. And if I plug it in, the LED RGB code works because I've saved it as main.py. And that's how we run code without the computer. You get it all written up, store it in main.py, and the Pico will always run that file if it's stored on it. If you want to edit the code, then you can do so by plugging in the Pico, go back into Thonny, open up main.py, edit it, save it, put it back. As long as it's called main.py, it's going to run it when it first gets powered on. Super easy.

Now we need to power it. And to do that, there are two common ways to do so. The first is the way we've been doing with micro USB. And the second is by connecting our power directly to vSYS.

Let's start with the micro USB, because it's probably the easiest to do. Very straightforward. Plug the micro USB into the Pico, and the other end into some sort of USB power supply, like a phone charger, one of those bricks that you plug into the wall, or a power bank like this. Any 5 volt USB power source that you can charge your phone off, you should be able to power your Pico off quite happily.

Something worth noting here is that while power banks are a really great way to easily power your Pico with battery power, they may have some issues doing so. Long story short, the Pico consumes a very, very small amount of power, and many power banks are designed to turn off if they don't sense enough power being drawn from them. It's just a power-saving thing. For example here, I've got my Pico plugged in, and if I plug in this, you can see that it powers on, and it's not detecting enough power being drawn, and it shuts off. And it's no longer supplying power to the Pico. Not all of these have that power-saving feature. And if your project draws a bit more power, you may be able to satisfy that power-saving requirement mode. Like this RGB LED here is actually drawing enough to keep it on. If you've got one lying around, just plug your project into it and see if it will keep it powered.

Another great way to power your Pico is with one of these. It takes three AAs, and it has a micro USB cable that you plug into your Pico, and the three AAs should happily output about five volts for your Pico.

So besides powering it via USB, we can power it through the V-SYS pin on the Pico. To do so, you're going to need a power source that can provide 1.8 to 5.5 volts, which might come in the form of some AA batteries, a solar panel, a LiPo battery, or a benchtop power supply, as long as it's between 1.8 and 5.5 volts. Then you plug the ground or the negative of your power supply to the Pico's ground, and then the positive terminal to V-SYS, and it should power up nicely.

Now there is something extremely important to remember here. Do not plug in USB power and V-SYS power at the same time, because you are most likely going to damage or destroy something. The voltages are probably going to be mismatched, and you'll have voltage backfeeding to a power source, and that's not good. Something will break or go bang. That's why we recommend when using V-SYS to power your project, you use a diode for an extra level of protection.

Here I am powering V-SYS, but between the positive of my power supply and V-SYS, I have put a diode, which only allows power to move in one direction. It creates kind of a one-way street for electricity. And if the diode is placed like this, I can safely power it with two power sources at the same time. I'd like to repeat, only with this diode here can you power it with two power sources at once.

Diodes are polar, which means they have a correct orientation. There is a line on one side of the diode. This is the cathode, and it must be connected to the V-SYS pin of the Pico. But what diode should you use? Well, a Schottky diode or a general-purpose rectifying diode should work as long as it can handle up to one amp of forward current. We have one linked in our course page on our website that is suitable for this application. Link in the description for our YouTube audience. This is only a recommendation, though. If you don't want to use a diode, you can do so if you wish. Just be extremely vigilant that you don't plug both power sources in at the same time.

For example, I've got it powered with V-SYS right now, and I want to update some code. So I'll plug it into my computer and open up Thonny. Oops, I accidentally forgot I've got both power sources plugged in at once by accident. And maybe my USB port on my computer is damaged. If only I had a diode to protect me from this exact situation.

So, three key takeaways. One, you can store files on the Pico and main.py is the code that the Pico will first run when it is powered on. Two, the Pico can be powered through micro USB and through V-SYS. And three, you cannot power the Pico through both of these power sources at once without a diode for protection.

Comments


Loading...
Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.