Free Shipping over ₹1299

ESP32 Test Codes

Oceanlabz ESP32 Preloaded Code Guide

1. Overview
Each ESP32 board from Oceanlabz is rigorously tested to ensure quality and functionality. A preloaded code is included on the board to allow you to verify that the ESP32 is working correctly before uploading your custom code.

2. Accessing the Preloaded Code
The preloaded code is configured with the following Wi-Fi credentials:

  • SSID: OL-ESP32-AP
  • Password: 12345678

Simply power on the ESP32 and check that it connects to your Wi-Fi network using these credentials. This step confirms the Wi-Fi functionality of the board.

3. Purpose of the Preloaded Code
This preloaded code is intended purely for functionality testing. By connecting to the specified Wi-Fi, you can confirm that the ESP32’s Wi-Fi module, power, and communication are all operational.

4. Uploading Your Custom Code
Once you’ve confirmed that the ESP32 board is functioning correctly, feel free to upload your own code. The board is ready for any projects you want to explore.

5. Troubleshooting
If you encounter issues connecting to Wi-Fi or uploading your code, please check esp32 troubleshoot guide

Test Code – 1

First, make sure you have the ESPAsyncWebServer library and the WiFi library installed in your Arduino IDE. You can install them from the Library Manager.

#include <WiFi.h>
#include <ESPAsyncWebServer.h>

const char* ssid = "OL-ESP32-AP";
const char* password = "12345678";

#define LED_BUILTIN 2

AsyncWebServer server(80);

const char* htmlPage = R"rawliteral(
<!DOCTYPE HTML>
<html>
<head>
  <title>OceanLabz ESP32</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      margin: 0;
      padding: 0;
      background: #f0f0f0;
    }
    header {
      background: #007bff;
      color: white;
      padding: 10px 0;
      text-align: center;
      font-size: 24px;
    }
    .container {
      width: 90%;
      max-width: 900px;
      margin: 20px auto;
      background: white;
      padding: 20px;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    }
    h2 {
      color: #007bff;
      border-bottom: 2px solid #007bff;
      padding-bottom: 5px;
    }
    p {
      line-height: 1.6;
    }
  </style>
</head>
<body>
  <header>OceanLabz ESP32</header>
  <div class="container">
    <h2>Technical Specifications</h2>
    <p><strong>Microcontroller:</strong> ESP32-D0WDQ6</p>
    <p><strong>Clock Frequency:</strong> Up to 240 MHz</p>
    <p><strong>Flash Memory:</strong> 4 MB (external SPI flash)</p>
    <p><strong>SRAM:</strong> 520 KB</p>
    <p><strong>WiFi:</strong> 802.11 b/g/n</p>
    <p><strong>Bluetooth:</strong> v4.2 BR/EDR and BLE</p>
    <p><strong>Operating Voltage:</strong> 3.3V</p>
    <p><strong>Operating Temperature Range:</strong> -40°C to 125°C</p>
    <p><strong>GPIO Pins:</strong> 34 (some pins have specific functions)</p>
  </div>
</body>
</html>
)rawliteral";  

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

  // Initialize LED pin as output
  pinMode(LED_BUILTIN, OUTPUT);

  // Set up access point
  WiFi.softAP(ssid, password);

  IPAddress IP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(IP);

  // Serve HTML page
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send(200, "text/html", htmlPage);
  });

  server.begin();
}

void loop() {
  // Blink LED to indicate the server is running
  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
}

Test Code – 2

#include <WiFi.h>
#include <BluetoothSerial.h>

const int ledPin = 2; // Built-in LED on most ESP32 boards

// WiFi credentials
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";

// Bluetooth Serial object
BluetoothSerial ESP_BT;

// Touch sensor pin and threshold
const int touchPin = T0; // Touch pin 0 is GPIO 4
const int touchThreshold = 40;

// WiFi connection state
bool wifiConnected = false;
unsigned long wifiAttemptStartTime = 0;
const unsigned long wifiTimeout = 10000; // 10 seconds timeout

void setup() {
  // Initialize serial communication
  Serial.begin(115200);
  while (!Serial) {
    ; // Wait for serial port to connect. Needed for native USB port only
  }
  Serial.println("ESP32 Serial Test");

  // Initialize LED pin as output
  pinMode(ledPin, OUTPUT);

  // Initialize Bluetooth
  if (!ESP_BT.begin("ESP32_BT_Test")) {
    Serial.println("An error occurred initializing Bluetooth");
  } else {
    Serial.println("Bluetooth initialized");
  }

  // Start WiFi connection attempt
  WiFi.begin(ssid, password);
  wifiAttemptStartTime = millis();

  // Test touch sensor
  int touchValue = touchRead(touchPin);
  Serial.print("Touch sensor value: ");
  Serial.println(touchValue);
  if (touchValue < touchThreshold) {
    Serial.println("Touch detected");
  } else {
    Serial.println("No touch detected");
  }
}

void loop() {
  // Blink LED
  digitalWrite(ledPin, HIGH); // Turn the LED on
  delay(500);                 // Wait for half a second
  digitalWrite(ledPin, LOW);  // Turn the LED off
  delay(500);                 // Wait for half a second

  // Send message via Bluetooth
  ESP_BT.println("Hello from ESP32 Bluetooth!");

  // Print touch sensor value periodically
  int touchValue = touchRead(touchPin);
  Serial.print("Touch sensor value: ");
  Serial.println(touchValue);

  // Non-blocking WiFi connection attempt
  if (!wifiConnected) {
    if (WiFi.status() == WL_CONNECTED) {
      wifiConnected = true;
      Serial.println("\nConnected to WiFi");
    } else if (millis() - wifiAttemptStartTime > wifiTimeout) {
      Serial.println("\nWiFi connection attempt timed out");
      // Optionally, you can start another connection attempt
      WiFi.begin(ssid, password);
      wifiAttemptStartTime = millis();
    }
  } else {
    Serial.println("Already connected to WiFi");
  }

  delay(2000); // Wait for 2 seconds before repeating
}

Comment (1)

  1. #include #include #include #include #include#if !defined(I2S_COMM_FORMAT_STAND_I2S) #define I2S_COMM_FORMAT_STAND_I2S I2S_COMM_FORMAT_I2S #endif#define WIFI_SSID "Allen Hom." #define WIFI_PASSWORD "Allenhome$1" #define GEMINI_KEY "AIzaSyD8e-xkNhNV-JEE6MsXy0ecZ3tQ1nce1JA" #define ELEVEN_KEY "sk_d5e788eb16fdc446e857527f258bf02c509c914b31dc96bb" #define VOICE_ID "nPczCjzI2devNBz1zQrb"#define BUTTON_PIN 0 #define MIC_BCLK 41 #define MIC_WS 42 #define MIC_DIN 2 #define SPK_BCLK 47 #define SPK_WS 45 #define SPK_DOUT 21#define SAMPLE_RATE 16000 #define RECORD_SAMPLES (SAMPLE_RATE * 5)int16_t* recordBuffer = nullptr; volatile bool isBusy = false;void initI2S() { i2s_config_t i2s_config = { .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_TX), .sample_rate = SAMPLE_RATE, .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT, .communication_format = (i2s_comm_format_t)I2S_COMM_FORMAT_STAND_I2S, .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, .dma_buf_count = 8, .dma_buf_len = 64, .use_apll = false }; i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL); i2s_pin_config_t mic_pins = { .bck_io_num = MIC_BCLK, .ws_io_num = MIC_WS, .data_out_num = -1, .data_in_num = MIC_DIN }; i2s_set_pin(I2S_NUM_0, &mic_pins); i2s_driver_install(I2S_NUM_1, &i2s_config, 0, NULL); i2s_pin_config_t spk_pins = { .bck_io_num = SPK_BCLK, .ws_io_num = SPK_WS, .data_out_num = SPK_DOUT, .data_in_num = -1 }; i2s_set_pin(I2S_NUM_1, &spk_pins); }void runAI() { isBusy = true; HTTPClient http; http.begin("https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent?key=" + String(GEMINI_KEY)); http.addHeader("Content-Type", "application/json"); JsonDocument doc; JsonArray contents = doc["contents"].to(); JsonObject obj0 = contents.add(); JsonArray parts = obj0["parts"].to(); JsonObject part0 = parts.add(); // PERSONALIZED PROMPT FOR ALLEN part0["text"] = "You are Jarvis, a loyal AI assistant. Always start every response with 'Vanakkam Allen'. Address the user as Allen. Solve math, provide recipes, suggest music. Use respectful Tanglish. No 'Amma'."; JsonObject part1 = parts.add(); part1["inline_data"]["mime_type"] = "audio/wav"; part1["inline_data"]["data"] = base64::encode((uint8_t*)recordBuffer, RECORD_SAMPLES*2);String body; serializeJson(doc, body); if(http.POST(body) == 200) { JsonDocument out; deserializeJson(out, http.getString()); String reply = out["candidates"][0]["content"]["parts"][0]["text"].as(); http.end(); http.begin("https://api.elevenlabs.io/v1/text-to-speech/" + String(VOICE_ID) + "/stream?output_format=pcm_16000"); http.addHeader("xi-api-key", ELEVEN_KEY); JsonDocument tts; tts["text"] = reply; tts["model_id"] = "eleven_multilingual_v2"; String ttsBody; serializeJson(tts, ttsBody); if(http.POST(ttsBody) == 200) { WiFiClient* stream = http.getStreamPtr(); uint8_t buf[512]; while(http.connected() && (stream->available() || stream->connected())) { size_t len = stream->readBytes(buf, sizeof(buf)); size_t written; i2s_write(I2S_NUM_1, buf, len, &written, portMAX_DELAY); } } } http.end(); isBusy = false; }void setup() { setCpuFrequencyMhz(240); // Max clock for ESP32-S3 pinMode(BUTTON_PIN, INPUT_PULLUP); WiFi.begin(WIFI_SSID, WIFI_PASSWORD); while (WiFi.status() != WL_CONNECTED) delay(100); if (psramInit()) { recordBuffer = (int16_t*)heap_caps_malloc(RECORD_SAMPLES * 2, MALLOC_CAP_SPIRAM); // Allocate in 8MB PSRAM } initI2S(); }void loop() { if (digitalRead(BUTTON_PIN) == LOW && !isBusy) { size_t r; i2s_read(I2S_NUM_0, recordBuffer, RECORD_SAMPLES * 2, &r, portMAX_DELAY); runAI(); } }

Leave a Reply

Your email address will not be published. Required fields are marked *

Need Help?