Skip to main content

Ssd1306 – Writing text

To write text onto the display, you must define the text size, color, and the starting coordinate from which the text will be drawn onto the display.

void loop() {
delay(1000);
// Clear the last image shown on screen
display.clearDisplay();
// Normal 1:1 pixel scale
display.setTextSize(1);
// Draw white text
display.setTextColor(SSD1306_WHITE);
// Start at top-left corner
display.setCursor(0, 0);
// Message we want to display
String message = "Hello World!";
// Inform the display of the text you want to print
display.print(message);
// Display the message
display.display();
}
Hello world displayed

display.clearDisplay()

Clears contents of display buffer (sets all pixels to off).

Returns value: None

⚠️
Because the clearDisplay() function only clears the buffer, it has no immediate effect on the screen. The display() function must still be called.

display.setTextColor(uint16_t c, uint16_t bg)

Set text font color with custom background color

Returns value: None

Function parameters:

TypeNameDescription
int16_tcWhat color the text will be
int16_tbgOptional, what color the background will be, if not set then it is transparent

display.setCursor(int16_t x, int16_t y)

Sets text cursor location

Returns value: None

Function parameters:

TypeNameDescription
int16_txx coordinate of cursor
int16_tyy coordinate of cursor

display.print(const char* message)

Stores the given message into buffer

Returns value: None

Function parameters:

TypeNameDescription
const char*messagetext that will be shown on display