Micropython 硬件开发入门

Micropython 硬件开发入门

一、环境搭建

  • Python 3

  • mpfshell - lite:

​ 在 python3.5 以上使用命令 pip install mpfshell-lite 即可安装,接着输入 mpfs 即可打开运行。

  • 終端在VSCode上运行

    scode–>ctrl+shift+p–>打开用户配置–> 搜索 terminal.integrated.shell.windows
    “terminal.integrated.shell.windows”: “C:\Windows\system32\cmd.exe”

二、基本操作

分为两层

​ os(.py 软件 操作系统
​ mpy(repl进入 硬件Ctrl+Q退出)

view (搜索串口)

open(打开串口)

close(关闭串口)

  • 第一层(代码编写 放置)

    mpfs [/]> put text.py

mpfs [/]> get boot.py

mpfs [/]> runfile text.py (put+调试)

  • 第二层(进入板子) repl

mpfs [/]> repl

调试 execfile(‘test.py’)

Exit REPL with Ctrl+Q

执行顺序

  1. boot.py
  2. main.py

三、优点

防止程序崩溃 try 块

While 1:
     try:
         # 读取温度
     except:
          print("error")

main.py

from machine import pin

power=Pin(15,Pin.OUT)
power.on()

if power.value() == 1:
    #要执行的代码
    execfile('/task1.py')
else:
    pass
    #download
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值