Extra 5% OFF Use Code: OL05
Free Shipping over ₹999

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
}

    Leave a Reply

    Your email address will not be published.

    Need Help?