# Pico SDK appendix sh1106 display example problem

**URL:** <https://forums.pimoroni.com/t/pico-sdk-appendix-sh1106-display-example-problem/16136>\
**Category:** Support\
**Created:** [February 5, 2021, 5:01pm UTC](https://forums.pimoroni.com/t/pico-sdk-appendix-sh1106-display-example-problem/16136 "2021-02-05T17:01:01Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tonygo2](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/tonygo2/32/7814_2.png) [@Tonygo2](https://forums.pimoroni.com/u/Tonygo2)\
**Post date:** [February 5, 2021, 5:01pm UTC](https://forums.pimoroni.com/t/pico-sdk-appendix-sh1106-display-example-problem/16136/1 "2021-02-05T17:01:01Z")

</div>

I’m using the suggested library from:  
GitHub - robert-hh/SH1106: MicroPython driver for the SH1106 OLED controller

To drive my Pimoroni 1.12” sh1106 display

Unfortunately, there appears to be a slight problem. I have routines to draw lines, boxes, circles etc, which work properly on other displays, including the ssd1306, which I have tried successfully on my Pico. The display on the sh1106 overflows from the right edge of the screen to the start of the next line on left side.

Here is my code.

```
# Display Image & text on I2C driven ssd1306 OLED display 
from machine import Pin, I2C
from sh1106 import SH1106_I2C
import framebuf
from time import sleep
import math
WIDTH = 128 # oled display width
HEIGHT = 128 # oled display height

i2c = I2C(0, scl=Pin(9), sda=Pin(8), freq=200000) # Init I2C using pins GP8 & GP9 (default I2C0 pins)
print("I2C Address : "+hex(i2c.scan()[0]).upper()) # Display device address
print("I2C Configuration: "+str(i2c)) # Display I2C config

oled = SH1106_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")

# Load the raspberry pi logo into the framebuffer (the image is 32x32)
fb = framebuf.FrameBuffer(buffer, 32, 32, framebuf.MONO_HLSB)

# Clear the oled display in case it has junk on it.
oled.fill(0)

# Blit the image from the framebuffer to the oled display
oled.blit(fb, 96, 0)

def horiz(l,t,r,c): # left, top, right colour
    n = r-l+1 # Horizontal line
    for i in range(n):
        oled.pixel(l + i, t , c)

def vert(l,t,b,c): # left, top, bottom, colour
    n = b-t+1 # Vertical line
    for i in range(n):
        oled.pixel(l, t+i, c)

def box(l,t,r,b,c): # left, top, right, bottom, colour
    horiz(l,t,r,c) # Hollow rectangle
    horiz(l,r,b,c)
    vert(l,t,b,c)
    vert(r,t,b,c)

def block(l,t,r,b,c): # left, right, top, bottom, colour
    n = b-t+1 # Solid rectangle
    for i in range(n):
        horiz(l,t+i,r-1,c) # One line at a time

def line(x,y,xx,yy,c): # (x,y) to (xx,yy)
    if x > xx:
        t = x # Swap co-ordinates if necessary
        x = xx
        xx = t
        t = y
        y = yy
        yy = t
    if xx-x == 0: # Avoid div by zero if vertical
        vert(x,min(y,yy),max(y,yy),c)
    else: # Draw line one dot at a time L to R
        n=xx-x+1
        grad = float((yy-y)/(xx-x)) # Calculate gradient
        for i in range(n):
            y3 = y + int(grad * i)
            oled.pixel(x+i,y3,c) # One dot at a time

def display(t): # Time in seconds
    oled.show() # Show new screen and wait
    sleep(t)

def circle(cx,cy,r,c): # Centre (x,y), radius, colour
    for angle in range(0, 90, 2): # 0 to 90 degrees in 2s
        y3=int(r*math.sin(math.radians(angle)))
        x3=int(r*math.cos(math.radians(angle)))
        oled.pixel(cx-x3,cy+y3,c) # 4 quadrants
        oled.pixel(cx-x3,cy-y3,c)
        oled.pixel(cx+x3,cy+y3,c)
        oled.pixel(cx+x3,cy-y3,c)

oled.fill(0) # Clear screen BLACK
oled.show()

box(1,1,125,125,1) # OK
oled.text("OK",50,60,1)
circle(64,64,50,1)
oled.show()
sleep(4)

oled.fill(0) # Clear screen BLACK
oled.show()

box(0,0,127,127,1)
oled.text("Problem",40,60,1)
circle(64,64,50,1)
oled.show()
sleep(5)

```

It is a first batch 1.12" display and I had a similar problem with it on the Pi - only recently solved with a Pimoroni package update.

I could do with some help as I’m sure others will hit the same snag.

Temporary solution: Keep away from the edges!

---

<div class="post-metadata">

**Author:** ![Shoe](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Shoe](https://forums.pimoroni.com/u/Shoe)\
**Post date:** [February 5, 2021, 9:25pm UTC](https://forums.pimoroni.com/t/pico-sdk-appendix-sh1106-display-example-problem/16136/2 "2021-02-05T21:25:06Z")

</div>

I was getting that as well, at a guess it’s part of the underlying code for the screen starting to write at the wrong position and rolling over.

I _would_ take a poke and see if I could fix it (unlikely) but I was playing around with the framebuffer module and seem to have gotten my Pico stuck in a boot loop, any time it loads `main.py` it’s unresponsive. Ugh.

Again, if we could access the filesystem over USB, this would be trivial to fix…

---

<div class="post-metadata">

**Author:** ![Tonygo2](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/tonygo2/32/7814_2.png) [@Tonygo2](https://forums.pimoroni.com/u/Tonygo2)\
**Post date:** [February 5, 2021, 10:05pm UTC](https://forums.pimoroni.com/t/pico-sdk-appendix-sh1106-display-example-problem/16136/3 "2021-02-05T22:05:19Z")

</div>

Would nuking the Pico help to break out and then put the uf2 file back in? You could then start again. I’m not putting main.py on the Pico but running from Thonny with the files on the PC.

---

<div class="post-metadata">

**Author:** ![Shoe](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Shoe](https://forums.pimoroni.com/u/Shoe)\
**Post date:** [February 5, 2021, 11:00pm UTC](https://forums.pimoroni.com/t/pico-sdk-appendix-sh1106-display-example-problem/16136/4 "2021-02-05T23:00:10Z")

</div>

No, I uploaded a C++ .uf2 file, but that doesn’t seem to wipe the python files off the file system so as soon as I went back to MicroPython it got stuck on main.py again.

I was about to go and read up on using the SWD debugging interface, but the loop seemed to be after trying one of the framebuffer methods. It occurred to me that just unplugging the OLED would mean the I2C bus connection would fail and the framebuffer call wouldn’t run, and that sorted it.

---

<div class="post-metadata">

**Author:** ![Tonygo2](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/tonygo2/32/7814_2.png) [@Tonygo2](https://forums.pimoroni.com/u/Tonygo2)\
**Post date:** [February 6, 2021, 9:32am UTC](https://forums.pimoroni.com/t/pico-sdk-appendix-sh1106-display-example-problem/16136/5 "2021-02-06T09:32:09Z")

</div>

Refreshing flash memory.  
You can download flash\_nuke.uf2 here  
[Getting Started with Raspberry Pi Pico – Raspberry Pi](https://www.raspberrypi.org/documentation/pico/getting-started/)  
it takes out ALL the files leaving a clean Pico ready to load a new .uf2 file.

---

<div class="post-metadata">

**Author:** ![Shoe](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Shoe](https://forums.pimoroni.com/u/Shoe)\
**Post date:** [February 6, 2021, 11:37am UTC](https://forums.pimoroni.com/t/pico-sdk-appendix-sh1106-display-example-problem/16136/6 "2021-02-06T11:37:08Z")

</div>

Oh, I’d totally missed that somehow. Thanks, I’ll bear that in mind in case I ever hit the same thing again.

---

<div class="post-metadata">

**Author:** ![rafalozan0](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/rafalozan0/32/7673_2.png) [@rafalozan0](https://forums.pimoroni.com/u/rafalozan0)\
**Post date:** [March 6, 2021, 4:08am UTC](https://forums.pimoroni.com/t/pico-sdk-appendix-sh1106-display-example-problem/16136/7 "2021-03-06T04:08:46Z")

</div>

Hi, i have a question, how can i make an image like the raspberry logo, but with my own image? I’m experimenting with my new Pico, but i don’t know how can i make another picture in hex array, also, if someone can explain, what is a byte array? thanks in advance!

---

<div class="post-metadata">

**Author:** ![Tonygo2](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/tonygo2/32/7814_2.png) [@Tonygo2](https://forums.pimoroni.com/u/Tonygo2)\
**Post date:** [March 6, 2021, 7:36am UTC](https://forums.pimoroni.com/t/pico-sdk-appendix-sh1106-display-example-problem/16136/8 "2021-03-06T07:36:32Z")

</div>

A byte array is a list of bytes (8 bits) - an array of one dimension. The values , in the range 0 to 255, in denary can be expressed in hexadecimal, 00 to FF, The same method can be used to store a string of characters with their ASCII code values in some systems.  
Each hex number in the list represents a single byte with each bit representing a single pixel.

I’ve done something like this before with an Arduino and a Nokia display. I wrote it up and you can find it here:  
[Nokia 5110 Arduino Project From Start to Hero - Tutorial45](https://tutorial45.com/nokia-5110-arduino-lcd/)

The tools for producing the ‘STAR’ image may help you on your way. If I have time I will may try to give it a go with Pico and SSD1306. You need to find out if the bytes are used vertically or horizontally (trial and error?)

Hope this helps - best of luck

---

<div class="post-metadata">

**Author:** ![Tonygo2](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/tonygo2/32/7814_2.png) [@Tonygo2](https://forums.pimoroni.com/u/Tonygo2)\
**Post date:** [March 7, 2021, 10:21am UTC](https://forums.pimoroni.com/t/pico-sdk-appendix-sh1106-display-example-problem/16136/9 "2021-03-07T10:21:01Z")

</div>

I’ve just posted how to make your own icons here in Tutorial Discussions.

[Pico and SSD1306 - bounce your own Icons - Discussion / Learning Resources - Pimoroni Buccaneers](https://forums.pimoroni.com/t/pico-and-ssd1306-bounce-your-own-icons/16548)

I’ve done it for SSD1306 but it should give you more ideas. Best of luck.

---

<div class="post-metadata">

**Author:** ![rafalozan0](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/rafalozan0/32/7673_2.png) [@rafalozan0](https://forums.pimoroni.com/u/rafalozan0)\
**Post date:** [March 8, 2021, 2:53am UTC](https://forums.pimoroni.com/t/pico-sdk-appendix-sh1106-display-example-problem/16136/10 "2021-03-08T02:53:09Z")

</div>

¡Hi Tony! thank you so much for your kindly help, with the help of your tutorial i be able to put my custom character in the oled display, i faced some problems like the LCDAssistant doesn’t work, it only gives me values like 0x00, but i used this online tool instead of the LCDAssistant [http://tomeko.net/online\_tools/file\_to\_hex.php](http://tomeko.net/online_tools/file_to_hex.php) , the image contained some rare random pixels on the top, but i moved the picture at the -15 coordinate. in the display to make it invisible, also i delete all the “0x00” cause i think they are useless, and this action don’t do anything in the image or in the random pixels, i will keep investigating about the random pixels, but in theory, the thing that i wanted to do is done, again, thank you so much for your help, i know that your tutorial will help so many people!

---

<div class="post-metadata">

**Author:** ![Tonygo2](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/tonygo2/32/7814_2.png) [@Tonygo2](https://forums.pimoroni.com/u/Tonygo2)\
**Post date:** [March 8, 2021, 10:52am UTC](https://forums.pimoroni.com/t/pico-sdk-appendix-sh1106-display-example-problem/16136/11 "2021-03-08T10:52:27Z")

</div>

Your file converter gives all the data in the file including the header. It is far too long.  
See here for BMP format which starts with a header block which is not needed in the program.

[BMP - Image File Format](https://docs.fileformat.com/image/bmp/)  
You only need 128 bytes (32 lines of 4 bytes per line.)

Glad you are making progress.

---

<div class="post-metadata">

**Author:** ![johnheap](https://avatars.discourse-cdn.com/v4/letter/j/7feea3/32.png) [@johnheap](https://forums.pimoroni.com/u/johnheap)\
**Post date:** [June 12, 2021, 4:52pm UTC](https://forums.pimoroni.com/t/pico-sdk-appendix-sh1106-display-example-problem/16136/12 "2021-06-12T16:52:14Z")

</div>

Hi Tonygo2  
You may have already sorted this - but I was hacking together a Sh1106 driver in C for the Pico (basically copying the python in sh1106.py but without the fancy Framebuf bits). I came across the same problem. However in the python function show() it sets the \_LOW\_COLUMN\_ADDRESS to 2. Now this may well be for a reason I don’t understand but… if I set it to 0 my overlap problems go away.  
Cheers,  
John

---

<div class="post-metadata">

**Author:** ![peter-l5](https://avatars.discourse-cdn.com/v4/letter/p/77aa72/32.png) [@peter-l5](https://forums.pimoroni.com/u/peter-l5)\
**Post date:** [October 7, 2022, 2:20pm UTC](https://forums.pimoroni.com/t/pico-sdk-appendix-sh1106-display-example-problem/16136/13 "2022-10-07T14:20:49Z")

</div>

Hi,  
This problem happens because the SH1106 chip drives displays that are 132x64 pixels (not 128 pixels wide), so a two pixel adjustment is needed. But the SH1107chip will drive panels up to 128x128 - so no adjustment is needed.  
If anyone is looking for a driver for the Pimoroni or adafruit SH1107 1.12 inch displays I’ve put one on GitHub. further info at this post: [SH1107 OLED display driver](https://forums.pimoroni.com/t/sh1107-1-2-oled-micropython-library/16667/2)  
Peter

---

<div class="post-metadata">

**Author:** ![Tonygo2](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/tonygo2/32/7814_2.png) [@Tonygo2](https://forums.pimoroni.com/u/Tonygo2)\
**Post date:** [October 8, 2022, 8:59am UTC](https://forums.pimoroni.com/t/pico-sdk-appendix-sh1106-display-example-problem/16136/14 "2022-10-08T08:59:25Z")

</div>

Thank you.  
This is fantastic.  
I’d put the sh1107 display in the ‘ **mistake to have bought it** ’ box as I’d been able to get it to work.  
Now it is doing everything - great!
