#include #include #include #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels // Declaration for SSD1306 display connected using I2C #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); String receivedText = ""; // Variable to store received text void setup() { // Initialize serial communication Serial.begin(9600); // Initialize OLED display if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Serial.println(F("SSD1306 allocation failed")); for(;;); } // Clear the display display.clearDisplay(); display.display(); } void loop() { // Check if there is serial data available if (Serial.available() > 0) { // Read the entire string until newline character '\n' receivedText = Serial.readStringUntil('\n'); // Clear the display display.clearDisplay(); // Print the received text on OLED display display.setTextSize(1); display.setTextColor(SSD1306_WHITE); display.setCursor(0, 0); display.println(receivedText); display.display(); // Display the updated buffer } }