【micropython】用Raspberry Pi PICO学micropython

目录

用Raspberry Pi PICO学micropython

官方资料

https://datasheets.raspberrypi.org/pico/raspberry-pi-pico-python-sdk.pdf

https://www.raspberrypi.org/documentation/rp2040/getting-started/#getting-started-with-micropython

开箱

包装

板子使用了卷带包装,体积比较小

【micropython】用Raspberry Pi PICO学micropython

正面

正面包含了一个BOOTSEL按钮,用来进入刷机模式。

一个LED灯,接在PIN25引脚上

【micropython】用Raspberry Pi PICO学micropython

背面

【micropython】用Raspberry Pi PICO学micropython

说明

板件采用了2.54mm间距插针,并有兼容邮票孔,且背面没有任何器件,方便作为主控板贴到其他设备上

引脚图

【micropython】用Raspberry Pi PICO学micropython

开发环境搭建

1、下载固件

从micropython官网上下载固件,可以使用最新版本
https://micropython.org/download/rp2-pico/

2、烧录程序

按住BOOTSEL键,树莓派PICO会识别成U盘,将下载的uf2文件,拖拽到U盘里面进行烧录。

烧录后,设备会自动重启

注意

1、使用的USB线需要有数据传输功能,不能只能供电

2、必须按住BOOTSEL后,再插入USB线,中途不要松开按键,等出现U盘图标后再松开

3、识别成串口

程序烧录后,

【micropython】用Raspberry Pi PICO学micropython

异常

遇到了一个问题,使用PICO烧录固件后,串口无法通讯,从上图可以看见自行生成的串口号,与我的虚拟串口的串口号一样了。手工更改成了COM6后,就出现串口不输出任何东西的问题。

解决方法:

将虚拟串口号删除掉,然后使用他默认的串口号,问题解决

【micropython】用Raspberry Pi PICO学micropython

4、连接串口

使用串口调试设备,连接PICO的串口,然后按下回车键,可以看到>>>提示符

【micropython】用Raspberry Pi PICO学micropython

【micropython】用Raspberry Pi PICO学micropython

第一个程序

1、点亮LED灯

在REPL中,按下Ctrl+E键,进入粘贴模式,将以下代码粘贴入编辑区:

from machine import Pin
from time import sleep_ms
led=Pin(25,Pin.OUT)
while True:
     led.value(1)
     sleep_ms(500)
     led.value(0)
     sleep_ms(500)


使用Ctrl+D键,退出粘贴模式并运行

【micropython】用Raspberry Pi PICO学micropython

可以看到板载的LED灯,以1s的频率进行闪烁。

2、使用MU编辑器

1、模式选择

首先在模式里面选择位RP2040

【micropython】用Raspberry Pi PICO学micropython

2、进入REPL

点击REPL,进入交互功能,可以看到Python版本和平台

【micropython】用Raspberry Pi PICO学micropython

3、运行程序

编写程序,点击运行:

【micropython】用Raspberry Pi PICO学micropython

可以看到板载LED灯闪烁。

使用Ctrl+B键退出,若不能退出先执行Ctrl+C键中断程序运行
【micropython】用Raspberry Pi PICO学micropython

上一篇:树莓派Pico开发板硬件扩展接口及电源模块解析


下一篇:RASPBERRY PI PICO 树莓派PICO开发板双核高性能低功耗RP2040芯片