<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.squirrelslair.ca/index.php?action=history&amp;feed=atom&amp;title=Displaying_Simple_Bitmaps_in_MicroPython</id>
	<title>Displaying Simple Bitmaps in MicroPython - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.squirrelslair.ca/index.php?action=history&amp;feed=atom&amp;title=Displaying_Simple_Bitmaps_in_MicroPython"/>
	<link rel="alternate" type="text/html" href="https://wiki.squirrelslair.ca/index.php?title=Displaying_Simple_Bitmaps_in_MicroPython&amp;action=history"/>
	<updated>2026-04-29T16:36:56Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.2</generator>
	<entry>
		<id>https://wiki.squirrelslair.ca/index.php?title=Displaying_Simple_Bitmaps_in_MicroPython&amp;diff=3523&amp;oldid=prev</id>
		<title>Ttenbergen: you probably didn&#039;t mean to leave that there.</title>
		<link rel="alternate" type="text/html" href="https://wiki.squirrelslair.ca/index.php?title=Displaying_Simple_Bitmaps_in_MicroPython&amp;diff=3523&amp;oldid=prev"/>
		<updated>2022-05-08T18:57:08Z</updated>

		<summary type="html">&lt;p&gt;you probably didn&amp;#039;t mean to leave that there.&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 11:57, 2022 May 8&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l10&quot;&gt;Line 10:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 10:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The hardware I&amp;#039;m using is a Raspberry Pi Pico RP2040 (running MicroPython 1.18) and an SSD1327 128x128 OLED display.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The hardware I&amp;#039;m using is a Raspberry Pi Pico RP2040 (running MicroPython 1.18) and an SSD1327 128x128 OLED display.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;To handle the image conversion, I&#039;m using the GIMP.&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/nowiki&amp;gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;To handle the image conversion, I&#039;m using the GIMP.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;First, you need a picture that works well as a 1-bit image. Whether you draw it yourself or take a photograph, or are making your own custom font, as long as it&amp;#039;s small enough to fit in the microcontroller&amp;#039;s memory and is viewable on the display, you should be off to the races.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;First, you need a picture that works well as a 1-bit image. Whether you draw it yourself or take a photograph, or are making your own custom font, as long as it&amp;#039;s small enough to fit in the microcontroller&amp;#039;s memory and is viewable on the display, you should be off to the races.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Ttenbergen</name></author>
	</entry>
	<entry>
		<id>https://wiki.squirrelslair.ca/index.php?title=Displaying_Simple_Bitmaps_in_MicroPython&amp;diff=3522&amp;oldid=prev</id>
		<title>Hal: Convert and display a 1-bit image of size x, y on an OLED with MicroPython</title>
		<link rel="alternate" type="text/html" href="https://wiki.squirrelslair.ca/index.php?title=Displaying_Simple_Bitmaps_in_MicroPython&amp;diff=3522&amp;oldid=prev"/>
		<updated>2022-05-07T22:24:29Z</updated>

		<summary type="html">&lt;p&gt;Convert and display a 1-bit image of size x, y on an OLED with MicroPython&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{TidBit&lt;br /&gt;
|shortDescription=Convert and display a 1-bit image of size x, y on an OLED with MicroPython&lt;br /&gt;
|skillSet=Arduino; Electronics; Programming; Python; Raspberry Pi&lt;br /&gt;
|featured=Yes&lt;br /&gt;
}}&lt;br /&gt;
MicroPython&amp;#039;s framebuf library contains functions to draw primitives, display 8x8 pixel size text, and a blit function that allows you to draw your own custom bitmap to the display.&lt;br /&gt;
&lt;br /&gt;
It&amp;#039;s capable of doing 16-bit colour but to keep things simple and small, this is how to do it in 1-bit (on/off).&lt;br /&gt;
&lt;br /&gt;
The hardware I&amp;#039;m using is a Raspberry Pi Pico RP2040 (running MicroPython 1.18) and an SSD1327 128x128 OLED display.&lt;br /&gt;
&lt;br /&gt;
To handle the image conversion, I&amp;#039;m using the GIMP.&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First, you need a picture that works well as a 1-bit image. Whether you draw it yourself or take a photograph, or are making your own custom font, as long as it&amp;#039;s small enough to fit in the microcontroller&amp;#039;s memory and is viewable on the display, you should be off to the races.&lt;br /&gt;
&lt;br /&gt;
I&amp;#039;m going to use the Squirrel&amp;#039;s Lair logo:&lt;br /&gt;
[[File:Squirrelslair_orig.png]]&lt;br /&gt;
&lt;br /&gt;
And I want the display to show a small version of it at the top left.&lt;br /&gt;
&lt;br /&gt;
Loading it into GIMP I can see it&amp;#039;s 307x254 pixels, which is too large to fit on the display, so I resized it so that the largest dimension (307) was downsized to 32:&lt;br /&gt;
[[File:Squirrelslair_resized_32x27.png]]&lt;br /&gt;
&lt;br /&gt;
So now I have an image that&amp;#039;s 32x27 pixels. So far, so good. Now to convert it to 1bpp - in GIMP, that&amp;#039;s Image -&amp;gt; Mode -&amp;gt; Indexed -&amp;gt; Use black and white (1-bit) palette, and hit Convert.&lt;br /&gt;
&lt;br /&gt;
That gives me an image that looks like this:&lt;br /&gt;
[[File:Squirrelslair_resized_32x27-1bpp.png]]&lt;br /&gt;
&lt;br /&gt;
Which is the right size and only 1bpp. Depending on how you want your image to appear, you can invert the colours (in GIMP, that&amp;#039;s Colors -&amp;gt; Invert).&lt;br /&gt;
&lt;br /&gt;
So now we&amp;#039;ve got a nice little logo to show. Since it&amp;#039;s a small image and the RP2040 has a good amount of RAM, the easiest thing to do is embed the bitmap right in the program. To make this easy, use GIMP to export the image as a .xbm file with the following settings:&lt;br /&gt;
[[File:Xbm_export.png]]&lt;br /&gt;
&lt;br /&gt;
If you open the .xbm file you created in a text editor, you&amp;#039;ll see something like the following:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;#define squirrelslair_resized_32_1bit_not_inverted_width 32&lt;br /&gt;
#define squirrelslair_resized_32_1bit_not_inverted_height 27&lt;br /&gt;
static unsigned char squirrelslair_resized_32_1bit_not_inverted_bits[] = {&lt;br /&gt;
   0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0xfc, 0x03, 0x00, 0x00,&lt;br /&gt;
   0xfe, 0x07, 0x50, 0x00, 0xfe, 0x0f, 0x70, 0x00, 0xfe, 0x0f, 0xf8, 0x00,&lt;br /&gt;
   0xfe, 0x0f, 0xf8, 0x01, 0x8e, 0x0f, 0xf8, 0x01, 0x84, 0x0f, 0xfc, 0x03,&lt;br /&gt;
   0x80, 0x0f, 0xfe, 0x39, 0x80, 0x0f, 0x3f, 0x44, 0xc0, 0xe7, 0x3f, 0x44,&lt;br /&gt;
   0xc0, 0xf7, 0x3f, 0x46, 0xc0, 0xfb, 0xff, 0x3f, 0xc0, 0xff, 0xff, 0x01,&lt;br /&gt;
   0xc0, 0xff, 0x7f, 0x00, 0xc0, 0xff, 0x1f, 0x00, 0xc0, 0xff, 0x1f, 0x00,&lt;br /&gt;
   0xc0, 0xff, 0x3f, 0x00, 0xc0, 0xff, 0x3f, 0x00, 0x80, 0xff, 0x3f, 0x00,&lt;br /&gt;
   0x80, 0xff, 0x1f, 0x00, 0x00, 0xff, 0x1f, 0x00, 0x00, 0xff, 0x0f, 0x00,&lt;br /&gt;
   0x00, 0xfc, 0x07, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00 };&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The data between the {} is the bitmap. Displaying it in MicroPython is pretty easy:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
from machine import Pin, I2C&lt;br /&gt;
from ssd1327 import SSD1327_I2C&lt;br /&gt;
import framebuf&lt;br /&gt;
&lt;br /&gt;
# JUST THE TEXT BETWEEN THE CURLY BRACKETS!&lt;br /&gt;
bitmap_data = bytearray([0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0xfc, 0x03, 0x00, 0x00,&lt;br /&gt;
   0xfe, 0x07, 0x50, 0x00, 0xfe, 0x0f, 0x70, 0x00, 0xfe, 0x0f, 0xf8, 0x00,&lt;br /&gt;
   0xfe, 0x0f, 0xf8, 0x01, 0x8e, 0x0f, 0xf8, 0x01, 0x84, 0x0f, 0xfc, 0x03,&lt;br /&gt;
   0x80, 0x0f, 0xfe, 0x39, 0x80, 0x0f, 0x3f, 0x44, 0xc0, 0xe7, 0x3f, 0x44,&lt;br /&gt;
   0xc0, 0xf7, 0x3f, 0x46, 0xc0, 0xfb, 0xff, 0x3f, 0xc0, 0xff, 0xff, 0x01,&lt;br /&gt;
   0xc0, 0xff, 0x7f, 0x00, 0xc0, 0xff, 0x1f, 0x00, 0xc0, 0xff, 0x1f, 0x00,&lt;br /&gt;
   0xc0, 0xff, 0x3f, 0x00, 0xc0, 0xff, 0x3f, 0x00, 0x80, 0xff, 0x3f, 0x00,&lt;br /&gt;
   0x80, 0xff, 0x1f, 0x00, 0x00, 0xff, 0x1f, 0x00, 0x00, 0xff, 0x0f, 0x00,&lt;br /&gt;
   0x00, 0xfc, 0x07, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00])&lt;br /&gt;
&lt;br /&gt;
# Now put that bitmap into a blittable framebuffer.&lt;br /&gt;
# the 32 and 27 are the x and y dimensions of the image.&lt;br /&gt;
# framebuf.MONO_HMSB means it&amp;#039;s a 1bpp image with MSB first.&lt;br /&gt;
framebuffer_to_show = framebuf.FrameBuffer(bitmap_data, 32, 27, framebuf.MONO_HMSB)&lt;br /&gt;
&lt;br /&gt;
# Now set up the display instance.&lt;br /&gt;
# Your setup will change depending on the MCU and display&lt;br /&gt;
# you have and pins you use.&lt;br /&gt;
# Using the Pico I2C channel 1 on pins 6 and 7, and the&lt;br /&gt;
# OLED is an SSD1327 that&amp;#039;s 128x128 pixels.&lt;br /&gt;
display = I2C(1, sda=Pin(6), scl=Pin(7), freq=400000)&lt;br /&gt;
oled = SSD1327_I2C(128, 128, display)&lt;br /&gt;
&lt;br /&gt;
# Now clear the display&lt;br /&gt;
oled.fill(0)&lt;br /&gt;
oled.show()&lt;br /&gt;
&lt;br /&gt;
# And blit the image to the display at coordinates 0,0:&lt;br /&gt;
oled.framebuf.blit(framebuffer_to_show, 0, 0)&lt;br /&gt;
oled.show()&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And here&amp;#039;s the result (sorry about the condition of the film on the display!):&lt;br /&gt;
[[File:Squirrelslair_logo_OLED.jpg|320px|left]]&lt;/div&gt;</summary>
		<author><name>Hal</name></author>
	</entry>
</feed>