/********* Pleasedontcode.com **********
Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- Terms and Conditions:
You have a non-exclusive, revocable, worldwide, royalty-free license
for personal and commercial use. Attribution is optional; modifications
are allowed, but you're responsible for code maintenance. We're not
liable for any loss or damage. For full terms,
please visit pleasedontcode.com/termsandconditions.
- Project: OLED Messaging
- Source Code compiled for: ESP32 DevKit V1
- Source Code created on: 2024-08-25 15:19:53
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* Display "Hello, World!" on the SSD1306 OLED using */
/* I2C communication with SDA on pin D21 and SCL on */
/* pin D22, ensuring proper initialization of the */
/* Adafruit SSD1306 library. */
/****** END SYSTEM REQUIREMENTS *****/
/********* User code review feedback **********
#### Feedback 1 ####
- print on serial that esp32 is alive on loop function
********* User code review feedback **********/
/****** DEFINITION OF LIBRARIES *****/
#include
#include // https://github.com/stblassitude/Adafruit_SSD1306_Wemos_OLED.git
#include // https://github.com/olikraus/U8g2_for_Adafruit_GFX
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
/***** DEFINITION OF I2C PINS *****/
const uint8_t display_SSD1306OledDisplay_I2C_PIN_SDA_D21 = 21; // SDA pin
const uint8_t display_SSD1306OledDisplay_I2C_PIN_SCL_D22 = 22; // SCL pin
const uint8_t display_SSD1306OledDisplay_I2C_SLAVE_ADDRESS = 0x3C; // I2C address (0x3C is common for SSD1306)
/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
// Create an instance of the display object
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); // Initialize display with I2C
// Create an instance for U8g2 using the Adafruit display
U8G2_FOR_ADAFRUIT_GFX u8g2_for_adafruit_gfx; // Create an instance for U8g2
void setup(void)
{
// Initialize serial communication for debugging
Serial.begin(9600);
// Initialize the display with I2C address
display.begin(SSD1306_SWITCHCAPVCC, display_SSD1306OledDisplay_I2C_SLAVE_ADDRESS);
display.clearDisplay(); // Clear the display buffer
// Connect u8g2 procedures to Adafruit GFX
u8g2_for_adafruit_gfx.begin(display);
// Set up the display
display.setTextSize(1); // Set text size
display.setTextColor(SSD1306_WHITE); // Set text color
display.setCursor(0, 0); // Set cursor position
display.println(F("Hello, World!")); // Print message
display.display(); // Refresh the display
delay(2000); // Delay for 2 seconds
}
void loop(void)
{
// Main code to run repeatedly
display.clearDisplay(); // Clear the display buffer
display.setCursor(0, 0); // Set cursor position
display.println(F("ESP32 with OLED")); // Print message
display.display(); // Refresh the display
delay(2000); // Delay for 2 seconds
// Print to serial to indicate ESP32 is alive
Serial.println("ESP32 is alive!"); // Print message to serial monitor
}
/* END CODE */