What is the ESP32-C2?

The ‘C2’ is a recent RISC-V product from Espressif. It is also known as the ESP8684. It appears that they are positioning it as a replacement for the venerable 8266. As such it does an admirable job. Rather than list all of it’s features we will just highlight major differences compared to the well known ESP32.

  • It is only a single-core MCU running at 120 MHz.
  • SRAM is 256 KBytes (plus 16K cache).
  • 576K of in-chip flash – similar to the ESP-8285
  • WiFi and Bluetooth – but no BT Classic.
  • Only 14 GPIOs
  • the usual collection of SPI, I2C, Analog, Timers etc.
  • NO I2S or RMT

Does not have an RMT or I2S peripheral – which means we will be using SPI for future NEOpixel explorations.

The Built-in freeRTOS is a much anticipated improvement over the 8266.

Espressif-IDE:

My previous exploration on installing the IDE may prove helpful.

The Espressif IDE includes examples of using various peripherals to get us started. Here we will discover the GPIOs to get some blinking happening. There is no real need to address the Serial peripheral – Serial printf is automatically initialized at compile time by the IDE.

TIP – Baud Rate:

When our first dev board or raw chip falls off of the slow boat from China (or Canada) we connect it to a serial monitor and, all too often, find it just displays gibberish which no amount of adjusting baud rate in the monitor program will cure. The secret trick here is to pay attention to the internal oscillator frequency of the chip itself. Supposedly the C2 may come with a 26MHz or a 40MHz internal crystal. I have only seen 26MHz versions. It appears that most devices come with a bootloader compiled with the Crystal frequency #defined at 40MHz. There is no magic switch to fix this – we just need to set the Main XTAL config in the sdkconfig file to 26 MHz. This will give our apps a nice clean 115,200 baud serial output. Doing this from within the IDE can be a little time consuming due to the fact that the editor opens a JSON config server each time we want to edit the sdkconfig file – the server is helpful, BUT, there are a lot of options. We can do this manually outside of the IDE by, closing the IDE, editing the sdkconfig file directly (I use geany). Around line 720 we find the Main XTAL Config options which should be obvious. We are better off not exploring any deeper in the sdk file – We may find that the default baud rate is actually set to 74880 but this is assuming a 40MHz XTAL – we get 115,200 after setting the main XTAL Freq to 26MHz. We can than open the IDE and carry on – Each time we compile, an updated bootloader is installed using the sdkconfig preference we have set.Fortunately the above does not affect the Flash uploading baudrate. Even if we see gibberish in the our serial monitor, uploads work fine.

                --------------  --------------  -------------- --------------  --------------  --------------  --------------  --------------

GPIO Blinker

We will explore GPIOs using the “generic gpio” template which we can install by following the guidelines given in the above-mentioned previous exploration. It blinks 2 GPIOs which are specified in the sdkconfig file under CONFIG_GPIO_OUTPUT_0 18 around line 278. (line 389 if doing this manually)

TIP – F3 :: if we highlight CONFIG_GPIO_OUTPUT_0 on line 36 of “gpio_example_main.c” file, the IDE will open the sdk file without going through the tedious config server. I was using my own CanHobby ESP32-C2 – 1U board which has an LED on GPIO 18 so I modified the sdk file accordingly. The commercial TZT board I also have does not have an LED.

app_main() starts with setting up the GPIOs as outputs. Note that GPIO_OUTPUT_PIN_SEL is the “OR” of the 2 GPIO values, seeing as they are both set to OUTPUT. Highlighting this in the editor pops up a brief description of the ...

Read more »