Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SH1107 128x128 OLED text jumbled around #2433

Open
chauens opened this issue Apr 22, 2024 Discussed in #2430 · 6 comments
Open

SH1107 128x128 OLED text jumbled around #2433

chauens opened this issue Apr 22, 2024 Discussed in #2430 · 6 comments

Comments

@chauens
Copy link

chauens commented Apr 22, 2024

Discussed in #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 <U8g2lib.h>
#include <Wire.h>
#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
Copy link
Author

chauens commented Apr 23, 2024

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
Copy link
Owner

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
Copy link
Author

chauens commented Apr 24, 2024 via email

@chauens
Copy link
Author

chauens commented Apr 26, 2024

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
Copy link

xray-bit commented May 8, 2024

Hi, @chauens, I got the same problem.

the default display config for sh1107_128x128 has a big x offset (check L519-520):

u8g2/csrc/u8x8_d_sh1107.c

Lines 501 to 523 in 3e86287

static const u8x8_display_info_t u8x8_sh1107_128x128_display_info =
{
/* chip_enable_level = */ 0,
/* chip_disable_level = */ 1,
/* post_chip_enable_wait_ns = */ 20,
/* pre_chip_disable_wait_ns = */ 10,
/* reset_pulse_width_ms = */ 100, /* */
/* post_reset_wait_ms = */ 100, /* far east OLEDs need much longer setup time */
/* sda_setup_time_ns = */ 100, /* cycle time is 100ns, so use 100/2 */
/* sck_pulse_width_ns = */ 100, /* cycle time is 100ns, so use 100/2, AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
/* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
/* spi_mode = */ 0, /* active high, rising edge */
/* i2c_bus_clock_100kHz = */ 4,
/* data_setup_time_ns = */ 40,
/* write_pulse_width_ns = */ 150, /* sh1107: cycle time is 300ns, so use 300/2 = 150 */
/* tile_width = */ 16,
/* tile_height = */ 16,
/* default_x_offset = */ 96,
/* flipmode_x_offset = */ 96,
/* pixel_width = */ 128,
/* pixel_height = */ 128
};

you can try to use pimoroni's config or seeed's config :

u8g2/csrc/u8x8_d_sh1107.c

Lines 600 to 622 in 3e86287

static const u8x8_display_info_t u8x8_sh1107_pimoroni_128x128_display_info =
{
/* chip_enable_level = */ 0,
/* chip_disable_level = */ 1,
/* post_chip_enable_wait_ns = */ 20,
/* pre_chip_disable_wait_ns = */ 10,
/* reset_pulse_width_ms = */ 100, /* */
/* post_reset_wait_ms = */ 100, /* far east OLEDs need much longer setup time */
/* sda_setup_time_ns = */ 100, /* cycle time is 100ns, so use 100/2 */
/* sck_pulse_width_ns = */ 100, /* cycle time is 100ns, so use 100/2, AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
/* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
/* spi_mode = */ 0, /* active high, rising edge */
/* i2c_bus_clock_100kHz = */ 4,
/* data_setup_time_ns = */ 40,
/* write_pulse_width_ns = */ 150, /* sh1107: cycle time is 300ns, so use 300/2 = 150 */
/* tile_width = */ 16,
/* tile_height = */ 16,
/* default_x_offset = */ 0,
/* flipmode_x_offset = */ 0,
/* pixel_width = */ 128,
/* pixel_height = */ 128
};

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
Copy link
Author

chauens commented May 9, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants