If you’re looking for a way to get started with programming, the Raspberry Pico W and MicroPython is a great option. MicroPython is a lean and efficient implementation of the Python 3 programming language that is optimised to run on microcontrollers. The Raspberry Pico W is a tiny computer that measures just 51mm x 21mm.
Despite its size, the Pico W is powerful enough to run MicroPython and even has WiFi and Bluetooth connectivity built-in.
With MicroPython, you can learn how to write code to control the Pico’s GPIO pins, blink LEDs, create games, and even build robots 🙂 Lets get started!
What is MicroPython?
MicroPython is an increasingly popular programming language that is largely compatible with Python 3 but optimized to run on a microcontroller.
The programming language is easy to get started with if you are already familiar with Python and perfect for getting started with working with controlling electronics and microcontrollers such as Raspberry Pico and Pico W.
Here is a good explanation of the basic differences between Python and MicroPython:
What is Raspberry Pico W?
Raspberry Pico is a microcontroller that makes it easy to control different types of electronics. Pico W is a newer version based on the pi’s RP2040 chip that arrived in 2022. W stands for Wireless and the device has both wifi and bluetooth.
The low price and simplicity make the device perfect to get started with for beginners in “physical computing”.
The easiest way to start working with the Pico W is to push the board’s pins down into a breadboard. This means that you can immediately get started with connecting electronics to the card.
Get started with MicroPython
To get started with MicroPython, you must first install the Python programming language on your computer.
Download Python: https://www.python.org/downloads/
Tutorial for Installing Python on Windows:
Install Python on mac:
Install Micropython on Your Pico W
To install MicroPython on your Pico W, you can follow the instructions on the Raspberry Pi website:
NOTE: be sure to download the latest UF2 file for Pico W and not the one for Pico:
After you’ve finished installing MicroPyton, it’s time to install a text editor/IDE.
Install the Editor/IDE for MicroPython
An IDE, Integrated Development Environment (an: Integrated Development Environment), is an application that contains a text editor, compiler, debugger and a number of other functions that facilitate programming and testing.
Here in MicroPython, we will work with Thonny, which can be downloaded here: https://thonny.org/
“Hello LED” in Micropython and Raspberry Pico W
1. In the editor, enter the following code:
import machine import time led = machine.Pin("LED", machine.Pin.OUT) led.on() time.sleep(1) led.off()
2. Save the file locally on your computer as hello.py
3. Connect your pico at the bottom right corner of Thonny
The coupling should look like the following in the shell and the device should be visible at the bottom right corner:
4. To run the code, click on the green play button in the menu at the top left.
5. When you run the code, the built-in LED should light up for one second.
Tutorials and Courses
There are a lot of good tutorials to get you started with MicroPython and Pico W. Many tutorials are for the “regular” and older Pico and can be easily adapted to W as the cards are quite similar.
Here I have made an adaptation of peppe80’s led / switch button tutorial to be able to use the Pico W’s internal led instead of an external led.
import machine from machine import Pin buttonPIN = 16 button = Pin(buttonPIN, Pin.IN, Pin.PULL_UP) led = machine.Pin("LED", machine.Pin.OUT) def get_button(): return not button.value() def button_press_function(): led.on() def button_released_function(): led.off() while True: if get_button() == 1: button_press_function() else: button_released_function()
There are also other tutorials made specifically for pico w, for example this one where you learn how to connect to WIFI:
Use Your New Skills in Micropython
The MicroPython Challenge:
Create your own simple program that takes in data from any sensor and sends back a response that changes depending on the inputted data.