Updates:
- 2023/10/04: finally published, added CircuitPython which should work better than MicroPython
- 2023/09/25: retesting WiFi, still fails with latest firmware
- 2023/02/03: starting writeup
Introduction
Wemos S2-Mini is a ESP32-S2FN4R2 chip on a small module, supporting to run MicroPython and connecting to existing WiFi or operating as WiFi Access Point – it’s ideal as IoT device, or easy add-on to 3D printing infrastructure to probe sensors and make them WiFi compatible.
Features
- ESP32-S2FN4R2 (WIFI IC)
- Type-C USB
- 4MB Flash
- 2MB PSRAM
- 27x IO
- ADC, DAC, I2C, SPI, UART, USB OTG
- Compatible with LOLIN D1 mini shields
- Compatible with MicroPython, Arduino, CircuitPython and ESP-IDF
At the price of barely EUR 2.00 on Aliexpress (2023/02) this is a very affordable IoT device.
Note: MicroPython on ESP32-S2 seem not able to connect to an WiFi AP, and also not operate as WiFi AP itself. Before you follow any steps below, read it first through entirely and decide whether MicroPython or CircuitPython is more suitable – for me both approaches fail to provide WiFi connectivity.
Installing MicroPython (no WiFi)
My modules came without MicroPython unlike advertised, I had to upload the latest MicroPython firmware myself:
- download latest MicroPython firmware (near bottom of the page)
- attach module with USB-C cable to the computer (e.g. running Linux as in my case)
- press Button “0” and hold down, press Button “RST” briefly, wait 2 secs, release Button “0”
- use
./esptool.py --port /dev/ttyACM0 --baud 1000000 write_flash -z 0x1000 firmware-LOLIN_S2_MINI-v1.19.1-669-gd4b9df176.bin
Adadfruit ampy
In order to use the modules, one requires ampy
which is installed via
% pip3 install adafruit-ampy
and provides ampy
command line interface:
Usage: ampy [OPTIONS] COMMAND [ARGS]...
ampy - Adafruit MicroPython Tool
Ampy is a tool to control MicroPython boards over a serial connection.
Using ampy you can manipulate files on the board's internal filesystem and
even run scripts.
Options:
-p, --port PORT Name of serial port for connected board. Can optionally
specify with AMPY_PORT environment variable. [required]
-b, --baud BAUD Baud rate for the serial connection (default 115200).
Can optionally specify with AMPY_BAUD environment
variable.
-d, --delay DELAY Delay in seconds before entering RAW MODE (default 0).
Can optionally specify with AMPY_DELAY environment
variable.
--version Show the version and exit.
--help Show this message and exit.
Commands:
get Retrieve a file from the board.
ls List contents of a directory on the board.
mkdir Create a directory on the board.
put Put a file or folder and its contents on the board.
reset Perform soft reset/reboot of the board.
rm Remove a file from the board.
rmdir Forcefully remove a folder and all its children from the board.
run Run a script and print its output.
so you can put (upload), run, delete files – essentially you have a small filesystem where files reside, to run/execute or read from or write to.
Booting Module
By default /boot.py
is executed, where some default behavior can be defined.
No WiFi (Yet)
As first I uploaded wifimgr.py
and webserver.py
(see main.py
), along with default wifi.dat
:
myssid;password
which contains the SSID / Password of the WiFi AP I wanted the module to connect to. All 3 files I uploaded ampy -p /dev/ttyACM0 put wifimgr.py
and so on, one can only upload one file at a time with ampy
.
Finally one can ampy -p /dev/ttyACM0 run webserver.py
As of 2023/09 with MicroPython V1.20.0 I was not able connect the module to an existing WiFi neither have it operate as Access Point (AP) itself – both cases failed; quite disappointing.
Firmware | Boot | REPL | WiFi Client | AP |
---|---|---|---|---|
LOLIN_S2_MINI-v1.19.1-669 | ok | ok | failed | failed |
LOLIN_S2_MINI-20230228-unstable-v1.19.1-910 | ok | ok | failed | failed |
LOLIN_S2_MINI-20230426-v1.20.0 | ok | ok | failed | failed |
LOLIN_S2_MINI-20230914-unstable-v1.20.0-475 | ok | ok | failed | failed |
Installing CircuitPython (no WiFi)
Alternatively you can install CircuitPython, for such you
- download CircuitPython (
adafruit-circuitpython-....bin
) - download Bootloader, near bottom of page (
tinyuf2...zip
)
Install once Bootloader
- unzip bootloader
tinyuf2....zip
and press button “0” and hold, press button “RST” briefly, and release button “0” again, then run this code (Linux):
% python3 ../esptool/esptool.py --chip esp32s2 --port /dev/ttyACM0 --baud 1000000 write_flash -z 0x0 tinyuf2/combined.bin
then press button “RST” again, after few seconds the board appears like a USB disk, and then you copy the adafruit-circuitpython-....bin
into the USB disk – once done, it does reboot itself again (or press button “RST” again).
It will again appear as USB disk named “CIRCUITPY”, that means CircuitPython has been successfully installed and is active running.
Running Code on CircuitPython
Well, you create on that USB disk a new file called code.py
which is executed as default when its content changes – so you can edit it directly. Any other files which that code.py
needs resides in the same root folder.
The lib/
folder contains all libraries, which you can copy from CircuitPython Libraries, you download a .zip file with all libraries and unzip it and then individually copy libraries you need into the lib/
which become then active right away.
The console is viewable if you start
% tio /dev/ttyACM0
I tried to run a web-server example, but it failed with ConnectionError: Unknown failure 2
– so neither MicroPython or CircuitPython are providing working WiFi connectivity.
No WiFi Yet
I’m quite surprised to see my Wemis S2-Mini fail to connect to my WiFi network, regardless of MicroPython or CircuitPython – it seems to me the libraries involved as faulty for both approaches, I cannot believe that this is a hardware problem, but is a software problem.
References
- WEMOS S2-mini
- CircuitPython
- MicroPython (WiFi doesn’t work as tried)