Raspberry Pi Pico, MicroPython and GPIO for beginners board
We designed this PCB to assist you with the MicroPython introduction tutorial found on Raspberry Pi Foundation projects. We will be directing you with links to the different sections of the Raspberry Pi Foundation’s introduction while supplying the code and a few fun projects on our page right here.
At the end of the tutorial we’ll be including some webpage projects. You can find their webpage here. Make sure you have a Pico W available for these projects. You will have one if you ordered our beginner’s kit.
What you will need to complete the projects:
(Most of what you’ll need is available in kit form )
- Raspberry pi Pico W
- PiShop’s MODB beginners board (Also available in a kit)
- 11 x Female to Female jumper cables
- USB A to micro B cable
- 2 x AA battery box with switch
- A laptop or PC
- Internet connection
Project Pinout (Board – Pico)
Use your female to female jumpers to connect the board to your Pico as per the below pin-out notes. Remember it is always advisable to unplug power from your Pico before making any changes to your GPIO cables.
RGB
Pin1 – Pico pin 2 (GP1) – Red
Pin2 – Pico pin 4 (GP2) – Green
Pin3 – Pico pin 5 (GP3) – Blue
LED’s
Pin4 – Pico pin 9 (GP6) – Red LED
Pin5 – Pico pin 11 (GP8) – Yellow LED
Pin6 – Pico pin 17 (GP13) – Green LED
Buzzer
Pin7 – Pico pin 7 (GP5)
Button
Pin8 – Pico pin 24 (GP18)
Potentiometer
Pin9 – Pico pin 36 (3V3)
Pin10 – Pico pin 31 (GP26)
Pin11 – Pico pin 33 (GND)
After connecting your jumpers you’ll have to install Thonny on your laptop or PC. You will find instructions here after which you have to add the MicroPython firmware.
Make sure to install the picozero library as a Thonny package
Resistors
Resistors are used in circuits to reduce the flow of electrical current. Certain components, such as LEDs, can break or have a reduced lifetime if too much current flows through them. You will find more info on resistors here.
LEDs
When using LEDs with a Raspberry Pi Pico, you should use a resistor of around 100Ω (say Ohms). Any resistor from 75Ω-220Ω will work. For this project we opted to use 220Ω and 330Ω resistors. A future update might make use of only 220Ω resistors.
You will find the LED tutorial here and the code below.
from picozero import LED
from time import sleep
green = LED(13)
green.on()
sleep(2)
green.off()
Well, we do have a green, yellow and red LED on the board so let’s get some traffic light action going… When you run (F5) the below code you’ll have the three LEDs play the role of a traffic light. We have created a loop here that will run until we stop it manually . Ctrl+F2 will stop the app or click the STOP button in Thonny
from picozero import LED
from time import sleep
green = LED(13)
yellow = LED(8)
red = LED(6)
while True:
green.on()
sleep(2)
green.off()
yellow.on()
sleep(1)
yellow.off()
red.on()
sleep(2)
red.off()
Did you notice on the tutorial that you have commands to blink or pulse the LEDs? You can have lots of fun with these little lights. Think mini town/railroad project.
Below is an example of blinking. This will blink the Red LED 3 times.
from picozero import LED
from time import sleep
led = LED(6) # Red LED
print("Blinking")
led.blink(on_time=1, off_time=0.5, n=3, wait=True)
RGB LEDs
These LEDs produce a range of colours by combining Red(R), Green(G) and Blue(B) light.
RGB LEDs have 4 legs rather than two. Our projects use common cathode RGB LEDs which means one leg needs connecting to a GND pin and the other three legs need connecting to GPIO pins. RGBs are available in transparent and diffused. You can follow the tutorial here.
from picozero import RGBLED
from time import sleep
rgb = RGBLED(red = 1, green = 2, blue = 3)
while True:
rgb.color = (255, 0, 0)
sleep(0.5)
rgb.color = (0, 255, 0)
sleep(0.5)
rgb.color = (0, 0, 255)
sleep(0.5)
Try manipulating the colours by changing the values in brackets as per the below code. Can you notice any changes?
while True:
rgb.color = (255, 255, 0)
sleep(0.5)
rgb.color = (0, 255, 255)
sleep(0.5)
rgb.color = (255, 0, 255)
sleep(0.5)
Buzzers
There are two main types of buzzers, an active buzzer and a passive buzzer. An active buzzer always plays the same tone. A passive buzzer can play a variety of tones. It requires a connection to be made and a specific signal to play the chosen tone. We use an active buzzer on our beginner board. You can have a look at the passive buzzer tutorial here or continue to the below code to use the active buzzer on our board
from machine import Pin
from time import sleep
buzzer = Pin(5, Pin.OUT) # create output pin on GPIO5
buzzer.on() # set pin to "on" (high) level
sleep(2)
buzzer.off() # set pin to "off" (low) level
You should have heard just a plain boring beep sound for 2 seconds. That beep can be very useful in projects to indicate an error or some other result.
Buttons and switches
The Raspberry Pi Pico can detect when an input is connected between GND and one of the GP pins. We use a tactile button on our board for the projects. You can follow the tutorial here.
Using the Button code as per the tutorial is fairly easy as you can see. If you want to use the code on our board just remove the jumper cable from pin 9(3V3) and move the jumper cable from pin 11(GND) to pin 9. You can use the code below.
from picozero import Button
from time import sleep
button = Button(18)
while True:
if button.is_pressed:
print("Button is pressed")
else:
print("Button is not pressed")
sleep(0.1)
Move the GND cable back to pin 11 and replace the 3V3 cable on pin 9. We have opted for this setup as we prefer to use the button in the same way as a logic sensor will work by returning a 3V3 (high) signal on the pin you are reading. The PIR is a typical example of such a logic sensor. Use the code below to read the button as a logic (high) input signal.
from picozero import Speaker
from machine import Pin
from time import sleep
button = Pin(18, Pin.IN, Pin.PULL_DOWN)
speaker = Speaker(5)
while True:
print(button.value())
if button.value()==1:
speaker.on()
else:
speaker.off()
sleep(0.1)
You can change the code to the below to use the LED’s. You will see the green LED turns on when you run the code. Every time you press the button the board will act like a traffic light turning to yellow and red. After three seconds it will change to green and wait for the next button press.
from picozero import Speaker, LED
from machine import Pin
from time import sleep
button = Pin(18, Pin.IN, Pin.PULL_DOWN)
speaker = Speaker(5)
green = LED(13)
yellow = LED(8)
red = LED(6)
green.on()
yellow.off()
red.off()
while True:
print(button.value())
if button.value()==1:
green.off()
yellow.on()
sleep(1)
yellow.off()
red.on()
sleep(3)
red.off()
green.on()
sleep(0.1)
Potentiometers
A potentiometer is a resistor that allows you to change the value of the resistance. They are often just called pots.
Turning the dial on the potentiometer will change the resistance of the potentiometer, which can then be read by the Raspberry Pi Pico. We use a 1K potentiometer on our board. You can follow the tutorial here.
from picozero import Pot # Pot is short for Potentiometer
from time import sleep
dial = Pot(0) # Connected to pin A0 (GP_26)
while True:
print(dial.value)
sleep(0.1) # slow down the output
As mentioned earlier with logic pins you’ll see the potentiometer gives readings between 0 and 1. Let’s make this more meaningful by using the LEDs to show the output result. You will see the LEDs acting like a slider or “bargraph” indicating the returned result. You can also use your RGB for a similar result.
from picozero import Pot # Pot is short for Potentiometer
from time import sleep
from picozero import LED
dial = Pot(0) # Connected to pin A0 (GP_26)
red = LED(6)
yellow = LED(8)
green = LED(13)
#Set all LEDs to off
green.off()
yellow.off()
red.off()
while True:
potresult=dial.value*100 # x100 to convert to a percentage
print(potresult)
sleep(0.1) # slow down the output
if potresult < 5: #All LEDs off below 5
green.off()
yellow.off()
red.off()
elif potresult < 33: #5 to 32 green on
green.on()
yellow.off()
red.off()
elif potresult < 66 and potresult > 33: #33 to 66 green and yellow on
green.on()
yellow.on()
red.off()
else: # 66 and up all on
green.on()
yellow.on()
red.on()
Powering your Pico
If you want to run your Raspberry Pi Pico without it being attached to a computer, you need to use a USB power supply or a suitable battery pack and connectors.
Safe operating voltages are between 1.8V and 5.5V.
To automatically run a MicroPython program, simply save it to the device with the name main.py
You can follow the tutorial here.
You’ll find a 2 x AA battery box with switch included in our beginners kit or you can order one loose. You can find batteries here.
Follow the below steps to test your project running from batteries
- Unplug your USB cable from your laptop or PC.
- Make sure the battery box is switched off
- Test the battery pack on your Pico, using the red cable to VSYS pin39 and black cable to GND pin38.
- Remember that the Pico will run whatever program you saved as main.py on startup.
- Switch on the battery box and wait a few seconds for the Pico to start running your app.
- Your Pico project is now fully mobile and off-grid.
You can also run your Pico project from mains using our official power supply.
But I want to use the W in Raspberry Pi Pico W!
Raspberry Pi Pico W is a Raspberry Pi product that adds WiFi capability to the Raspberry Pi Pico, allowing you to connect the device to a WiFi network. In this guide, you will learn how to use a Raspberry Pi Pico W, how to connect it to a WiFi network, and then how to turn it into a web server to control digital outputs from a browser, and to receive sensor data. You can follow the tutorial here.
You can also have a look at our Pico W with DHT22 kit using a webpage to display temperature and humidity or making the data available for Home Assistant.
Resources
We have added the below links to the picozero and micropython websites should you need to do some research or up you skills.
https://picozero.readthedocs.io/en/latest/index.html
https://docs.micropython.org/en/latest/
More Pico projects