Lesson plan

OLED graphics and fonts lesson plan

Pixel screens on an Uno with 2 KB of RAM: the SSD1306’s 1 KB framebuffer byte by byte, lines and circles, fonts, sprites, U8g2’s page mode, an SH1106 beside it through a TCA9548A, and a two-screen pocket space game.

4 chapters, 7 lessons, about 6 hours, on the Arduino Uno R3. Every lesson runs in the browser, with nothing to install.

The unit

Objectives and materials

By the end, students can

  • The framebuffer, and the shapes drawn into it.
  • Fonts, bitmaps and a sprite that flies.
  • Page mode, and two screens that share one address.
  • A pocket space game with a dashboard on a second screen.

Materials for the whole unit

  • Arduino Uno R3
  • Half breadboard
  • I2C multiplexer, TCA9548A
  • OLED display, 1.3 inch SH1106
  • OLED display, 128x64
  • Potentiometer
  • Pushbutton

Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.

Chapter 1. About 1 h 40 min

Pixels in memory

The framebuffer, and the shapes drawn into it.

LessonTimeWhat students do
The SSD1306 framebufferA 128x64 OLED is 1024 bytes in eight pages. Write bytes straight into the frame, count the pixels they light, and see what that kilobyte costs an Uno with 2048 bytes of RAM.50 min
  1. Run it
  2. Half the RAM, gone
  3. Bytes stand on end
  4. The bottom row
  5. A column down the middle
  6. A thicker stripe
  7. Why this layout
Pixels and linesAdafruit_GFX lines, rectangles and circles, each one’s pixels counted, then a radar whose sweep follows a knob, and the trick that sends 29 ms of changes instead of a 348 ms frame.50 min
  1. A line is a staircase
  2. Rectangles share corners
  3. Circles
  4. The radar
  5. Sweep it
  6. Point it anywhere
  7. A bigger circle

Materials

  • Arduino Uno R3
  • Half breadboard
  • OLED display, 128x64
  • Potentiometer
  • Pushbutton

Check for understanding

Each student finishes "Pixels and lines" on their own, without opening the hints. The simulator checks 7 of its 7 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "A bigger circle".

Chapter 2. About 1 h 40 min

Text and pictures

Fonts, bitmaps and a sprite that flies.

LessonTimeWhat students do
FontsThe built-in 6x8 cell at sizes 1 to 3, getTextBounds() to center a score that follows a knob, and a GFXfont whose cursor sits on the baseline, the classic OLED gotcha.50 min
  1. Three sizes
  2. Center the score
  3. Turn the knob
  4. On the screen
  5. The baseline gotcha
  6. Go bigger
  7. What fonts cost
Bitmaps and spritesA 16x16 rocket packed into 32 bytes of flash, flown across a starfield: the knob climbs, the button fires a laser, and each frame rubs out only where the ship was.50 min
  1. Thirty-two bytes of rocket
  2. Fly a lap
  3. Climb
  4. Fire
  5. Count the screen
  6. Full speed
  7. Make your own sprite

Materials

  • Arduino Uno R3
  • Half breadboard
  • OLED display, 128x64
  • Potentiometer
  • Pushbutton

Check for understanding

Each student finishes "Bitmaps and sprites" on their own, without opening the hints. The simulator checks 7 of its 7 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Make your own sprite".

Chapter 3. About 1 h 35 min

Less RAM, more screens

Page mode, and two screens that share one address.

LessonTimeWhat students do
U8g2 pagesU8g2’s picture loop draws Saturn one page at a time: a 128-byte buffer, eight passes a frame, and the strict rule that every pass draws the same picture. Plus an honest note on what Mokxi models.45 min
  1. A different library
  2. The picture loop
  3. Move the moon
  4. Saturn on the screen
  5. What is real here, and what is not
  6. Two pages at a time
SH1106 and two screensAn SSD1306 and an SH1106, both at 0x3C, behind a TCA9548A. The Uno has room for one 1 KB frame, so the SH1106 is drawn a page at a time through a 128-byte strip, from column 2.50 min
  1. Two screens, one address
  2. No room for a second frame
  3. Choose a channel
  4. The left screen
  5. The right screen, a page at a time
  6. Turn the knob
  7. What makes an SH1106 different

Materials

  • Arduino Uno R3
  • Half breadboard
  • I2C multiplexer, TCA9548A
  • OLED display, 1.3 inch SH1106
  • OLED display, 128x64
  • Potentiometer
  • Pushbutton

Check for understanding

Each student finishes "SH1106 and two screens" on their own, without opening the hints. The simulator checks 7 of its 7 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "What makes an SH1106 different".

Chapter 4. About 1 h

Boss project

A pocket space game with a dashboard on a second screen.

LessonTimeWhat students do
Boss: a pocket dashboardA pocket space game on two screens: a rocket dodging asteroids on the SSD1306, a fuel gauge, score and high score on the SH1106. One 1 KB frame, one 128-byte strip, a laser and shields.60 min
  1. Launch
  2. The game screen
  3. The dashboard
  4. Fire!
  5. Crash
  6. Dodge
  7. Shields up
  8. Make it yours and share it

Materials

  • Arduino Uno R3
  • Half breadboard
  • I2C multiplexer, TCA9548A
  • OLED display, 1.3 inch SH1106
  • OLED display, 128x64
  • Potentiometer
  • Pushbutton

Check for understanding

Each student finishes "Boss: a pocket dashboard" on their own, without opening the hints. The simulator checks 8 of its 8 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Make it yours and share it".

Your class

Teach this unit as a class

Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.

The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.