This guide will walk you through the process of setting up Visual Studio Code (VS Code) for programming the Raspberry Pi Pico W using the MicroPico module, and then driving RGB LEDs (e.g. WS2812B). The Raspberry Pi Pico W is a microcontroller board with built-in Wi-Fi capabilities, and the MicroPico module allows you to program it using MicroPython.
RPi Pico W pinout
All electronics will be explained in a futur post.
Short walks through MicroPython environment from installation to testing the onboard LED.
.uf2
firmware file onto the mounted storage device.Ctrl+Shift+X
.
RPi Pico W pinout
Ctrl+Shift+P
and then “Initialize MicroPico project”Ctrl+Shift+P
..py
extension in your project folder.Ctrl+Shift+P
) and type “MicroPico: Upload and Run” to upload and run your script on the Pico W.
Run
Terminal shows up
Ctrl+Shift+P
) and type “MicroPico: Serial Monitor”.Here is a simple example of a MicroPython script to blink an onboard LED:
import machine
import time
# Initialize the onboard LED
led = machine.Pin("LED", machine.Pin.OUT)
# Blink the LED indefinitely
while True:
led.on()
time.sleep(1)
led.off()
time.sleep(1)
The folowing code provides another way of driving the led by setting a timer (newbies)
import machine
import time
# Initialize the onboard LED
led = machine.Pin("LED", machine.Pin.OUT)
# Create a Timer object
timer = machine.Timer()
# Define a function with timer as parameter
def toggle_led(timer):
led.toggle()
# Initialise the timer to call the function *toggle_led*
# *period* in milliseconds
# *mode* calling the function periodically (vs one shot)
# *callback* the function to be called
timer.init(period=200, mode=machine.Timer.PERIODIC, callback=toggle_led)
def main():
print("Hello, world!")
while True:
... # do what you want
# Call main function
main()
You can find it here
LED
Here is an example on how to drive the RGB stripes.
# Setting the GP0 pin (#1 on the RP2040's connector)
pin = machine.Pin(0)
# Setting the number of stripes
ledQty = 2
# Create a strip object
strip = neopixel.NeoPixel(pin,ledQty)
# set color BRG (24=3*8 bits)
b = 30
r = 30
g = 0
strip[0] = (b, r, g) # type: ignore | purple
b = 0
r = 30
g = 30
strip[1] = (b, r, g) # type: ignore | yellow
strip.write()s
RGB first colours
# Do something completly random (what? it's my code!)
while True:
time.sleep_ms(20)
b = b+10
g = g+5
if b > 80:
g = g+10
strip[0] = (g,30,15) # type: ignore
strip[1] = (0, b, g) # type: ignore
strip.write()
RGB random
At this stage, all components have not been selected. Details regarding the electronics will be outlined in a separate post. The next one will focus on how to run an HTTP server on the Pico, and drive the LED via the server. For more information, please see: https://github.com/mekiisupertramp/wallframe/blob/main/rgb.py