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?
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);
}
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.
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
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)