官方网站Buy a Raspberry Pi Pico – Raspberry Pi,大部分固件、SDK、硬件资料都可以找到。
一、micropython部分
1、刷入官方给的固件,安装Thonny就可以使用,写法参考官方SDK以及micropython,在Thonny中输入help()也能查看各种库,串口部分官方没介绍,写法与micropython类似。
from machine import UART
uart = UART(0, 115200, bits=8, parity=None, stop=1, tx=Pin(0), rx=Pin(1))
uart.write('abc')
这个写法可以接收到数据再读取,避免没有收到数据的时候在uart.read(2)里卡死
while uart.any() > 0:
dat = uart.read(2)
micropython网站https://docs.micropython.org/en/latest/library/index.html
2、自己写的class要保存到Pico里才能被读到,其他程序可以写在本地或者Pico。
3、两个i2c.writeto直接至少间隔0.2s,否则会报错OSError: 5
4、定时中断写法,频率不宜过高否则会卡死
from machine import Timer
tim = Timer()
times_ = 0
def tick(timer):
global times_
times_ = times_ + 1
if times_ > 100:
times_ = 0
tim.init(freq = 10,mode = Timer.PERIODIC,callback = tick)
二、C部分
1、写C的环境搭建比较麻烦,要安装ARM GCC compiler(要环境变量)、CMake(要环境变量)、Build Tools for Visual Studio 2019、Python 3(要环境变量)、Git,之后在Git拉SDK。
git clone -b master https://github.com/raspberrypi/pico-sdk.git
cd pico-sdk
git submodule update --init
cd ..
git clone -b master https://github.com/raspberrypi/pico-examples.git
在用Developer Command Prompt for VS 2019,设置环境变量到SDK路径。
setx PICO_SDK_PATH “…\pico-sdk”
建立工程可以下载https://github.com/raspberrypi/pico-project-generator,输入py -3 ./pico_project.py --gui建立,之后把c程序放进去,定位到build文件夹,执行cmake ..和nmake即可生成uf2文件。