SimpleOLED library

Simple text-only library for OLED SSD1306 via i2c

This library allows to display text on an OLED display controlled by the SSD1306. It is possible to use both sizes (128x64 and 128x32).

In contrast to other display drivers, this driver does not hold a buffer for execution of paint operations in memory, so the very limited SRAM on Arduino boards stays available for other needs.

Therefore enhanced paint operations (circles, flood fill, lines etc.) are not possible directly. The library is designed for displaying text.

Three fonts are available:

  1. The default font is a very tiny font with 6x8 pixels per character.
  2. The Topaz font is a font inspired by Amiga OS 2.x and above. In contrast to the original font, the character mapping complies (with small exceptions) to ISO-8859-1.
  3. The C64 font is inspired by the font of the Commodore 64. The character mapping also complies to ASCII, but as the original C64 font, it does not have the special characters needed in some languages.
Font Topaz on SSD1306

Requirements

The library uses the Arduino wire library.

Usage

The OLED SSD1306 must be connected via I2C (aka TwoWire, TWI or simply Wire).

ArduinoDisplay
+5VVCC
GNDGND
SDASDA
SCLSCL

An instance of the class "SimpleOLED" is needed. As first argument, the constructor expects the I2C address of the display (usually 0x3C), followed by the width (128) and the height (32 or 64) in pixels.

#define DISPLAY_I2C_ADDR 0x3C
#define DISPLAY_WIDTH 128
#define DISPLAY_HEIGHT 32

SimpleOLED Display(DISPLAY_I2C_ADDR, DISPLAY_WIDTH, DISPLAY_HEIGHT);

Functions

begin()

This function must be called to initialise the display and switch it on.

Example:

Display.begin();
end()

This function switches off the display.

Example:

Display.end();
clear()

This function clears the whole content of the display and sets the cursor to the top left corner.

Example:

Display.clear();
setFont(char *Name, bool DoubleHeight)

This function changes the font for the following operations. Possible fonts are "default", "Topaz" and "C64". The font height can be set with the parameter "DoubleHeight" - false means 8 pixels, true means 16 pixels.

After changing the font, the cursor position must be set again (see setCursor).

Example:

Display.setFont("Topaz", true);
setCursor(uint8_t Column, uint8_t Row)

This function sets the cursor position for the following print operations. The values are in characters, not in pixels.

Example:

Display.setCursor(8, 1);
print(char *String)

This function writes a string to the display. The only special character is "\n", which performs a carriage return and a line feed.

Example:

Display.print("Hello World!");
println(char *String)

This function works exactly like the print function, but it adds a carriage return / line feed at the end of the line.

Example:

Display.println("Hello World!");

Download

Version: 5.2
© 1996-2024 by Stefan Trippler (stef2024@[REM0VE]trippler.de)
Impressum

Valid HTML 4.01 Strict Valid CSS