Project tutorial
Pixel Art on OLED Display

Pixel Art on OLED Display © CC BY

Make your pixel art look delightfully retro using an OLED display. We'll see how to make your own image, and animate it.

  • 1 comment
  • 20 respects

Components and supplies

A000066 iso both
Arduino UNO & Genuino UNO
Any boards compatible with Arduino IDE
Adafruit Monochrome 128x32 I2C OLED graphic display
Any display compatible with U8g2

Apps and online services

About this project

I love pixel art and OLED display makes it even cooler!

It may seem really hard to draw on this type of display, but with some practice you can make your own logo, even animation!

Choose your image

We will use a 128x32 display (128x64 are also really common if you want more space) so it's best to choose a small image.

GameBoy sprites are the easiest to work with but keep in mind we are limited to black/white while the GameBoy can display 4 shades of gray.

You can download sprites from to get you started.

Convert images to pixel art

In our first example we will use the logo.

We need to :

  • resize our image to 128x32
  • redraw the image to use two colors
  • converts it to XBM (Arduino code)

You can use any software to make your images, but I recommend Krita.

  • Resize the image to the nearest size of your screen (128x32) : Image -->Scale to New Size
  • Increase the canvas size : Image --> Resize Canvas

In brush presets, choose Pixel Art

Then redraw your image:

White will be no color (black) and black will be color (Blue / White depending on your screen).

Press X to switch between color on Krita

Convert your pixel art to Arduino code

  • Save your image as XBM
  • Also save it as PNG, you won't be able to edit the XBM file!

Open the xbm file with a text editor and change the variable name

Original file

#define _width 128
#define _height 32
static char _bits[] = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00... };


#define logo_width 128
#define logo_height 32
static const unsigned char logo[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00... };

Display your logo

It's best to keep the logo in another.hfile, so it will be easier to read your code.

We will use U8g2 library (which supports a LOT of screens)

#include <Wire.h> //I2C
#include <U8g2lib.h>
#include "logo.h"
//I2C SSD1306 128x32 (search U8g2 examples for other display)
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);
void setup() {
 u8g2.begin(); //Start Screen
void loop() {
void drawLogo() {
 do {
   u8g2.drawXBMP(0, 0, logo_width, logo_height, logo); 
 } while ( u8g2.nextPage() );

I also put the png and xbm files inside a res/ folder in my code, so I can remember what was my logo.h file.

Upload your code, and voilà!

Animation - position

You can animate your pixel art in two ways:

  • Change his position
  • Use multiple images

So if we want to move your sprite from left to right, we just have to change his x position right?

If you use an Arduino Uno, this will work but with more powerful boards (like the Arduino MKR1010) your animation will go too fast!

We need to limit the refresh rate of our animation, of course, we could simply use a delay but it will not allow us to do other things at the same time.

So we will use AsyncDelay library to manage this efficiently

#include <AsyncDelay.h>
const int FPS = 1000 / 30; //30 FPS
AsyncDelay tick;
void setup(){
  tick.start(FPS, AsyncDelay::MILLIS);
void loop(){

Last thing, we want our image to go outside the screen at the right and slowly appears on the left.

So we reset the position at the size of the OLED Width (128) with the width of the image (128+36).

And set the position to -36 so the image appears to be coming from the left.

void loop() {
 if (tick.isExpired()) {
   pos_x = pos_x + X;
   if (pos_x > OLED_WIDTH + cannon_width) {
     pos_x = -cannon_width;

And here is the result !

Animation - multiples images

Another way to animate image is to use multiple images.

Instead of changing the X position, I make a switch conditionand increase the value animation_state.

void drawAnimation() {
 do {
   switch (animation_state) {
     case 0:
       u8g2.drawXBMP(0, 0, logo_width, logo_height, logo_1);
     case 1:
       u8g2.drawXBMP(0, 0, logo_width, logo_height, logo_2);
     case 2:
       u8g2.drawXBMP(0, 0, logo_width, logo_height, logo_3);
     case 3:
       u8g2.drawXBMP(0, 0, logo_width, logo_height, logo_4);
     case 4:
       u8g2.drawXBMP(0, 0, logo_width, logo_height, logo_5);
     case 5:
       u8g2.drawXBMP(0, 0, logo_width, logo_height, logo_6);
 } while ( u8g2.nextPage() );

Since I want to reverse the animation I used a boolean (animation_direction) so the animation will go backward.

   if (animation_direction) {
   } else {
   if (animation_state == 5) {
     animation_direction = true;
   if (animation_state == 0) {
     animation_direction = false;

Here is the result:

If you combine these two techniques, we can make complex animation:

I hope this tutorial will be useful and you will have as much fun with your OLED screen as I have.

If you made some pixel art please share them in the comment or mention me on twitter @m4dnerd.


OLED Image
This example show the logo
OLED Animation (position)
This example show mario cannon move from left to right
OLED Animation (multiple images)
This example show an animated logo
Combined example of animation with mario walking and then going into a pipe.
Github repo with all codes


OLED Schematic
How to plug an OLED display to an Arduino Uno
Oled arduino uno 4zjzixjl6a


Team members

  • 3 projects
  • 1 follower
  • 3 projects
  • 1 follower

Additional contributors

  • I learnt how to use xbm image using his m5stick watch code by Eggfly
  • This amazing library to manage display is really great! by olikraus
  • I found my sprites here by The Spriters Ressource

Published on

February 23, 2019

Members who respect this project

ProfilepicPhotoIch fv1lkw7gizPhotoPloureiroPhotoPhotoSaulofilho

and 12 others

See similar projects
you might like

Similar projects you might like

Arduino Pong Game - OLED Display

Project tutorial by Nick Koumaris

  • 1 comment
  • 13 respects

Programmable Pocket Power Supply with OLED Display

Project tutorial by Shahariar

  • 34 respects

Smart Poetic OLED Display Badge

Project tutorial by Ashwini kumar sinha

  • 9 respects

GPS Location Display With GPS And TFT Display Shields

Project tutorial by Boian Mitov

  • 31 respects

Arduino OLED Temperature Display with Real Time Clock

Project tutorial by Keval Doshi

  • 33 respects
Add projectSign up / Login