In this project, you’ll learn how to programme a Raspberry Pi Pico using MicroPython by connecting it to another computer.

It is a microcontroller with a low price tag. Microcontrollers are little computers, but they lack huge amounts of storage and auxiliary devices to which they can be connected (for example, keyboards or monitors).

Use digital inputs and outputs

Parts required

  • Resistor between about 50 and 330 ohms
  • an LED
  • pair of M-M jumper 
  • Raspberry Pi Pico

Schematic diagram

Connecting LED with Raspberry PI Pico
Connecting LED with Raspberry PI Pico

In this example, the LED is connected to pin 15.

Run your program and your LED should start to blink. If it’s not working, check your wiring to be sure that the LED is connected.

Next, let’s try and control the LED using a button.

Digital inputs and outputs in raspberry pi pico
Digital inputs and outputs

The button is on pin 14, and is connected to the 3.3V pin on your Raspberry Pi Pico. This means when you set up the pin, you need to tell MicroPython that it is an input pin and needs to be pulled down.

CODE

from machine import Pin
import time

led = Pin(15, Pin.OUT)
button = Pin(14, Pin.IN, Pin.PULL_DOWN)

while True:
    if button.value():
	    led.toggle()
        time.sleep(0.5)
from machine import Pin, Timer
led = Pin(15, Pin.OUT)
timer = Timer()

def blink(timer):
    led.toggle()

timer.init(freq=2.5, mode=Timer.PERIODIC, callback=blink)

You can also check on

author avatar
arathy j