Pico and SSD1306 - bounce your own Icons - Tutorial

Make your own Icons

Download paint.net and LCD assistant from here:

Using paint.net create a New drawing with 32 x 32 pixels.

You probably need to zoom in quite a lot. Use CTRL ++ to enlarge image.

Select the pencil tool.

At the top near the middle disable antialiasing.

In the bottom left of the screen click on the black square to pick black brush colour.

Draw your design on the picture. I left the edge pixels white, like the Raspberry image.

Save as a 1-bit, BMP image, with 0 dithering. ie Image.bmp

Start LCD Assistant and open the file you just created.

Set orientation to HORIZONTAL, Size endianness(?) to Little and Pixels/byte to 8

Save Output as a txt file ie Image.txt

Open the file in NotePad

Copy the block of code starting const and paste into the code under the buffer definition in Thonny.

This now needs a bit of editing:

Delete the semi colon at the end. Change the braces {} to brackets ()

Find and replace ‘ , 0’ ( – comma space zero) with \

Edit the start of each line and replace the initial 0 with a \

Delete the commas from the end of each line.

Insert b” after the opening bracket and “ before the closing bracket.

Insert bytearray between the = and the bracket

Delete the newlines to make a single very long line starting:

buffer4 = bytearray(b”\x00\x ………… “)

Carefully compare the syntax with the original buffer line. (The original Raspberry code has some ‘funny’ characters - probably where the lines were broken in transmission.) The new code should be consistent in its format: \xNN\xNN\x…) It is very easy for the odd ‘x’ to get lost so check carefully.

Comment out the original buffer line

Change the line

fb = framebuf.FrameBuffer(buffer3, 32, 32, framebuf.MONO_HLSB)

To

fb = framebuf.FrameBuffer(buffer4, 32, 32, framebuf.MONO_HLSB)

Save and run your program.

Here is my finished edit:

# Bouncing Pico Icon
# Tony Goodhew 8th March 2021
# SSD1306 I2C with SCL on GP9 and SDA on GP8
# Needs SSD1306 library installed
# See https://www.instructables.com/SSD1306-With-Raspberry-Pi-Pico/
# for download if needed
from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
import framebuf
from time import sleep

WIDTH  = 128                                            # oled display width
HEIGHT = 64                                             # oled display height

i2c = I2C(0)                                            # Init I2C using I2C0 defaults, SCL=Pin(GP9), SDA=Pin(GP8), freq=400000
print("I2C Address      : "+hex(i2c.scan()[0]).upper()) # Display device address
print("I2C Configuration: "+str(i2c))                   # Display I2C config

oled = SSD1306_I2C(WIDTH, HEIGHT, i2c)                  # Init oled display

# Raspberry Pi logo as 32x32 bytearray
#buffer = bytearray(b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00|?\x00\x01\x86@\x80\x01\x01\x80\x80\x01\x11\x88\x80\x01\x05\xa0\x80\x00\x83\xc1\x00\x00C\xe3\x00\x00~\xfc\x00\x00L'\x00\x00\x9c\x11\x00\x00\xbf\xfd\x00\x00\xe1\x87\x00\x01\xc1\x83\x80\x02A\x82@\x02A\x82@\x02\xc1\xc2@\x02\xf6>\xc0\x01\xfc=\x80\x01\x18\x18\x80\x01\x88\x10\x80\x00\x8c!\x00\x00\x87\xf1\x00\x00\x7f\xf6\x00\x008\x1c\x00\x00\x0c \x00\x00\x03\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
# Pico logo as 32 x 32 byte array
buffer3 = bytearray(b"\x00\x00\x00\x00\x7F\x80\x01\x98\x7F\x80\x03\xFC\x60\x60\x03\x6C\x60\x60\x03\xFC\x60\x18\x03\xFC\x60\x18\x01\x98\x60\x60\x00\xF0\x60\x60\x00\x60\x7F\x80\x00\x00\x7F\x80\x00\x00\x60\x00\x00\x00\x66\x3C\x0F\x00\x66\x7F\x3F\xC0\x60\x63\x30\xC0\x66\x60\x20\x40\x66\x60\x20\x40\x66\x60\x20\x40\x66\x63\x30\xC0\x66\x7F\x3F\xC0\x06\x3C\x0F\x00\x00\x00\x00\x00\x00\x00\x00\x00\x3F\xFF\xFF\xF8\x00\x00\x00\x00\x3F\xFF\xFF\xF8\x00\x00\x00\x00\x15\x55\x55\x50\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
# Load the logo into the framebuffer (the image is 32x32)
fb = framebuf.FrameBuffer(buffer3, 32, 32, framebuf.MONO_HLSB)
# Clear the oled display in case it has junk on it.
oled.fill(0)
dx = 1
dy = 1
x = 13
y = 10
c = 1
while True:
    oled.blit(fb, x, y)
    x = x + dx
    y = y + dy
    if (x == 95) or (x == 1):
        dx = dx * -1
    if (y == 31) or (y == 1):
        dy = dy * -1
    oled.show()

I’ve not tried it yet but you should be able to create images in multiples of 8x8 up to 128 x 64 pixels. Obviously, the full-size ones will not bounce but can be displayed as ‘artwork’.

Video available here:
Pico & SSD1306 Icons : 4 Steps (with Pictures) - Instructables