Problem with oled 1,3" U8G2 lib

I'm using the oled 1.3" I2C but it doesn't work on the arduino Mega 2560 what could be the problem?
If using the same oled on the arduino nano works, it just doesn't work with the mega.
The example I used was the one provided by the libraria U8G2 "Hello World", I configure oled, but it only works on Nano.
Is it necessary to configure any pins for the Mega?

Thanks
José Rodrigues

Show the constructor statement. i.e. copy-paste one line to your message.
Post a wiring diagram. e.g. pencil drawing, photo or Fritzing.

Repeat for Nano.
Repeat for Mega2560

David.

The constructor statement is the same without any changes for both the Nano and Mega boards.
The only change I make is in the IDE to choose the board.
I made a montage with the image to reduce the size and remain preceptible.

#include <Arduino.h>
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);


// End of constructor list


void setup(void) {
  u8g2.begin();
}

void loop(void) {
  u8g2.clearBuffer();					// clear the internal memory
  u8g2.setFont(u8g2_font_ncenB08_tr);	// choose a suitable font
  u8g2.drawStr(0,10,"Hello World!");	// write something to the internal memory
  u8g2.sendBuffer();					// transfer internal memory to the display
  delay(1000);  
}

Thanks
José Rodrigues

I also use the image of the Nano that I forgot.

Thanks
José Rodrigues

The constructor statement looks fine:

U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

Both of your JPGs look correct. I would expect the Mega2560 to work 100%.

David.

Is there any way to test the SDA and SCL pins?
Is it possible to use other pins from the Mega to make the communication?

Thanks
José Rodrigues

Yes, from u8g2setupcpp · olikraus/u8g2 Wiki · GitHub

you can use random GPIO pins:

U8G2_SH1106_128X64_NONAME_F_SW_I2C(rotation, clock, data [, reset]) [full framebuffer, size = 1024 bytes]

This would solve broken HW SDA, SCL pins.
But I would always be more suspicious of connecting wires/soldering than a factory-made Mega2560.

Regarding headers, shield pins, breadboard, ...
I made a block of 8 LEDs with SIL resistor pack and 8x1 male header. A floating GND wire and male pin.
This means I can test wiring with a pin wiggle / rotate sketch.

David.

It seems that the SDA pin is low, I have to see if there is a problem with the internal pull-up resistors.
I will see the best way to solve the problem now that it is identified.

10:38:49.156 -> 
10:38:49.156 -> ********************************************************************
10:38:49.224 -> Serial Initialized
10:38:49.224 -> --------------------------------------------------------------------
10:38:49.293 -> I2CexpDiag - i2c LCD i/o expander backpack diagnostic tool
10:38:49.362 -> --------------------------------------------------------------------
10:38:49.430 -> hd44780 lib version: 1.1.0
10:38:49.465 -> --------------------------------------------------------------------
10:38:49.534 -> Reported Arduino Revision: 1.8.12
10:38:49.568 -> CPU ARCH: AVR - F_CPU: 16000000
10:38:49.602 -> --------------------------------------------------------------------
10:38:49.706 -> SDA digital pin: 20
10:38:49.706 -> SCL digital pin: 21
10:38:49.740 -> --------------------------------------------------------------------
10:38:49.808 -> Checking for required external I2C pull-up on SDA - STUCK LOW
10:38:49.876 -> Checking for required external I2C pull-up on SCL - NO
10:38:49.944 -> ********************************************************************
10:38:50.013 -> ERROR: SDA or SCL stuck pin
10:38:50.048 -> ********************************************************************
10:38:50.117 -> I2C bus not usable

Thanks for everything
José Rodrigues

The diagnostic shows that your MEGA2560 has got broken SDA, SCL pins.

I suggest that you try SW I2C on some different GPIO pins.
SW I2C must have external pullup resistors. They are often already mounted on SH1106 boards.

You can test the SW I2C constructor on your Nano. If ok on the Nano, it should work on the Mega. (use the same GPIO pin numbers for bit-banging SDA, SCL)

David.

Ok, I will try this solution, but first I will see if I can solve the board problem, as it can be a cold weld that can be corrected.

Thank you David
José Rodrigues

Hello José

I have the same display and had to issues with this lib
One more thing you can do

the "F" version is better but havyer, try changing it to a "1" and i use another config

as so

U8G2_SH1106_128X64_NONAME_F_SW_I2C(rotation, clock, data [, reset]) [full framebuffer, size = 1024 bytes]

change to

U8G2_SH1106_128X64_NONAME_1_SW_I2C(rotation, clock, data [, reset]) [full framebuffer, size = 1024 bytes]

or you can use one of this

/**** U8G2 Display settings *****/
//U8G2_SH1106_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);