提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
前言
MCU用来用去还得是Raspberry Pi系列,语言选来选去还得是MicroPython,对于初学者来讲太友好了。虽然我是一个高级C++开发,还是感慨Python的上手很容易,学习成本很低。
一、MicroPython是什么?
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.
The MicroPython pyboard is a compact electronic circuit board that runs MicroPython on the bare metal, giving you a low-level Python operating system that can be used to control all kinds of electronic projects.
MicroPython is packed full of advanced features such as an interactive prompt, arbitrary precision integers, closures, list comprehension, generators, exception handling and more. Yet it is compact enough to fit and run within just 256k of code space and 16k of RAM.
MicroPython aims to be as compatible with normal Python as possible to allow you to transfer code with ease from the desktop to a microcontroller or embedded system.
简而言之,为MCU专门开发的Python,可以运行在资源紧张的设备上。学习上手难度又没有C和C++那么难。
二、使用步骤
1.下载Phonny IDE
选则自己的操作系统版本下载并安装
2.安装MicroPython固件
Raspberry Pi Pico要使用MicroPython需要先安装MicroPython固件到设备上。
第一步:
准备一条USB数据线一头先接到电脑USB口上。
第二步:
按住Raspberry Pi Pico上的BOOT按钮不松并将USB另一头插到Raspberry Pi Pico的USB口上(一啊般是Micro USB或Type-C)。
这个时候你的电脑上出现一个U盘,如果没出现就检查系下电脑USB驱动或设备问题。第三步:
打开Phonny软件并在右下角找到你的设备(串口转USB)并安装MicroPython解释器,等待完成。
3.测试Demo
MicroPython固件烧录完成后拔下USB并重新插上(不需要按BOOT)就进入开发模式了。
写一个LED闪烁的Demo:
from machine import Pin,Timer
led = Pin(25,Pin.OUT)
timer = Timer()
def blink(timer):
led.toggle()
timer.init(freq=2.5, mode=Timer.PERIODIC, callback=blink)
点击运行并选则推送到设备上
这个时候Raspberry Pi Pico上的LED灯就开始闪烁了。
总结
1、几乎没什么难度