We have been using the esp8266, especially the esp-01 and esp-01s modules, to manage the sensor network for quite some time and with the limitation in terms of the number of pins used, the system must be designed to work with STM32F103C8T6 or STM32F401CCU6/STM32F411CEU6. To ensure stable operation, no problems with the esp8266’s WDT were encountered, and over time, espressif released several other microcontrollers such as esp32, esp32-s2, esp32-c3 and esp32-s3.

We have tested and used esp32 almost all the time until esp32-s2 with LILYGO board made us try to order it. The main problem is that the development tools are very late. However, as of now, espressif has released a development kit for Arduino or Arduino Core for ESP32 version 2.0 with support for esp32 esp32-s2 and esp32c3, making it work with ESP32 and ESP32-S2. We got the esp-c3-32s board so this article was born.

This article is compiled from the datasheet of ESP32-C3 WROOM-02, in this article we use the board as shown in Figure 1. The example program is to drive an RGB LED on the board to work by using Arduino Core for ESP32 and the improved ESP-IDF from the article in Ep. 3

(Figure. 1 ESP32-C3)

ESP32-C3

ESP32-C3 is a SoC (System on Chip), originally ESP32-C3 called ESP-C3 to replace esp8266 and has a different processor architecture, which is changed from Tensilica L106, which is a 32-bit RISC processor to 32-bit RISC-V, with both versions having the same core, one core.

Features

From the picture of the function diagram of the ESP32-C3 in Figure 2, the details of the work can be explained as follows.

  1. 32 bits RISC-V
    1. 160MHz speed from the 40MHz crystal that comes with the module.
    2. There are 22 GPIO pins, but 15 are usable, as the module comes with either 2 or 4MB of external flash memory (AI Thinker’s ESP-C3-32s module has a 2MB ROM).
    3. 400KB internal RAM memory
      1. Used as cache memory (Cache Memory) 16KB
      2. Remaining 386KB
    4. 8KB memory in RTC (Real-time clock) module
    5. Internal ROM size 384KB
    6. Support power saving mode.
    7. Support to add external flash memory.
  2. Connection
    1. Support WiFi communication.
      1. IEE802.11 b/g/n
      2. Frequency 2412 to 2484 MHz or 2.4GHz
      3. bandwidth 20MHz and 40MHz
      4. speed in 1T1R mode up to 150Mbps
      5. 802.11mc FTM
      6. Supports
        1. Station
        2. SoftAP
        3. Station+SoftAP
        4. promiscuous or mode in which the controller that controls the communication forwards all traffic received to the central processing unit. This allows package sniffing to analyze package data.
    2. Supports Bluetooth
      1. Supports Bluetooth 5 and Bluetooth mesh
      2. Supports 125Kbps, 500Kbps, 1Mkbps and 2Mbps
  3. Peripherals
    1. GPIO
    2. SPI
    3. UART
    4. I2C
    5. I2S
    6. Remote Control Peripheral
    7. LED PWM controller
    8. DMA Controller
    9. TWAI® Controller รองรับ  CAN bus
    10. USB Serial/JTAG controller
    11. Temperature sensor
    12. SAR
    13. ADC
  4. Conditions of use
    1. 3.0 ~ 3.6V
    2. Temperature
      1. –40 ~ 85 °C
      2. –40 ~ 105 °C
  5. Security that is supported at the hardware level are:
    1. Supports RSA-3072 secure boot, which is RSA-based encryption with a 3072-bit key.
    2. Supports AES-128-XTS flash memory encryption.
  6. Software Development
    1. Developed via ESP-IDF
    2. Developed via Arduino with Arduino core for ESP32.
  7. Module appearance
    1. ESP32-C3 WROOM-02 has PCB as antenna as shown Figure 3.
    2. ESP32-C3 WROOM-02U has connector for connecting antenna outside the body as shown in Figure 4.
  8. Implementation
    1. Smart Home
      1.  Control the lighting system.
      2. Smart Button.
      3. Smart plug.
      4. Home Locator.
    2. Industrial Automation
      1. Industrial robots
      2. Mesh Network
      3. HMI (Human Machine Interface)
      4. Industrial field bus
    3. Health Care
      1. Health Monitor
      2. Baby Monitor
    4. Consumer Electronics
      1. Smart Watch/bracelet
      2. Over-the-top (OTT) devices
      3. WiFi and Bluetooth speaker
      4. Logger toys and proximity sensing toys
    5. Smart Agriculture
      1. Smart greenhouse
      2. Smart irrigation
      3. Agriculture robot
    6. Retail and Catering
      1. POS (Point-of-sell) Machine
      2. Service robot
    7. Audio Device
      1. Internet Music Players
      2. Live Streaming devices
      3. Internet Radio players
    8. Generic Low-power IoT Sensor Hubs
    9. Generic Low-power IoT Data Loggers
(Figure. 2 Workflow diagram of ESP32-C3)
From page 6 of esp-c3-32s document
(Figure. 3 ESP32-WROOM-02 module)
From fig. 8 page 24 of ESP-32 WROOM-02 Dataheet
(Figure. 4 ESP32-WROOM-02U module)
From fig. 9 page 24 of ESP-32 WROOM-02 Dataheet

The schematic diagram of the board is shown in Figure 5, it is found that on the board there is an RGB LED that is connected to Pin IO3, IO4 and IO5 to control the emitting of red, green and blue ones.

(Figure. 5 Circuit of WaveShare’s Nodemcu-esp-c3-32s-kit)
From

GPIO

esp32-c3 has 22 pins of GPIO, which are GPIO0 to GPIO21, which have the following functions:

GPIOAnalog FunctionNote
GPIO0ADC1_CH0RTC, XTAL
GPIO1ADC1_CH1RTC, XTAL
GPIO2ADC1_CH2Strapping pin, RTC, FSPIQ
GPIO3ADC1_CH3RTC, connect to red LED
GPIO4 ADC1_CH4RTC, connect to green LED, FSPIHD, MTMS
GPIO5ADC2_CH0RTC, connect to blue LED usable in Deep Sleep, FSPIWP, MTDI
GPIO6FSPICLK, MTCK
GPIO7FSPID, MTD0
GPIO8Strapping pin
GPIO9Strapping pin
GPIO10FSPICS0
GPIO11
GPIO12SPIO/1 use with SPI Flash and PSRAM shouldn’t be used
GPIO13SPIO/1 use with SPI Flash and PSRAM shouldn’t be used
GPIO14SPIO/1 use with SPI Flash and PSRAM shouldn’t be used
GPIO15SPIO/1 use with SPI Flash and PSRAM shouldn’t be used
GPIO16SPIO/1 use with SPI Flash and PSRAM shouldn’t be used
GPIO17SPIO/1 use with SPI Flash and PSRAM shouldn’t be used
GPIO18USB-JTAG if use as GPIO, USB-JTAG will unavailable
GPIO19USB-JTAG if use as GPIO, USB-JTAG will unavailable
GPIO20RX0
GPIO21TX0

Installation

Installing the Arduino core for ESP32 kit is done by defining the following json in File/Preferences.

https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

after that go to Tools/Board…/Boards Manager, select esp32 and install, you will get Arduino core for ESP32 development kit in your machine.

Configuration

The configuration for Ai Thinker esp-c3-32s modules must set the Flash size to 2MB as shown in Figure 5.

(Figure. 6 Board configuration)

Example Code

An example of programming to control the LED that comes with the microcontroller board to be installed is as follows.

void setup() {
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
}

void loop() {
  for (int i = 3; i < 6; i++) {
    digitalWrite(i, LOW);
    delay(250);
    digitalWrite(i, HIGH);
    delay(250);
  }
}

From the code, it can be found that the pins used to communicate with the RGB LEDs on the board are pins 3, 4 and 5 that are connected to pins LED_R, LED_G and LED_B. To drive the LED on, you must send a digital signal 1, because this causes the pin to have voltage on the pin connected to the LED and the other pin of the LED to be connected to GND, thus completing the current flow through it, causing the LED to light up. The example picture of the work is shown in Figure 7.

(Figure. 7 Result from the code)

The code for the ESP-IDF modified from the article ESP-IDF Ep.3 : GPIO Output is as follows.

#include <stdio.h>
#include <time.h>
#include <string.h>
#include <math.h>
#include "driver/gpio.h"
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#define LED_R_PIN 3
#define LED_G_PIN 4
#define LED_B_PIN 5

void app_main(void)
{  
  printf("C3 LEDs"); 
  gpio_pad_select_gpio(LED_R_PIN);
  gpio_set_direction(LED_R_PIN, GPIO_MODE_OUTPUT);
  gpio_pad_select_gpio(LED_G_PIN);
  gpio_set_direction(LED_G_PIN, GPIO_MODE_OUTPUT);
  gpio_pad_select_gpio(LED_B_PIN);
  gpio_set_direction(LED_B_PIN, GPIO_MODE_OUTPUT);

  while(1) {
    gpio_set_level(LED_R_PIN, 1);
    vTaskDelay( 500/portTICK_PERIOD_MS );
    gpio_set_level(LED_R_PIN, 0 );
    vTaskDelay( 500/portTICK_PERIOD_MS );
    gpio_set_level(LED_G_PIN, 1);
    vTaskDelay( 500/portTICK_PERIOD_MS );
    gpio_set_level(LED_G_PIN, 0 );
    vTaskDelay( 500/portTICK_PERIOD_MS );
    gpio_set_level(LED_B_PIN, 1);
    vTaskDelay( 500/portTICK_PERIOD_MS );
    gpio_set_level(LED_B_PIN, 0 );
    vTaskDelay( 500/portTICK_PERIOD_MS );
    gpio_set_level(LED_R_PIN, 1 );
    gpio_set_level(LED_G_PIN, 1 );
    gpio_set_level(LED_B_PIN, 0 );
    vTaskDelay( 500/portTICK_PERIOD_MS );
    gpio_set_level(LED_R_PIN, 0 );
    gpio_set_level(LED_G_PIN, 1 );
    gpio_set_level(LED_B_PIN, 1 );
    vTaskDelay( 500/portTICK_PERIOD_MS );
    gpio_set_level(LED_R_PIN, 1 );
    gpio_set_level(LED_G_PIN, 0 );
    gpio_set_level(LED_B_PIN, 1 );
    vTaskDelay( 500/portTICK_PERIOD_MS );
    gpio_set_level(LED_R_PIN, 1 );
    gpio_set_level(LED_G_PIN, 1 );
    gpio_set_level(LED_B_PIN, 1 );
    vTaskDelay( 500/portTICK_PERIOD_MS );
    gpio_set_level(LED_R_PIN, 0 );
    gpio_set_level(LED_G_PIN, 0 );
    gpio_set_level(LED_B_PIN, 0 );
    vTaskDelay( 500/portTICK_PERIOD_MS );
  }
}

Conclusion

From this article, it will be found that the ESP32-C3 is a new alternative to espressif that decided to try the market by using RISC-V as a central processor and we also found its best development tool is still espressif’s ESP-IDF due to its complete functionality and update to fix problems faster than the Arduino core for ESP32, which is normal. Because the upstream must be stable before the downstream will be changed. Finally, have fun with programming.

If you want to talk with us, feel free to leave comments below!!

References

  1. ESP32-C3 DevKitM-1
  2. ESPRESSIF ESP32-C3
  3. ESP32-C3 WROOM-02 Datasheet
  4. WaveShare ESP-C3-Kit

(C) 2020-2021, By Jarut Busarathid and Danai Jedsadathitikul
Updated 2021-12-20