mcauser / micropython-ssd1327

MicroPython driver for SSD1327 128x128 4-bit greyscale OLED displays
MIT License
25 stars 10 forks source link

off-set shifted a bit #1

Closed dattasaurabh82 closed 3 years ago

dattasaurabh82 commented 5 years ago

First of all Thanks a lot for this library .

I'm using a Chinese 1.5" OLED Module bought from taobao. It's not from seeed studio.

Now when I used this with my wemos D1 mini, I found an issue: When I issue this command display.text('Seeed Studio',0, 0, 15) I get the offset moved down. shifted off set on screen

to make my life easier, I started by creating a separate class in your ssd1327.py, for my display, which is 128x128

class OLED_128X128(SSD1327_I2C):
    def __init__(self, i2c):
        super().__init__(128, 128, i2c)

    def rotate(self, rotate):
        self.poweroff()
        self.write_cmd(SET_DISP_OFFSET)
        self.write_cmd(0x60 if rotate else 0x20) # 0x20=0 degrees, 0x60=180 degrees
        self.write_cmd(SET_SEG_REMAP)
        self.write_cmd(0x42 if rotate else 0x51) # 0x51=0 degrees, 0x42=180 degrees
        self.poweron()

    def lookup(self, table):
        # GS0 has no pre-charge and current drive
        self.write_cmd(SET_GRAYSCALE_TABLE)
        for i in range(0,15):
            self.write_cmd(table[i])

Then this line caught my eye: self.write_cmd(SET_DISP_OFFSET)

Then I found, in the class SSD1327 under def init_display(self): SET_DISP_OFFSET, 0x20, # Set vertical offset by COM from 0~127 I modified it to:

# SET_DISP_OFFSET, 0x20, # Set vertical offset by COM from 0~127
SET_DISP_OFFSET, 0x00, # Set vertical offset by COM from 0~127

Then I uploaded the modified lib to my wemos and upon testing with:

import ssd1327
from machine import I2C, Pin
i2c = I2C(sda=Pin(4), scl=Pin(5))
display = ssd1327.OLED_128X128(i2c)
display.fill(0)
display.text('Seeed Studio',0, 0, 15)
display.text('Seeed Studio',0, 120, 15)# to get the full range
display.show()

I get correct placements: corrected off set on screen

May be you can make a scope for this in a better solution in your library and then we can all benefit from it. This is the current modified version after I forked from you

Thank you again.

FerdyGuliker commented 5 years ago

I can confirm this works. You might need to Reset your board after the modifications. I didn't create a new class but used the existing SSD1327_I2C class instead: display = ssd1327.SSD1327_I2C(128, 128, i2c, 60)

bungernut commented 4 years ago

I can also confirm this works with this https://www.sparkfun.com/products/15890 This also addresses this: https://forum.micropython.org/viewtopic.php?t=3452 Thanks!

mcauser commented 3 years ago

I've set the default SET_DISP_OFFSET to 0x00 and in SEEED_OLED_96X96 set it to 0x20, rather than the other way around.

This is a 128x128 display, so the default really should be for a 128x128 display. I only had a 96x96 to test with.

In your OLED_128X128 code above, in def rotate, you're setting the offset to 0x60/0x20 and remap to 0x42/0x51 I believe these are the values for a 96x96 screen, not a 128x128.

If you have a 128x128 display handy, could you let me know what the offset/remap values should be and I can move the def rotate up to the SSD1327 class?

rodrigocmn commented 3 years ago

I've just tested with my WS OLED 128x128. Setting offset to 0x80/0x00 worked for me.

mcauser commented 3 years ago

Thanks @rodrigocmn

I've updated the offset, column and row address calculations to be based on the display size. Moved rotate() to base SSD1327 class. Removed unused external_vcc argument. Removed unused import time. Gave show a tiny speed boost by using existing column and row addresses calculated on init. Added framebuf.line support.

WS_OLED_128X128 isn't really needed anymore, as it doesn't provide anything custom. Will remove it in a later version.