olikraus / u8g2

U8glib library for monochrome displays, version 2
Other
4.91k stars 1.02k forks source link

SH1107 128x128 OLED text jumbled around #2433

Open chauens opened 2 months ago

chauens commented 2 months ago

Discussed in https://github.com/olikraus/u8g2/discussions/2430

Originally posted by **chauens** April 18, 2024 Hi, I am using the Adafruit 5297 128x128 OLED with the U8g2 library and have a problem with the way the text is displayed. The OLED is mounted into an enclosure with its top pointing up as described on Adafruits website. Using a simple code to display "Hello World!" starting at line position 0 shows: "World! Hello" . If I use rotation 90 degrees the text shows correct, correct sequence, but of course turned sideways... 90 degrees. I can't turn the OLED in the enclosure and I want to use U8G2 since it offers the power save mode and more importantly has the option to define the boards I2C SDA/SCL pins since my board (ESP32 Feather) is not using the defaults. Any ideas how to get around this? Any help appreciated. This is the test code: #include #include #define I2C_Adr 0x3d //OLED I2C address #define SDA 23 //sda pin# on ESP32 board is 23 (some boards use 21) #define SCL 22 //scl pin# on ESP32 board is 22 #define rotation U8G2_R0 //flawed, but I need this rotation U8G2_SH1107_128X128_F_HW_I2C u8g2(rotation, U8X8_PIN_NONE, SCL, SDA); void setup(void) { int i2cAdr = (I2C_Adr * 2); //per u8g2 reference manual address must be multiplied by 2 u8g2.setI2CAddress(i2cAdr); u8g2.begin(); u8g2.setFont(u8g2_font_helvR10_tf); } void loop(void) { u8g2.clearDisplay(); u8g2.drawStr(0,15,"Hello World!"); u8g2.sendBuffer(); delay(500); u8g2.drawStr(0,30,"1234567890"); u8g2.sendBuffer(); delay(1000); } ---------------------------------------- B.t.w. "1234567890" displays like "567890 1234" I uploaded a shortened version of Adafruits "Hello World" test sketch onto the ESP32 board and found that the text is displayed correctly. So it seems to me that the problem is in U8G2 for the SH1107 chip. I would like to stick with u8g2 for the power save mode (screen saver).
chauens commented 2 months ago

I need to add: the option to define SDA and SCL pins is not an issue. Just connect the OLED where Adafruit wants it. But I want to be able to use the "screen saver" which Adafruit does not seem to have.

olikraus commented 2 months ago

The reference position for the string is the lower left corner of the glyphs (baseline) as you can see in the example image here: https://github.com/olikraus/u8g2/wiki/u8g2reference#drawstr

This can be change with the font-position functions: https://github.com/olikraus/u8g2/wiki/u8g2reference#setfontpostop

Wrap around effects can be avoided by putting u8g2 into 16 bit mode (see FAQ https://github.com/olikraus/u8g2/blob/master/doc/faq.txt). 16 Bit mode is automatically activated with ESP32.

chauens commented 2 months ago

Thank you for your reply. I have read the documentation. And according to it and your comments the following lines of code should show the following as it actually does in the first working example:

OLED display 128x64:

U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE, 22, 21); u8g2.setFont(u8g2_font_ncenB14_tr); u8g2.drawStr(0,15,"Hello World!");

displays as expected: Hello World!

Not working example:

OLED dislay 128x128:

U8G2_SH1107_128X128_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE, 22, 21); u8g2.setFont(u8g2_font_ncenB14_tr); u8g2.drawStr(0,15,"Hello World!");

displays: lo World! Hel

I hope this explains the problem I am encountering a little better. I provided screen shots in attached files. Please advise. Thank you. Christoph


From: olikraus @.> Sent: Tuesday, April 23, 2024 11:04 PM To: olikraus/u8g2 @.> Cc: chauens @.>; Author @.> Subject: Re: [olikraus/u8g2] SH1107 128x128 OLED text jumbled around (Issue #2433)

The reference position for the string is the lower left corner of the glyphs (baseline) as you can see in the example image here: https://github.com/olikraus/u8g2/wiki/u8g2reference#drawstr

This can be change with the font-position functions: https://github.com/olikraus/u8g2/wiki/u8g2reference#setfontpostop

Wrap around effects can be avoided by putting u8g2 into 16 bit mode (see FAQ https://github.com/olikraus/u8g2/blob/master/doc/faq.txt). 16 Bit mode is automatically activated with ESP32.

— Reply to this email directly, view it on GitHubhttps://github.com/olikraus/u8g2/issues/2433#issuecomment-2074034509, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A4F33R5VCJCJ4XMH3SYXFEDY644MPAVCNFSM6AAAAABGTGED4OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZUGAZTINJQHE. You are receiving this because you authored the thread.

chauens commented 2 months ago

Using the Adafruit_SH110X.h and Adafruit_GFX.h libraries provides the solution to the problem as well as a "screen saver" as I just found out. So I wil go this route. I leave this open for now for you to decide wether this can be fixed. I don't think I'm doing anything wrong or missed something. See my previous comment. Thank you

xray-bit commented 1 month ago

Hi, @chauens, I got the same problem.

the default display config for sh1107_128x128 has a big x offset (check L519-520): https://github.com/olikraus/u8g2/blob/3e86287a55e819bc8be66a5c2674f07e5e140ff1/csrc/u8x8_d_sh1107.c#L501-L523

you can try to use pimoroni's config or seeed's config : https://github.com/olikraus/u8g2/blob/3e86287a55e819bc8be66a5c2674f07e5e140ff1/csrc/u8x8_d_sh1107.c#L600-L622

I don't use Arduino, but I think you can try to use U8G2_SH1107_PIMORONI_128X128_F_HW_I2C instead of U8G2_SH1107_128X128_F_HW_I2C for initialization

chauens commented 1 month ago

Hi, thank you for the tip, that appears to be very helpful. I will try that. Meanwhile I went back to using a 128x64 display because it actually is physically wider. I would need to use a smaller font to display the same number of characters per line on the 128x128 OLED... at least on the one I got, making it harder to read. So it may take some time until I get around to do another test with 128x128 OLED.