Skip to content

Instantly share code, notes, and snippets.

@idriszmy
Last active November 6, 2022 09:32
Show Gist options
  • Save idriszmy/0c0902b159efa37a1aeaef913d0990d9 to your computer and use it in GitHub Desktop.
Save idriszmy/0c0902b159efa37a1aeaef913d0990d9 to your computer and use it in GitHub Desktop.
Display bitmap file on SSD1306/SSD1315 OLED using Raspberry Pi Pico W and CircuitPython
#
# Display bitmap file on SSD1315 OLED using Raspberry Pi Pico W and CircuitPython
#
# References and credit to
# - https://tutorial.cytron.io/2021/12/21/display-image-on-the-graphic-lcd-using-maker-nano-rp2040-and-circuitpython/
#
# Raspberry Pi Pico W
# - [Maker Pi Pico Mini] https://my.cytron.io/p-maker-pi-pico-mini-simplifying-projects-with-raspberry-pi-pico
# Arduino Grove Sensor Kit for Beginner, OR
# - https://my.cytron.io/p-arduino-grove-sensor-kit-for-beginner
# Grove - OLED Display 0.96 inch
# - https://my.cytron.io/p-grove-oled-display-0p96-inch-ssd1315
#
# Additional Libraries
# - adafruit_bus_device
# - adafruit_display_text
# - adafruit_displayio_ssd1306.mpy
#
# Update:
# 6 Nov 2022 - Tested with CircuitPython Pico W 8.0.0-beta.4
#
import time
import board
import busio
import displayio
import terminalio
from adafruit_display_text import label
import adafruit_displayio_ssd1306
displayio.release_displays()
i2c_oled = busio.I2C(scl=board.GP5, sda=board.GP4)
display_bus = displayio.I2CDisplay(i2c_oled, device_address=0x3C)
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=64, rotation=180)
# Open the file
with open("/Cytron.bmp", "rb") as bitmap_file:
# Setup the file as the bitmap data source
bitmap = displayio.OnDiskBitmap(bitmap_file)
# Create a TileGrid to hold the bitmap
tile_grid = displayio.TileGrid(
bitmap,
pixel_shader = getattr(
bitmap,
'pixel_shader',
displayio.ColorConverter()
)
)
# Create a Group to hold the TileGrid
group = displayio.Group()
# Add the TileGrid to the Group
group.append(tile_grid)
# Add the Group to the Display
display.show(group)
print("Done!")
# Loop forever so you can enjoy your image
while True:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment