Bestilt før kl. 14.00 på hverdage = afsendt samme dag 30 dages fortrydelsesret 1 års garanti
← Terug til oversigten

Tilslutningsdiagram og kodeeksempel

Sådan tilslutter du Mini OLED display blå 0.91 inch 128x32 I2C til en Arduino UNO eller ESP32, med en eksempelsketch, du kan uploade med det samme.

0,91-tommer I2C OLED-display demo

Dette projekt viser, hvordan man tilslutter og viser tekst samt en aktiv tæller på en 0,91-tommer (128x32) I2C OLED-skærm. Skærmen tilsluttes direkte til Arduino Uno’s I2C-ben (A4 til SDA, A5 til SCL). Når den tændes, viser skærmen en titelbjælke og opdaterer en løbende sekundtæller.

Tilslutningsdiagram: Mini OLED display blå 0.91 inch 128x32 I2C på en Arduino UNO
Tilslutningsdiagram · Klik for at forstørre
Tilslutningstabel: Mini OLED display blå 0.91 inch 128x32 I2C på en Arduino UNO
Tilslutningstabel · Klik for at forstørre
0_91_inch_I2C_OLED_Display_Demo.ino · kompileret og testet
/*
 * ==================================================================
 *  Generated by Codey.online  —  https://www.codey.online
 * ==================================================================
 *  Project   : 0.91-inch I2C OLED Display Demo
 *  Board     : Arduino UNO (arduino:avr:uno)
 *  Parts     : OLED Display 0.91 inch
 *  Libraries : U8g2 2.36.19
 *
 *  Codey Online is an AI-powered browser IDE for Arduino and ESP32.
 *  Describe your project and Codey writes the code, draws the wiring
 *  diagram and uploads it to your board, straight from the browser.
 *  This code is free to use, modify and share, without warranty.
 * ==================================================================
 */

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

// 0.91" OLED display is a 128x32 SSD1306 I2C module
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

unsigned long seconds = 0;

void setup() {
  Wire.begin();
  u8g2.begin();
}

void loop() {
  u8g2.clearBuffer();

  // Header text
  u8g2.setFont(u8g2_font_6x10_tr);
  u8g2.drawStr(0, 10, "0.91\" OLED Demo");

  // Separator line
  u8g2.drawHLine(0, 14, 128);

  // Uptime counter
  u8g2.drawStr(0, 28, "Uptime: ");
  u8g2.setCursor(50, 28);
  u8g2.print(seconds);
  u8g2.print(" s");

  u8g2.sendBuffer();

  seconds++;
  delay(1000);
}

Nødvendige biblioteker: U8g2 2.36.19

Wiring diagram and example code generated by Codey.online — https://www.codey.online

0.91 Inch OLED Display med ESP32

Dette eksempel forbinder et 0.91-inch 128x32 I2C OLED-display til ESP32. Sketchen initialiserer displayet og viser en velkomstbesked sammen med en opdateret runtime-tæller. Forbind displayet til ESP32's standard I2C-ben (GPIO 21 for SDA og GPIO 22 for SCL), forsynet med 3.3V.

Tilslutningsdiagram: Mini OLED display blå 0.91 inch 128x32 I2C på en ESP32 DevKit V1
Tilslutningsdiagram · Klik for at forstørre
Tilslutningstabel: Mini OLED display blå 0.91 inch 128x32 I2C på en ESP32 DevKit V1
Tilslutningstabel · Klik for at forstørre
0_91_Inch_OLED_Display_with_ESP32.ino · kompileret og testet
/*
 * ==================================================================
 *  Generated by Codey.online  —  https://www.codey.online
 * ==================================================================
 *  Project   : 0.91 Inch OLED Display with ESP32
 *  Board     : ESP32 DEVKIT V1 (esp32:esp32:esp32doit-devkit-v1)
 *  Parts     : OLED Display 0.91 inch
 *  Libraries : Adafruit SSD1306 2.5.16, Adafruit GFX Library 1.12.6
 *
 *  Codey Online is an AI-powered browser IDE for Arduino and ESP32.
 *  Describe your project and Codey writes the code, draws the wiring
 *  diagram and uploads it to your board, straight from the browser.
 *  This code is free to use, modify and share, without warranty.
 * ==================================================================
 */

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

int counter = 0;

void setup() {
  Serial.begin(115200);

  // Initialize I2C on ESP32 default pins (SDA=21, SCL=22)
  Wire.begin(21, 22);

  if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;); // Halt if OLED not found
  }

  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.println(F("ESP32 OLED Demo"));
  display.display();
  delay(1500);
}

void loop() {
  display.clearDisplay();
  
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.println(F("ESP32 DevKit V1"));
  
  display.setTextSize(2);
  display.setCursor(0, 14);
  display.print(F("Count: "));
  display.println(counter);
  
  display.display();

  Serial.print(F("Current count: "));
  Serial.println(counter);

  counter++;
  delay(1000);
}

Nødvendige biblioteker: Adafruit SSD1306 2.5.16, Adafruit GFX Library 1.12.6

Wiring diagram and example code generated by Codey.online — https://www.codey.online