DEV Community

Cover image for How to Use VSCode with Raspberry Pi Pico W and MicroPython
Shilleh
Shilleh

Posted on • Updated on

How to Use VSCode with Raspberry Pi Pico W and MicroPython

** The extension is now called MicroPico **

This tutorial demonstrates how to start coding on the Raspberry Pi Pico or Pico W using Visual Studio Code. Connecting to the Raspberry Pi Pico W in VScode can help you write and debug code more efficiently, and improve your development workflow for embedded systems projects. This integration can help you streamline your development workflow and reduce the time it takes to get your code up and running on the Raspberry Pi Pico W.

Step 1-) Install MicroPython on Pico

Plugin the device into the computer while holding the bootsel button.

Go to https://micropython.org/download/ and download the latest version for the Pico or Pico W

Drag the UF2 file onto your Pico once it is done downloading. *It should show up on your Desktop as RP1-RP2.

Once it is done, the RP1-RP2 will disappear.

Unplug and replug the Pico (without holding the bootsel). You need to do this so VSCode can find the device.

Step 2-) Download Pico-W-Go Extension

Make sure you have Python 3.9 installed on your computer. It is one of the requirements for the extension.

Go to extensions in VSCode and install the extension. Search β€œPico”. Note that it was previously called Pico-Go.

Step 3-) Write Code

Create a directory on your local computer, and open the empty directory on VSCode

Configure the Pico-W-Go environment. Run Pico-W-Go > Configure Project command via Ctrl+Shift+P (or the equivalent on your platform) VS Code command palette. This will import stubs for autocompletion and the settings into your project folder. For the auto-completion to work, the extension prompts you (after project configuration) to install recommended extensions mentioned.

Create a Python file in the directory and add the following code:

from machine import Pin
from time import sleep

pin = Pin("LED", Pin.OUT)

while True:
    pin.toggle()
    sleep(1)
Enter fullscreen mode Exit fullscreen mode

Make sure the Pico is connected (shown on the bottom of the screen)

Run the current file (by right-clicking the file name and selecting Run current file)

You should see the LED start blinking! If you did, congrats.

You can use other operations in the library, such as deleting all code on your device or downloading files from the Pico, which will help you develop your projects faster. Overall, developing on VSCode has several advantages over Thonny and may be your preferred IDE for developing on the Raspberry Pi Pico.

Conclusion
Hope I saved you some time, if I did please subscribe to the channel for more useful tips that will help you in your coding endeavors.

Top comments (8)

Collapse
 
hmwhse profile image
Frank

I tried to do this on Opensuse and I could not get it to work. The only pico extension I could find that mentioned the pi pico was micropico. For good measure I also installed Pico asm syntax highlighter, as I'm trying to use PIO. The problem is that VS won't connect to my Pico. It keeps telling me it can't find a COM port, not surprising as Linux doesn't have com ports. I've disabled the auto connect feature as it looks suspiciously windoze centric to me, and appears to be looking for a com port, and instead put the device address (/dev/ttyACM0) in the manual com (sic) device field. Still it won't connect. Is there something else I need to do?
Thanks.

Collapse
 
keeganevans profile image
Keegan Evans

If you are still having this issue or for anyone else encountering it, one thing that I have found that can cause it(besides any of the normal mis-configuration stuff), is not having an updated version of pyserial installed in the python-interpreter being used by VSCode. Check which interpreter is being used, then update pyserial(available via pip and conda). This might be in the docs somewhere, but it was not obvious to me when I first started encountering this issue.

Collapse
 
shilleh profile image
Shilleh

What version of Python do you have on your machine? Try upgrading that, think you need 3.9 or greater, there are a couple of other pre-reqs they list on their package, you can see more in the VSCode documentation. For a sanity check, you could go to Thonny and try to connect there first. Let me know what you get.

Collapse
 
hmwhse profile image
Frank

@shilleh thanks for the reply.
I have Python version 3.11 installed on my PC. I've logged off and restarted the system, but still no joy. The "connect" command returns an error message saying "connection to pico lost". Any other command returns a message saying "connect to pico first".
I've tried this on KDE Neon too (a debian based distro) and have the same problem, so it's not just Suse.
fwiw Thonny has no problem connecting to the pico (so it's not a hardware issue) and reports that it has Micropython V1.20.0 on 2023-04-26 installed. On both Suse and Neon.

:-\

Thread Thread
 
shilleh profile image
Shilleh

Hey Frank, it is honestly hard to tell without being on the operating system. Would love to hop on a call and debug with you if you like. Could be that the package is simply incompatible with that OS. If anything you could contact the people who maintain the package and I hope they would be responsive. Sorry about this but I lack expertise here as I never even heard of Opensuse before this comment.

Thread Thread
 
hmwhse profile image
Frank

@shilleh thanks for the reply. Thanks for the offer of a call, but it's not really a big deal, I use Thonny most of the time anyway. I was interested in using VS Code as I've used it before (using PlatformIO and C) and like it. So I thought it might be good for Micropython as well, but there are alternatives, like Pycharm and Eric7. I might have to give them a shot.
Opensuse is one of the biggest Linux distros, very popular in Europe. I think it was originally developed in Germany. Opensuse and Red Hat are the only commercially supported Linuxes I believe, and of course Fedora is the free version of Red Hat. So changes to Red Hat are released in Fedora first before they are released to their paying Red Hat customers, to make sure no disasters occur presumably...
;-)

Collapse
 
kalkwst profile image
Kostas Kalafatis

Heyo,

Would you please consider embedding your video here instead of just linking to it? This way folks can see your content and discuss things on DEV without having to navigate elsewhere.

You might not have realized, but DEV actually allows folks to embed YouTube & Vimeo videos via Liquid Tags. For instance, writing:

{% embed https://www.youtube.com/watch?v=dQw4w9WgXcQ %}

Creates:

By the way, here's a link to the editor guide where you can see other liquid tags and formatting options.

Hope this is helpful! πŸ™‚

Collapse
 
shilleh profile image
Shilleh

Thanks I did not realize that, let me edit the posts then