├── 01_pin_names ├── .gitignore ├── include │ └── README ├── pin_names │ ├── main.cpp │ └── pin_names.ino └── platformio.ini ├── 02_blink_pulse_led ├── .gitignore ├── blink_pulse_led │ ├── blink_pulse_led.ino │ └── main.cpp ├── include │ └── README ├── lib │ └── README ├── platformio.ini └── test │ └── README ├── 03_scan_wifi ├── .gitignore ├── include │ └── README ├── lib │ └── README ├── platformio.ini ├── scan_wifi │ ├── main.cpp │ └── scan_wifi.ino └── test │ └── README ├── 04_wifi_connect ├── .gitignore ├── include │ └── README ├── lib │ └── README ├── platformio.ini ├── test │ └── README └── wifi_connect │ ├── main.cpp │ ├── secrets.h.template │ └── wifi_connect.ino ├── 05_wifi_tx_power ├── .gitignore ├── include │ └── README ├── lib │ └── README ├── platformio.ini ├── test │ └── README └── wifi_tx_power │ ├── main.cpp │ ├── secrets.h.template │ └── wifi_tx_power.ino ├── 06_async_web_led ├── .gitignore ├── async_web_led │ ├── async_web_led.ino │ ├── html.h │ ├── main.cpp │ └── secrets.h.template ├── include │ └── README └── platformio.ini ├── 07_ble_led ├── .gitignore ├── ble_led │ ├── ble_led.ino │ └── main.cpp ├── include │ └── README └── platformio.ini ├── 08_ble_led2 └── ble_led2 │ ├── ble_led2.ino │ └── main.cpp ├── COPYING ├── README.md ├── images ├── dir_tree.jpg └── pinout_top_big_logo.png └── resources ├── README.md ├── pins_arduino.h └── super_mini_esp32c3.json /01_pin_names/.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | .vscode/.browse.c_cpp.db* 3 | .vscode/c_cpp_properties.json 4 | .vscode/launch.json 5 | .vscode/ipch 6 | -------------------------------------------------------------------------------- /01_pin_names/include/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project header files. 3 | 4 | A header file is a file containing C declarations and macro definitions 5 | to be shared between several project source files. You request the use of a 6 | header file in your project source file (C, C++, etc) located in `src` folder 7 | by including it, with the C preprocessing directive `#include'. 8 | 9 | ```src/main.c 10 | 11 | #include "header.h" 12 | 13 | int main (void) 14 | { 15 | ... 16 | } 17 | ``` 18 | 19 | Including a header file produces the same results as copying the header file 20 | into each source file that needs it. Such copying would be time-consuming 21 | and error-prone. With a header file, the related declarations appear 22 | in only one place. If they need to be changed, they can be changed in one 23 | place, and programs that include the header file will automatically use the 24 | new version when next recompiled. The header file eliminates the labor of 25 | finding and changing all the copies as well as the risk that a failure to 26 | find one copy will result in inconsistencies within a program. 27 | 28 | In C, the usual convention is to give header files names that end with `.h'. 29 | It is most portable to use only letters, digits, dashes, and underscores in 30 | header file names, and at most one dot. 31 | 32 | Read more about using header files in official GCC documentation: 33 | 34 | * Include Syntax 35 | * Include Operation 36 | * Once-Only Headers 37 | * Computed Includes 38 | 39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html 40 | -------------------------------------------------------------------------------- /01_pin_names/pin_names/main.cpp: -------------------------------------------------------------------------------- 1 | // Main module of pin_mames 2 | // Copyright: see notice in pin_names.ino 3 | 4 | #include 5 | 6 | int TRUE_LED_PIN = 8; // modify if needed in the following if/else ladder 7 | 8 | // Define the title macro and fill in BOOT_BUILTIN as needed for each board 9 | 10 | #if defined(ARDUINO_MAKERGO_C3_SUPERMINI) 11 | #define TITLE "MakerGO C3 SuperMini" 12 | //static const uint8_t BOOT_BUILTIN = 9; // defined in pins_arduino.h 13 | #define BOOT_BUILTIN BOOT_BUILTIN 14 | #elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI) 15 | #define TITLE "Nologo ESP32C3 Super Mini" 16 | static const uint8_t BOOT_BUILTIN = 9; 17 | #define BOOT_BUILTIN BOOT_BUILTIN 18 | #elif defined(ARDUINO_SUPER_MINI_C3) 19 | #define TITLE "DfRobot Beetle ESP32-C3" //"Modified ESP32 C3 DEVKITC 02" 20 | static const uint8_t BOOT_BUILTIN = 9; 21 | #define BOOT_BUILTIN BOOT_BUILTIN 22 | #elif defined(ARDUINO_SUPER_MINI_ESP32C3) 23 | #define TITLE "Custom ESP32C3 Super Mini" 24 | //static const uint8_t BOOT_BUILTIN = 9; //defined in pins_arduino.h 25 | //#define BOOT_BUILTIN BOOT_BUILTIN //defined in pins_arduino.h 26 | #elif defined(ARDUINO_ESP32C3_DEV) 27 | #define TITLE "ESP32-C3 Dev Module" 28 | static const uint8_t BOOT_BUILTIN = 9; // defined in pins_arduino.h 29 | #define BOOT_BUILTIN BOOT_BUILTIN 30 | 31 | #else 32 | #error "Unknown device" 33 | #endif 34 | 35 | unsigned long pinstime = 0; 36 | 37 | void iopins(void) { 38 | if ((pinstime) && (millis() - pinstime < 10000)) return; 39 | 40 | Serial.println("\nArduino I/O Pin Names and Numbers"); 41 | Serial.print("Board: "); 42 | Serial.println(TITLE); 43 | 44 | Serial.printf("\nThe symbolic name and corresponding I/O number of the 6 analogue pins\n"); 45 | Serial.printf(" A0 = %d\n", A0); 46 | Serial.printf(" A1 = %d\n", A1); 47 | Serial.printf(" A2 = %d\n", A2); 48 | Serial.printf(" A3 = %d\n", A3); 49 | Serial.printf(" A4 = %d\n", A4); 50 | Serial.printf(" A5 = %d\n", A5); 51 | 52 | Serial.println("\nThe I/O number of the 13 digital pins"); 53 | for (int i=0; i<11; i++) { 54 | Serial.printf(" %2d\n", i); 55 | } 56 | Serial.println(" 20"); 57 | Serial.println(" 21"); 58 | 59 | Serial.println("\nThe symbolic name and corresponding I/O number of the 7 pins connected to default serial peripherals"); 60 | Serial.printf(" TX = %2d [UART]\n", TX); 61 | Serial.printf(" RX = %2d [UART]\n", RX); 62 | 63 | Serial.printf(" SCL = %2d [I2C]\n", SCL); 64 | Serial.printf(" SDA = %2d [I2C]\n", SDA); 65 | 66 | Serial.printf(" SS = %2d [SPI]\n", SS); 67 | Serial.printf("MOSI = %2d [SPI]\n", MOSI); 68 | Serial.printf("MISO = %2d [SPI]\n", MISO); 69 | Serial.printf(" SCK = %2d [SPI]\n", SCK); 70 | 71 | #if defined(ARDUINO_MAKERGO_C3_SUPERMINI) || defined(ARDUINO_SUPER_MINI_ESP32C3) 72 | Serial.printf(" TX1 = %2d [UART1]\n", TX1); 73 | Serial.printf(" RX1 = %2d [UART1]\n", RX1); 74 | #endif 75 | 76 | Serial.print("\nOther connected devices"); 77 | Serial.printf("\n BOOT_BUILTIN [BUTTON]= %d", BOOT_BUILTIN); 78 | 79 | #ifdef LED_BUILTIN 80 | Serial.printf("\n LED_BUILTIN = %2d", LED_BUILTIN); 81 | #endif 82 | #ifdef BUILTIN_LED 83 | Serial.printf("\n BUILTIN_LED = %2d", BUILTIN_LED); 84 | #endif 85 | #ifdef LED_BUILTIN 86 | if (LED_BUILTIN != TRUE_LED_PIN) Serial.printf("\n ** LED_BUILTIN should be = %d **", TRUE_LED_PIN); 87 | #endif 88 | 89 | Serial.println("\n\nPress the boot button to test"); 90 | pinstime = millis(); 91 | } 92 | 93 | int bootbtn = 0; 94 | 95 | void setup() { 96 | Serial.begin(); 97 | delay(2000); // 2 second delay should be sufficient for USB-CDC 98 | Serial.println("\n\nList ESP32C3 based board I/O pin names and numbers"); 99 | 100 | #ifdef BOOT_BUILTIN // in case a board without boot button added 101 | pinMode(BOOT_BUILTIN, INPUT); 102 | bootbtn = digitalRead(BOOT_BUILTIN); 103 | Serial.printf("Boot button default value: %d\n", bootbtn); 104 | #endif 105 | Serial.println("Setup completed"); 106 | } 107 | 108 | void loop() { 109 | iopins(); 110 | #ifdef BOOT_BUILTIN 111 | if (bootbtn != digitalRead(BOOT_BUILTIN)) { 112 | bootbtn = digitalRead(BOOT_BUILTIN); 113 | Serial.printf("Boot button value: %d\n", bootbtn); 114 | } 115 | #endif 116 | } 117 | -------------------------------------------------------------------------------- /01_pin_names/pin_names/pin_names.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * pin_names.ino 3 | * 4 | * List I/O pin names and numbers of supported Super Mini ESP32-C3 boards 5 | * 6 | * This is a stub to satisfy the Arduino IDE, the source code is in 7 | * the file main.cpp in the same directory. 8 | * 9 | * This sketch will compile in the Arduino IDE 10 | * 11 | * 1- Add https://espressif.github.io/arduino-esp32/package_esp32_index.json 12 | * in the Additional Boards Manager URLS in the Preferences window. 13 | * 2- Install platform esp32 by Espressif version 3.0.1 or newer with the Boards Manager 14 | * 3- Select the MakerGO ESP32 C3 SuperMini board 15 | * 16 | * This sketch will also compile in PlatformIO with platform espressif32 v6.6.0 or newer 17 | * 18 | * Use the following platformio.ini configuration file 19 | * [env:dfrobot_beetle_esp32c3] 20 | * platform = espressif32 21 | * board = dfrobot_beetle_esp32c3 22 | * framework = arduino 23 | * 24 | * or use 25 | * [env:super_mini_esp32c3] 26 | * platform = espressif32 27 | * board = super_mini_esp32c3 28 | * framework = arduino 29 | * if the the board definition file super_mini_esp32c3.json and the variant pin 30 | * definition file pins_arduino.h have been added as explained in 31 | * https://github.com/sigmdel/supermini_esp32c3_sketches/tree/main/resources 32 | * 33 | * Michel Deslierres 34 | * May 8, 2024 35 | * 36 | * Copyright 2024, Michel Deslierres. No rights reserved, this code is in the public domain. 37 | * In those jurisdictions where this may be a problem, the BSD Zero Clause License applies. 38 | * 39 | */ 40 | 41 | // SPDX-License-Identifier: 0BSD 42 | -------------------------------------------------------------------------------- /01_pin_names/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [platformio] 12 | ; Make the Arduino IDE happy (.INO file must be in a directory of the same name) 13 | src_dir = pin_names 14 | ;default_envs = super_mini_c3 15 | default_envs = super_mini_esp32c3 16 | 17 | [extra] 18 | baud=460800 19 | 20 | [env] 21 | platform = espressif32 22 | framework = arduino 23 | ;upload_port = /dev/ttyACM0 24 | ;monitor_port = /dev/ttyACM0 25 | monitor_speed = ${extra.baud} 26 | 27 | ; using a "near enough" board definition 28 | [env:super_mini_c3] 29 | board = dfrobot_beetle_esp32c3 30 | build_flags = 31 | -D ARDUINO_SUPER_MINI_C3 32 | 33 | ; using a custom added board definition 34 | [env:super_mini_esp32c3] 35 | board = super_mini_esp32c3 36 | -------------------------------------------------------------------------------- /02_blink_pulse_led/.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | .vscode/.browse.c_cpp.db* 3 | .vscode/c_cpp_properties.json 4 | .vscode/launch.json 5 | .vscode/ipch 6 | -------------------------------------------------------------------------------- /02_blink_pulse_led/blink_pulse_led/blink_pulse_led.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * blink_pulse_led.ino 3 | * 4 | * Alternately blinks (heartbeat) and pulses the on board LED 5 | * of an ESP32-C3 based Super Mini 6 | * 7 | * This is a stub to satisfy the Arduino IDE, the source code is in 8 | * the file main.cpp in the same directory. 9 | * 10 | * This sketch will compile in the Arduino IDE 11 | * 12 | * 1- Add https://espressif.github.io/arduino-esp32/package_esp32_index.json 13 | * in the Additional Boards Manager URLS in the Preferences window. 14 | * 2- Install platform esp32 by Espressif version 3.0.1 or newer with the Boards Manager 15 | * 3- Select the MakerGO ESP32 C3 SuperMini board 16 | * 17 | * This sketch will also compile in PlatformIO with platform espressif32 v6.6.0 or newer 18 | * 19 | * Use the following platformio.ini configuration file 20 | * [env:dfrobot_beetle_esp32c3] 21 | * platform = espressif32 22 | * board = dfrobot_beetle_esp32c3 23 | * framework = arduino 24 | * 25 | * or use 26 | * [env:super_mini_esp32c3] 27 | * platform = espressif32 28 | * board = super_mini_esp32c3 29 | * framework = arduino 30 | * if the the board definition file super_mini_esp32c3.json and the variant pin 31 | * definition file pins_arduino.h have been added as explained in 32 | * https://github.com/sigmdel/supermini_esp32c3_sketches/tree/main/resources 33 | * 34 | * Michel Deslierres 35 | * May 8, 2024 36 | * 37 | * Copyright 2024, Michel Deslierres. No rights reserved, this code is in the public domain. 38 | * In those jurisdictions where this may be a problem, the BSD Zero Clause License applies. 39 | * 40 | */ 41 | 42 | // SPDX-License-Identifier: 0BSD 43 | -------------------------------------------------------------------------------- /02_blink_pulse_led/blink_pulse_led/main.cpp: -------------------------------------------------------------------------------- 1 | // Main module of blink_pulse_led 2 | // Copyright: see notice in blink_pulse.ino 3 | 4 | #include 5 | 6 | #if defined(ARDUINO_SUPER_MINI_ESP32C3) 7 | static uint8_t ledPin = BUILTIN_LED; // LED connected to digital pin 8 | #else 9 | static uint8_t ledPin = 8; // LED connected to digital pin 10 | #endif 11 | 12 | static uint8_t ledOn = LOW; 13 | 14 | void setup() { 15 | // declaring LED pin as output 16 | pinMode(ledPin, OUTPUT); 17 | } 18 | 19 | #define DELTA 10 20 | #define DELAY 50 21 | 22 | unsigned long delaytime = 0; 23 | int delta = 5; 24 | int fade = 0; 25 | 26 | void pulse(void) { 27 | if (millis() - delaytime > DELAY) { 28 | fade += delta; 29 | if (fade <= 0) { 30 | fade = 0; 31 | delta = DELTA; 32 | } else if (fade >= 255) { 33 | fade = 255; 34 | delta = - DELTA; 35 | } 36 | analogWrite(ledPin, fade); 37 | delaytime = millis(); 38 | } 39 | } 40 | 41 | 42 | #define ON_TIME 80 43 | #define OFF_TIME 840 44 | 45 | unsigned long beattime = 0; 46 | int beatcount = 0; 47 | int beatdelay = 0; 48 | 49 | /* beatcount 50 | 0 = on short 51 | 1 = off short 52 | 2 = on short 53 | 3 = off long 54 | */ 55 | 56 | void heartbeat(void) { 57 | if (millis() - beattime > beatdelay) { 58 | if ((beatcount & 1) == 1) 59 | digitalWrite(ledPin, 1-ledOn); 60 | else 61 | digitalWrite(ledPin, ledOn); 62 | if (beatcount == 3) { 63 | beatdelay = OFF_TIME; 64 | beatcount = 0; 65 | } else { 66 | beatdelay = ON_TIME; 67 | beatcount++; 68 | } 69 | beattime = millis(); 70 | } 71 | } 72 | 73 | unsigned long timer = 0; 74 | bool doHeartBeat = true; 75 | 76 | void loop() { 77 | if (doHeartBeat) 78 | heartbeat(); 79 | else 80 | pulse(); 81 | if (millis() - timer > 10000) { 82 | doHeartBeat = (!doHeartBeat); 83 | pinMode(ledPin, OUTPUT); 84 | timer = millis(); 85 | } 86 | // do other stuff here 87 | } 88 | -------------------------------------------------------------------------------- /02_blink_pulse_led/include/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project header files. 3 | 4 | A header file is a file containing C declarations and macro definitions 5 | to be shared between several project source files. You request the use of a 6 | header file in your project source file (C, C++, etc) located in `src` folder 7 | by including it, with the C preprocessing directive `#include'. 8 | 9 | ```src/main.c 10 | 11 | #include "header.h" 12 | 13 | int main (void) 14 | { 15 | ... 16 | } 17 | ``` 18 | 19 | Including a header file produces the same results as copying the header file 20 | into each source file that needs it. Such copying would be time-consuming 21 | and error-prone. With a header file, the related declarations appear 22 | in only one place. If they need to be changed, they can be changed in one 23 | place, and programs that include the header file will automatically use the 24 | new version when next recompiled. The header file eliminates the labor of 25 | finding and changing all the copies as well as the risk that a failure to 26 | find one copy will result in inconsistencies within a program. 27 | 28 | In C, the usual convention is to give header files names that end with `.h'. 29 | It is most portable to use only letters, digits, dashes, and underscores in 30 | header file names, and at most one dot. 31 | 32 | Read more about using header files in official GCC documentation: 33 | 34 | * Include Syntax 35 | * Include Operation 36 | * Once-Only Headers 37 | * Computed Includes 38 | 39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html 40 | -------------------------------------------------------------------------------- /02_blink_pulse_led/lib/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link into executable file. 4 | 5 | The source code of each library should be placed in an own separate directory 6 | ("lib/your_library_name/[here are source files]"). 7 | 8 | For example, see a structure of the following two libraries `Foo` and `Bar`: 9 | 10 | |--lib 11 | | | 12 | | |--Bar 13 | | | |--docs 14 | | | |--examples 15 | | | |--src 16 | | | |- Bar.c 17 | | | |- Bar.h 18 | | | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html 19 | | | 20 | | |--Foo 21 | | | |- Foo.c 22 | | | |- Foo.h 23 | | | 24 | | |- README --> THIS FILE 25 | | 26 | |- platformio.ini 27 | |--src 28 | |- main.c 29 | 30 | and a contents of `src/main.c`: 31 | ``` 32 | #include 33 | #include 34 | 35 | int main (void) 36 | { 37 | ... 38 | } 39 | 40 | ``` 41 | 42 | PlatformIO Library Dependency Finder will find automatically dependent 43 | libraries scanning project source files. 44 | 45 | More information about PlatformIO Library Dependency Finder 46 | - https://docs.platformio.org/page/librarymanager/ldf.html 47 | -------------------------------------------------------------------------------- /02_blink_pulse_led/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [platformio] 12 | ; Make the Arduino IDE happy (.INO file must be in a directory of the same name) 13 | src_dir = blink_pulse_led 14 | ;default_envs = super_mini_c3 15 | default_envs = super_mini_esp32c3 16 | 17 | [extra] 18 | baud=460800 19 | 20 | [env] 21 | platform = espressif32 22 | framework = arduino 23 | ;upload_port = /dev/ttyACM0 24 | ;monitor_port = /dev/ttyACM0 25 | monitor_speed = ${extra.baud} 26 | 27 | ; using a "near enough" board definition 28 | [env:super_mini_c3] 29 | board = dfrobot_beetle_esp32c3 30 | build_flags = 31 | -D ARDUINO_SUPER_MINI_C3 32 | 33 | ; using a custom added board definition 34 | [env:super_mini_esp32c3] 35 | board = super_mini_esp32c3 36 | -------------------------------------------------------------------------------- /02_blink_pulse_led/test/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for PlatformIO Test Runner and project tests. 3 | 4 | Unit Testing is a software testing method by which individual units of 5 | source code, sets of one or more MCU program modules together with associated 6 | control data, usage procedures, and operating procedures, are tested to 7 | determine whether they are fit for use. Unit testing finds problems early 8 | in the development cycle. 9 | 10 | More information about PlatformIO Unit Testing: 11 | - https://docs.platformio.org/en/latest/advanced/unit-testing/index.html 12 | -------------------------------------------------------------------------------- /03_scan_wifi/.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | .vscode/.browse.c_cpp.db* 3 | .vscode/c_cpp_properties.json 4 | .vscode/launch.json 5 | .vscode/ipch 6 | -------------------------------------------------------------------------------- /03_scan_wifi/include/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project header files. 3 | 4 | A header file is a file containing C declarations and macro definitions 5 | to be shared between several project source files. You request the use of a 6 | header file in your project source file (C, C++, etc) located in `src` folder 7 | by including it, with the C preprocessing directive `#include'. 8 | 9 | ```src/main.c 10 | 11 | #include "header.h" 12 | 13 | int main (void) 14 | { 15 | ... 16 | } 17 | ``` 18 | 19 | Including a header file produces the same results as copying the header file 20 | into each source file that needs it. Such copying would be time-consuming 21 | and error-prone. With a header file, the related declarations appear 22 | in only one place. If they need to be changed, they can be changed in one 23 | place, and programs that include the header file will automatically use the 24 | new version when next recompiled. The header file eliminates the labor of 25 | finding and changing all the copies as well as the risk that a failure to 26 | find one copy will result in inconsistencies within a program. 27 | 28 | In C, the usual convention is to give header files names that end with `.h'. 29 | It is most portable to use only letters, digits, dashes, and underscores in 30 | header file names, and at most one dot. 31 | 32 | Read more about using header files in official GCC documentation: 33 | 34 | * Include Syntax 35 | * Include Operation 36 | * Once-Only Headers 37 | * Computed Includes 38 | 39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html 40 | -------------------------------------------------------------------------------- /03_scan_wifi/lib/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link into executable file. 4 | 5 | The source code of each library should be placed in an own separate directory 6 | ("lib/your_library_name/[here are source files]"). 7 | 8 | For example, see a structure of the following two libraries `Foo` and `Bar`: 9 | 10 | |--lib 11 | | | 12 | | |--Bar 13 | | | |--docs 14 | | | |--examples 15 | | | |--src 16 | | | |- Bar.c 17 | | | |- Bar.h 18 | | | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html 19 | | | 20 | | |--Foo 21 | | | |- Foo.c 22 | | | |- Foo.h 23 | | | 24 | | |- README --> THIS FILE 25 | | 26 | |- platformio.ini 27 | |--src 28 | |- main.c 29 | 30 | and a contents of `src/main.c`: 31 | ``` 32 | #include 33 | #include 34 | 35 | int main (void) 36 | { 37 | ... 38 | } 39 | 40 | ``` 41 | 42 | PlatformIO Library Dependency Finder will find automatically dependent 43 | libraries scanning project source files. 44 | 45 | More information about PlatformIO Library Dependency Finder 46 | - https://docs.platformio.org/page/librarymanager/ldf.html 47 | -------------------------------------------------------------------------------- /03_scan_wifi/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [platformio] 12 | ; Make the Arduino IDE happy (.INO file must be in a directory of the same name) 13 | src_dir = scan_wifi 14 | ;default_envs = super_mini_c3 15 | default_envs = super_mini_esp32c3 16 | ;default_envs = seeed_xiao_esp32c3 17 | 18 | [extra] 19 | baud=460800 20 | 21 | [env] 22 | platform = espressif32 23 | framework = arduino 24 | ;upload_port = /dev/ttyACM0 25 | ;monitor_port = /dev/ttyACM0 26 | monitor_speed = ${extra.baud} 27 | 28 | ; using a "near enough" board definition 29 | [env:super_mini_c3] 30 | board = dfrobot_beetle_esp32c3 31 | build_flags = 32 | -D ARDUINO_SUPER_MINI_C3 33 | 34 | ; using a custom added board definition 35 | [env:super_mini_esp32c3] 36 | board = super_mini_esp32c3 37 | 38 | ; using XIAO ESP32C for comparisons 39 | [env:seeed_xiao_esp32c3] 40 | board = seeed_xiao_esp32c3 41 | -------------------------------------------------------------------------------- /03_scan_wifi/scan_wifi/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This sketch demonstrates how to scan WiFi networks. 3 | * The API is based on the Arduino WiFi Shield library, but has significant changes as newer WiFi functions are supported. 4 | * E.g. the return value of `encryptionType()` different because more modern encryption is supported. 5 | * Source: https://github.com/espressif/arduino-esp32/tree/master/libraries/WiFi/examples/WiFiScan 6 | */ 7 | #include 8 | #include "WiFi.h" 9 | 10 | void setup() { 11 | Serial.begin(); 12 | // Set WiFi to station mode and disconnect from an AP if it was previously connected. 13 | WiFi.mode(WIFI_STA); 14 | WiFi.disconnect(); 15 | delay(2000); 16 | Serial.println("Setup done"); 17 | } 18 | 19 | void loop() { 20 | Serial.println("Scan start"); 21 | 22 | // WiFi.scanNetworks will return the number of networks found. 23 | int n = WiFi.scanNetworks(); 24 | Serial.println("Scan done"); 25 | if (n == 0) { 26 | Serial.println("no networks found"); 27 | } else { 28 | Serial.print(n); 29 | Serial.println(" networks found"); 30 | Serial.println("Nr | SSID | RSSI | CH | Encryption"); 31 | for (int i = 0; i < n; ++i) { 32 | // Print SSID and RSSI for each network found 33 | Serial.printf("%2d", i + 1); 34 | Serial.print(" | "); 35 | Serial.printf("%-32.32s", WiFi.SSID(i).c_str()); 36 | Serial.print(" | "); 37 | Serial.printf("%4ld", WiFi.RSSI(i)); 38 | Serial.print(" | "); 39 | Serial.printf("%2ld", WiFi.channel(i)); 40 | Serial.print(" | "); 41 | switch (WiFi.encryptionType(i)) { 42 | case WIFI_AUTH_OPEN: Serial.print("open"); break; 43 | case WIFI_AUTH_WEP: Serial.print("WEP"); break; 44 | case WIFI_AUTH_WPA_PSK: Serial.print("WPA"); break; 45 | case WIFI_AUTH_WPA2_PSK: Serial.print("WPA2"); break; 46 | case WIFI_AUTH_WPA_WPA2_PSK: Serial.print("WPA+WPA2"); break; 47 | case WIFI_AUTH_WPA2_ENTERPRISE: Serial.print("WPA2-EAP"); break; 48 | case WIFI_AUTH_WPA3_PSK: Serial.print("WPA3"); break; 49 | case WIFI_AUTH_WPA2_WPA3_PSK: Serial.print("WPA2+WPA3"); break; 50 | case WIFI_AUTH_WAPI_PSK: Serial.print("WAPI"); break; 51 | default: Serial.print("unknown"); 52 | } 53 | Serial.println(); 54 | delay(10); 55 | } 56 | } 57 | Serial.println(""); 58 | 59 | // Delete the scan result to free memory for code below. 60 | WiFi.scanDelete(); 61 | 62 | // Wait a bit before scanning again. 63 | delay(5000); 64 | } 65 | -------------------------------------------------------------------------------- /03_scan_wifi/scan_wifi/scan_wifi.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * scan_wifi.ino 3 | * 4 | * Prints a list of available wifi networks every five seconds with 5 | * an ESP32-C3 based Super Mini 6 | * 7 | * This is a stub to satisfy the Arduino IDE, the source code is in 8 | * the file main.cpp in the same directory. 9 | * 10 | * This sketch will compile in the Arduino IDE 11 | * 12 | * 1- Add https://espressif.github.io/arduino-esp32/package_esp32_index.json 13 | * in the Additional Boards Manager URLS in the Preferences window. 14 | * 2- Install platform esp32 by Espressif version 3.0.1 or newer with the Boards Manager 15 | * 3- Select the MakerGO ESP32 C3 SuperMini board 16 | * 17 | * This sketch will also compile in PlatformIO with platform espressif32 v6.6.0 or newer 18 | * 19 | * Use the following platformio.ini configuration file 20 | * [env:dfrobot_beetle_esp32c3] 21 | * platform = espressif32 22 | * board = dfrobot_beetle_esp32c3 23 | * framework = arduino 24 | * 25 | * or use 26 | * [env:super_mini_esp32c3] 27 | * platform = espressif32 28 | * board = super_mini_esp32c3 29 | * framework = arduino 30 | * if the the board definition file super_mini_esp32c3.json and the variant pin 31 | * definition file pins_arduino.h have been added as explained in 32 | * https://github.com/sigmdel/supermini_esp32c3_sketches/tree/main/resources 33 | * 34 | * Michel Deslierres 35 | * May 8, 2024 36 | * 37 | * Source: Example WiFiScan.ino in the arduino-esp32 core 38 | * @https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/examples/WiFiScan/WiFiScan.ino 39 | * 40 | * License: unknown for the example file. 41 | * The GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 applies for 42 | * the complete arduino-esp32 package. See 43 | * https://github.com/espressif/arduino-esp32/blob/master/LICENSE.md 44 | */ 45 | -------------------------------------------------------------------------------- /03_scan_wifi/test/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for PlatformIO Test Runner and project tests. 3 | 4 | Unit Testing is a software testing method by which individual units of 5 | source code, sets of one or more MCU program modules together with associated 6 | control data, usage procedures, and operating procedures, are tested to 7 | determine whether they are fit for use. Unit testing finds problems early 8 | in the development cycle. 9 | 10 | More information about PlatformIO Unit Testing: 11 | - https://docs.platformio.org/en/latest/advanced/unit-testing/index.html 12 | -------------------------------------------------------------------------------- /04_wifi_connect/.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | .vscode/.browse.c_cpp.db* 3 | .vscode/c_cpp_properties.json 4 | .vscode/launch.json 5 | .vscode/ipch 6 | -------------------------------------------------------------------------------- /04_wifi_connect/include/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project header files. 3 | 4 | A header file is a file containing C declarations and macro definitions 5 | to be shared between several project source files. You request the use of a 6 | header file in your project source file (C, C++, etc) located in `src` folder 7 | by including it, with the C preprocessing directive `#include'. 8 | 9 | ```src/main.c 10 | 11 | #include "header.h" 12 | 13 | int main (void) 14 | { 15 | ... 16 | } 17 | ``` 18 | 19 | Including a header file produces the same results as copying the header file 20 | into each source file that needs it. Such copying would be time-consuming 21 | and error-prone. With a header file, the related declarations appear 22 | in only one place. If they need to be changed, they can be changed in one 23 | place, and programs that include the header file will automatically use the 24 | new version when next recompiled. The header file eliminates the labor of 25 | finding and changing all the copies as well as the risk that a failure to 26 | find one copy will result in inconsistencies within a program. 27 | 28 | In C, the usual convention is to give header files names that end with `.h'. 29 | It is most portable to use only letters, digits, dashes, and underscores in 30 | header file names, and at most one dot. 31 | 32 | Read more about using header files in official GCC documentation: 33 | 34 | * Include Syntax 35 | * Include Operation 36 | * Once-Only Headers 37 | * Computed Includes 38 | 39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html 40 | -------------------------------------------------------------------------------- /04_wifi_connect/lib/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link into executable file. 4 | 5 | The source code of each library should be placed in an own separate directory 6 | ("lib/your_library_name/[here are source files]"). 7 | 8 | For example, see a structure of the following two libraries `Foo` and `Bar`: 9 | 10 | |--lib 11 | | | 12 | | |--Bar 13 | | | |--docs 14 | | | |--examples 15 | | | |--src 16 | | | |- Bar.c 17 | | | |- Bar.h 18 | | | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html 19 | | | 20 | | |--Foo 21 | | | |- Foo.c 22 | | | |- Foo.h 23 | | | 24 | | |- README --> THIS FILE 25 | | 26 | |- platformio.ini 27 | |--src 28 | |- main.c 29 | 30 | and a contents of `src/main.c`: 31 | ``` 32 | #include 33 | #include 34 | 35 | int main (void) 36 | { 37 | ... 38 | } 39 | 40 | ``` 41 | 42 | PlatformIO Library Dependency Finder will find automatically dependent 43 | libraries scanning project source files. 44 | 45 | More information about PlatformIO Library Dependency Finder 46 | - https://docs.platformio.org/page/librarymanager/ldf.html 47 | -------------------------------------------------------------------------------- /04_wifi_connect/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [platformio] 12 | ; Make the Arduino IDE happy (.INO file must be in a directory of the same name) 13 | src_dir = wifi_connect 14 | ;default_envs = super_mini_c3 15 | default_envs = super_mini_esp32c3 16 | ;default_envs = seeed_xiao_esp32c3 17 | 18 | [extra] 19 | baud=460800 20 | 21 | [env] 22 | platform = espressif32 23 | framework = arduino 24 | ;upload_port = /dev/ttyACM0 25 | ;monitor_port = /dev/ttyACM0 26 | monitor_speed = ${extra.baud} 27 | 28 | ; using a "near enough" board definition 29 | [env:super_mini_c3] 30 | board = dfrobot_beetle_esp32c3 31 | build_flags = 32 | -D ARDUINO_SUPER_MINI_C3 33 | 34 | ; using a custom added board definition 35 | [env:super_mini_esp32c3] 36 | board = super_mini_esp32c3 37 | 38 | ; using XIAO ESP32C for comparisons 39 | [env:seeed_xiao_esp32c3] 40 | board = seeed_xiao_esp32c3 41 | -------------------------------------------------------------------------------- /04_wifi_connect/test/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for PlatformIO Test Runner and project tests. 3 | 4 | Unit Testing is a software testing method by which individual units of 5 | source code, sets of one or more MCU program modules together with associated 6 | control data, usage procedures, and operating procedures, are tested to 7 | determine whether they are fit for use. Unit testing finds problems early 8 | in the development cycle. 9 | 10 | More information about PlatformIO Unit Testing: 11 | - https://docs.platformio.org/en/latest/advanced/unit-testing/index.html 12 | -------------------------------------------------------------------------------- /04_wifi_connect/wifi_connect/main.cpp: -------------------------------------------------------------------------------- 1 | // Main module of wifi_connect 2 | // Copyright: see notice in wifi_connect.ino 3 | 4 | #include 5 | #include 6 | #include "secrets.h" 7 | 8 | //#define TRY_TX_POWER 9 | // Define the above macro to set the Wi-Fi tx power level 10 | // before attempting to connect to a Wi-Fi network. 11 | 12 | #ifdef TRY_TX_POWER 13 | #define TX_POWER WIFI_POWER_11dBm 14 | // Set the above macro to the power level. See 15 | // https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/src/WiFiGeneric.h 16 | #endif 17 | 18 | //#define TEST_DISCONNECT 19 | // Define the above macro to verify that WiFi.disconnect(true, true) 20 | // truly wipes the WiFi data from non volatile storage 21 | 22 | #define TIMEOUT 120000 // 2 minutes 23 | 24 | unsigned long connect_time = 0; 25 | unsigned long etime = 0; 26 | unsigned long dottime = 0; 27 | int count = 0; 28 | 29 | void start_connecting(void) { 30 | if (WiFi.isConnected()) { 31 | Serial.println("Disconnecting"); 32 | WiFi.setAutoReconnect(false); 33 | WiFi.disconnect(true, true); 34 | while (WiFi.isConnected()) delay(5); 35 | Serial.println("Disconnected"); 36 | delay(5000); 37 | } 38 | Serial.printf("\nAttempting to connect to the Wi-Fi network for %.1f sec.\n", (1.0*TIMEOUT)/1000); 39 | 40 | WiFi.mode(WIFI_STA); 41 | WiFi.setAutoReconnect(false); 42 | #ifdef TRY_TX_POWER 43 | if (count) { 44 | delay(25); 45 | if (WiFi.getTxPower() != TX_POWER) { 46 | WiFi.setTxPower(TX_POWER); 47 | delay(25); 48 | } 49 | } 50 | Serial.printf("Wi-Fi TX power set to: %d\n", WiFi.getTxPower()); 51 | #endif 52 | connect_time = millis(); 53 | dottime = millis(); 54 | #ifdef TEST_DISCONNECT 55 | if (count > 4) // making sure that data was wiped 56 | WiFi.begin(); 57 | /* will fail 58 | Connecting to WiFi access point 59 | [ 42188][E][WiFiSTA.cpp:317] begin(): connect failed! 0x300a 60 | and esp_err_to_name(0x300a) --> "ESP_ERR_WIFI_SSID" 61 | proving that a valid SSID is no longer in NVS 62 | */ 63 | else 64 | #endif 65 | WiFi.begin(ssid, password); 66 | } 67 | 68 | void getStatus(void) { 69 | switch(WiFi.status()) { 70 | case WL_NO_SSID_AVAIL: 71 | Serial.println("[WiFi] SSID not found"); 72 | break; 73 | case WL_CONNECT_FAILED: 74 | Serial.print("[WiFi] Failed - WiFi not connected! Reason: "); 75 | return; 76 | break; 77 | case WL_CONNECTION_LOST: 78 | Serial.println("[WiFi] Connection was lost"); 79 | break; 80 | case WL_SCAN_COMPLETED: 81 | Serial.println("[WiFi] Scan is completed"); 82 | break; 83 | case WL_DISCONNECTED: 84 | Serial.println("[WiFi] WiFi is disconnected"); 85 | break; 86 | case WL_CONNECTED: 87 | Serial.print("[WiFi] WiFi is connected. IP address: "); 88 | Serial.println(WiFi.localIP()); 89 | break; 90 | default: 91 | Serial.print("[WiFi] WiFi Status: "); 92 | Serial.println(WiFi.status()); 93 | break; 94 | } 95 | } 96 | 97 | void setup() { 98 | Serial.begin(); 99 | delay(2000); 100 | Serial.println(); 101 | #ifdef TEST_DISCONNECT 102 | Serial.print("sp_err_to_name(0x300a) -> "); 103 | Serial.println(esp_err_to_name(0x300a)); 104 | #endif 105 | start_connecting(); 106 | } 107 | 108 | void loop() { 109 | if (WiFi.isConnected()) { 110 | etime = millis() - connect_time; 111 | Serial.print("\nWiFi is connected with IP address: "); 112 | Serial.println(WiFi.localIP()); 113 | Serial.printf("Time to connect: %u ms\n", etime); 114 | delay(1000); 115 | start_connecting(); 116 | count++; 117 | } else if (millis() - dottime > 2000) { 118 | Serial.print('.'); 119 | dottime = millis(); 120 | } 121 | if (millis() - connect_time > TIMEOUT) { 122 | Serial.printf("\nNot connected after %.1f seconds\n", (1.0*TIMEOUT)/1000); 123 | getStatus(); 124 | Serial.println("Retrying in 1 second"); 125 | delay(1000); 126 | count++; 127 | start_connecting(); 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /04_wifi_connect/wifi_connect/secrets.h.template: -------------------------------------------------------------------------------- 1 | // Replace with the correct network credentials 2 | const char* ssid = "***Wi-Fi***Network***Name***"; 3 | const char* password = "***Wi-Fi***Network***Password***"; 4 | -------------------------------------------------------------------------------- /04_wifi_connect/wifi_connect/wifi_connect.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * wifi_connect.ino 3 | * 4 | * Wi-Fi station connect example 5 | * 6 | * This is a stub to satisfy the Arduino IDE, the source code is in 7 | * the file main.cpp in the same directory. 8 | * 9 | * This sketch will compile in the Arduino IDE 10 | * 11 | * 1- Add https://espressif.github.io/arduino-esp32/package_esp32_index.json 12 | * in the Additional Boards Manager URLS in the Preferences window. 13 | * 2- Install platform esp32 by Espressif version 3.0.1 or newer with the Boards Manager 14 | * 3- Select the MakerGO ESP32 C3 SuperMini board 15 | * 16 | * This sketch will also compile in PlatformIO with platform espressif32 v6.6.0 or newer 17 | * 18 | * Use the following platformio.ini configuration file 19 | * [env:dfrobot_beetle_esp32c3] 20 | * platform = espressif32 21 | * board = dfrobot_beetle_esp32c3 22 | * framework = arduino 23 | * 24 | * or use 25 | * [env:super_mini_esp32c3] 26 | * platform = espressif32 27 | * board = super_mini_esp32c3 28 | * framework = arduino 29 | * if the the board definition file super_mini_esp32c3.json and the variant pin 30 | * definition file pins_arduino.h have been added as explained in 31 | * https://github.com/sigmdel/supermini_esp32c3_sketches/tree/main/resources 32 | * 33 | * Michel Deslierres 34 | * May 9, 2024 35 | 36 | * Based on WiFiClientConnect.ino 37 | * @ https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/examples/WiFiClientConnect/WiFiClientConnect.ino 38 | * 39 | * License of original work: 40 | ** This example code is in the Public Domain (or CC0 licensed, at your option.) 41 | ** 42 | ** Unless required by applicable law or agreed to in writing, this 43 | ** software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 44 | ** CONDITIONS OF ANY KIND, either express or implied. 45 | */ 46 | -------------------------------------------------------------------------------- /05_wifi_tx_power/.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | .vscode/.browse.c_cpp.db* 3 | .vscode/c_cpp_properties.json 4 | .vscode/launch.json 5 | .vscode/ipch 6 | -------------------------------------------------------------------------------- /05_wifi_tx_power/include/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project header files. 3 | 4 | A header file is a file containing C declarations and macro definitions 5 | to be shared between several project source files. You request the use of a 6 | header file in your project source file (C, C++, etc) located in `src` folder 7 | by including it, with the C preprocessing directive `#include'. 8 | 9 | ```src/main.c 10 | 11 | #include "header.h" 12 | 13 | int main (void) 14 | { 15 | ... 16 | } 17 | ``` 18 | 19 | Including a header file produces the same results as copying the header file 20 | into each source file that needs it. Such copying would be time-consuming 21 | and error-prone. With a header file, the related declarations appear 22 | in only one place. If they need to be changed, they can be changed in one 23 | place, and programs that include the header file will automatically use the 24 | new version when next recompiled. The header file eliminates the labor of 25 | finding and changing all the copies as well as the risk that a failure to 26 | find one copy will result in inconsistencies within a program. 27 | 28 | In C, the usual convention is to give header files names that end with `.h'. 29 | It is most portable to use only letters, digits, dashes, and underscores in 30 | header file names, and at most one dot. 31 | 32 | Read more about using header files in official GCC documentation: 33 | 34 | * Include Syntax 35 | * Include Operation 36 | * Once-Only Headers 37 | * Computed Includes 38 | 39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html 40 | -------------------------------------------------------------------------------- /05_wifi_tx_power/lib/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link into executable file. 4 | 5 | The source code of each library should be placed in an own separate directory 6 | ("lib/your_library_name/[here are source files]"). 7 | 8 | For example, see a structure of the following two libraries `Foo` and `Bar`: 9 | 10 | |--lib 11 | | | 12 | | |--Bar 13 | | | |--docs 14 | | | |--examples 15 | | | |--src 16 | | | |- Bar.c 17 | | | |- Bar.h 18 | | | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html 19 | | | 20 | | |--Foo 21 | | | |- Foo.c 22 | | | |- Foo.h 23 | | | 24 | | |- README --> THIS FILE 25 | | 26 | |- platformio.ini 27 | |--src 28 | |- main.c 29 | 30 | and a contents of `src/main.c`: 31 | ``` 32 | #include 33 | #include 34 | 35 | int main (void) 36 | { 37 | ... 38 | } 39 | 40 | ``` 41 | 42 | PlatformIO Library Dependency Finder will find automatically dependent 43 | libraries scanning project source files. 44 | 45 | More information about PlatformIO Library Dependency Finder 46 | - https://docs.platformio.org/page/librarymanager/ldf.html 47 | -------------------------------------------------------------------------------- /05_wifi_tx_power/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [platformio] 12 | ; Make the Arduino IDE happy (.INO file must be in a directory of the same name) 13 | src_dir = wifi_tx_power 14 | ;default_envs = super_mini_c3 15 | default_envs = super_mini_esp32c3 16 | ;default_envs = seeed_xiao_esp32c3 17 | 18 | [extra] 19 | baud=460800 20 | 21 | [env] 22 | platform = espressif32 23 | framework = arduino 24 | ;upload_port = /dev/ttyACM0 25 | ;monitor_port = /dev/ttyACM0 26 | monitor_speed = ${extra.baud} 27 | 28 | ; using a "near enough" board definition 29 | [env:super_mini_c3] 30 | board = dfrobot_beetle_esp32c3 31 | build_flags = 32 | -D ARDUINO_SUPER_MINI_C3 33 | 34 | ; using a custom added board definition 35 | [env:super_mini_esp32c3] 36 | board = super_mini_esp32c3 37 | 38 | ; using XIAO ESP32C for comparisons 39 | [env:seeed_xiao_esp32c3] 40 | board = seeed_xiao_esp32c3 41 | -------------------------------------------------------------------------------- /05_wifi_tx_power/test/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for PlatformIO Test Runner and project tests. 3 | 4 | Unit Testing is a software testing method by which individual units of 5 | source code, sets of one or more MCU program modules together with associated 6 | control data, usage procedures, and operating procedures, are tested to 7 | determine whether they are fit for use. Unit testing finds problems early 8 | in the development cycle. 9 | 10 | More information about PlatformIO Unit Testing: 11 | - https://docs.platformio.org/en/latest/advanced/unit-testing/index.html 12 | -------------------------------------------------------------------------------- /05_wifi_tx_power/wifi_tx_power/main.cpp: -------------------------------------------------------------------------------- 1 | // Main module of wifi_tx_power 2 | // Copyright: see notice in wifi_tx_power.ino 3 | 4 | #include 5 | #include 6 | #include "secrets.h" 7 | 8 | 9 | // Define the title macro as needed for each supported board 10 | 11 | #if defined(ARDUINO_MAKERGO_C3_SUPERMINI) 12 | #define TITLE "MakerGO C3 SuperMini" 13 | #elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI) 14 | #define TITLE "Nologo ESP32C3 Super Mini" 15 | #elif defined(ARDUINO_SUPER_MINI_C3) 16 | #define TITLE "DfRobot Beetle ESP32-C3" 17 | #elif defined(ARDUINO_SUPER_MINI_ESP32C3) 18 | #define TITLE "Custom ESP32C3 Super Mini" 19 | #elif defined(ARDUINO_XIAO_ESP32C3) 20 | #define TITLE "Seeed XIAO ESP32C3" 21 | elif defined(ARDUINO_ESP32C3_DEV) 22 | #define TITLE "ESP32-C3 Dev Module" 23 | #else 24 | #error "Unknown device" 25 | #endif 26 | 27 | #define TIMEOUT 120000 // 2 minutes, time until connection deemed impossible 28 | 29 | 30 | /* 31 | from ../.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFiGeneric.h 32 | 33 | typedef enum { 34 | WIFI_POWER_19_5dBm = 78,// 19.5dBm 35 | WIFI_POWER_19dBm = 76,// 19dBm 36 | WIFI_POWER_18_5dBm = 74,// 18.5dBm 37 | WIFI_POWER_17dBm = 68,// 17dBm 38 | WIFI_POWER_15dBm = 60,// 15dBm 39 | WIFI_POWER_13dBm = 52,// 13dBm 40 | WIFI_POWER_11dBm = 44,// 11dBm 41 | WIFI_POWER_8_5dBm = 34,// 8.5dBm 42 | WIFI_POWER_7dBm = 28,// 7dBm 43 | WIFI_POWER_5dBm = 20,// 5dBm 44 | WIFI_POWER_2dBm = 8,// 2dBm 45 | WIFI_POWER_MINUS_1dBm = -4// -1dBm 46 | } wifi_power_t; 47 | */ 48 | 49 | const int powerCount = 13; 50 | 51 | int power[powerCount] = { 52 | 0, 53 | WIFI_POWER_19_5dBm, WIFI_POWER_19dBm, WIFI_POWER_18_5dBm, WIFI_POWER_17dBm, 54 | WIFI_POWER_15dBm, WIFI_POWER_13dBm, WIFI_POWER_11dBm, WIFI_POWER_8_5dBm, 55 | WIFI_POWER_7dBm, WIFI_POWER_5dBm, WIFI_POWER_2dBm, WIFI_POWER_MINUS_1dBm}; 56 | 57 | const char *powerstr[powerCount] = { 58 | "WIFI_POWER_default", 59 | "WIFI_POWER_19_5dBm", "WIFI_POWER_19dBm", "WIFI_POWER_18_5dBm", "WIFI_POWER_17dBm", 60 | "WIFI_POWER_15dBm", "WIFI_POWER_13dBm", "WIFI_POWER_11dBm", "WIFI_POWER_8_5dBm", 61 | "WIFI_POWER_7dBm", "WIFI_POWER_5dBm", "WIFI_POWER_2dBm", "WIFI_POWER_MINUS_1dBm"}; 62 | 63 | int truepower[powerCount] = {0}; 64 | 65 | long ctimes[powerCount] = {0}; 66 | 67 | void print_ctimes(void) { 68 | bool err = false; 69 | 70 | Serial.printf("\nBoard: %s\n", TITLE); 71 | Serial.println("Connect time vs txPower\n"); 72 | Serial.printf("%24s | %5s | %5s | %8s\n", "enum", "want", "set", "time (ms)"); 73 | Serial.printf("%26s %7s %7s\n", "|", "|", "|"); 74 | for (int i=0; i= powerCount)) return; 92 | 93 | if (WiFi.isConnected()) { 94 | Serial.println("Disconnecting"); 95 | WiFi.setAutoReconnect(false); 96 | WiFi.disconnect(true, true); 97 | while (WiFi.isConnected()) delay(5); 98 | Serial.println("Disconnected"); 99 | delay(5000); 100 | } 101 | Serial.println(); 102 | WiFi.mode(WIFI_STA); 103 | delay(25); 104 | int cpower = power[pwindex]; 105 | WiFi.setTxPower((wifi_power_t)cpower); 106 | delay(25); 107 | Serial.printf("Settting txPower to %s (%d)\n", powerstr[pwindex], cpower); 108 | int tpower = WiFi.getTxPower(); 109 | if (tpower != cpower) Serial.println("Unable to set txPower"); 110 | truepower[pwindex] = tpower; 111 | Serial.printf("Running pwindex %d, wanted txPower %s (%d), set to %d\n", pwindex, powerstr[pwindex], cpower, tpower); 112 | Serial.print("Connecting to "); 113 | Serial.println(ssid); 114 | 115 | connect_time = millis(); 116 | dottime = millis(); 117 | WiFi.begin(ssid, password); 118 | } 119 | 120 | void getStatus(void) { 121 | switch(WiFi.status()) { 122 | case WL_NO_SSID_AVAIL: 123 | Serial.println("[WiFi] SSID not found"); 124 | break; 125 | case WL_CONNECT_FAILED: 126 | Serial.print("[WiFi] Failed - WiFi not connected! Reason: "); 127 | return; 128 | break; 129 | case WL_CONNECTION_LOST: 130 | Serial.println("[WiFi] Connection was lost"); 131 | break; 132 | case WL_SCAN_COMPLETED: 133 | Serial.println("[WiFi] Scan is completed"); 134 | break; 135 | case WL_DISCONNECTED: 136 | Serial.println("[WiFi] WiFi is disconnected"); 137 | break; 138 | case WL_CONNECTED: 139 | Serial.print("[WiFi] WiFi is connected. IP address: "); 140 | Serial.println(WiFi.localIP()); 141 | break; 142 | default: 143 | Serial.print("[WiFi] WiFi Status: "); 144 | Serial.println(WiFi.status()); 145 | break; 146 | } 147 | } 148 | 149 | 150 | void setup() { 151 | Serial.begin(); 152 | delay(2000); 153 | Serial.println(); 154 | #ifdef TEST_DISCONNECT 155 | Serial.print("sp_err_to_name(0x300a) -> "); 156 | Serial.println(esp_err_to_name(0x300a)); 157 | #endif 158 | WiFi.mode(WIFI_STA); 159 | delay(25); 160 | power[0] = WiFi.getTxPower(); // default tx power on boot 161 | //print_ctimes(); 162 | start_connecting(0); 163 | } 164 | 165 | int txIndex = 0; 166 | 167 | void loop() { 168 | if (txIndex == powerCount) { 169 | print_ctimes(); 170 | txIndex++; 171 | } 172 | if (txIndex > powerCount) return; 173 | 174 | if (millis() - dottime > 2000) { 175 | Serial.print('.'); 176 | dottime = millis(); 177 | } 178 | 179 | if (WiFi.isConnected()) { 180 | etime = millis() - connect_time; 181 | Serial.print("\nWiFi is connected with IP address: "); 182 | Serial.println(WiFi.localIP()); 183 | Serial.printf("Time to connect: %u ms\n", etime); 184 | ctimes[txIndex] = etime; 185 | delay(1000); 186 | txIndex++; 187 | if (txIndex >= powerCount) return; 188 | start_connecting(txIndex); 189 | } 190 | 191 | if (millis() - connect_time > TIMEOUT) { 192 | Serial.printf("\nNot connected after %u ms\n", TIMEOUT); 193 | getStatus(); 194 | ctimes[txIndex] = -1; 195 | txIndex++; 196 | if (txIndex >= powerCount) return; 197 | Serial.println("Retrying in 5 seconds with different txPower"); 198 | delay(5000); 199 | start_connecting(txIndex); 200 | } 201 | } 202 | -------------------------------------------------------------------------------- /05_wifi_tx_power/wifi_tx_power/secrets.h.template: -------------------------------------------------------------------------------- 1 | // Replace with the correct network credentials 2 | const char* ssid = "***Wi-Fi***Network***Name***"; 3 | const char* password = "***Wi-Fi***Network***Password***"; 4 | -------------------------------------------------------------------------------- /05_wifi_tx_power/wifi_tx_power/wifi_tx_power.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * wifi_tx_power.ino 3 | * 4 | * Tests each possible value for the Wi-Fi tx power and records 5 | * the time required to connect to the Wi-Fi network. 6 | * 7 | * This is a stub to satisfy the Arduino IDE, the source code is in 8 | * the file main.cpp in the same directory. 9 | * 10 | * This sketch will compile in the Arduino IDE 11 | * 12 | * 1- Add https://espressif.github.io/arduino-esp32/package_esp32_index.json 13 | * in the Additional Boards Manager URLS in the Preferences window. 14 | * 2- Install platform esp32 by Espressif version 3.0.1 or newer with the Boards Manager 15 | * 3- Select the MakerGO ESP32 C3 SuperMini board 16 | * 17 | * This sketch will also compile in PlatformIO with platform espressif32 v6.6.0 or newer 18 | * 19 | * Use the following platformio.ini configuration file 20 | * [env:dfrobot_beetle_esp32c3] 21 | * platform = espressif32 22 | * board = dfrobot_beetle_esp32c3 23 | * framework = arduino 24 | * 25 | * or use 26 | * [env:super_mini_esp32c3] 27 | * platform = espressif32 28 | * board = super_mini_esp32c3 29 | * framework = arduino 30 | * if the the board definition file super_mini_esp32c3.json and the variant pin 31 | * definition file pins_arduino.h have been added as explained in 32 | * https://github.com/sigmdel/supermini_esp32c3_sketches/tree/main/resources 33 | * 34 | * Michel Deslierres 35 | * May 10, 2024 36 | * 37 | * Copyright 2024, Michel Deslierres. No rights reserved, this code is in the public domain. 38 | * In those jurisdictions where this may be a problem, the BSD Zero Clause License applies. 39 | * 40 | */ 41 | 42 | // SPDX-License-Identifier: 0BSD 43 | -------------------------------------------------------------------------------- /06_async_web_led/.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | .vscode/.browse.c_cpp.db* 3 | .vscode/c_cpp_properties.json 4 | .vscode/launch.json 5 | .vscode/ipch 6 | -------------------------------------------------------------------------------- /06_async_web_led/async_web_led/async_web_led.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * async_web_led.ino 3 | * 4 | * Toggles the built-in LED on and off with a Web interface 5 | * 6 | * This sketch runs in PlatformIO but it will not compile in the 7 | * Arduino IDE with version 3.0.1 of esp32 core 8 | * 9 | * Michel Deslierres 10 | * June 21, 2023 11 | * 12 | * 13 | * Copyright 2024, Michel Deslierres. No rights reserved, this code is in the public domain. 14 | * In those jurisdictions where this may be a problem, the BSD Zero Clause License applies. 15 | * 16 | */ 17 | 18 | // SPDX-License-Identifier: 0BSD 19 | -------------------------------------------------------------------------------- /06_async_web_led/async_web_led/html.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const char html_index[] PROGMEM = R"rawliteral( 4 | 5 | 6 | 7 | %SERVERNAME% 8 | 9 | 10 | 11 | 18 | 19 | 20 |

%SERVERNAME%

21 |
%LEDSTATUS%
22 |

23 |
Using AsyncWebServer
24 | 25 | )rawliteral"; 26 | 27 | // Could use 28 | //

29 | // instead of 30 | //

31 | 32 | 33 | const char html_404[] PROGMEM = R"rawliteral( 34 | 35 | 36 | 37 | %SERVERNAME% 38 | 39 | 40 | 41 | 47 | 48 | 49 |

%SERVERNAME%

50 |

404 Error

51 |

52 | 53 | )rawliteral"; 54 | -------------------------------------------------------------------------------- /06_async_web_led/async_web_led/main.cpp: -------------------------------------------------------------------------------- 1 | // Main module of async_web_led PlatformIO/Arduino sketch 2 | // Copyright: see notice in async_web_led.ino 3 | 4 | #include 5 | #include 6 | #include // See: Note on Location of Async Libraries 7 | #include // See: Note on Location of Async Libraries 8 | #include "html.h" 9 | #include "secrets.h" 10 | 11 | #ifndef PLATFORMIO 12 | // WiFi.setTxPower(TX_POWER) may be needed for some SuperMini C3 boards 13 | // If using Arduino define TX_POWER here if needed: 14 | #define TX_POWER WIFI_POWER_11dBm 15 | // For PlatformIO, TX_POWER is defined in the platformio.ini config file. 16 | // Similarly 17 | //#define LED_ON LOW 18 | #endif 19 | 20 | #if defined(ARDUINO_MAKERGO_C3_SUPERMINI) 21 | #define TITLE "MakerGO C3 SuperMini WEB SERVER" 22 | //static const uint8_t BOOT_BUILTIN = 9; // defined in pins_arduino.h 23 | #define BOOT_BUILTIN BOOT_BUILTIN 24 | #elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI) 25 | #define TITLE "Nologo ESP32C3 Super Mini WEB SERVER" 26 | static const uint8_t BOOT_BUILTIN = 9; 27 | #define BOOT_BUILTIN BOOT_BUILTIN 28 | #elif defined(ARDUINO_SUPER_MINI_C3) 29 | #define TITLE "DfRobot Beetle ESP32-C3 WEB SERVER" //"Modified ESP32 C3 DEVKITC 02" 30 | static const uint8_t BOOT_BUILTIN = 9; 31 | #define BOOT_BUILTIN BOOT_BUILTIN 32 | #elif defined(ARDUINO_SUPER_MINI_ESP32C3) 33 | #define TITLE "Custom ESP32C3 Super Mini WEB SERVER" 34 | //static const uint8_t BOOT_BUILTIN = 9; //defined in pins_arduino.h 35 | //#define BOOT_BUILTIN BOOT_BUILTIN //defined in pins_arduino.h 36 | #elif defined(ARDUINO_ESP32C3_DEV) 37 | #define TITLE "ESP32-C3 Dev Module WEB SERVER" 38 | static const uint8_t BOOT_BUILTIN = 9; // defined in pins_arduino.h 39 | #define BOOT_BUILTIN BOOT_BUILTIN 40 | #elif defined(ARDUINO_XIAO_ESP32C3) 41 | #define TITLE "Seeed XIAO ESP32C3 WEB SERVER" 42 | static const uint8_t BOOT_BUILTIN = 9; // defined in pins_arduino.h 43 | #define BOOT_BUILTIN BOOT_BUILTIN 44 | #else 45 | #error "Unknown device" 46 | #endif 47 | 48 | #if defined(ARDUINO_SUPER_MINI_ESP32C3) 49 | static uint8_t ledPin = BUILTIN_LED; 50 | static uint8_t ledOn = LOW; 51 | #elif not defined(ARDUINO_XIAO_ESP32C3) 52 | static uint8_t ledPin = 8; 53 | static uint8_t ledOn = LOW; 54 | #else 55 | static uint8_t ledPin = LED_PIN; 56 | static uint8_t ledOn = LED_ON; 57 | #endif 58 | 59 | int ledState = 0; 60 | String ledStatus = "OFF"; 61 | 62 | void setLed(int value) { 63 | digitalWrite(ledPin, (value)? ledOn : 1-ledOn); 64 | ledState = value; 65 | ledStatus = ((digitalRead(ledPin) == ledOn) ? "ON" : "OFF"); 66 | Serial.printf("LED now %s.\n", ledStatus.c_str()); 67 | } 68 | 69 | void toggleLed(void) { 70 | setLed(1-ledState); 71 | } 72 | 73 | // Webserver instance using default HTTP port 80 74 | AsyncWebServer server(80); 75 | 76 | // Template substitution function 77 | String processor(const String& var){ 78 | if (var == "LEDSTATUS") return String(default_envs = seeed_xiao_esp32c3edStatus); 79 | if (var == "SERVERNAME") return String(TITLE); 80 | return String(); // empty string 81 | } 82 | 83 | // 404 error handler 84 | void notFound(AsyncWebServerRequest *request) { 85 | request->send_P(404, "text/html", html_404, processor); 86 | } 87 | 88 | void setup() { 89 | // Set the digital pin connected to the LED as an output 90 | pinMode(ledPin, OUTPUT); 91 | 92 | Serial.begin(); 93 | delay(1000); // 1 second delay should be sufficient 94 | 95 | setLed(0); 96 | 97 | WiFi.mode(WIFI_STA); 98 | 99 | #ifdef TX_POWER 100 | WiFi.setTxPower(TX_POWER); 101 | Serial.printf("Setting Wi-Fi Tx power to %d\n", TX_POWER); 102 | #endif 103 | 104 | // Connect to Wi-Fi network with SSID and password 105 | Serial.print("Connecting to "); 106 | Serial.println(ssid); 107 | 108 | WiFi.begin(ssid, password); 109 | while (WiFi.status() != WL_CONNECTED) { 110 | delay(100); 111 | Serial.print("."); 112 | } 113 | // Print local IP address and start web server 114 | Serial.println(""); 115 | Serial.println("WiFi connected."); 116 | Serial.println("IP address: "); 117 | Serial.println(WiFi.localIP()); 118 | 119 | // Setup and start Web server 120 | server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ 121 | Serial.println("Index page requested"); 122 | request->send_P(200, "text/html", html_index, processor); 123 | }); 124 | server.on("/led", HTTP_GET, [](AsyncWebServerRequest *request){ 125 | Serial.println("Web button pressed"); 126 | toggleLed(); 127 | request->send_P(200, "text/html", html_index, processor); // updates the client making the request only 128 | }); 129 | server.onNotFound(notFound); 130 | server.begin(); 131 | 132 | setLed(0); 133 | Serial.println("setup completed."); 134 | } 135 | 136 | void loop() { 137 | } 138 | -------------------------------------------------------------------------------- /06_async_web_led/async_web_led/secrets.h.template: -------------------------------------------------------------------------------- 1 | // Replace with the correct network credentials 2 | const char* ssid = "***Wi-Fi***Network***Name***"; 3 | const char* password = "***Wi-Fi***Network***Password***"; 4 | -------------------------------------------------------------------------------- /06_async_web_led/include/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project header files. 3 | 4 | A header file is a file containing C declarations and macro definitions 5 | to be shared between several project source files. You request the use of a 6 | header file in your project source file (C, C++, etc) located in `src` folder 7 | by including it, with the C preprocessing directive `#include'. 8 | 9 | ```src/main.c 10 | 11 | #include "header.h" 12 | 13 | int main (void) 14 | { 15 | ... 16 | } 17 | ``` 18 | 19 | Including a header file produces the same results as copying the header file 20 | into each source file that needs it. Such copying would be time-consuming 21 | and error-prone. With a header file, the related declarations appear 22 | in only one place. If they need to be changed, they can be changed in one 23 | place, and programs that include the header file will automatically use the 24 | new version when next recompiled. The header file eliminates the labor of 25 | finding and changing all the copies as well as the risk that a failure to 26 | find one copy will result in inconsistencies within a program. 27 | 28 | In C, the usual convention is to give header files names that end with `.h'. 29 | It is most portable to use only letters, digits, dashes, and underscores in 30 | header file names, and at most one dot. 31 | 32 | Read more about using header files in official GCC documentation: 33 | 34 | * Include Syntax 35 | * Include Operation 36 | * Once-Only Headers 37 | * Computed Includes 38 | 39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html 40 | -------------------------------------------------------------------------------- /06_async_web_led/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [platformio] 12 | ; Make the Arduino IDE happy (.INO file must be in a directory of the same name) 13 | src_dir = async_web_led 14 | ;default_envs = super_mini_c3 15 | default_envs = super_mini_esp32c3 16 | ;default_envs = seeed_xiao_esp32c3 17 | 18 | [extra] 19 | baud=460800 20 | 21 | [env] 22 | platform = espressif32 23 | framework = arduino 24 | ;upload_port = /dev/ttyACM0 25 | ;monitor_port = /dev/ttyACM0 26 | monitor_speed = ${extra.baud} 27 | lib_deps = esphome/ESPAsyncWebServer-esphome@^3.2.2 28 | 29 | ; using a "near enough" board definition 30 | [env:super_mini_c3] 31 | board = dfrobot_beetle_esp32c3 32 | build_flags = 33 | -D ARDUINO_SUPER_MINI_C3 34 | -D TX_POWER=WIFI_POWER_11dBm 35 | -D LED_ON=LOW 36 | 37 | ; using a custom added board definition 38 | [env:super_mini_esp32c3] 39 | board = super_mini_esp32c3 40 | build_flags = 41 | -D TX_POWER=WIFI_POWER_11dBm 42 | -D LED_ON=LOW 43 | 44 | [env:seeed_xiao_esp32c3] 45 | board = seeed_xiao_esp32c3 46 | ; Connecting an external LED: 47 | ; The diode's cathode (-, usually the short lead on the flat side of the LED) is connected to GND. 48 | ; The diode's anode (+, usually the long lead on the round side of the LED) is connected to a 49 | ; current limiting 240 ohm resistor. The other lead of the resistor is connected to an I/O pin. 50 | ; If the pins are inverted, then set LED_ON to LOW. 51 | -D LED_PIN=D4 52 | -D LED_ON=HIGH 53 | -------------------------------------------------------------------------------- /07_ble_led/.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | .vscode/.browse.c_cpp.db* 3 | .vscode/c_cpp_properties.json 4 | .vscode/launch.json 5 | .vscode/ipch 6 | -------------------------------------------------------------------------------- /07_ble_led/ble_led/ble_led.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * ble_led.ino 3 | * 4 | * Toggle an external LED on and off an app using Bluetooth LE 5 | * 6 | * This is a stub to satisfy the Arduino IDE, the source code is in 7 | * the file main.cpp in the same directory. 8 | * 9 | * This sketch will compile in the Arduino IDE 10 | * 11 | * 1- Add https://espressif.github.io/arduino-esp32/package_esp32_index.json 12 | * in the Additional Boards Manager URLS in the Preferences window. 13 | * 2- Install platform esp32 by Espressif version 3.0.1 or newer with the Boards Manager 14 | * 3- Select the MakerGO ESP32 C3 SuperMini board 15 | * 4- Install the ArduinoBLE (1.3.6 or newer) library with the Library Manager 16 | * 5- Temporarily move the directory ~/.arduino15/packages/esp32/hardware/esp32/3.0.1/libraries/BLE 17 | * outside of the ~/.arduino15/ tree to avoid name conflicts 18 | * 19 | * This sketch will also compile in PlatformIO with platform espressif32 v6.6.0 or newer 20 | * 21 | * Use the following platformio.ini configuration file 22 | * [env:dfrobot_beetle_esp32c3] 23 | * platform = espressif32 24 | * board = dfrobot_beetle_esp32c3 25 | * framework = arduino 26 | * lib_deps = arduino-libraries/ArduinoBLE@^1.3.2 27 | * 28 | * or use 29 | * [env:super_mini_esp32c3] 30 | * platform = espressif32 31 | * board = super_mini_esp32c3 32 | * framework = arduino 33 | * lib_deps = arduino-libraries/ArduinoBLE@^1.3.2 34 | * if the the board definition file super_mini_esp32c3.json and the variant pin 35 | * definition file pins_arduino.h have been added as explained in 36 | * https://github.com/sigmdel/supermini_esp32c3_sketches/tree/main/resources 37 | * 38 | * Michel Deslierres 39 | * May 10, 2024 40 | * 41 | * Copyright 2024, Michel Deslierres. No rights reserved, this code is in the public domain. 42 | * In those jurisdictions where this may be a problem, the BSD Zero Clause License applies. 43 | * 44 | 45 | // SPDX-License-Identifier: 0BSD 46 | -------------------------------------------------------------------------------- /07_ble_led/ble_led/main.cpp: -------------------------------------------------------------------------------- 1 | // Main module of ble_led PlatformIO/Arduino sketch 2 | // Copyright: see notice in ble_led.ino 3 | 4 | /* 5 | * Bluetooth (LE) controled LED sketch for XIAO ESP32C3 in platformIO 6 | * Based on 7 | * XIAO ESP32C3 Bluetooth Tutorial, Range test, and Home Automation 8 | * @ https://www.electroniclinic.com/xiao-esp32c3-bluetooth-tutorial-range-test-and-home-automation/#XIAO_ESP32C3_Home_Automation 9 | * by Shahzada Fahad (Engr) 10 | * 11 | * Turn LED on/off with either of the following Androi/IOS app: 12 | * nRF Connect for Mobile 13 | * Android: https://play.google.com/store/apps/details?id=no.nordicsemi.android.mcp&gl=US 14 | * IOS: https://apps.apple.com/us/app/nrf-connect-for-mobile/id1054362403 15 | * or 16 | * LightBlue 17 | * Android: https://play.google.com/store/apps/details?id=com.punchthrough.lightblueexplorer&gl=US 18 | * IOS: https://apps.apple.com/us/app/lightblue/id557428110 19 | */ 20 | 21 | #include // Needed in PlatformIO 22 | #include 23 | 24 | #ifndef PlatformIO 25 | #define LED_PIN 8 26 | #define LED_ON LOW 27 | #endif 28 | 29 | #if defined(LED_PIN) 30 | static uint8_t ledPin = LED_PIN; 31 | #elif defined(BUILTIN_LED) 32 | static uint8_t ledPin = BUILTIN_LED; 33 | #else 34 | #error "Unkown LED pin" 35 | #endif 36 | 37 | #if defined(LED_ON) 38 | static uint8_t ledOn = LED_ON; 39 | #else 40 | static uint8_t ledOn = HIGH; 41 | #endif 42 | 43 | int ledState = 0; 44 | String ledStatus = "OFF"; 45 | 46 | void setLed(int value) { 47 | digitalWrite(ledPin, (value)? ledOn : 1-ledOn); 48 | ledState = value; 49 | ledStatus = ((digitalRead(ledPin) == ledOn) ? "ON" : "OFF"); 50 | Serial.printf("LED now %s.\n", ledStatus.c_str()); 51 | } 52 | 53 | // Bluetooth® Low Energy LED Service 54 | BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); 55 | 56 | // Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, readable and writable by central 57 | BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); 58 | 59 | void setup() { 60 | // Set the digital pin connected to the LED as an output 61 | pinMode(ledPin, OUTPUT); 62 | digitalWrite(ledPin, 1-ledOn); 63 | 64 | Serial.begin(); 65 | delay(2000); // 2 second delay should be sufficient 66 | 67 | 68 | // begin initialization 69 | if (!BLE.begin()) { 70 | Serial.println("Could not start Bluetooth® Low Energy module!"); 71 | while (1); 72 | } 73 | 74 | Serial.println("Bluetooth® Low Energy (BLE) module started."); 75 | Serial.print("Local address: "); 76 | Serial.println(BLE.address()); 77 | 78 | // set advertised local name and service UUID: 79 | BLE.setLocalName("HOME Automation"); // this will appear in the App search result. 80 | BLE.setAdvertisedService(ledService); 81 | 82 | // add the characteristic to the service 83 | ledService.addCharacteristic(switchCharacteristic); 84 | 85 | // add service 86 | BLE.addService(ledService); 87 | // set the initial value for the characeristic, i.e. LED off 88 | switchCharacteristic.writeValue(0); 89 | Serial.println("LED service added."); 90 | 91 | BLE.advertise(); 92 | Serial.println("\"HOME Automation\" device now being advertised"); 93 | Serial.println("Setup completed."); 94 | } 95 | 96 | 97 | void loop() { 98 | // listen for Bluetooth® Low Energy peripherals to connect: 99 | BLEDevice central = BLE.central(); 100 | 101 | // if a central is connected to peripheral: 102 | if (central) { 103 | String dName = central.deviceName(); 104 | if (!dName.length()) 105 | dName = central.localName(); 106 | if (!dName.length()) 107 | dName = "device"; // default if no name is found for the newly connected device 108 | dName += ": " + central.address(); // add the latter's MAC address 109 | Serial.print("Connected to "); 110 | Serial.println(dName); 111 | 112 | while (central.connected()) { 113 | if (switchCharacteristic.written()) { 114 | int Rvalue=switchCharacteristic.value(); 115 | Serial.printf("Received switchCharacteristic = %02x.\n", Rvalue); 116 | 117 | if ((Rvalue == 0) || (Rvalue == 1)) { 118 | setLed(Rvalue); 119 | } else { 120 | Serial.println("Ignored, expected 00 or 01.\n"); 121 | } 122 | 123 | } 124 | } 125 | 126 | Serial.print("Disconnected from "); 127 | Serial.println(dName); 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /07_ble_led/include/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project header files. 3 | 4 | A header file is a file containing C declarations and macro definitions 5 | to be shared between several project source files. You request the use of a 6 | header file in your project source file (C, C++, etc) located in `src` folder 7 | by including it, with the C preprocessing directive `#include'. 8 | 9 | ```src/main.c 10 | 11 | #include "header.h" 12 | 13 | int main (void) 14 | { 15 | ... 16 | } 17 | ``` 18 | 19 | Including a header file produces the same results as copying the header file 20 | into each source file that needs it. Such copying would be time-consuming 21 | and error-prone. With a header file, the related declarations appear 22 | in only one place. If they need to be changed, they can be changed in one 23 | place, and programs that include the header file will automatically use the 24 | new version when next recompiled. The header file eliminates the labor of 25 | finding and changing all the copies as well as the risk that a failure to 26 | find one copy will result in inconsistencies within a program. 27 | 28 | In C, the usual convention is to give header files names that end with `.h'. 29 | It is most portable to use only letters, digits, dashes, and underscores in 30 | header file names, and at most one dot. 31 | 32 | Read more about using header files in official GCC documentation: 33 | 34 | * Include Syntax 35 | * Include Operation 36 | * Once-Only Headers 37 | * Computed Includes 38 | 39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html 40 | -------------------------------------------------------------------------------- /07_ble_led/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [platformio] 12 | ; Make the Arduino IDE happy (.INO file must be in a directory of the same name) 13 | src_dir = ble_led 14 | ;default_envs = super_mini_c3 15 | default_envs = super_mini_esp32c3 16 | ;default_envs = seeed_xiao_esp32c3 17 | 18 | [extra] 19 | baud=460800 20 | 21 | [env] 22 | platform = espressif32 23 | framework = arduino 24 | ;upload_port = /dev/ttyACM0 25 | ;monitor_port = /dev/ttyACM0 26 | monitor_speed = ${extra.baud} 27 | lib_deps = 28 | arduino-libraries/ArduinoBLE@^1.3.2 ; https://github.com/arduino-libraries/ArduinoBLE.git 29 | 30 | ; using a "near enough" board definition 31 | [env:super_mini_c3] 32 | board = dfrobot_beetle_esp32c3 33 | build_flags = 34 | -D ARDUINO_SUPER_MINI_C3 35 | -D TX_POWER=WIFI_POWER_11dBm 36 | -D LED_ON=LOW 37 | 38 | ; using a custom added board definition 39 | [env:super_mini_esp32c3] 40 | board = super_mini_esp32c3 41 | build_flags = 42 | -D TX_POWER=WIFI_POWER_11dBm 43 | -D LED_ON=LOW 44 | 45 | [env:seeed_xiao_esp32c3] 46 | board = seeed_xiao_esp32c3 47 | ; Connecting an external LED: 48 | ; The diode's cathode (-, usually the short lead on the flat side of the LED) is connected to GND. 49 | ; The diode's anode (+, usually the long lead on the round side of the LED) is connected to a 50 | ; current limiting 240 ohm resistor. The other lead of the resistor is connected to an I/O pin. 51 | ; If the pins are inverted, then set LED_ON to LOW. 52 | build_flags = 53 | -D LED_PIN=D4 54 | -D LED_ON=HIGH 55 | -------------------------------------------------------------------------------- /08_ble_led2/ble_led2/ble_led2.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * ble_led2.ino 3 | * Turn on or off the builtin LED with a Bluetooth LE app 4 | * with included macro to set BLE power level. 5 | * 6 | * This is a stub to satisfy the Arduino IDE, the source code is in 7 | * the file main.cpp in the same directory. 8 | * 9 | * This sketch will compile in the Arduino IDE 10 | * 11 | * 1- Add https://espressif.github.io/arduino-esp32/package_esp32_index.json 12 | * in the Additional Boards Manager URLS in the Preferences window. 13 | * 2- Install platform esp32 by Espressif version 3.0.2 or newer with the Boards Manager 14 | * 3- Select the MakerGO ESP32 C3 SuperMini board 15 | * 16 | * Michel Deslierres 17 | * July 4, 2024 18 | * 19 | * Copyright 2024, Michel Deslierres. No rights reserved, this code is in the public domain. 20 | * In those jurisdictions where this may be a problem, the BSD Zero Clause License applies. 21 | * */ 22 | // SPDX-License-Identifier: 0BSD 23 | -------------------------------------------------------------------------------- /08_ble_led2/ble_led2/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | // This is a simplified example which can use custom UUIDs in which case 7 | // the client will probably show the UUID for the service and characteristic 8 | // or it can use some more or less valid reserved UUID from the Bluetooth(R) 9 | // Assigned Numbers document https://www.bluetooth.com/specifications/assigned-numbers/ 10 | // 11 | #define USE_CUSTOM_UUIDS 12 | 13 | #define BLUETOOTH_NAME "BLE_LED2" 14 | 15 | #ifdef USE_CUSTOM_UUIDS 16 | // Custom UUID for service and characteristic must not conflict with a reserved UUID 17 | // that is no number in the XXXXXXXX-0000-1000-8000-00805F9B34FB range 18 | // Generated at https://www.guidgenerator.com/ 19 | // https://novelbits.io/uuid-for-custom-services-and-characteristics/ 20 | #define SERVICE_UUID "57a81fc3-3c5f-4d29-80e7-8b074e34888c" 21 | #define CHARACTERISTIC_UUID "2eeae074-8955-47f7-9470-73f85112974f" 22 | #else 23 | #define SERVICE_UUID "1815" //"00001815-0000-1000-8000-00805F9B34FB" // Automation IO Service 24 | //"1812" //"00001812-0000-1000-8000-00805F9B34FB" // Human Interface Device Service 25 | //"181c" //"0000181c-0000-1000-8000-00805F9B34FB" // User Data Service 26 | #define CHARACTERISTIC_UUID "2BE2" //"00002BE2-0000-1000-8000-00805F9B34FB" // Light Output 27 | //"2BO5" //"00002B05-0000-1000-8000-00805F9B34FB" // Power 28 | #endif 29 | 30 | #if defined(BUILTIN_LED) 31 | const uint8_t ledPin = BUILTIN_LED; 32 | const uint8_t ledOn = LOW; 33 | #else 34 | #error "ledPin not defined" 35 | #endif 36 | 37 | const char* ESP_PWR_LEVELS[] = { 38 | "ESP_PWR_LVL_N24", // 0, -24dbm 39 | "ESP_PWR_LVL_N21", // 1, -21dbm 40 | "ESP_PWR_LVL_N18", // 2, -18dbm 41 | "ESP_PWR_LVL_N15", // 3, -15dbm 42 | "ESP_PWR_LVL_N12", // 4, -12dbm 43 | "ESP_PWR_LVL_N9 ", // 5, -9dbm 44 | "ESP_PWR_LVL_N6 ", // 6, -6dbm 45 | "ESP_PWR_LVL_N3 ", // 7, -3dbm 46 | "ESP_PWR_LVL_N0 ", // 8, 0dbm 47 | "ESP_PWR_LVL_P3 ", // 9, +3dbm 48 | "ESP_PWR_LVL_P6 ", // 10, +6dbm 49 | "ESP_PWR_LVL_P9 ", // 11, +9dbm 50 | "ESP_PWR_LVL_P12", // 12, +12dbm 51 | "ESP_PWR_LVL_P15", // 13, +15dbm 52 | "ESP_PWR_LVL_P18", // 14, +18dbm 53 | "ESP_PWR_LVL_P21" // 15, +21dbm 54 | }; 55 | 56 | String PWR_LEVEL_STR(esp_power_level_t level) { 57 | if ((level < ESP_PWR_LVL_N24) || (level > ESP_PWR_LVL_P21)) { 58 | return String("ESP_PWR_LVL_INVALID"); 59 | } else { 60 | return String(ESP_PWR_LEVELS[level]); 61 | } 62 | } 63 | 64 | // leave undefined to use default BLE power level 65 | #define BLE_PWR_LEVEL ESP_PWR_LVL_N21 66 | 67 | BLEServer *pServer = nullptr; 68 | BLECharacteristic *pCharacteristic = nullptr; 69 | 70 | bool deviceConnected = false; 71 | 72 | class MyServerCallbacks: public BLEServerCallbacks { 73 | void onConnect(BLEServer* pServer) { 74 | deviceConnected = true; 75 | Serial.println("Device connected"); 76 | }; 77 | 78 | void onDisconnect(BLEServer* pServer) { 79 | deviceConnected = false; 80 | Serial.println("Device disconnected"); 81 | Serial.println("Restart advertising"); 82 | BLEDevice::startAdvertising(); 83 | } 84 | }; 85 | 86 | class WriteCallbacks : public BLECharacteristicCallbacks { 87 | void onWrite(BLECharacteristic *pCharacteristic) { 88 | String value = pCharacteristic->getValue().c_str(); 89 | if (value == "on") { 90 | digitalWrite(ledPin, ledOn); 91 | Serial.println("Received \"on\" value"); 92 | } else if(value == "off"){ 93 | digitalWrite(ledPin, 1-ledOn); 94 | Serial.println("Received \"off\" value"); 95 | } else { 96 | Serial.printf("Received non valid \"%s\" value \n", value.c_str()); 97 | } 98 | } 99 | }; 100 | 101 | 102 | void setup() { 103 | #if defined(ARDUINO_MAKERGO_C3_SUPERMINI) 104 | Serial.begin(); 105 | delay(1000); // should be enough for the USB CDC to initialize 106 | #else 107 | Serial.begin(115200); 108 | while (!Serial) delay(10); 109 | #endif 110 | 111 | Serial.println("Setup"); 112 | 113 | Serial.println("Initializing LED"); 114 | pinMode(ledPin, OUTPUT); 115 | digitalWrite(ledPin, 1-ledOn); 116 | 117 | Serial.println("Initializing BLEDevice"); 118 | BLEDevice::init(BLUETOOTH_NAME); 119 | 120 | // defined in 121 | esp_power_level_t esp_ble_tx_power = esp_ble_tx_power_get(ESP_BLE_PWR_TYPE_DEFAULT); 122 | Serial.print("Default BLE power level "); 123 | Serial.println(PWR_LEVEL_STR(esp_ble_tx_power)); 124 | 125 | #if defined(BLE_PWR_LEVEL) 126 | // https://github.com/nkolban/esp32-snippets/issues/197#issuecomment-344115566 127 | // http://esp-idf.readthedocs.io/en/latest/api-reference/bluetooth/controller_vhci.html?highlight=esp_ble_tx_power_set#_CPPv220esp_ble_tx_power_set20esp_ble_power_type_t17esp_power_level_t 128 | 129 | BLEDevice::setPower(BLE_PWR_LEVEL); 130 | delay(10); 131 | esp_ble_tx_power = esp_ble_tx_power_get(ESP_BLE_PWR_TYPE_DEFAULT); 132 | Serial.print("BLE power level set to "); 133 | Serial.print(PWR_LEVEL_STR(esp_ble_tx_power)); 134 | Serial.print(" wanted "); 135 | Serial.println(PWR_LEVEL_STR(BLE_PWR_LEVEL)); 136 | #endif 137 | 138 | Serial.println("Creating a BLE server"); 139 | pServer = BLEDevice::createServer(); 140 | pServer->setCallbacks(new MyServerCallbacks()); 141 | 142 | Serial.println("Adding a BLE service"); 143 | BLEService *pService = pServer->createService(SERVICE_UUID); 144 | 145 | Serial.println("Adding a BLE characteristic"); 146 | pCharacteristic = pService->createCharacteristic( 147 | CHARACTERISTIC_UUID, 148 | BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE); 149 | pCharacteristic->setCallbacks(new WriteCallbacks); 150 | 151 | Serial.println("Starting BLE service"); 152 | pService->start(); 153 | 154 | Serial.println("Add advertiser"); 155 | BLEAdvertising *pAdvertising = BLEDevice::getAdvertising(); 156 | pAdvertising->addServiceUUID(pService->getUUID()); 157 | pAdvertising->setScanResponse(true); 158 | 159 | Serial.println("Start BLE advertising"); 160 | BLEDevice::startAdvertising(); 161 | 162 | Serial.print("\nSetup completed, connect to "); 163 | Serial.println(BLUETOOTH_NAME); 164 | Serial.print("Address: "); 165 | Serial.println(BLEDevice::getAddress().toString().c_str()); 166 | } 167 | 168 | unsigned long timer = 0; 169 | 170 | void loop() { 171 | if (millis() - timer > 5000) { 172 | Serial.println(" - loop busy work"); 173 | timer = millis(); 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Copyright (C) 2023, Michel Deslierres 2 | 3 | Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. 4 | 5 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Super Mini ESP32C3 Arduino Sketches / PlatformIO Projects 2 | 3 | **Source code that accompanies [First Look at the Super Mini ESP32-C3](https://sigmdel.ca/michel/ha/esp8266/super_mini_esp32c3_en.html).** 4 | 5 | --- 6 | 7 | **Code source qui accompagne [Coup d'oeil sur la carte de développement Super Mini ESP32-C3](https://sigmdel.ca/michel/ha/esp8266/super_mini_esp32c3_en.html).** 8 | 9 | --- 10 | 11 | ![Super Mini ESP32C3 Pinout](images/pinout_top_big_logo.png) 12 | 13 | --- 14 | 15 | **Table of Content** 16 | 17 | 18 | 19 | - [1. Introduction](#1-introduction) 20 | - [2. Arduino IDE Notes](#2-arduino-ide-notes) 21 | - [3. PlatformIO Notes](#3-platformio-notes) 22 | - [4. List of Projects](#4-list-of-projects) 23 | 24 | **Hello world! sketches:** 25 | - [01_pin_names](#01_pin_names) 26 | - [02_blink_pulse_led](#02_blink_pulse_led) 27 | 28 | **Wi-Fi connectivity sketches:** 29 | - [03_scan_wifi](#03_scan_wifi) 30 | - [04_wifi_connect](#04_wifi_connect) 31 | - [05_wifi_tx_power](#05_wifi_tx_power) 32 | 33 | **Bluetooth connectivity sketches** 34 | - [07_ble_led](#07_ble_led) 35 | - [08_ble_led2](#08_ble_led2) 36 | 37 | **Working example:** 38 | - [06_async_web_led](#06_async_web_led) 39 | 40 | [5. Licence](#5-licence) 41 | 42 | 43 | 44 | ## 1. Introduction 45 | 46 | The Super Mini ESP32C3 boards are small simplified versions of the original Espressif development boards for the ESP32-C3 microcontroller. Unlike older Espressif microcontrollers, the C3 has a RISC-V core. 47 | 48 | It seems that there is more than one manufacturer of these boards that differ in more or less subtle ways. The pin diagram above shows the markings on four boards purchased from a Chinese vendor in late April 2024. There are no labels identifying the red power LED to the left of the USB connector and the blue LED under the reset (RST) button. There are no other components near the single component between the ESP32-C3 chip and the red ceramic antenna labelled C3. Other boards and the [schematic](https://wiki.icbbuy.com/doku.php?id=developmentboard:esp32-c3mini#schematic) have other components which may explain the problems encountered with Wi-Fi connectivity. 49 | 50 | It should be possible to compile these projects in the Arduino IDE or in PlatformIO, although there are difficulties in a couple of cases if using the Arduino IDE. 51 | 52 | ## 2. Arduino IDE Notes 53 | 54 | Arduino sketches must have an `.ino` file name extension and must be contained in a directory that has the same name as the Arduino sketch (excluding the extension). Consequently the `01_pin_names` project contains a directory named `pin_names` that in turn contains the Arduino sketch `pin_names.ino`. That file is only a long comment. This is not a problem because the Arduino IDE will import all source files found in the sketch directory. The actual code is in `main.cpp` which is the default name of a PlatformIO project. 55 | 56 | ![Directory tree](images/dir_tree.jpg) 57 | 58 | To compile and then upload the sketch in the Arduino IDE, click on the **File** top menu, click on **Open...**, then navigate to the `pin_names.ino` file and open it with the system file manager. 59 | 60 | Following the instructions in [Installing using Arduino IDE](https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html#installing-using-arduino-ide) the latest release of the Arduino-ESP32 framework was installed by entering the following URL 61 | ``` 62 | https://espressif.github.io/arduino-esp32/package_esp32_index.json 63 | ``` 64 | into the `Additional Board Manager URLs` field of the Arduino Preferences. Using the board manager install the Espressif Arduino core `esp32 version 3.0.1` or newer. It should then be possible to select `MakerGO ESP32 C3 SuperMini` as the board. 65 | 66 | ## 3. PlatformIO Notes 67 | 68 | Because of the Arduino sketch naming constraints, the `main.cpp` file of a project is not stored in the default `src` directory. A `src_dir` entry in the `platformio.ini` configuration file provides the name of the directory in which `main.cpp` is found. That will be the name of the Arduino sketch as shown below for the `01_pin_names` project. 69 | 70 | ```ini 71 | [platformio] 72 | ; Make the Arduino IDE happysupermini_esp32c3_sketches (github)% (.INO file must be in a directory of the same name) 73 | src_dir = pin_names 74 | ``` 75 | 76 | PlatformIO will "convert" the sketch `.ino` file, but that is of no consequence since it contains only comments. 77 | 78 | ## 4. List of Projects 79 | 80 | The projects can be grouped in three categories. 81 | 82 | **Hello world! sketches:** 83 | --- 84 | 85 | ### 01_pin_names 86 | Lists the I/O pin names and numbers of the Super Mini ESP32-C3 board. 87 | 88 | ### 02_blink_pulse_led 89 | Alternately blinks (heartbeat) and pulses the on-board LED of the Super Mini board. 90 | 91 | **Wi-Fi connectivity sketches:** 92 | --- 93 | 94 | ### 03_scan_wifi 95 | Prints a list of available Wi-Fi networks every five seconds. The Super Mini does not manage to find as many networks as the XIAO ESP32C3. Edit `secrets.h.template` and save as `secrets.h` before compiling. 96 | 97 | ### 04_wifi_connect 98 | Wi-Fi connection example. The Super Mini may very well fail to connect. Define the TRY_TX_POWER macro to see if that solves the problem. It may be necessary to change the value of the TX_POWER macro. Edit `secrets.h.template` and save as `secrets.h` before compiling. 99 | 100 | ### 05_wifi_tx_power 101 | Tests each predefined value for the Wi-Fi TX (transmit) power and records the time required to connect to the Wi-Fi network. Edit `secrets.h.template` and save as `secrets.h` before compiling. 102 | 103 | The table shows times needed to connect to a Wi-Fi network in milliseconds as a function of the radio TX power setting. The tests were run only once on a XIAO ESP32C3 and once on each of four different Super Mini boards. The `-` signifies that a connection was not made within two minutes. 104 | 105 | | | XIAO | SM 1 | SM 2 | SM 3 | SM 4 | 106 | | --- | :---: | :---:| :---: | :---:| :---:| 107 | | WIFI_POWER_default | 1143 | - | - | - | - | 108 | | WIFI_POWER_19_5dBm | 443 | - | 1230 | - | - | 109 | | WIFI_POWER_19dBm | 430 | 477 | - | - | - | 110 | | WIFI_POWER_18_5dBm | 440 | 546 | 961 | - | - | 111 | | WIFI_POWER_17dBm | 391 | 443 | 389 | 532 | - | 112 | | WIFI_POWER_15dBm | 404 | 410 | 425 | 422 | - | 113 | | WIFI_POWER_13dBm | 376 | 729 | 684 | 469 | 1440 | 114 | | WIFI_POWER_11dBm | 429 | 423 | 399 | 409 | 484 | 115 | | WIFI_POWER_8_5dBm | 729 | 1929 | 414 | 425 | 443 | 116 | | WIFI_POWER_7dBm | 1923 | 718 | 413 | 430 | 399 | 117 | | WIFI_POWER_5dBm | 904 | 388 | 427 | 546 | 442 | 118 | | WIFI_POWER_2dBm | 678 | 507 | 390 | 937 | 408 | 119 | 120 | Three conclusions can be drawn. 121 | 122 | 1. The XIAO connected with the Wi-Fi router no matter the TX power setting. That may not be all that significant since the router was 1 metre away. 123 | 124 | 2. Not one of the four Super Mini boards was able to connect to the Wi-Fi network with the default TX power setting. 125 | 126 | 3. There is significant variation between the Super Mini boards. 127 | 128 | 4. The Chinese vendor supplied ESP32-C3 Super Mini boards have a 3.3V regulator with a peak current rating of 250 mA (SMD LLVB). This is insufficient to power everything given that the [official datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf) (page 52). specifies Wi-Fi current consumption @18.5dbm as 276mA or greater. 129 | 130 | When deploying a board, it may be necessary to test it multiple times in the position it will be used to find the proper TX power setting. 131 | 132 | **Bluetooth connectivity sketches:** 133 | --- 134 | 135 | ### 07_ble_led 136 | 137 | A rudimentary example of the Bluetooth® Low Energy (BLE) capabilities of the ESP32-C3. The microcontroller is set up as a BLE peripheral with a LED service and as switch characteristic. Any central (client) device can turn the LED on or off by sending a proper message. [Bluetooth Controlled LED](https://sigmdel.ca/michel/ha/xiao/xiao_esp32c3_intro_en.html#ble) explains how to use **LightBlue**, an Android and presumably IOS application, to do that. 138 | 139 | The Super Mini C3 boards that were tested did not do well. Sometimes the connection between the microcontroller and the Android tablet would require a considerable amount of time. At other times, the tablet had to be almost touching the microcontroller for the connection to be made. It happened that a connection could not be established at all even if **LightBlue** had found the Super Mini when it scanned for devices. By contrast, the XIAO-ESP32C3 was dependable. 140 | 141 | This project is basically the same as **06_ble_led** in [xiao_esp32c3_sketches](https://github.com/sigmdel/xiao_esp32c3_sketches). Contrary what is stated in the documentation for that previous version, the project can be compiled in the Arduino IDE. It's definitely not properly set up for that. The `ble_led.ino` file has details on how to do it. 142 | 143 | ### 08_ble_led2 144 | 145 | This project is similar to the previous one except for the use of the BLE library instead of the ArduinoBLE library. The [BLE library](https://github.com/espressif/arduino-esp32/tree/master/libraries/BLE) included in the ESP32 core for Arduino was the creation of [Neil Kolban](https://github.com/nkolban/ESP32_BLE_Arduino). This makes it possible to set the BLE power level. Unlike setting Wi-Fi TX (transmit) power, setting the BLE power level did not result in obvious improvements in Bluetooth connectivity. Only BLE power type `ESP_BLE_PWR_TYPE_DEFAULT` with power levels -21dbm, -15dbm, -9dbm, -3dbm, +3dbm + 9dbm, +15dbm and +21dbm, were tested. BLE power settings are more complex than Wi-Fi transmit power settings, so there may be something to gain in investigating this further. 146 | 147 | Perhaps this test was done incorrectly. Any help on this subject would be appreciated. 148 | 149 | 150 | **Working example:** 151 | --- 152 | 153 | ### 0.6_async_web_led 154 | 155 | Toggles the built-in LED on and off with a Web interface. It may be necessary to specify a valid Wi-Fi tx power as determined with the previous sketch. Edit `secrets.h.template` and save as `secrets.h` before compiling. 156 | 157 | Aside from setting the radio TX power and handling the fact that the built-in LED is active LOW, this project is the same as **05_async_web_led** in [xiao_esp32c3_sketches](https://github.com/sigmdel/xiao_esp32c3_sketches). 158 | 159 | This project cannot easily be compiled in the Arduino IDE: 160 | 161 | > The project uses the `esphome/ESPAsyncWebServer-esphome@^3.2.0` library which in turns depends on the `AsyncTCP` library. The latter depends on `IPv6Address.h` which is no longer included in the esp32 v3.0.1 core used in Arduino. So the `esphome` libraries cannot be copied to a private library directory for use in Arduino unless esp32 v2.0.17 were used (see [ptillisch](https://forum.arduino.cc/t/ide-2-3-2-ip46address-h-error/1272197/4)). If the older esp32 core were used, the `MakerGO ESP32 C3 SuperMini board` would not be defined. If we use v3.0.1, it seems that the `ESPAsyncWebServer` library loaded by the Arduino library manager which presumably does not require `IPv6Address.h` does not seem to support the ESP32-C3. 162 | 163 | ## 5. Licence 164 | 165 | Copyright 2024, Michel Deslierres. No rights reserved. 166 | 167 | While the copyright pertaining to included libraries must be respected, all the code by Michel Deslierres in this repository is in the public domain. In those jurisdictions where this may be a problem, the [BSD Zero Clause License](https://spdx.org/licenses/0BSD.html) applies. 168 | -------------------------------------------------------------------------------- /images/dir_tree.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sigmdel/supermini_esp32c3_sketches/ff45329251c85df2658aa8f8df2a4aa70507ba01/images/dir_tree.jpg -------------------------------------------------------------------------------- /images/pinout_top_big_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sigmdel/supermini_esp32c3_sketches/ff45329251c85df2658aa8f8df2a4aa70507ba01/images/pinout_top_big_logo.png -------------------------------------------------------------------------------- /resources/README.md: -------------------------------------------------------------------------------- 1 | # Adding a Super Mini Board Definition in PlatformIO 2 | 3 | Two files need to be added to define the Super Mini ESP32-C3 development board described in [First Look at the Super Mini ESP32-C3](https://sigmdel.ca/michel/ha/esp8266/super_mini_esp32c3_en.html). They are contained in this directory. 4 | 5 | 1. `super_mini_esp32c3.json` is the board definition file. It references the next file. 6 | 7 | 2. `pins_arduino.h` is the variant pin definition file. 8 | 9 | They should be copied to the correct subdirectory of the `platformio` directory. The location of the latter depends on the operating system and where PlatformIO was initially installed. The *default* locations are as follows. 10 | 11 | Linux: 12 | 1. `~/.platformio/platforms/espressif32/boards/super_mini_esp32c3.json` 13 | 14 | 2. `~/.platformio/packages/framework-arduinoespressif32/variants/super_mini_esp32c3/pins_arduino.h` 15 | 16 | In practice this means: `home//.platformio/...`. 17 | 18 | Windows: 19 | 20 | 1. `%HOMEPATH%\.platformio\platforms\espressif32\boards\super_mini_esp32c3.json` 21 | 22 | 2. `%HOMEPATH%\.platformio\packages/framework-arduinoespressif32/variants/super_mini_esp32c3/pins_arduino.h` 23 | 24 | In practice this means: `C:\Users\\.platformio\...`. 25 | 26 | 27 | Note that in the second case, the `super_mini_esp32c3` directory in which `pins_arduino.h` is saved will have to be created. 28 | 29 | **NOTE:** 30 | 31 | The above will work, in the sense that the new board will show up in the Project Wizard. However, the two additional files will be deleted when the `espressif32` platform is updated or reinstalled. 32 | 33 | There is a simple way to add a locally defined custom board definition to a project. See [Custom Embedded Boards](https://docs.platformio.org/en/latest/platforms/creating_board.html#installation) and [boards_dir](https://docs.platformio.org/en/latest/projectconf/sections/platformio/options/directory/boards_dir.html#projectconf-pio-boards-dir). However adding the variant `pins_arduino.h` file is not that easy. See [Custom board missing file: pins_arduino.h: No such file or directory](https://community.platformio.org/t/custom-board-missing-file-pins-arduino-h-no-such-file-or-directory/36622). 34 | 35 | Hopefully, a future release of the `espressif32` platform will include a correct Super Mini dev board definition and the problem will become moot. 36 | -------------------------------------------------------------------------------- /resources/pins_arduino.h: -------------------------------------------------------------------------------- 1 | #ifndef Pins_Arduino_h 2 | #define Pins_Arduino_h 3 | 4 | #include 5 | 6 | static const uint8_t LED_BUILTIN = 8; 7 | #define BUILTIN_LED LED_BUILTIN // backward compatibility 8 | #define LED_BUILTIN LED_BUILTIN 9 | 10 | static const uint8_t BOOT_BUILTIN = 9; // boot button 11 | #define BOOT_BUILTIN BOOT_BUILTIN 12 | 13 | #define TX1 0 14 | #define RX1 1 15 | 16 | static const uint8_t TX = 21; 17 | static const uint8_t RX = 20; 18 | 19 | static const uint8_t SDA = 8; 20 | static const uint8_t SCL = 9; 21 | 22 | static const uint8_t SS = 7; 23 | static const uint8_t MOSI = 6; 24 | static const uint8_t MISO = 5; 25 | static const uint8_t SCK = 4; 26 | 27 | static const uint8_t A0 = 0; 28 | static const uint8_t A1 = 1; 29 | static const uint8_t A2 = 2; 30 | static const uint8_t A3 = 3; 31 | static const uint8_t A4 = 4; 32 | static const uint8_t A5 = 5; 33 | 34 | #endif /* Pins_Arduino_h */ 35 | -------------------------------------------------------------------------------- /resources/super_mini_esp32c3.json: -------------------------------------------------------------------------------- 1 | { 2 | "build": { 3 | "arduino": { 4 | "ldscript": "esp32c3_out.ld" 5 | }, 6 | "core": "esp32", 7 | "extra_flags": [ 8 | "-DARDUINO_SUPER_MINI_ESP32C3", 9 | "-DARDUINO_USB_MODE=1", 10 | "-DARDUINO_USB_CDC_ON_BOOT=1" 11 | ], 12 | "f_cpu": "160000000L", 13 | "f_flash": "80000000L", 14 | "flash_mode": "qio", 15 | "hwids": [ 16 | [ 17 | "0x303a", 18 | "0x1001" 19 | ] 20 | ], 21 | "mcu": "esp32c3", 22 | "variant": "super_mini_esp32c3" 23 | }, 24 | "connectivity": [ 25 | "wifi" 26 | ], 27 | "debug": { 28 | "openocd_target": "esp32c3.cfg" 29 | }, 30 | "frameworks": [ 31 | "arduino", 32 | "espidf" 33 | ], 34 | "name": "ESP32C3-SuperMini", 35 | "upload": { 36 | "flash_size": "4MB", 37 | "maximum_ram_size": 327680, 38 | "maximum_size": 4194304, 39 | "require_upload_port": true, 40 | "speed": 460800 41 | }, 42 | "url": "https://wiki.icbbuy.com/doku.php?id=developmentboard:esp32-c3mini#esp32-c3mini", 43 | "vendor": "ICBbuy" 44 | } 45 | --------------------------------------------------------------------------------