Buy from USA | Buy from UK | Buy from DE | Buy from IT | Buy from FR | Buy from ES | ここでご購入を! |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
In this lesson, you will learn how to read digital data (1/0 which is high/low voltage) from a Pico digital pin and output 0/1 data (low voltage/high voltage signal) to Pico digital pins. This is also called digital I/O (input/output) programming.
In order to program digital I/O, firstly we need to know the Pico pin layout :
From above picture, you can see most of the Pico pins have a light green label which is the GPIO number. i.e. Physical pin number 20, green label is GP15. This means Physical Pin 20’s GPIO number is 15. This is very important in python programming. We will use this GPIO number to write/read data from that pin.
In above circuit graph, you can see that:
LED negative pin connected to GND through 220 ohm resistor
LED Positive pin connected to GP16
Push button pin 1 connected to 3.3V
Push button pin 2 connected to GP14
You can download lesson 2 python code from http://osoyoo.com/driver/pico/lesson2/pico-lesson2.py
You can use Thonny to open pico-lesson2.py and load it to Pico later.
Here is the full code with comments:
from machine import Pin import time led = Pin(16, Pin.OUT) button = Pin(14, Pin.IN,Pin.PULL_DOWN) while True: if button.value(): print("Button is pressed!") led.toggle() time.sleep(0.5)
Step 1: Connect Pico board to one of USB ports in your PC
Step 2: If you haven’t installed Thonny Software or don’t know how to use Thonny IDE, please read lesson 1
Step 3: Now open the Thonny Python IDE, click Run to select MicroPython for Rapsberry Pi Pico as Interpreter :
Also please select the COM port which your Pico board is connected :
After that, click OK to save the setting.
Step 4: Now copy the python code to Thonny window as following:
Step 5: Click the little ► button ,the save page will pop up as following photo ;
select Raspberry Pi Pico as destination.
Step 7:Name the file as pico-lesson2.py, then click OK
Step 8: Click the little ► button again to run the Python code.
Now you can try to press the Push Button in the breadboard. You will see the LED status will toggle whenever you press the button.
Also in the Thonny Shell Window, you will see “Button is pressed!” when you press the button.
After the operation is complete, press Ctrl+C to end the command.
DownLoad Url osoyoo.com