Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8035

General • Inland 1.3" OLED, Adafruit SHT31-D, Pico2 W display issues

$
0
0
µcontroller: Raspberry Pi Pico 2 W
temp and humidity sensor: Adafruit SHT31-D
screen: Inland (Micro Center) 1.3" OLED 128x64
firmware: adafruit-circuitpython-raspberry_pi_pico2_w-en_US-9.2.8
/lib contents:
/adafruit_bus_device/
/adafruit_display_text/
adafruit_displayio_sh1106.py
adafruit_sht31d.mpy

I spent the better part of today going back and forth with ChatGPT to get this setup working. I can understand the concepts of programming, but I am not a programmer, so I have to rely on ChatGPT to do the heavy lifting. I went through a few different drivers for the screen and attempted to fix the x offset by patching the Adafruit driver to accept an x_offset, but in the end, all I had to do was use `splash = displayio.Group(x=4)` to shift the display over. However, no matter how much I shift the display, the right side shows errant pixels (see image).

Image

Contents of code.py:

Code:

import boardimport busioimport timeimport displayiofrom adafruit_displayio_sh1106 import SH1106import terminaliofrom adafruit_display_text import labelimport adafruit_sht31dfrom fourwire import FourWiredisplayio.release_displays()# I2C for SHT31-Di2c = busio.I2C(scl=board.GP1, sda=board.GP0)sensor = adafruit_sht31d.SHT31D(i2c)# SPI for OLEDspi = busio.SPI(clock=board.GP2, MOSI=board.GP3)# Display busdisplay_bus = FourWire(    spi,    command=board.GP6,    chip_select=board.GP5,    reset=board.GP7)# Initialize display (no x_offset, which caused an error)display = SH1106(display_bus, width=128, height=64)# Delay to let contrast stabilizetime.sleep(2)# Create display groupsplash = displayio.Group(x=10)display.root_group = splash# Labelstemp_label = label.Label(terminalio.FONT, text="Temp: -- °C", x=0, y=20)hum_label = label.Label(terminalio.FONT, text="Humidity: -- %", x=0, y=40)splash.append(temp_label)splash.append(hum_label)# Main loopwhile True:    temp = sensor.temperature    hum = sensor.relative_humidity    temp_label.text = f"Temp: {temp:.1f} C"    hum_label.text = f"Humidity: {hum:.1f} %"    print(temp_label.text, hum_label.text)    time.sleep(2)
Contents of adafruit_displayio_sh1106.py:

Code:

# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries# SPDX-FileCopyrightText: Copyright (c) 2021 ladyada for Adafruit Industries## SPDX-License-Identifier: MIT"""`adafruit_displayio_sh1106`================================================================================DisplayIO compatible library for SH1106 OLED displays* Author(s): ladyadaImplementation Notes--------------------**Hardware:****Software and Dependencies:*** Adafruit CircuitPython firmware for the supported boards:  https://github.com/adafruit/circuitpython/releases"""# Support both 8.x.x and 9.x.x. Change when 8.x.x is discontinued as a stable release.try:    from typing import Unionexcept ImportError:    passfrom busdisplay import BusDisplayfrom fourwire import FourWirefrom i2cdisplaybus import I2CDisplayBus__version__ = "0.0.0+auto.0"__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_SH1106.git"# Sequence from sh1106 framebuf driver formatted for displayio init_INIT_SEQUENCE = (    b"\xae\x00"  # display off, sleep mode    b"\xd5\x01\x80"  # divide ratio/oscillator: divide by 2, fOsc (POR)    b"\xa8\x01\x3f"  # multiplex ratio = 64 (POR)    b"\xd3\x01\x00"  # set display offset mode = 0x0    b"\x40\x00"  # set start line    b"\xad\x01\x8b"  # turn on DC/DC    b"\xa1\x00"  # segment remap = 1 (POR=0, down rotation)    b"\xc8\x00"  # scan decrement    b"\xda\x01\x12"  # set com pins    b"\x81\x01\xff"  # contrast setting = 0xff    b"\xd9\x01\x1f"  # pre-charge/dis-charge period mode: 2 DCLKs/2 DCLKs (POR)    b"\xdb\x01\x40"  # VCOM deselect level = 0.770 (POR)    b"\x20\x01\x20"    b"\x33\x00"  # turn on VPP to 9V    b"\xa6\x00"  # normal (not reversed) display    b"\xa4\x00"  # entire display off, retain RAM, normal status (POR)    b"\xaf\x00"  # DISPLAY_ON)class SH1106(BusDisplay):    """    SH1106 driver for use with displayio    :param bus: The bus that the display is connected to.    :param int width: The width of the display. Maximum of 132    :param int height: The height of the display. Maximum of 64    :param int rotation: The rotation of the display. 0, 90, 180 or 270.    """    def __init__(self, bus: Union[FourWire, I2CDisplayBus], **kwargs) -> None:        init_sequence = bytearray(_INIT_SEQUENCE)        super().__init__(            bus,            init_sequence,            **kwargs,            color_depth=1,            grayscale=True,            pixels_in_byte_share_row=False,            data_as_commands=True,            brightness_command=0x81,            single_byte_bounds=True,            SH1107_addressing=True,)        self._is_awake = True  # Display starts in active state (_INIT_SEQUENCE)    @property    def is_awake(self) -> bool:        """        The power state of the display. (read-only)        `True` if the display is active, `False` if in sleep mode.        """        return self._is_awake    def sleep(self) -> None:        """        Put display into sleep mode. The display uses < 5uA in sleep mode.        Sleep mode does the following:            1) Stops the oscillator and DC-DC circuits            2) Stops the OLED drive            3) Remembers display data and operation mode active prior to sleeping            4) The MP can access (update) the built-in display RAM        """        if self._is_awake:            self.bus.send(0xAE, [])  # 0xAE = display off, sleep mode            self._is_awake = False    def wake(self) -> None:        """        Wake display from sleep mode        """        if not self._is_awake:            self.bus.send(0xAF, [])  # 0xAF = display on            self._is_awake = True            
I can always print a case that covers the edge as a last resort, but I would prefer to figure out how to fix this. Any ideas?

Statistics: Posted by arrowj — Thu Jun 05, 2025 1:24 am



Viewing all articles
Browse latest Browse all 8035

Trending Articles