Skip to content

Raspberry Pi Pico W MPU6050: Install libraries in VSCode | ShillehTek

December 01, 2023

Video Tutorial

Watch first if you want to follow the full VSCode workflow for installing and using third-party MicroPython libraries on the Raspberry Pi Pico W.

If you need the editor setup first, watch Part 1 below.

Project Overview

This tutorial shows how to use Visual Studio Code (VSCode) with a Raspberry Pi Pico W in MicroPython to install and use a third-party library for an MPU6050 accelerometer/IMU, so your project can import the module and run normally.

The key idea is to find the library (often on GitHub), download the required files (for example, imu.py), place them in a lib folder on the Pico W, and then upload the project.

You can download an interactive version of this project on Razzl, code included: https://www.razzl.com/

Where to Donate to Shilleh: https://www.buymeacoffee.com/mmshilleh

  • Time: 10 to 20 minutes
  • Skill level: Beginner
  • What you will build: A working VSCode workflow to add third-party MicroPython libraries to a Pico W project (example: MPU6050 IMU)

Parts List

From ShillehTek

External

  • Raspberry Pi Pico W - the MicroPython board used in this workflow
  • Visual Studio Code (VSCode) - the editor used to manage files and upload to the Pico W
  • MicroPython firmware for Pico W - required to run the code and import libraries
  • GitHub - common place to find MicroPython libraries (for example, an MPU6050 imu.py file)

Note: Many MicroPython libraries are distributed as .py files (or small folders). The Pico W typically looks for imported libraries in a lib folder on the device.

Step-by-Step Guide

Step 1 - Get setup with VSCode

Goal: Make sure your VSCode environment is ready to work with the Raspberry Pi Pico W in MicroPython.

What to do: Follow the Part 1 video to set up the editor on your local computer and connect it to your Pico W workflow.

Expected result: VSCode is set up and you are ready to add files and upload a project to the Pico W.

Step 2 - Find the library you need on GitHub

Goal: Locate the correct third-party package files for your MicroPython project.

What to do: Search online for the library you need. Many MicroPython packages are hosted on GitHub.

In this example, an MPU6050 accelerometer requires an IMU file so you can import the MPU6050 object in your code.

One approach is to search for: "mpu6050 micropython imu.py", then download the required file(s) from the GitHub repository.

Expected result: You have the needed .py library file(s) saved locally and ready to copy to the Pico W project.

Step 3 - Create a lib folder on the Pico W and copy the files

Goal: Put the third-party library files where MicroPython on the Pico W can find them.

What to do: In VSCode, create a folder named lib on the Pico W. Drag the downloaded library file(s) into that lib folder.

This is the folder where the Pico W looks for library files.

Expected result: Your Pico W has a lib directory containing the third-party library file(s) needed by your project.

Step 4 - Upload the project to the Pico W and run

Goal: Run examples or your own code that depend on third-party libraries from within VSCode.

What to do: Upload the whole project to the Pico W (including the lib folder and any library files you added), then run your code.

Expected result: Your MicroPython project runs in VSCode on the Pico W and can import and use the third-party package.

Step 5 - Optional: try upip, but prefer known-good library files

Goal: Understand an alternative method and why it may not always work reliably.

What to do: You can try the upip command, but some libraries are not well maintained, and not all libraries are available via pip-style installs.

When possible, download the latest version yourself and drag it onto the device as described above.

Expected result: You know when to use manual library placement versus relying on upip.

Conclusion

You now have a repeatable way to use VSCode with a Raspberry Pi Pico W in MicroPython while adding third-party libraries (like an MPU6050 IMU module) by downloading files from GitHub and placing them in a lib folder on the device.

Want the exact parts used in this build? Grab them from ShillehTek.com. If you want help customizing this workflow for your product, lab setup, or a client project, check out our IoT consulting services.