Monday, February 22, 2021

Install MicroPython on ESP32 using Thonny Python IDE, on Raspberry Pi.

Steps to install MicroPython firmware on ESP32 (ESP32-DevKitC V4, with ESP32-WROVER-E) using Thonny Python IDE, on Raspberry Pi/Raspberry Pi OS(32-bit). Include install esptool plug-ins.

Visit http://micropython.org/download/, scroll down to select Generic ESP32 module.
Download firmware (.bin) using either ESP-IDF v3.x or v4.x.

There are various daily firmware for ESP32-based boards, with separate firmware for boards with and without external SPIRAM, using either ESP-IDF v3.x or v4.x.

Non-SPIRAM firmware will work on any board, whereas SPIRAM enabled firmware will only work on boards with 4MiB of external pSRAM.

And currently,
Firmware built with ESP-IDF v4.x, with support for BLE and PPP, but no LAN.
Firmware built with ESP-IDF v3.x, with support for BLE, LAN and PPP. MicroPython v1.14 was the last version to support ESP-IDF v3.x.

If in doubt use v4.x.

Run Thonny

Run in Raspberry Pi OS Start Menu:
> programming > Thonny Python IDE

Install esptool plus-ins:

In Thonny menu:
> Tools > Manager plug-ins...
Search and install esptool

Install MicroPython firmware:

In Thonny menu:
> Run > Select Interpreter...

Select MicroPython (ESP32) from the interpreter or device drop-down box.
Click Install or Update firmware.

Select the USB port connected to ESP32.
Browse to load firmware.
Click Install.

Once Done, MicroPython installed on ESP32.

Example:

upyESP32_scan.py, example to scan available WiFi networks.
import uos
import network

print("----- MicroPython -----")
for u in uos.uname():
    print(u)
print("-----------------------")

sta_if = network.WLAN(network.STA_IF)
print(sta_if)
sta_if.active(True)
for ap in sta_if.scan():
    print(ap)

upyESP32_connect.py, example to connect WiFi network.
import uos
import network

print("----- MicroPython -----")
for u in uos.uname():
    print(u)
print("-----------------------")

def do_connect():
    sta_if = network.WLAN(network.STA_IF)
    if not sta_if.isconnected():
        print('connecting to network...')
        sta_if.active(True)
        sta_if.connect('ssid', 'password')
        while not sta_if.isconnected():
            pass
    print('network config:', sta_if.ifconfig())
    
do_connect()


Next:

No comments: