24  OLED screen

A screen is an essential component in many projects, offering a visual interface to communicate information to users. Here are some general uses and benefits:

  1. Real-Time Data Display: Screens allow you to show real-time data such as sensor readings, system status, or user instructions, making the device more interactive and user-friendly.

  2. Debugging and Monitoring: During development, a screen can be invaluable for debugging and monitoring the performance of your system, showing error messages or status updates.

  3. User Interaction: Screens enable user interaction by displaying menus, prompts, or feedback, making the device intuitive and easy to use.

  4. Aesthetic and Functional Design: Adding a screen enhances both the aesthetics and functionality of a project, giving it a polished and professional look.

A screen bridges the gap between technology and the user by providing clear, accessible communication.

24.1 OLED code

Download code
#include <Wire.h>
#include <U8g2lib.h>

// Initialize the display (change constructor according to your OLED model)
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

void setup() {
  // initialize the display
  u8g2.begin();
  
  // display a startup message
  u8g2.clearBuffer();                // clear the internal memory

    // Small text
  u8g2.setFont(u8g2_font_6x10_tr);
  u8g2.drawStr(3, 10, "S-Hello");

  // Medium text
  u8g2.setFont(u8g2_font_ncenB08_tr);
  u8g2.drawStr(3, 30, "M-Hello");

  // Large text
  u8g2.setFont(u8g2_font_fur20_tr);
  u8g2.drawStr(3, 60, "L-Hello");

  // transfer buffer to the display
  u8g2.sendBuffer();      
  
  delay(5000); // wait 
}

void loop() {
  static int counter = 0;
  
  // update the screen
  u8g2.clearBuffer();
  u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font
  u8g2.drawStr(3, 16, "Counter:");
  u8g2.drawStr(73, 16, String(counter).c_str());
  u8g2.sendBuffer();
  
  // increment the counter
  counter++;
  
  // wait for 1 second
  delay(1000);
}