S2 Mini

Powerful ESP32-S2 Board That Works With ESP8266 Shields

The pink S2 Mini microcontroller board (aka LOLIN S2 Mini or Wemos S2 Mini) uses the much more powerful single-core ESP32-S2 microcontroller. This board is preserving pin compatibility to the ESP8266 D1 Mini and can serve as an ideal replacement for ESP8266-based projects. Like the ESP8266, the ESP32-S2 does not support bluetooth.

Its additional capabilities (including generous 26 GPIOs) are exposed via two additional pin header rows.

Thanks to its form factor and pin-compatibility, you can continue to use shields originally designed for the D1 Mini (i.e. battery shields).

The ESP32-S2 Mini uses an unusual design for communicating via USB cable: it exposes different ports in normal mode vs. firmware upload mode, and because of this, many tools like ESPHome Web Tool are incompatible with this board (as of this writing). Classic IDEs work flawlessly. If you are using ESPHome and experience trouble flashing this board, there are great and simple-to-use workarounds. Generally, try and enable OTA (wireless over-the-air updates) so you can bypass its strange USB communication interface (the only flaw this otherwise excellent board seems to have).

While the S2 Mini microcontroller board is exceptional value for the money, the ESP32-S2 microcontroller used on this board does not seem to be as mainstream as other microcontrollers, resulting incomplete documentation and half-hearted support: i.e. the pins_arduino.h file shipped with the Espressif ESP32 Kit needs manual tweaking to be able to use common pin labels like D0 or D1 in your code. For experienced users, the ESP32-S2 Mini is excellent bang for the buck (this board is regularly available for under €2). As a rookie, you might want to avoid the ESP32-S2 altogether and stick to trusted and well-established microcontroller types like ESP8266 or ESP32.

S2 Mini Technical Data

Item Value
CPU ESP32-S2FN4R2 WiFi SoC, Xtensa single-core 32-bit LX7 microprocessor
Speed 240MHz
Coprocessor RISC-V ULP Coprocessor

The relatively new ESP32-S2FN4R2 chip integrates flash and psram into the S2 silicon.

Due to its form factor, the S2 Mini does not expose all available hardware pins. With 27 GPIOs, this board is most sufficient for most DIY projects.

Item Value
Digital IO Pins 27
Clock Speed 240MHz
Flash 4MB
PSRAM 2MB
SRAM 320KB
SRAM in RTC 16KB (8KB accessible by ULP coprocessor)
Temperature Sensor -20-+110C
eFuse 1792bit for user data
SAR ADC 2x13bit, up to 20 channels, best for voltages <2.45V
DAC 2x8bit, second DAC has fixable issues
Touch 12xtouch sensing IOs
SPI 4x, SPI2 and SPI3 usable: HSPI and VSPI
I2S 1x
I2C 2x
UART 2x
DVP 8/16 camera interface 1x
LCD interface 1x8bit serial, 1x8/16/24bit parallel
TWAI (CAN-Bus) 1x, ISO11898-1 (CAN Specification 2.0)
PWM controller 8x
USB OTG 1.1/PHY host and device support
Cryptographic Hardware accelerators for AES, ECB/CBC/OFB/CFB/CTR, GCM, SHA, RSA, ECC (Digital Signature)
Size 34.4x25.4mm
Weight 2.4g

Power consumption in its sleep modes is lower compared to classic ESP32:

Operation Current
Normal (WiFi) 310mA peak
Modem-Sleep 12-19mA
Light-Sleep 450uA
Deep-Sleep 20-190uA

Power regulation is done by a ME6211C33 regulator:

Item Value
Input voltage 4.7-6.5V
Operating Voltage 2-6V
Max current [email protected]/3.3Vout

Hardware I2C Interface

Any pin can emulate a I2C interface (or define additional ones). Only the hardware I2C interface uses optimized hardware that does not put load on the microcontroller and is faster.

Pin Label Description
33 SCA Data
35 SDL Clock

Hardware SPI Interface

Any pin can emulate a SPI interface (or define additional ones). Only the hardware SPI interface uses optimized hardware that does not put load on the microcontroller. When connecting components with high data rates (i.e. displays), try and use hardware SPI for much higher frame rates.

Pin Label Alternate Labels Description
11 MOSI SDO, SDA Master Out SLave In
9 MISO SDI Master In Slave Out
7 CLK SCL, SCLK Clock
12 SS Chip Select  

Since the S2 Mini is pin-compatible to D1 Mini, you can simply look up pins for the D1 Mini if you can’t find documentation for ESP32-S2. Documentation for D1 Mini is much more readily available.

Pins And Compatible Shields

The board comes with 32 pins in 2x2 rows of 8. The outer pins are compatible with ESP8266 D1 Mini pins. D1 Mini-compatible shields can therefore be used with the S2 Mini as well:

In an effort to maintain maximum backwards compatibility, the S2 Mini board designers changed the order of some pin pairs: pins 2-11 are always located on the board in pairs, i.e. 2/3, 4/5, 6/7, 8/9, 10/11. For some pins, this scheme is reversed: pins 12 and 13 are located as 13/12 instead of 12/13 to preserve pin compatibility to the D1 Mini:

Only the outer pins match the D1 Mini pins (as the two inner lines of pins were added). Both pin 11 and 12 are used for the hardware SPI interface though. If the board designers would not have switched pins 12 and 13 around, then pin 12 would have been located on the inner lines of pins and thus become inaccessible for D1 Mini-compatible shields.

This allows users to continue to use i.e. battery shields to add charging and battery power supply via existing D1 Mini Shields for portable projects:

Software-configurable pins (such as GPIOs and the pin for the built-in LED) are not compatible with ESP8266 D1 Mini. Since these pins can be adjusted freely in software in the S2, converting software from ESP8266 D1 Mini to S2 Mini is a matter of checking and potentially reassigning pin numbers.

S2 Mini Pinout

The pin numbers printed on the backside of the breakout board represent the exposed GPIO numbers. I.e., pin marked 1 represents GPIO1.

Pin Remark Description
EN   Reset button
3V3   direct power supply to CPU
VBUS   connected to ME6211C33 voltage regulator
0 not exposed Boot button pulls it low
1-6   general purpose: analog input (ADC1) and digital in/output
7 SPI SCK general purpose: analog input (ADC1) and digital in/output
8   general purpose: analog input (ADC1) and digital in/output
9 SPI MISO general purpose: analog input (ADC1) and digital in/output
10   general purpose: analog input (ADC1) and digital in/output
11 SPI MOSI general purpose: analog input (ADC2) and digital in/output
12 SPI SS general purpose: analog input (ADC2) and digital in/output
13-14   general purpose: analog input (ADC2) and digital in/output
15 internal LED general purpose: analog input (ADC2) and digital in/output
16   general purpose: analog input (ADC2) and digital in/output
17 DAC1 general purpose: analog input (ADC2) and digital in/output
18 DAC2 general purpose: analog input (ADC2) and digital in/output
19, 20 not exposed USB D1/D2, connected to the USB C connector
21   general purpose digital in/output
33 I2C SDA general purpose digital in/output
34   general purpose digital in/output
35 I2C SCL general purpose digital in/output
36-40   general purpose digital in/output

The ADC2 (and thus analog inputs at GPIO11-GPIO18) can only be used when WiFi is disabled.

Prototyping

The S2 Mini uses dual line header pins (2x8 pins on both sides for a total of 32 pins).

This design was necessary to keep the hardware compatibility to the predecessor ESP8266 D1 Mini board: the outer 8-pin headers match the header pins in a ESP8266 D1 Mini (for power and GND pins at least).

You cannot of course use dual line header pins with a prototyping bread board as this would short circuiting both header pin lines.

Soldering Header Pins

For prototyping, it makes most sense to solder the outer header pins normally for a ESP8266 D1 Mini-compatible foot print.

The inner header pins should not be connected to the bread board. Instead, solder the header pins on top: this way, the additional pins can be connected using female DuPont cables.

Fixing Missing Pins

When programming the S2 Mini in platform.io, the translation between true hardware pins and common pin labels is performed automatically: the IDE looks up the appropriate version of the file pins_arduino.h in the folder %USERPROFILE%\.platformio\packages\framework-arduinoespressif32\variants\lolin_s2_mini.

Pin Declarations Missing

At the time of this writing, the appropriate file pins_arduino.h does exit but is incomplete. It does not define the common pin labels for all digital pins.

Whenever you try and compile source code that refers to a Dx pin, compilation files with an exception.

There does not seem to exist an officially updated version of this file. To fix, you have two choices:

  • Quick Fix: Replace the common pin labels in the code with the actual hardware pin numbers. Since with S2 Mini the numbers are identical, you would i.e. change D2 by 2. If you do this, the code will compile but is now specific for S2 Mini and will no longer work on different microcontroller boards.
  • Permanent Fix: Open the file %USERPROFILE%.platformio\packages\framework-arduinoespressif32\variants\lolin_s2_mini\pins_arduino.h in a text editor, and add the missing declarations. You find an example below. When you do this, you might lose your changes with the next update of the espressif32 arduino framework, though.
#ifndef Pins_Arduino_h
#define Pins_Arduino_h

#include <stdint.h>

// Default USB Settings
#define USB_VID 			0x303a
#define USB_PID 			0x80C2
#define USB_MANUFACTURER 	"WEMOS.CC"
#define USB_PRODUCT 		"LOLIN-S2-MINI"
#define USB_SERIAL 			"0"


// Default USB FirmwareMSC Settings
#define USB_FW_MSC_VENDOR_ID 		"ESP32-S2" 		//max 8 chars
#define USB_FW_MSC_PRODUCT_ID 		"Firmware MSC"	//max 16 chars
#define USB_FW_MSC_PRODUCT_REVISION	"1.23" 			//max 4 chars
#define USB_FW_MSC_VOLUME_NAME 		"S2-Firmware" 	//max 11 chars
#define USB_FW_MSC_SERIAL_NUMBER 	0x00000000

#define EXTERNAL_NUM_INTERRUPTS 46
#define NUM_DIGITAL_PINS        48
#define NUM_ANALOG_INPUTS       20

#define analogInputToDigitalPin(p)  (((p)<20)?(analogChannelToDigitalPin(p)):-1)
#define digitalPinToInterrupt(p)    (((p)<48)?(p):-1)
#define digitalPinHasPWM(p)         (p < 46)

static const uint8_t LED_BUILTIN = 15;
#define BUILTIN_LED  LED_BUILTIN // backward compatibility

static const uint8_t TX = 39;
static const uint8_t RX = 37;

static const uint8_t SDA = 33;
static const uint8_t SCL = 35;

static const uint8_t SS    = 12;
static const uint8_t MOSI  = 11;
static const uint8_t MISO  = 9;
static const uint8_t SCK   = 7;

static const uint8_t A0 = 1;
static const uint8_t A1 = 2;
static const uint8_t A2 = 3;
static const uint8_t A3 = 4;
static const uint8_t A4 = 5;
static const uint8_t A5 = 6;
static const uint8_t A6 = 7;
static const uint8_t A7 = 8;
static const uint8_t A8 = 9;
static const uint8_t A9 = 10;
static const uint8_t A10 = 11;
static const uint8_t A11 = 12;
static const uint8_t A12 = 13;
static const uint8_t A13 = 14;
static const uint8_t A14 = 15;
static const uint8_t A15 = 16;
static const uint8_t A16 = 17;
static const uint8_t A17 = 18;
static const uint8_t A18 = 19;
static const uint8_t A19 = 20;

static const uint8_t D1 = 1;
static const uint8_t D2 = 2;
static const uint8_t D3 = 3;
static const uint8_t D4 = 4;
static const uint8_t D5 = 5;
static const uint8_t D6 = 6;
static const uint8_t D7 = 7;
static const uint8_t D8 = 8;
static const uint8_t D9 = 9;
static const uint8_t D10 = 10;
static const uint8_t D11 = 11;
static const uint8_t D12 = 12;
static const uint8_t D13 = 13;
static const uint8_t D14 = 14;
static const uint8_t D15 = 15;
static const uint8_t D16 = 16;
static const uint8_t D17 = 17;
static const uint8_t D18 = 18;
static const uint8_t D33 = 33;
static const uint8_t D34 = 34;
static const uint8_t D35 = 35;
static const uint8_t D36 = 36;
static const uint8_t D37 = 37;
static const uint8_t D38 = 38;
static const uint8_t D39 = 39;
static const uint8_t D40 = 40;

static const uint8_t T1 = 1;
static const uint8_t T2 = 2;
static const uint8_t T3 = 3;
static const uint8_t T4 = 4;
static const uint8_t T5 = 5;
static const uint8_t T6 = 6;
static const uint8_t T7 = 7;
static const uint8_t T8 = 8;
static const uint8_t T9 = 9;
static const uint8_t T10 = 10;
static const uint8_t T11 = 11;
static const uint8_t T12 = 12;
static const uint8_t T13 = 13;
static const uint8_t T14 = 14;

static const uint8_t DAC1 = 17;
static const uint8_t DAC2 = 18;

#endif /* Pins_Arduino_h */

Uploading Firmware

These are the steps to upload new firmware to S2 Mini using platformio:

  1. Connect S2 Mini to computer using USB-C cable. Make sure to use a data cable and not just a power cable.
  2. Hold button 0, then short-press button RST. Once you release button RST, the computer should play the sound for new USB device discovery.
  3. Upload the firmware in platformio by clicking Upload. Platformio will search for a port, then force the S2 Mini in reset, and then find a port and upload the sketch.
  4. Once the upload is done, short-press RST again. Now, the sketch should execute.

If the S2 Mini is not recognized by your computer (no “new USB device” sound plays after you pressed the keys as described above), make sure the USB cable is fully plugged in, try and reverse the plugs, and use a different cable. Apparently, the USB connectors on this board do not always have proper contact. Trying with a different USB cable often solve the issue.

If changing the USB cable does not help, reboot your PC. It is frequently the case that USB communications fail over time, or that other running software blocks USB discovery. Rebooting the PC can then solve the issue which is not at all related to this particular board. It is related to USB and can occur with (any) microcontroller board/type that is using USB.

If the issue still persists, check to see whether the board gets warmer as usual. The build quality of these boards is not always great, and there have been instances where solder residue was short-circuiting CPU contacts. Closely inspect the board and all solderings.

ESPHome

For flashing S2 Mini in ESPHome, the ESPHome Web Tool is incompatible with this board and does not work (as of this writing). Use this workaround instead to upload ESPHome firmware or to provision the board with the generic ESPHome firmware.

Once you have successfully uploaded ESPHome firmware at least once via USB cable, you can then use OTA to wirelessly upload any future firmware updates, effectively bypassing the S2 Mini USB incompatibilities.

Materials

S2 Mini Datasheet
S2 Mini Schematics
S2 Mini Dimensions
ME6211 voltage regulator

Comments

Please do leave comments below. I am using utteran.ce, an open-source and ad-free light-weight commenting system.

Here is how your comments are stored

Whenever you leave a comment, a new github issue is created on your behalf.

  • All comments become trackable issues in the Github Issues section, and I (and you) can follow up on them.

  • There is no third-party provider, no disrupting ads, and everything remains transparent inside github.

Github Users Yes, Spammers No

To keep spammers out and comments attributable, all you do is log in using your (free) github account and grant utteranc.es the permission to submit issues on your behalf.

If you don’t have a github account yet, go get yourself one - it’s free and simple.

If for any reason you do not feel comfortable with letting the commenting system submit issues for you, then visit Github Issues directly, i.e. by clicking the red button Submit Issue at the bottom of each page, and submit your issue manually. You control everything.

Discussions

For chit-chat and quick questions, feel free to visit and participate in Discussions. They work much like classic forums or bulletin boards. Just keep in mind: your valued input isn’t equally well trackable there.

  Show on Github    Submit Issue

(content created May 04, 2024 - last updated Jul 16, 2024)