Experiment with a real RISC-V

I choose ESP32-C3 chip to demonstrate a real RISC-V in action.  The board contains 32-bit RISC-V core, WiFi, Bluetooth, and other functions suitable for embedded systems such as general I/O, real-time clock etc. 

The Board

Here is the link to the board.

https://www.digikey.co.th/th/products/detail/espressif-systems/ESP32-C3-DEVKITM-1U/15198974

Here is the link to datasheet of ESP32-C3 chip.

https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/hw-reference/esp32c3/user-guide-devkitm-1.html
https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf

Get the IDE

For the software, Arduino IDE is an easiest development tool to be used to program this board.  Download and install the latest version for your system (Windows, Mac, Linux).

https://www.arduino.cc/en/software

We begin with the step to configure Arduino IDE for this board.  First you have to set the preference to the right source to get the correct board configuration.

Arduino > Preferences > Additional-Board- Manager URL

Set it to this site:

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

click OK

If there is no error you can proceed to choose the download the correct board configuration.  If there is an error, it is usually "the site not found".  Please check the URLs and repeat the step. 

Download the board configuration

Arduino > Tools > [some board]  > Boards Manager

Search for "esp32" select any version 2.0.0 or higher to be installed. Install them.  It should include "ESP32-C3 dev board" configuration. I install version 2.0.0 without any problem. 

Select the board

After install the correct board configuration, you should have the right board appear under Tools.  Choose the board:

Arduino > Tools > Board "ESP32C3 dev module" > ESP32 arduino > ESP32C3 Dev Module

Now we can try to connect the board and run some program.

Connect the board

Use the cable, micro-USB to USB, to connect the board to your computer. The red LED on the board should lit up.  Beware that, now the board has the power, you should be careful not the let the metal pins to touch any metal (such as a screwdriver) otherwise it might short circuit and fry your board.  Rest the board on a paperback book is nice.

Choose the serial port

Your computer now is connected to the board via a port. You must choose the port in Arduino.

Arduino > Tools > Port > COM3  (choose the one appear in your system)

OK now we can try to program the board.

Now that Arduino has the ESP32 package, it will contain many example programs of the appropriate board.  We will use one of them, "WiFiScan" which will use WiFi module in the board to scan the surrounding WiFi and report them on a serial monitor of Arduino.

Arduino > Files > Examples > [Examples for ESP32C3 dev module] > WiFi > WiFiScan

A new window will pop up with "WiFiScan" source, ready to be compiled.

Here is the code:

/*
 *  This sketch demonstrates how to scan WiFi networks.
 */
#include "WiFi.h"

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

    // Set WiFi to station mode and disconnect from an AP if it was previously connected
    WiFi.mode(WIFI_STA);
    WiFi.disconnect();
    delay(100);

    Serial.println("Setup done");
}

void loop()
{
    Serial.println("scan start");

    // WiFi.scanNetworks will return the number of networks found
    int n = WiFi.scanNetworks();
    Serial.println("scan done");
    if (n == 0) {
        Serial.println("no networks found");
    } else {
        Serial.print(n);
        Serial.println(" networks found");
        for (int i = 0; i < n; ++i) {
            // Print SSID and RSSI for each network found
            Serial.print(i + 1);
            Serial.print(": ");
            Serial.print(WiFi.SSID(i));
            Serial.print(" (");
            Serial.print(WiFi.RSSI(i));
            Serial.print(")");
            Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*");
            delay(10);
        }
    }
    Serial.println("");

    // Wait a bit before scanning again
    delay(5000);
}

I will explain what this program do.  In the setup, wifi module is set to station mode and it is also disconnect from an access point if it was previously connected.  Here, we also initialise an output to the serial monitor port on Arduino with the bit rate 115200.

In the main loop, we scan the available wifi with WiFi.scanNetworks().  Then, print out each AP found, its SSID and RSSI. Wait 5 seconds and repeat the scan.

Compile and Download to the board

Once the board is power up, click RST then BOOT.  Now the board is ready to accept the download machine code.  At Arduino IDE, click UPLOAD, it will compile WiFiScan program and download to the board.  When it completes the download, you just click RST (reset) to start the board running this program.

If the download failed, you need to check the serial port setting (such as COM3), then, click RST at the board then click BOOT.  Try upload again.

To see the result, open a serial monitor in Arduino.  Arduino > Tools > Serial Monitor.  Then, set the correct bit rate at bottom right corner of the terminal window.  You will see the output from the board running WiFiScan program.

Happy experimenting !!

last update 24 April 2022