I’m trying to get started with programming this display with python 3.
this program:
from luma.core.interface.serial import i2c
from luma.core.render import canvas
from luma.oled.device import sh1106
serial = i2c(port=1, address=0x3C)
device = sh1106(serial, width=128, height=128, rotate=2, mode=“1”)
with canvas(device) as draw:
draw.rectangle(device.bounding_box, outline=“white”, fill=“black”)
draw.text((10,40), “Hello World”, fill=“white”)
falls over on line 5 with the following error:
Traceback (most recent call last):
File “/home/pi/luma.examples/examples/tonyTest1.py”, line 5, in
device = sh1106(serial, width=128, height=128, rotate=2, mode=“1”)
File “/usr/local/lib/python3.5/dist-packages/luma/oled/device.py”, line 66, in init
“Unsupported display mode: {0} x {1}”.format(width, height))
luma.core.error.DeviceDisplayModeError: Unsupported display mode: 128 x 128
What should I put in the brackets on line 5?
If I leave out both the width and height the left hand half of the display lights up with random dots in the top left and bounding box and the end of “rld” displayed.
Suggestions most welcome.
Apologies for raising an old thread, however for the benefit of anyone else coming across this question, heres an answer. I believe the above code should now work - perhaps it was due to a bug (missing resolution settings) in the oled package at the time.
I use this successfully with the python 3.7 version of the package, and it does not generate any error
device = sh1106(serial, width=128, height=128, rotate=2, mode=1)
The 128 x 128 resolution is now set correct on L62 in /usr/local/lib/python3.7/dist-packages/luma/oled/device/init.py
Thanks for the reply but I still cannot get this to work. (This is a first for a Pimoroni board.)
I’m using a Pi 3 with a newly setup SD card (today) with OS installed via the Pi Imager and updated. When I try to run the installer I get the message
luma.core requires Python ‘> 3.5, <4’ but the running Python is 2.7.16
How can I move on?
I’m using the script currently on the Pimoroni web site for this device.
Just found this topic as I’m searching for ways to change the font size on this display. I’m using it with a Pico and this code works so might help you Tony
# Display Image & text on I2C driven SH1106 OLED display
from machine import I2C, ADC
from sh1106 import SH1106_I2C
import framebuf
WIDTH = 128 # oled display width
HEIGHT = 128 # 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 = 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)
# Add some text
oled.text("Raspberry Pi",5,5)
oled.text("Pico",5,15)
# Finally update the oled display so the image & text is displayed
oled.show()
Thanks. I’ve decided that my display is probably not an sh1106. Does not say what it is!