Python으로 MCU를 구동하면 하드웨어 독립적으로 간단하고 빠르게 검증 해 볼수 있는 장점이 있다.
Raspberry Pi Pico도 Python을 지원 하는데 소형 MCU에서 돌아가는 MicroPython을 지원한다.
먼저 MicroPython 홈페이지에서 RP2040용 펌웨어를 다운로드 받아 설치 한다.
MicroPython - Python for microcontrollers
MicroPython is a lean and efficient implementation of the Python 3 programming language that includes a small subset of the Python standard library and is optimised to run on microcontrollers and in constrained environments.
micropython.org
IDE 툴은 여러가지가 있지만 많이 사용하는 Thonny 를 사용하면 될것 같다.
Thonny, Python IDE for beginners
Download version 3.3.13 for Windows • Mac • Thonny Python IDE for beginners Features Easy to get started. Thonny comes with Python 3.7 built in, so just one simple installer is needed and you're ready to learn programming. (You can also use a s
thonny.org
Thonny 설치후 Pi pico의 시리얼 포트를 설정하면 접속이 되고 간단히 테스트 해 볼 수 있다.

간단히 RP2040 보드의 LED를 제어 하는 예제를 실행 해보자.
from machine import Pin
import utime
led = Pin(25, Pin.OUT)
while True:
led.toggle();
utime.sleep_ms(400);
작성한 코드를 PC에 저장해서 구동하거나 RP2040에 저장할 수도 있다.
main.py 로 저장하면 부팅후 바로 실행된다.
타이머 인터럽트를 이용해 특정 주기로 LED 제어하는 예제도 테스트 해보자
from machine import Pin, Timer
led = Pin(25, Pin.OUT)
tim = Timer()
def tick(timer):
global led
led.toggle()
tim.init(freq=2.5, mode=Timer.PERIODIC, callback=tick)