Large fonts on a tiny OLED & ATiny85

Introduction

It is very challenging to compress code in small memory micro-controller unit (MCU) such as Digispark ATtiny85, which is offering only 6kB. Suppose you want to attach it to a tiny OLED (128x32 pixels) and make it write easily readable huge fonts (16x32 pixels WxH). And after this feast, you may still want to make the Attiny85 do, more than simply writing something! This means: leave memory available from the 6kB!

Sketch uses 3756 bytes (62%) of program storage space. Maximum is 6012 bytes.

Global variables use 69 bytes of dynamic memory.

The Purpose

  • Add some useful functionality to the magnificent ATtiny85.
  • Make the smallest OLED display (128x32) look big!

Components

  1. 0.91 Inch 128x32 IIC I2C Blue OLED LCD Display SSD1306 Driver. Details here.
  2. Digistump Digispark ATtiny85 development board. My board is a version B with micro-USB. The more common has details here.

Image

1. The small OLED display with "huge" digits.

Schematic

4. Schematic for the connections.

On the Fritzing schematic are shown the four connections. In my case, power is provided by the USB connector.

Arduino Code

This is an example showing the use of digits and a few useful characters like , - . / and :

In this way a normal display of real numbers is possible.

/* Digispark ATtiny85 to small OLED 128x32 by I2C

* https://github.com/datacute/Tiny4kOLED

* Tiny4kOLED.h: SSD1306xLED-Drivers for OLED 128x32 displays

* @created: 2014-08-12 @author: Neven Boyanov

* Source code available at: https://bitbucket.org/tinusaur/ssd1306xled

* @ modified for 16x32 fonts: 2017-01-12 @author: M. V. Predoi

* Fits into Digispark ATtiny85 (6012 bytes). 52 bytes of dynamic memory.

* ATtiny85 OLED

* <<------>>

* PB0 SDA

* PB2 SCL

* 5V VCC

* GND GND

*

*/

#include <Tiny4kOLED.h>

#include <TinyWireM.h>

// ============================================================================

void setup() {

oled.begin();

oled.clear();

oled.on();

}

void loop() {

oled.clear(); //all black

oled.setFont(FONT16X32); // 1 raw of 8 characters exactly fills 128x32

//next line: oled.setCursor(X IN PIXELS, Y - NO EFFECT since 32 bits is max height);

oled.setCursor(0, 0);

oled.print(F("-23.56:/")); //wrap strings in F() to save RAM!

delay(5000); // To see the display "refresh"

}

User guide

Latest version:

  • As I expected, Stephen Denne (datacute), the author of the Tiny4kOLED library, has updated the fonts in his library and included in sept. 2019 the fonts presented in this project. You are encouraged to download his library: https://github.com/datacute/TinyOLED-Fonts.
  • Initial contribution from jan. 2017 required:

Upload OUR library "Tiny4kOLED", to the Arduino libraries folder. If you already have it, replace it with this one. It includes the original one and adds support for the set of 15fonts 16x32. You can find our modified library in our Files page (see bottom of this page).

Open the Tiny4kOLED.h and un-comment the fonts you intend to use. Only the 16x32 fonts, means a total memory of 2944 bytes ( 48%) for this example. If you need all fonts available, running only this small example will require 5412 bytes (90%): not much room for any other code on ATtiny85.

The original Tiny4kOLED library (with only 6x8 and 8x16 fonts) can be found at: https://github.com/datacute/Tiny4kOLED, which is adapted after: https://github.com/digistump/DigistumpArduino/tree/master/digistump-avr/libraries/DigisparkOLED.

Project New Contributions

The contributions of this project to the Arduino and Digistump community are:

  • A large font, although only digits and several symbols, can be used for e.g. showing time or any numerical output.
  • The library with this new font still fits in the 6kB EPROM of ATtiny85. For other MCU's the font can be extended to a full ASCII set.
  • These contributions were appreciated by users and even by the author of the original library, who included these fonts in new versions.