Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

SH1107 OLED Featherwing only vertical 64x128?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

SH1107 OLED Featherwing only vertical 64x128?

by mdroberts1243 on Fri Sep 18, 2020 3:31 am

I've been able to get a basic adafruit_framebuf driver working for the SH1107 OLED. But it seems that it is only practical with this controller to use it as a vertical 64 x 128 display:

SH1107_64x128.jpg
Basic framebuf primitives drawn on SH1107 64 x 128 OLED Featherwing
SH1107_64x128.jpg (971.14 KiB) Viewed 70 times


Is there any easy way to work with this display in a horizontal orientation? Like a library that would let me write into my framebuf rotated?

I'm skeptical that there will be a displayio support for this featherwing... it seems the existing displayio drivers only support display controllers that have a unique byte command for setting column address, etc. This SH1107 controller requires some bit ORing to produce column high and low addresses and page settings, sigh.

mdroberts1243
 
Posts: 9
Joined: Tue May 16, 2017 11:35 am

Re: SH1107 OLED Featherwing only vertical 64x128?

by mdroberts1243 on Fri Sep 18, 2020 12:53 pm

So I found a setting in adafruit_framebuf that lets me set rotation:

Code: Select all | TOGGLE FULL SIZE
    # natively the Featherwing is a 64 x 128 vertical display
    oled = sh1107_i2c.SH1107_I2C(NATIVE_WIDTH, NATIVE_HEIGHT, device)
    oled.rotation = 1     # orient as a horizontal display 128 x 64

Using this setting I was able to render graphic primitives properly onto a 128 x 64 frame:

Code: Select all | TOGGLE FULL SIZE
    # Desired horizontally-oriented framebuf
    WIDTH = 128
    HEIGHT = 64

    oled.rect(0, 0, WIDTH, HEIGHT, True)
    oled.line(2, 2, WIDTH - 2, HEIGHT - 2, True)
    oled.fill_rect(72, 0, 8, 8, True)
    oled.fill_rect(80, 8, 16, 16, True)
    oled.fill_rect(96, 24, 32, 32, True)
    oled.circle(64,32,30,True)
#    print_buffer(oled)
    oled.show()

But text seems to be truncated at the NATIVE_WIDTH of the display (see picture below):

Code: Select all | TOGGLE FULL SIZE
    oled.text('123456789012345678901234567890', 0, 0, True, size=1)
    oled.text('123456789012345678901234567890', 0, 8, True, size=2)
    oled.text('123456789012345678901234567890', 0, 24, True, size=3)

Is this a known issue? Is there a way around this?

Horiz_OLED.jpg
Some primitives and text rendered horizontally on 64x128 OLED
Horiz_OLED.jpg (373.94 KiB) Viewed 67 times

mdroberts1243
 
Posts: 9
Joined: Tue May 16, 2017 11:35 am

Re: SH1107 OLED Featherwing only vertical 64x128?

by tannewt on Fri Sep 18, 2020 1:53 pm

mdroberts1243 wrote:I'm skeptical that there will be a displayio support for this featherwing... it seems the existing displayio drivers only support display controllers that have a unique byte command for setting column address, etc. This SH1107 controller requires some bit ORing to produce column high and low addresses and page settings, sigh.


I intend on adding a quirk mode to displayio for this display. I just have been heads down on the ESP32-S2 port.

Any chance you'd like to try hacking it into CircuitPython core?

Nice work getting framebuf going!

tannewt
 
Posts: 1830
Joined: Thu Oct 06, 2016 8:48 pm

Re: SH1107 OLED Featherwing only vertical 64x128?

by mdroberts1243 on Fri Sep 18, 2020 4:49 pm

tannewt wrote:
mdroberts1243 wrote:I'm skeptical that there will be a displayio support for this featherwing... it seems the existing displayio drivers only support display controllers that have a unique byte command for setting column address, etc. This SH1107 controller requires some bit ORing to produce column high and low addresses and page settings, sigh.


I intend on adding a quirk mode to displayio for this display. I just have been heads down on the ESP32-S2 port.

Any chance you'd like to try hacking it into CircuitPython core?

Nice work getting framebuf going!


I started out looking to hack displayio for this display. I stopped looking into it when in my ignorance I couldn't seem to locate where the actual set_column and set_row are done! I'd be willing to take a second look if someone can point me in the right direction.

mdroberts1243
 
Posts: 9
Joined: Tue May 16, 2017 11:35 am

Re: SH1107 OLED Featherwing only vertical 64x128?

by mdroberts1243 on Fri Sep 18, 2020 5:48 pm

mdroberts1243 wrote:So I found a setting in adafruit_framebuf that lets me set rotation:
[SNIP]
But text seems to be truncated at the NATIVE_WIDTH of the display (see picture below):
[SNIP]
Is this a known issue? Is there a way around this?

I found where in adafruit_framebuf text() the characters are clipped when rotated. Rotation settings weren't taken into account by text() so I added some logic to the function to switch the width and height checks around appropriately:
Code: Select all | TOGGLE FULL SIZE
    def text(self, string, x, y, color, *, font_name="font5x8.bin", size=1):
        """Place text on the screen in variables sizes. Breaks on \n to next line.

        Does not break on line going off screen.
        """
        # the following logic prevents characters from being clipped
        #      if the frame buffer is rotated.
        # determine our effective width/height, taking rotation into account
        frame_width = self.width
        frame_height = self.height
        if self.rotation == 1 or self.rotation == 3:
            frame_width, frame_height = frame_height, frame_width

        for chunk in string.split("\n"):
            if not self._font or self._font.font_name != font_name:
                # load the font!
                self._font = BitmapFont(font_name)
            width = self._font.font_width
            height = self._font.font_height
            for i, char in enumerate(chunk):
                char_x = x + (i * (width + 1)) * size
                if (
                    char_x + (width * size) > 0
                    and char_x < frame_width        # use our effective frame_width from any rotation
                    and y + (height * size) > 0
                    and y < frame_height            # use our effective frame_height from any rotation
                ):
                    self._font.draw_char(char, char_x, y, self, color, size=size)
            y += height * size

Now I can write strings of text across the whole 'width' of the SH1107 OLED Feather. I feel like I have a fully working framebuf for SH1107 now!

mdroberts1243
 
Posts: 9
Joined: Tue May 16, 2017 11:35 am

Re: SH1107 OLED Featherwing only vertical 64x128?

by mdroberts1243 on Fri Sep 18, 2020 8:49 pm

FWIW I just did a PR to fix the text() method in adafruit_framebuf: https://github.com/adafruit/Adafruit_Ci ... uf/pull/37

It's a small change but will help those that want to use the Featherwing SH1107 128x64 with Circuitpython and framebuf.

-mark.

mdroberts1243
 
Posts: 9
Joined: Tue May 16, 2017 11:35 am

Re: SH1107 OLED Featherwing only vertical 64x128?

by mdroberts1243 on Sat Sep 19, 2020 12:29 am

For those that might be interested, I threw the little framebuf driver and example code into a github repository: https://github.com/mdroberts1243/mdrobe ... SH1107_I2C

Hope it helps!

-mark.

mdroberts1243
 
Posts: 9
Joined: Tue May 16, 2017 11:35 am

Re: SH1107 OLED Featherwing only vertical 64x128?

by mdroberts1243 on Mon Sep 21, 2020 11:57 am

tannewt wrote:
I intend on adding a quirk mode to displayio for this display. I just have been heads down on the ESP32-S2 port.

Any chance you'd like to try hacking it into CircuitPython core?

Nice work getting framebuf going!


Hi Scott, I want to thank you for the high-level introduction to DisplayIO in the live stream. Very helpful!

Looking at the source code over the weekend, I was thinking to hack in a new quirk, "bool column_and_page_addressing" as a way to introduce the changes to support the SH1107 OLED display. The natural orientation of the 128x64 in this mode is vertical (64x128) however and a rotation would be needed to be enabled in DisplayIO to have a more useful horizontal display on the FeatherWing. There is a 'vertical' mode of addressing supported in the SH1107, which might give a way to horizontally paint the screen but all the existing drivers online seem to use column and page addressing. I'm not sure how generally useful the column and page mode quirk would be though, but SSD1306 does have it too, sort of.

What do you think? --Mark.

PS Is this the best way to communicate about this?

mdroberts1243
 
Posts: 9
Joined: Tue May 16, 2017 11:35 am

Re: SH1107 OLED Featherwing only vertical 64x128?

by tannewt on Mon Sep 21, 2020 2:02 pm

Hi Mark,
The discord is the quickest way to sync up: https://adafru.it/discord I try and check the forum here once a day.

I think the rotation should be handled at a higher level by `Display`. It's ok if the quirk is only used by this driver. Display already has a lot of parameters for this reason. We expect most folks to use the drivers that hide these options.
~Scott

tannewt
 
Posts: 1830
Joined: Thu Oct 06, 2016 8:48 pm

Please be positive and constructive with your questions and comments.