microrobotics icon

ESP Wroom 32 with OLED WebServer

microrobotics | PRO | 05/11/23 07:21:48 AM UTC | 0 ⭐ | 2180 👁️ | Never ⏰ | []
Arduino |

1.69 KB

|

None

|

0 👍

/

0 👎

/*
This is a simple example of using an ESP32 with a built-in OLED display, and a web server to update the display. This example uses the ESPAsyncWebServer library and Adafruit's SSD1306 library to control the OLED display.
 
This example creates a simple web server on the ESP32. When you navigate to the root of the server (http://<esp32-ip-address>/), you can pass a parameter with the message you want to display on the OLED screen (http://<esp32-ip-address>/?<your_message>). The ESP32 will then display this message on the OLED screen.
*/
 
void setup() {
  // Serial port for debugging purposes
  Serial.begin(115200);
  
  // Specify the SDA and SCL pins. SDA=5, SCL=4
  Wire.begin(5, 4);
  
  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x64
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }
 
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println(F("Connecting to WiFi..."));
  display.display();
 
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  display.println(F("WiFi connected"));
  display.display();
 
  // Route for root / web page
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    String message = request->getParam(0)->value();
    display.clearDisplay();
    display.setCursor(0,0);
    display.println(message);
    display.display();
    request->send(200, "text/plain", "Message received");
  });
 
  // Start server
  server.begin();
}
 

Comments