The Doc whom IoT Professionals trust

Schlagwort: AI-THINKER

Deep Dive on the ESP32-S from Ai-Thinker

Reading Time: 3 Minutes

The ESP32-S from Ai-Thinker is a small-size, low-power wireless module for a wide variety of applications like a low-power sensor with a demanding task such as voice encoding. It is based on the famous ESP32 from Espressif, more precisely the ESP32-D0WDQ6 chip, designed to be scalable and adaptive. Please have a look at the following post for an in-detail description of the related features and specifications of the ESP32 chip (coming soon). The ESP32-S is Ai-Thinker’s equivalent to the ESP32-WROOM-32 module from Espressif, equaling in the form factor and specifications.

ESP32-S Front-View
Front View (Source)
ESP32-S Back View
Back View (Source)

Pin Definitions

ESP32-S Pin Layout
ESP32-S Pin-Out

The ESP32-S has a length of 18 mm, a width of 25.5 mm and a height of 2.8 mm ∓ 0.1 mm. Furthermore, it has 38 pins, defined as follows (cf. Datasheet):

The following table shows the name, type, number and function of the pins on the left-side of the ESP32-S:

ESP32-S Pin-Out
NameTypeGPIOFunction
GNDPGround
3V3PPower Supply: 3.3V (VDD), 500 mA
ENIChip-enable Signal (Active high)
SENSOR_VPIADC_H, ADC1_CH0, RTC_GPIO0
SENSOR_VNIADC1_CH3, ADC_H, RTC_GPIO3
IO34IGPIO34ADC1_CH6, RTC_GPIO4
IO35IGPIO35ADC1_CH7, RTC_GPIO5
IO32I/OGPIO32XTAL_32K_P (32.768kHz crystal oscillator input), ADC1_CH4, TOUCH9, RTC_GPIO9
IO33I/OGPIO33XTAL_32K_N (32.768kHz crystal oscillator output), ADC1_CH5, TOUCH8, RTC_GPIO8
IO25I/OGPIO25DAC_1, ADC2_CH8, RTC_GPIO6, EMAC_RXD0
IO26I/OGPIO26DAC_2, ADC2_CH9, RTC_GPIO7, EMAC_RXD1
IO27I/OGPIO27ADC2_CH7, TOUCH7, RTC_GPIO17, EMAC_RX_DV
IO14I/OGPIO14ADC2_CH6, TOUCH6, RTC_GPIO16, MTMS, HSPICLK, HS2_CLK, SD_CLK, EMAC_TXD2
IO12I/OGPIO12ADC2_CH5, TOUCH5, RTC_GPIO15, MTDI, HSPIQ, HS2_DATA2, SD_DATA2, EMAC_TXD3
Mapping of the pins at the left-side of the ESP32-S

The following table shows the name, type, number and function of the pins on the bottom of the ESP32-S:

ESP32-S Pin-Out
NameTypeGPIOFunction
GNDPGround
IO13I/OGPIO13ADC2_CH4, TOUCH4, RTC_GPIO14, MTCK, HSPID, HS2_DATA3, SD_DATA3, EMAC_RX_ER
SHD/SD2I/OGPIO9SD_DATA2, SPIHD, HS1_DATA2, U1RXD
SWP/SD3I/OGPIO10SD_DATA3, SPIWP, HS1_DATA3, U1TXD
SCS/CMDI/OGPIO11SD_CMD, SPICS0, HS1_CMD, U1RTS
SCK/CLKI/OGPIO6SD_CLK, SPICLK, HS1_CLK, U1CTS
SDO/SD0I/OGPIO7SD_DATA0, SPIQ, HS1_DATA0, U2RTS
SDI/SD1I/OGPIO8SD_DATA1, SPID, HS1_DATA1, U2CTS
IO15I/OGPIO15ADC2_CH3, TOUCH3, MTDO, HSPICS0, RTC_GPIO13, HS2_CMD, SD_CMD, EMAC_RXD3
IO2I/OGPIO2ADC2_CH2, TOUCH2, RTC_GPIO12, HSPIWP, HS2_DATA0, SD_DATA0
Mapping of the pins at the botom of the ESP32-S

The following table shows the name, type, number and function of the pins on the right-side of the ESP32-S:

ESP32-S Pin-Out
NameTypeGPIOFunction
IO0I/OGPIO0ADC2_CH1, TOUCH1, RTC_GPIO11, CLK_OUT1, EMAC_TX_CLK
IO4I/OGPIO4ADC2_CH0, TOUCH0, RTC_GPIO10, HSPIHD, HS2_DATA1, SD_DATA1, EMAC_TX_ER
IO16I/OGPIO16HS1_DATA4, U2RXD, EMAC_CLK_OUT
IO17I/OGPIO17HS1_DATA5, U2TXD, EMAC_CLK_OUT_180
IO5I/OGPIO5VSPICS0, HS1_DATA6, EMAC_RX_CLK
IO18I/OGPIO18VSPICLK, HS1_DATA7
IO19I/OGPIO19VSPIQ, U0CTS, EMAC_TXD0
NC
IO21I/OGPIO21VSPIHD, EMAC_TX_EN
RXD0I/OGPIO3U0RXD, CLK_OUT2
TXD0I/OGPIO1U0TXD, CLK_OUT3, EMAC_RXD2
IO22I/OGPIO22VSPIWP, U0RTS, EMAC_TXD1
IO23I/OGPIO23VSPID, HS1_STROBE
GNDPGround
Pin Mapping

Modules and Functions

(coming soon)

Electrical Characteristics

(coming soon)

Schematic Diagram

ESP32-S Schematic Diagram
Schematic Diagram of the ESP32-S (Source)

Using the SD Card in 1-Bit Mode on the ESP32-CAM from AI-Thinker

Reading Time: 2 Minutes

The ESP32-CAM from AI-Thinker has an on-board connector for micro SD cards:

ESP32 CAM Front-View
Front View (Source)
ESP32 CAM Back-View
Back View (Source)

The ESP32 connects to an SD card via the SDMMC Host Driver, more precisely via slot 1. It is a 4-bit slot and uses the HS2_* signals in the PIN MUX. The following table shows the pin and signal mappings (cf. schematic diagram):

SignalGPIOComment
HS2_CMDGPIO15Exposed
HS2_CLKGPIO14Exposed
HS2_DATA0GPIO02Exposed
HS2_DATA1GPIO04Exposed and also connected to on-board SMD LED
HS2_DATA2GPIO12Exposed
HS2_DATA3GPIO13Exposed
Pin mapping of slot 1 of the ESP32’s SDMMC host peripheral

As shown above, the ESP32-CAM uses the GPIO pins GPIO02, GPIO04, GPIO13 and GPIO15 for reading and writing data to the SD card. To use the SD card in the ‚1-Bit‘ or ‚1-Wire‘ mode, just initialize the SD card with the following code (cf. Espressif Arduino core for the ESP32):

bool begin(const char * mountpoint="/sdcard", bool mode1bit=false); // cf. SD_MMC.h
SD_MMC.begin("/sdcard", true);

By setting the parameter mode1bit to true, the ESP32-CAM just uses the GPIO02 to read and write data to the SD card, which frees up the GPIO pins GPIO04 (HS_DATA1), GPIO12 (HS_DATA2), and GPIO13 (HS_DATA3) as further GPIO pins for input or output. To use one or all of these GPIO pins for input or output, you have to define the GPIO pin accordingly after the initialization of the SD card. Otherwise, the initialization of the SD card would re-configure the GPIO pins again. For instance, the following code snippet configures the GPIO pin GPIO12 as an output pin and sets it to low:

pinMode(12, OUTPUT);
digitalWrite(4, LOW);

Please note that the ESP32-CAM uses the GPIO04 to connect to the on-board flash light as well – the SMD (Surface-Mount Device) LED (Light-Emitting Diode). To prevent the SMD LED from glowing, use the following code:

#include "SD_MMC.h"
#include "SPI.h"

#define BUILTIN_LED 4

void setup() {
    Serial.begin(115200);

    // Initialize the SD card
    if (!SD_MMC.begin("/sdcard", true)){
        Serial.println("Failed to mount SD card");
        return;
    }

    // Specify that LED pin
    pinMode(BUILTIN_LED, OUTPUT);
    digitalWrite(BUILTIN_LED, LOW);

    // Check for an SD card
    uint8_t cardType = SD_MMC.cardType();
    if (cardType == CARD_NONE){
        Serial.println("No SD card attached");
        return;
    }

    // <Put your init code here>
}


void loop() {
  // <Put your main code here, to run repeatedly>
  Serial.println("loop end, 10sec delay");
  delay(10000);
}

© 2024 Dr. Mountain

Theme von Anders NorénHoch ↑