Typewriter animation on ATtiny1616 with OLED

A project log for ATtiny 1-series with Arduino support

Creating a break-out board for the ATtiny1616 where sketches can be uploaded from Arduino with the Arduino UNO or a modified AVR JTAG ICE

Sander van de BorSander van de Bor 07/27/2019 at 20:530 Comments

The small 0.97" and 1.3" OLED displays are great and easy to work with, here is an example:

On the older ATtiny's, like the ATtiny84a, I was only able to use the U8glib with U8x8 (text output only). Memory limitations did not allow other fonts available with U8g2. Fortunately the new ATtiny 0- and 1-series, not only have hardware SPI to control the OLED., but also more memory to use U8g2.

Example from the animation above uses the RESET, DC and CS on pins 9, 10 and 11. By placing the OLED directly underneath these pins on the breadboard it only requires 4 additional wires. 2 wires for power (VCC and GROUND), and 2 wires for the SPI (CLK on pin 16 and MOSI on pin 14).

I created the typewriter animation as follows:

#include <U8g2lib.h>
#include <SPI.h>

U8G2_SH1106_128X64_NONAME_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 11, /* dc=*/ 10, /* reset=*/ 9);

void setup(void) {

char message[] = {"Hackaday!ATtiny1616"};
int posX[19] = {0,20,35,48,61,76,90,102,115, /* second row */ 0,18,33,44,54,70,84,95,106,115};
int posY[19] = {30,29,31,30,28,29,30,33,35, /* second row */ 58,61,61,60,58,59,60,63,61,60};

void loop(void) {
  u8g2.clearBuffer();         // clear the internal memory
  u8g2.sendBuffer();          // transfer internal memory to the display
  u8g2.setFont(u8g2_font_ncenR18_tr); // choose a suitable font
  for (byte i = 0; i < sizeof(message) - 1; i++) {
    char writeText[] = {message[i],'\0'};   // Add a NULL after character
    u8g2.drawStr(posX[i],posY[i],writeText);  // write something to the internal memory
    u8g2.sendBuffer();          // transfer internal memory to the display