# MicroPython控制器

### 第一部分：硬件准备

#### 1.1 需要准备的硬件

* NyBoard USB上载模块（CH340C）
* NyBoard WiFi模块

#### &#x20; 1.2 硬件连接&#x20;

将WiFi模块插入USB上载器的模块配置接口上，在windows设备管理器找到对应的COM口。

<div><figure><img src="/files/40HZNviW993CpXxCbTab" alt=""><figcaption></figcaption></figure> <figure><img src="/files/ojuwxFrAv4WT79Lzd1WX" alt=""><figcaption></figcaption></figure></div>

### 第二部分：软件准备

#### 2.1 下载 Thonny

下载最新版本的Thonny，Thonny是一个开箱即用的Python编辑器，原生提供了MicroPython的支持。

&#x20;[下载地址](https://thonny.org/)

<figure><img src="/files/cptGK1AQ4HY6u40RDrSF" alt=""><figcaption></figcaption></figure>

#### 2.2 下载 MicroPython固件

MicroPython官方网站上提供了已经编译好的ESP8266固件，因为我们的[WiFi模块](https://docs.petoi.com/v/chinese/tong-xin-mo-kuai/wifi-mo-kuai-esp8266)为4MB， 请选择`ESP8266 with 2MiB+ flash`名称的最新固件，下载bin文件即可。&#x20;

[固件下载地址](https://micropython.org/download/esp8266/)

#### 2.3 烧录 MicroPython固件

将MicroPython固件烧录至WiFi模块有两种方法：

* 使用ESPtool下载工具，可以更加精确控制Flash的分区和使用
* 使用Thonny自带工具，比较方便

为了方便我们使用Thonny自带的烧录工具。 具体步骤如下：

1. 打开Thonny软件，主界面如下图。Thonny默认配置使用安装目录下的Python解释器。

   <figure><img src="/files/4EglZqB7NfanH3tTFqId" alt=""><figcaption></figcaption></figure>
2. 打开`Tools -> Options（选项）`，进入选项页面。在第一个`General`界面，我们可以选择需要的语言 （需要重新启动Thonny）。

   <figure><img src="/files/XuBl7ZzUrJwZ8kqF0fTB" alt=""><figcaption></figcaption></figure>
3. 打开第二个选项卡`Interpreter（解释器）`，我们将默认的Python3解释器更换为`MicroPython(ESP8266)`后， 选择对应的端口。

   <figure><img src="/files/BQol8CQ6y4wYbqEwaw9G" alt=""><figcaption></figcaption></figure>
4. 此时我们的WiFi模块还未烧录MicroPython固件，点击上图右下角的`Install or update firmware` 使用内置的烧录程序更新固件。
5. 选择WiFi模块所在的端口(COMx)，选择下载的MicroPython固件（bin文件）所在的位置。 勾选下载模式（flash mode）为：`from image file(keep)`（速度会比较慢，但是只需要烧录一次且不容易出错）， 勾选`全片擦除（Erase flash before installing）`。按下`安装(install)`键。

   <figure><img src="/files/VqnaJfIlARIkOdtUj7mj" alt=""><figcaption></figcaption></figure>
6. 界面的左下角会显示进度，先擦除Flash，再写入固件。当出现`完成（Done）`字样的时候，表示已经烧录完成了。

   <figure><img src="/files/wzovg76lPOUZXmDk4Crs" alt=""><figcaption></figcaption></figure>
7. 软件准备工作到此结束，关闭下载界面会出现如下显示。红字乱码是因为ESP8266启动时会打印一串非115200波特率的代码，这段代码无法被MicroPython Shell识别。 当出现Python标志性&#x7684;**`>>>`**&#x7B26;号时，表示固件烧录成功。

   <figure><img src="/files/FjqQmvQ9vk9EuACloBys" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.petoi.com/chinese/api/micropython-kong-zhi-qi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
