目录

准备

硬件

  • NodeMCU(ESP32) 开发板

  • 数据线,一头是 USB-A 接口,另一头是 Micro-USB 接口。

软件

PINOUT

搭建 MicroPython 开发环境

  • 运行 esptool.py read_mac 命令,确认连接成功。
    $ esptool.py read_mac
    esptool.py v3.0
    Found 2 serial ports
    Serial port /dev/cu.usbserial-1410
    Connecting....
    Detecting chip type... ESP32
    Chip is ESP32-D0WD (revision 1)
    Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
    Crystal is 40MHz
    MAC: 3c:61:05:06:81:9c
    Uploading stub...
    Running stub...
    Stub running...
    MAC: 3c:61:05:06:81:9c
    Hard resetting via RTS pin...
    

烧录固件

  1. 下载 ESP32固件,选择Firmware with ESP-IDF v3.x下面的GENERIC类别。
    wget http://micropython.org/resources/firmware/esp32-idf3-20210202-v1.14.bin
    
  2. 擦除 Flash 芯片
    esptool.py --chip esp32 --port /dev/cu.usbserial-1410 erase_flash
    
  3. 烧录固件
    esptool.py --chip esp32 --port /dev/cu.usbserial-1410 --baud 460800 write_flash -z 0x1000 esp32-idf3-20210202-v1.14.bin
    

验证成功

SecureCRT (交互解释器)

  • SecureCRT Connect Config
  • 输入帮助函数 help()

测试例子:点亮开发板的蓝灯

  • 亮蓝灯 Pin(2, Pin.IN)
  • 灭蓝灯 Pin(2, Pin.OUT)
    >>> from machine import Pin
    >>> Pin(2, Pin.IN)
    >>> Pin(2, Pin.OUT)
    

打开低功耗蓝牙

import network
import ubluetooth

wlan = network.WLAN(network.STA_IF)
wlan.active(True)

ble = ubluetooth.BLE()
ble.active(True)
  • 如果不先打开WIFI将会出现下面的错误
    import ubluetooth
    ble = ubluetooth.BLE()
    ble.active(True)
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    OSError: [Errno 110] ETIMEDOUT
    

参考资料