Week 4 · Session 2

Meet the Raspberry Pi Pico 2 W

Your code is about to control a physical object for the first time.

Not Quite a Computer

  • A laptop runs an operating system, and your program is one of many things it juggles
  • The Pico 2 W runs one program at a time, straight against the hardware, with nothing in between
  • When your code says "turn the LED on," that instruction is not simulated. It happens

What Is Actually on the Board

  • GPIO pins: General Purpose Input/Output. Each one can send or read an electrical signal
  • 3.3 volts is the signal level the board works in, not the 120V from a wall outlet
  • A dual-core processor at 150MHz runs your code
  • Flash memory keeps your program stored even after you unplug the board

The Built-In LED

  • Every Pico 2 W has one LED already wired to the board, no extra parts needed
  • from machine import Pin gives you the tool for controlling any pin
  • led = Pin("LED", Pin.OUT): "LED" is the name MicroPython gives this pin, spelled exactly that way, and Pin.OUT means your code controls it

On and Off Are Electrical, Not Metaphorical

  • led.on() sends 3.3V through the pin. led.off() drops it back to 0V
  • An LED only lets current flow in one direction, and lights up while it does

Making a Blink Visible

  • import time, then time.sleep(0.5) pauses your program for half a second
  • Without a pause, on and off happen faster than your eye can register, so it just looks dim
  • led.on(), time.sleep(0.5), led.off(), time.sleep(0.5) is a complete, visible blink

Try It: The Decision, Without the Hardware

This runs right here: the same if/else as Session 1, standing in for the real thing.

  • Change led_state to False and run again
  • On the actual board, print(...) becomes led.on() and led.off()

              

Install Now

One Extension: MicroPico

This is the only new thing to install. MicroPython is already on your board.

  • In VS Code: View, then Extensions
  • Search for MicroPico and install the one by paulober (its id is paulober.pico-w-go)
  • It sends a Python file from VS Code to the board and shows what the board prints back

Do This Now

Open Your Course Folder

MicroPico works inside a folder, so open the one you made in Week 2 before anything else.

  • File, then Open Folder, and choose cmpsc100
  • View, then Command Palette. Type MicroPico and choose MicroPico: Initialize MicroPico Project
  • Once per folder. New buttons appear in the bar along the bottom of the window, including Run and Pico Disconnected

Do This Now

A File to Test the Board

  • In the Explorer on the left, right-click activities, choose New File, and name it led_test.py
  • Type these three lines into it, then save
  • from machine import Pin
  • led = Pin("LED", Pin.OUT)
  • led.on()

Do This Now

Connect the Cable

  • The small end goes into the port on the Pico, the large end into your laptop
  • Use the cable from your kit. Some charging cables carry power but no data, and the board will never appear
  • The board itself shows nothing when plugged in. No light is normal
  • The bottom bar now reads Pico Connected. If it still says Disconnected, click it once, or unplug and plug back in

Session 3

Lab 2 Releases at Lecture Time

The usual 2:30 lab is the Alumni Panel this week (mandatory). Lab 2 posts Friday morning instead.

  • Three of its four stages use only the decisions from Session 1 and this board from today. Start with those
  • The tree line stage joins two conditions with or, which Monday covers
  • Bring your Pico box to the class session on Friday morning
  • Write your name on the box with a Sharpie before you leave today
← Exit
1 / 12