This is an old revision of the document!
We will be using the ESP32-C6 Sparrow board as the main development board for the lab assignments.
Also, for the most of the labs, we will be using the Visual Studio Code and Platformio environment, which you can download from here
After downloading and installing the PlatformIO extension, create a new project using any ESP32-C6 board. After project creation, you will need to edit the platformio.ini file and replace it with the following:
; PlatformIO Project Configuration File ; ; Build options: build flags, source filter ; Upload options: custom upload port, speed and extra flags ; Library options: dependencies, extra library storages ; Advanced options: extra scripting ; ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html [env:esp32-c6-sparrow] platform = https://github.com/FarhadGUL06/platform-espressif32.git board = esp32-c6-sparrow framework = arduino ; Serial monitor options monitor_speed = 115200 lib_deps = adafruit/Adafruit NeoPixel@^1.11.0 adafruit/Adafruit GFX Library@^1.11.9 adafruit/Adafruit SSD1306@^2.5.10 dantudose/LTR308 library@^1.0 https://github.com/sparkfun/SparkFun_MAX1704x_Fuel_Gauge_Arduino_Library stm32duino/STM32duino LSM6DSL@^2.0.0
The board has a Neopixel attached on GPIO3 of the ESP32-C6 processor. Let's test if the board is working properly by turning on the LED. Use the code below:
#include <Arduino.h> #include <Adafruit_NeoPixel.h> // --- config --- #define LED_PIN 3 // your NeoPixel data pin #define NUM_PIXELS 1 // change if you have more #define BRIGHTNESS 30 // 0..255 (keep modest if powered from USB) // Most WS2812/NeoPixel strips are GRB @ 800 kHz: #define PIXEL_TYPE (NEO_GRB + NEO_KHZ800) Adafruit_NeoPixel strip(NUM_PIXELS, LED_PIN, PIXEL_TYPE); static void solid(uint32_t c, uint16_t ms) { for (uint16_t i = 0; i < NUM_PIXELS; i++) strip.setPixelColor(i, c); strip.show(); delay(ms); } void setup() { strip.begin(); strip.setBrightness(BRIGHTNESS); strip.show(); // all off // Quick RGB sanity check (each color ~300 ms) solid(strip.Color(255, 0, 0), 300); // Red solid(strip.Color( 0, 255, 0), 300); // Green solid(strip.Color( 0, 0, 255), 300); // Blue solid(strip.Color( 0, 0, 0), 200); // Off } void loop() { // Smooth rainbow using HSV -> RGB with gamma correction static uint16_t hue = 0; // 0..65535 uint32_t c = strip.gamma32(strip.ColorHSV(hue)); for (uint16_t i = 0; i < NUM_PIXELS; i++) strip.setPixelColor(i, c); strip.show(); hue += 256; // step size (smaller = slower) delay(20); // frame rate (~50 FPS) }
Load this WiFi scanner code:
#include <Arduino.h> #include <WiFi.h> // Arduino-ESP32 WiFi (works on ESP32-C6 with Arduino 3.x) static const char* authModeToStr(wifi_auth_mode_t m) { switch (m) { case WIFI_AUTH_OPEN: return "OPEN"; case WIFI_AUTH_WEP: return "WEP"; case WIFI_AUTH_WPA_PSK: return "WPA_PSK"; case WIFI_AUTH_WPA2_PSK: return "WPA2_PSK"; case WIFI_AUTH_WPA_WPA2_PSK: return "WPA/WPA2_PSK"; case WIFI_AUTH_WPA2_ENTERPRISE:return "WPA2_ENT"; case WIFI_AUTH_WPA3_PSK: return "WPA3_PSK"; case WIFI_AUTH_WPA2_WPA3_PSK: return "WPA2/WPA3"; case WIFI_AUTH_WAPI_PSK: return "WAPI_PSK"; case WIFI_AUTH_OWE: return "OWE"; default: return "UNKNOWN"; } } void setup() { Serial.begin(115200); delay(300); // Scan as a station, disconnected WiFi.mode(WIFI_STA); WiFi.persistent(false); WiFi.disconnect(true, true); WiFi.setSleep(false); Serial.println("\nWiFi scanner ready."); } void loop() { Serial.println("\n--- Scanning... ---"); // Synchronous scan; set 2nd arg to true to include hidden SSIDs int n = WiFi.scanNetworks(/*async=*/false, /*show_hidden=*/true); if (n <= 0) { Serial.println("No networks found."); } else { Serial.printf("Found %d network(s):\n", n); for (int i = 0; i < n; ++i) { String ssid = WiFi.SSID(i); String bssid = WiFi.BSSIDstr(i); int32_t rssi = WiFi.RSSI(i); int32_t ch = WiFi.channel(i); auto auth = (wifi_auth_mode_t)WiFi.encryptionType(i); bool hidden = (ssid.length() == 0); // no API needed if (hidden) ssid = "(hidden)"; Serial.printf("%2d) %-32s BSSID:%s CH:%2ld RSSI:%4ld dBm AUTH:%s\n", i + 1, ssid.c_str(), bssid.c_str(), (long)ch, (long)rssi, authModeToStr(auth) ); } } WiFi.scanDelete(); // free RAM delay(5000); }
Build, Upload and Monitor the results. You should be able to see a periodic scan of the available WiFi networks in your proximity.
Load the “SimpleBleDevice” example. Install on your phone an app that scans nearby Bluetooth devices, such as this BLE Scanner. Check if your device is in the list.