Close

Figuring Out the OLED

A project log for Tippy Timer

A simple "box" to make it easier to time out discrete intervals.

bud-bennettBud Bennett 04/16/2022 at 21:040 Comments

The OLED display is driven by the SSD1360 IC. The datasheet is available from Adafruit for your viewing pleasure. There is no PIC library that I'm aware of to make it easier to drive the display. The SSD1306 divides the display up into 4 horizontal pages and 128 vertical segments. There are three methods to address the display -- I chose the default method of manually addressing each page and segment. When you send a data byte to the OLED it fills up 8 sequential pixels from the top of the page to the bottom.

I decided to assign digit locations to 4 areas. The 10 minute digit occupies segments 0-27, the 1 minute digit occupies segments 28-56, etc. The colon gets 16 segments in the middle. Each digit must have the same number of segments to make the coding easier.

After the mapping was completed I needed to create graphical characters for the 10 digits. First, I created a 28 x 32 grid of the pixels in each digit space. Then I found a font that appealed to me -- Reem Kufi -- scaled up to 600pts and placed each character over the grid with some transparency, so you could still see the grid lines. As so:

There is a bit more room to the right than to the left to allow for proper spacing. Then I laboriously filled in each byte position for every segment of every page. The result is a large display with fairly crisp characters. I made some small errors along the way that will have to be corrected after the main program is completed.

Each character, plus an all-zeros blank character, was then transferred into the program memory of the PIC at the end of the program memory space. This requires 1232 bytes of program memory out of a total of 14k bytes. Here's an example of the "2" character:

Digit2:
    DB    0x00,0x00,0xc0,0xe0,0xf8,0xfc,0xfe,0x7e,0x3e,0x1f,0x1f,0x1f,0x1f
    DB    0x1f,0x1f,0x3f,0x3e,0xfe,0xfc,0xfc,0xf8,0xf0,0xc0,0x00,0x00,0x00
    DB    0x00,0x02,0x3f,0xff,0xff,0xff,0xf4,0xc0,0x00,0x00,0x00,0x00,0x00
    DB    0x00,0x00,0x00,0x00,0xc0,0xff,0xff,0xff,0xff,0x3f,0x00,0x00,0x00
    DB    0x00,0x00,0x00,0x00,0x01,0x03,0x01,0x00,0x00,0x00,0x00,0x80,0xc0
    DB    0xe0,0xf8,0xfc,0xff,0x3f,0x1f,0x0f,0x07,0x01,0x00,0x00,0x00,0x00
    DB    0x00,0x00,0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff,0xff,0xff
    DB    0xf3,0xf1,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0x00,0x00

When this is written to the OLED RAM, the Page number and segment start location is set to the digit location and then all 28 bytes are written in a single I2C communication for that page. Then the next Page is written, etc. until all four pages contain the character data for that digit. The other four digits and colon are written similarly. The entire I2C communication for all four digits requires about 220ms.

This was a lot of effort.

Discussions