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.
1. The small OLED display with "huge" digits.
4. Schematic for the connections.
On the Fritzing schematic are shown the four connections. In my case, power is provided by the USB connector.
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"
}
Latest version:
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.
The contributions of this project to the Arduino and Digistump community are: