用于在micropython系统上远程执行的jupyter笔记本内核。
jupyter-micropython-remote的Python项目详细描述
jupyter内核通过repl与micropython板交互 接口。
通常通过usb/串行接口与micropython板一起使用, 不过,它也应该通过webrepl(可在esp8266上获得 仅限)。还包括micorpython项目的一些高级功能 管理;运行mpy cross、上载文件、将本地libs同步到micropython等。
微蟒
这个内核需要来自https://github.com/micropython/micropython/pull/3836的micropython支持 在发布时,它不在当前版本1.9.4中,因此需要1.9.5之前的主/每日快照
安装
确保在板上安装了足够多的新micropython(见上文)。
您还需要Python3.6或更高版本,以确保它在当前版本中可用 命令行。可选(推荐)使用您喜爱的pipenv/virtualenv设置 建立一个干净的环境来运行jupyter。
然后安装此模块:
pip install jupyter_micropython_remote
使用shell命令将内核安装到jupyter中:
python -m mpy_kernel.install
这将向jupyter注册内核,以便在 笔记本
运行
现在运行jupyter笔记本:
jupyter notebook
在笔记本中单击右上角的“新建笔记本”按钮, 应该会看到列出的micropython内核显示名称。
第一个单元格需要如下:
%connect <device> --baudrate=115200 --user='micro' --password='python' --wait=0
例如:
%connect "USB-SERIAL CH340""
或与您连接到 micropython/esp8266和。
<device>和参数与用于运行标准 pyboard.py:
device can be serial port device or name device can start with "exec:" "Execute a process and emulate serial connection using its stdin/stdout." device can start with "execpty:" Execute a process which creates a PTY and prints slave PTY as first line of its output, and emulate serial connection using this PTY device can be an ip address for webrepl communication
现在您应该能够通过运行 细胞。
目录中有一个micropythondemo.ipynb文件 显示了一些特性。
如果一个单元中断时间太长,它可能会响应“内核” ->;“中断”命令。
或者击中逃跑然后“我”两次。
进行软重启(当需要清除模块并恢复时 一些内存)类型:
%reboot
您可以使用以下命令列出所有功能:
%lsmagic
mprepl
micropython模块的通信接口基于mprepl和pyboard。 mprepl最初来自https://github.com/micropython/micropython/pull/3034
此模块使用micropython中的虚拟文件系统(需要1.9.4) 要挂载本地PC的工作目录,jupyter是从实际的micropython中运行的 目录中的环境/remote/
这允许您使用 放松。
import os print(os.listdir("/remote/")
还有一个注入的Util类和一些额外的文件处理工具, 以^{tt5}结尾$ 将所有文件/文件夹从源复制到目标,可以选择包含或排除 正则表达式过滤器。
Util.sync("/remote/src", "/lib/", delete=True, include=".*\.mpy")
有关详细信息,请参见文件mpy_kernel/mprepl_utils.py。
%本地
单个单元也可以在本地PC上运行,而不是在远程PC上运行 以%local
开头的单元格作为内核这对于直接处理本地文件、使用ipywidgets等非常有用。 这里的命令将由标准的ipython内核运行。
在%local单元格中,还有一个特殊的全局函数remote(),它 将单个字符串参数传递给要运行的micropython板,返回 命令中的任何stdout。例如:
micropython单元
from machine import Pin import neopixel pixels = neopixel.NeoPixel(Pin(4, Pin.OUT), 1) def set_colour(r, g, b): pixels[0] = (r, g, b) pixels.write() set_colour(0xff, 0xff, 0xff)
本地单元格
%local import colorsys from ipywidgets import interact, Layout, FloatSlider def set_hue(hue): r, g, b = (int(p*255) for p in colorsys.hsv_to_rgb(hue, 1.0, 1.0)) remote(f"set_colour({r}, {g}, {b})") slider = FloatSlider(min=0,max=1.0,step=0.01, layout=Layout(width='80%', height='80px')) interact(set_hue, hue=slider)
贡献
请用任何你认为合适的方式使用和改进这个内核!
我更喜欢对主回购请求拉取:https://gitlab.com/alelec/jupyter_micropython_remote 我会很高兴的如果您还不在gitlab上,请查看并接受遗留github上的任何内容:https://github.com/andrewleech/jupyter_micropython_remote
背景
这个jupyter micropython内核最初是基于惊人的工作 完成时间 https://github.com/goatchurchprime/jupyter_micropython_remote.git