Skip to content

Instantly share code, notes, and snippets.

@wesleyit
Created November 10, 2023 22:15
Show Gist options
  • Save wesleyit/90356160fc4dd6c18974076b55d42c80 to your computer and use it in GitHub Desktop.
Save wesleyit/90356160fc4dd6c18974076b55d42c80 to your computer and use it in GitHub Desktop.
A very simple code to display text using an OLED display built in to NodeMCU
#include <Arduino.h>
#include <U8g2lib.h>
#include <Wire.h>
// This line will initialize the OLED display properly
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 12, /* data=*/ 14, /* reset=*/ U8X8_PIN_NONE);
#define U8LOG_WIDTH 14 // Width of ulog object
#define U8LOG_HEIGHT 4 // Height of ulog object
// The size necessary for the ulog buffer
uint8_t u8log_buffer[U8LOG_WIDTH * U8LOG_HEIGHT];
U8G2LOG u8g2log;
void setup(void) {
// Init the display
u8g2.begin();
// Init the ulog object
u8g2log.begin(U8LOG_WIDTH, U8LOG_HEIGHT, u8log_buffer);
}
String nome = String("Em volta do buraco, tudo eh beira.\n--Ariano Suassuna\f");
int counter = 0;
void loop(void) {
// The text from the ulog object need to be printed
// before the screen is assembled
u8g2log.print(nome[counter]);
// Then, create the screen layout calling the ulog object
u8g2.firstPage();
do {
u8g2.setFont(u8g2_font_commodore64_tr); // font for the title
u8g2.setCursor(0, 14); // title position on the display
u8g2.print("Sabedoria:"); // output title
u8g2.setFont(u8g2_font_unifont_tf); // set the font for the terminal window
u8g2.drawLog(0, 28, u8g2log); // draw the terminal window on the display
} while (u8g2.nextPage());
if (counter > nome.length()) {
counter = 0;
}
else {
counter++;
}
delay(50);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment