01 PI PICO


颜色名 十六进制颜色值 颜色
Coral #FF7F50 rgb(255, 127, 80)

1.安装与上载程序

RASPBERRY PI PICO 树莓派PICO开发板双核高性能低功耗RP2040芯片 给出了PI PICO的购买,制作以及进行MicroPython的初始化的过程。特别是,对于Window7下,MicroPython初始化之后,对于USB对应的CDC驱动需要手动进行安装。安装之后就会在Windows中出现 “Pi Pico Serial Port(COM6)”对应的串口。 其中COM6的具体端口号根据电脑原本具有的串口的配置有关系。

在正确配置之后,便可以通过串口的交互,利用 REPL 进行交互执行测试程序了。

本文给出了使用Python自动通过串口将MicroPython上载到PI Pico进行允许的过程。详细的程序在 附录 1.自动上载MicroPython的Python给出。

2.MicroPython手册

对应的PI PICO 的MicroPython应用程序开发可以参见: PI Pico MicroPython开发数据手册

3.REPL

REPL(read_eval_print_loop)是MicroPython的用户交互模式。通过REPL MicroPython程序可以动态接收通过串行接口(UART,USB)用户输入的MicroPython的语句并进行解释执行。

为了便于用户的手工输入,REPL提供了Auto-Indent(自动缩进)功能,也就是根据输入的语句是否有冒号(:)结尾来在下一行输入时,自动增加自动缩进(Auto-Indent)的功能,这样会节省用户输入行首的空格。在Python语言中,它是根据每一行的行首空格的多少(对应的缩进级别Level)来定义编程语法功能区域,比如for, if, while,def 等等。

但是由于存在REPL的auto-indent功能,这也给自动程序加载造成了一定的麻烦。这一点在RASPBERRY PI PICO 树莓派PICO开发板双核高性能低功耗RP2040芯片实验中会发现,如果将Python文本程序通过串口发送到PI Pico,会因为有缩进造成实际接收到的程序与原来程序文本不同。

比如,原本如下的程序:

def foo():print('This is a test to show paste mode')print('Here is a second line')
foo()

在Auto-Indent的功能下,MicroPython接收到的信息如下:

>>> def foo():
...         print('This is a test to show paste mode')
...             print('Here is a second line')
...             foo()
...File "<stdin>", line 3
IndentationError: unexpected indent

根据MicroPython官方对于REPL的定义: MicroPython:REPL for upload file 可以利用REPL中通过CTRL-A,CTRL-B,CTRL-C,CTRL-D ( 具体CTRL-字符的编码 ) 等控制命令来切换AutoIndent的功能。

在MicroPython的REPL中使用CTRL-E(0x05)来使REPL切换到PASTE功能,当输入完所有的程序之后,通过CTRL-D(0x04)将REPL退出PASTE模式,并开始编译直接刚刚输入的命令。

Useful control commands:CTRL-C -- interrupt a running programCTRL-D -- on a blank line, do a soft reset of the boardCTRL-E -- on a blank line, enter paste mode

02 基本实验


1.基本测试程序

在附件2中给出了一个基本测试程序,包括以下三个功能:

  • 使用定时器的Callback功能,驱动板载LED(pin25)闪烁;
  • 输出 0~9的平方
  • 输出’hello’

执行udpppp之后,PI PICO串口反馈信息:

Open sport port COM6 Ok.MPY: soft reboot
MicroPython v1.14 on 2021-02-24; Raspberry Pi Pico with RP2040
Type "help()" for more information.
>>>
>>>
>>> from machine import Pin, Timer
>>> led = Pin(25, Pin.OUT)
>>> tim = Timer()
>>>
>>> def tick(timer):
...     global led
...     led.toggle()
...
...
...
>>> tim.init(freq=5, mode=Timer.PERIODIC, callback=tick)
>>>
>>> for i in range(10):
...     print(i**2)
...
...
...
0
1
4
9
16
25
36
49
64
81
>>> print('hello')
hello
>>>
>>>
>>>

▲ PI PICO执行程序现象

2.测试UART

▲ 串口1发送0x55,测量PIN4波形

#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# TESTUART.PY                  -- by Dr. ZhuoQing 2021-02-24
#
# Note:
#============================================================
from head import *
from machine                import UART,Pin
from time                   import sleep_us
uart = UART(1, baudrate=115200, tx=Pin(4), rx=Pin(5), bits=8, parity=None, stop=1)
led = Pin(25, Pin.OUT)
count = 0
for _ in range(100000):uart.write(b'\x55')sleep_us(1000)
#------------------------------------------------------------
#        END OF FILE : TESTUART.PY
#============================================================

※ 附录


1.自动上载MicroPython至PI Pico程序

```python
#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# UPPPP.PY                     -- by Dr. ZhuoQing 2021-02-24
#   Upload PI Pico Program.
#   Usage:
#       upppp filename COM1 & 100
#       upppp *             # Paste file into Thonny & execute
#
# Note:
#============================================================from head import *import serial
from _ast import Or
from serial.serialutil import SerialException#------------------------------------------------------------
THONNY_WINDOW = 'Thonny'def ThonnyExec():tspcopyclipboard()blanklineflag = 1clipstr = clipboard.paste().split('\n')pastr = []lastpasteline = ''for s in clipstr:if len(s) == 0: continuess = s.lstrip(' ')if len(ss) > 0:if ss[0] == '#': continueif ss.find('from head') >= 0: continueif len(ss) < 2:if blanklineflag != 0:continueblanklineflag = 1else:blanklineflag = 0else:if blanklineflag != 0:continueblanklineflag = 1if len(lastpasteline) > 0:pastr.append(lastpasteline)lastpasteline = sif len(lastpasteline) > 0:pastr.append(lastpasteline)if len(lastpasteline) > 2:pastr.append("\r")copystr = '\n'.join(pastr)tspcopystring(copystr)tspsendwindowkey(THONNY_WINDOW, "e", alt=1)tspsendwindowkey(THONNY_WINDOW, "av", control=1)tspsendwindowkey(THONNY_WINDOW, '%c'%(0x74), vk=1)tspfocuswindow("TEASOFT:1")printf("\a")#------------------------------------------------------------
if len(sys.argv) > 1:if sys.argv[1] in '. ;  *':ThonnyExec()printf("\a")exit()#------------------------------------------------------------
title = tspgetwindowtitle()
for t in title:if t.find('Thonny') == 0:ThonnyExec()printf("\a")exit()#------------------------------------------------------------
PORTNAME = 'COM6'
WAITTIMEMS = 500
WAIT_LOOP = 0#------------------------------------------------------------
doppath = tspgetdoppath()
filename = tspeditfileget()#filename = os.path.join(doppath, 'testpwm.py')
printf(filename)#------------------------------------------------------------
if len(sys.argv) > 1:for v in sys.argv[1:]:if len(v) > 3:if v[0:3] == 'COM':PORTNAME = vcontinueif v.isdigit():WAITTIMEMS = int(v)continueif v in '* % &'.split():WAIT_LOOP = 1continuefilebase = v + ".PY"filename = os.path.join(doppath, filebase)#------------------------------------------------------------
if not os.path.isfile(filename):printf("File %s does not exist !"%filename)exit()#------------------------------------------------------------
sport = serial.Serial()
sport.baudrate = 115200
sport.timeout = 0.1
try:sport.port = PORTNAME
except:printf('Set sport port %s error. '%PORTNAME)try:sport.open()
except serial.serialutil.SerialException:printf('Open sport port %s error.'%PORTNAME)
else:printf('Open sport port %s Ok.'%PORTNAME)
#------------------------------------------------------------
sport.write(b'\x03')                # Terminate the current program
sport.write(b'\x03')                # Terminate the current program
time.sleep(.05)
sport.write(b'\x04')                # Software reboot PI Pico
sport.timeout = 0.1
printf(sport.read(10000).decode('utf-8'))sport.timeout = 0.05
sport.write(b'\x05')               # Enter Paste mode
printf(sport.read(10000).decode('utf-8'))#------------------------------------------------------------
lastnullline = 0lastbyte = b''with open(filename, 'r') as f:for l in f.readlines():keepline = l.replace('\n', '\r')#----------------------------------------------------l = l.lstrip(' ')if len(l) > 0:if l.find('head') >= 0: continueif l[0] == '#': continueif len(l) <= 2:if lastnullline != 0:continuelastnullline = 1else:lastnullline = 0lbyte = bytes(keepline, 'utf-8')if len(lastbyte) > 0:sport.write(lastbyte)lastbyte = lbytecontinueif len(lastbyte) > 0:sport.write(lastbyte)#------------------------------------------------------------
sport.timeout = 0.1
printf(sport.read(10000).decode('utf-8'))
printf('\a')sport.write(b'\x04')               # Exit the paste mode
#------------------------------------------------------------
if WAIT_LOOP != 0:sport.timeout = 0.05while True:key = tspread()if key[8] == 2 or key[7] == 2:sport.write(b'\0x3')sport.write(b'\0x3')printf('\r\nUser Terminate .\a')breakreadstr = sport.read(10000).decode('utf-8')if len(readstr) > 0:tspshowinfor(readstr)else:sport.timeout = WAITTIMEMS / 1000.0printf(sport.read(10000).decode('utf-8'))#------------------------------------------------------------#------------------------------------------------------------
#        END OF FILE : UPPPP.PY
#============================================================
### <font  face=宋体 color=teal>2.测试程序</font>
使得开发板上的LED(PIN25)闪烁。```python
#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# TESTMIC.PY                   -- by Dr. ZhuoQing 2021-02-24
#
# Note:
#============================================================from head import *from machine import Pin, Timer
led = Pin(25, Pin.OUT)
tim = Timer()#------------------------------------------------------------
def tick(timer):global ledled.toggle()#--------------------------------------------------------tim.init(freq=5, mode=Timer.PERIODIC, callback=tick)for i in range(10):print(i**2)print('hello')#------------------------------------------------------------
#        END OF FILE : TESTMIC.PY
#============================================================

RASPBERRY PI PICO 开发板 基础测试相关推荐

  1. 全志H616高画质芯片香橙派Orange Pi Zero2开发板音频测试说明

    香橙派Zero2开发板搭载高画质旗舰型6K OTT处理器全志H616 四核 64位处理器,适配有Linux系统和安卓电视盒子系统,拥有512MB/1GB 内存可选,集成千兆以太网卡.蓝牙5.0+双频W ...

  2. RASPBERRY PI PICO 树莓派PICO开发板双核高性能低功耗RP2040芯片

    ▌01 RASPBERRY PICO 1.简介 RaspBerry Pi Pico是一款低价格.高性能的微控制器电路板,具有丰富灵活的数字接口,主要特点包括有: RP2040 microcontrol ...

  3. 物联网开发笔记(69)- 使用Micropython开发树莓派pico开发板raspberry pi pico之控制晶联JLX172104G-590液晶模块

    一.目的 这一节我们学习如何使用我们的树莓派pico开发板raspberry pi pico来控制晶联JLX172104G-590液晶模块. 二.环境 Win10 + 树莓派pico开发板raspbe ...

  4. 树莓派Pico(Raspberry Pi Pico) Windows开发环境—①开发工具链的安装

    Windows 下搭建 树莓派Pico(Raspberry Pi Pico) 的开发环境 在Microsoft Windows上安装工具链与其他平台有所不同.然而,一旦安装,RP2040的构建代码有点 ...

  5. 树莓派出微控制器了!Raspberry Pi Pico 只需 4 美元

    整理 | 郑丽媛 来源 | CSDN(ID:CSDNnews) 昨天,树莓派搞了个大动作:推出了首款微控制器开发板 Raspberry Pi Pico!该开发板基于树莓派开发的全新芯片--RP2040 ...

  6. 树莓派竟出微控制器了!Raspberry Pi Pico 只需 4 美元!

    [CSDN 编者按]树莓派进军微控制器市场了!而这场改革的开始只需 4 美元? 整理 | 郑丽媛 出品 | CSDN(ID:CSDNnews) 昨天,树莓派搞了个大动作:推出了首款微控制器开发板 Ra ...

  7. 在 Windows 中编程 Raspberry Pi Pico 的初学者指南

    在 Windows 中编程 Raspberry Pi Pico 的初学者指南 在本教程中,我们将了解如何在 Windows 系统中安装和设置用于编程 Raspberry Pi Pico 的 Visua ...

  8. Raspberry——Pi Pico和Pico W对比

    简介:在2020年6月30日,Raspberry Pi发布了Pico W,这是一块搭载了英飞凌CYW43439模块的单片机开发板,支持IEEE 802.11 b/g/n无线LAN和蓝牙5.2. 1.整 ...

  9. raspberry pi Pico使用MicroPython变砖后的解决方法

    使用raspberry pi Pico的原因 在硬件产品(单片机)的开发中我们往往需要借助一些额外的仪器/设备进行产品的辅助测试, 假设我们需要一个IO+ADC类型辅助设备, 以往的做法是 原理图-& ...

最新文章

  1. 2019.03.01 bzoj2555: SubString(sam+lct)
  2. 关于android.view.WindowLeaked(窗体泄露)的解决方案
  3. xcode升级之后,VVDocument失效的解决办法
  4. amd同步多线程_使用方法及感受_AMD Ryzen Threadripper 1950X_CPUCPU评测-中关村在线
  5. PC问题-VMware Workstation出现“文件锁定失败”
  6. android 7.0独立升级,爆料:Android 7.0用户将可自行升级!
  7. iOS学习笔记---oc语言第八天
  8. linux配置redis服务,Linux下安装Redis并设置相关服务
  9. 人脸离线识别模块_人脸消费机离线刷脸如何实现?
  10. PHP连接MySQL数据库的几种方法
  11. 【java】动态高并发时为什么推荐重入锁而不是Synchronized?
  12. 献给那些正在“奋起”的90后
  13. [转]Android 超高仿微信图片选择器 图片该这么加载
  14. wordnet的特点
  15. 面试官:如何实现扫码登录功能?
  16. Fedora34/35/36 软件闪退解决
  17. 2016 博客导读总结 个人感悟
  18. EM算法双硬币模型的python实现
  19. java基于ssm的洗衣店管理系统
  20. windows下phpStudy搭建WNMP虚拟机域名

热门文章

  1. 1501 二叉树最大宽度和高度
  2. 【源码分析】极验验证官方SDK源码分析和实现思路
  3. C# DEBUG 调试信息打印及输出详解
  4. svn客户端文件显示灰色的对号代表什么
  5. iSCSI故障查询列表
  6. 一招一式攻克linux(四)
  7. Linux-LAMP-访问控制Directory
  8. Windows安装Zookeeper和Dubbo(单机版本)
  9. Android FeceDetector(人脸识别)
  10. Soldier and Badges