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

[BUG] SSD1306 I2C display does not work #26389

Closed
1 task done
jonathanmlang opened this issue Nov 2, 2023 · 11 comments · Fixed by #26409
Closed
1 task done

[BUG] SSD1306 I2C display does not work #26389

jonathanmlang opened this issue Nov 2, 2023 · 11 comments · Fixed by #26409

Comments

@jonathanmlang
Copy link

Did you test the latest bugfix-2.1.x code?

Yes, and the problem still exists.

Bug Description

I uncommented #define MKS_12864OLED_SSD1306 in configuration.h
Added pin definitions in the board file, pins_CREALITY_V4.h
#define I2C_SCL_PIN PB10
#define I2C_SDA_PIN PB11

Compiled and flahsed fine,
Blank display.

Bug Timeline

Not sure

Expected behavior

Expected the display to show the marlin interface

Actual behavior

Nothing happens.

Steps to Reproduce

I uncommented #define MKS_12864OLED_SSD1306 in configuration.h
Added pin definitions in the board file, pins_CREALITY_V4.h
#define I2C_SCL_PIN PB10
#define I2C_SDA_PIN PB11

Version of Marlin Firmware

02010300

Printer model

Creality ender 3 with custom display wired to exp3 cable

Electronics

Creality v4.2.2 stm32 pcb

Add-ons

No response

Bed Leveling

None

Your Slicer

None

Host Software

None

Don't forget to include

  • A ZIP file containing your Configuration.h and Configuration_adv.h.

Additional information & file uploads

Configuration.zip

@jonathanmlang jonathanmlang changed the title [BUG] SSD1306 I2C display support appears to be missing [BUG] SSD1306 I2C display does not work. Nov 2, 2023
@ellensp
Copy link
Contributor

ellensp commented Nov 2, 2023

MKS_12864OLED_SSD1306 is not a I2C display by default, it is a SPI display. Yes the SSD1306 does i2c, if its wired that way. and the firmware is setup for it.

MKS_12864OLED_SSD1306 needs to the appropriate SPI pins

@ellensp ellensp closed this as completed Nov 2, 2023
@ellensp
Copy link
Contributor

ellensp commented Nov 2, 2023

If your playing with a generic i2c SSD1306 module, you need #define U8GLIB_SSD1306 not MKS_12864OLED_SSD1306

@jonathanmlang
Copy link
Author

Hello thanks for replying, Ive tried #define U8GLIB_SSD1306 but still no luck, no output at the pins as proven by an oscilloscope.

@thisiskeithb thisiskeithb reopened this Nov 3, 2023
@thisiskeithb thisiskeithb changed the title [BUG] SSD1306 I2C display does not work. [BUG] SSD1306 I2C display does not work Nov 3, 2023
@dbuezas
Copy link
Contributor

dbuezas commented Nov 9, 2023

Same here, I'm using an skr3 ez board on an Ultimaker 2.
I see the i2c clock for the i2c epprom on startup but no clock at all if I disable it (not a single pulse). I did manually set the i2c pins since disabling eeprom skips defining them.

I tried changing pins and software/hw i2c. It looks like Marlin isn't even trying to talk to the display at all.

Update: my case was unrelated. The skr3 uses software i2c and that isn't supported by u8glib

@ellensp
Copy link
Contributor

ellensp commented Nov 9, 2023

having a play

using a creality 4.2.2.controller and a 0.96" SSD1306 I2C module

I wired it up

  /**             LCD PORT
   *              ------
   *        PC6  | 1  2 | PB2
   *  (SDL) PB10 | 3  4 | PB11 (SDA)                               
   *        PB14   5  6 | PB13
   *        PB12 | 7  8 | PB15
   *         GND | 9 10 | 5V
   *              ------
   */

I added this code to Marlin/src/MarlinCore.cpp after SETUP_LOG("setup() completed.");

  SERIAL_ECHOLN("I2C scanner. Scanning ...");
  Wire.setSDA(PB11);
  Wire.setSCL(PB10);
  Wire.begin();
  for (byte i = 1; i < 120; i++)
  {
    hal.watchdog_refresh();
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      {
      SERIAL_ECHOLN("Found address: ",i);
      delay (1);
      }
  }
  SERIAL_ECHOLN ("Done.");

And #include <Wire.h> after #include <math.h>

Marlin boots and says

I2C scanner. Scanning ...
Found address: 60
Done.

60 is 3C, the expected address of the LCD, so this confirms the address and the wiring is OK

@ellensp
Copy link
Contributor

ellensp commented Nov 9, 2023

I'm getting clock and data... cant say if its the correct data. (this is well after the I2C scanner)
Edit, this was due to my i2c scanner code initializing Wire. Signals are not visible otherwise

NewFile0

@dbuezas
Copy link
Contributor

dbuezas commented Nov 9, 2023

Good idea with the i2c scan. I tried the same but with Software i2c and get this:

Screen disconnected

10:18:16.948 > I2C scanner. Scanning ...
10:18:16.957 > Found address: 80
10:18:16.962 > Done.

That should be the onboard EEPROM

Screen connected

10:18:16.948 > I2C scanner. Scanning ...
10:18:16.949 > Found address: 3
10:18:16.954 > Found address: 60
10:18:16.957 > Found address: 80
10:18:16.959 > Found address: 96
10:18:16.961 > Found address: 112
10:18:16.962 > Done.

So my wiring should be correct.

@ellensp
Copy link
Contributor

ellensp commented Nov 9, 2023

Odd, removing my I2C scanner code you dont get any output, as reported

but just add adding

  Wire.setSDA(PB11);
  Wire.setSCL(PB10);
  Wire.begin();

above SETUP_RUN(ui.init()); in Marlin/src/MarlinCore.cpp and you get a display!!

IMG_20231109_224738

Ignore the power bank, its just a weight to hold the wires in place.
This is far form a solution, more a hack, But my brain has quit for the day, will have to continue this later

@ellensp
Copy link
Contributor

ellensp commented Nov 9, 2023

@jonathanmlang

I purpose this as a fix. (basically it rearranges marlinui.cpp to setup the i2c pins before setting up the display, and changes the pin variable type)

diff --git a/Marlin/src/lcd/marlinui.cpp b/Marlin/src/lcd/marlinui.cpp
index 463d406110..fa511b4882 100644
--- a/Marlin/src/lcd/marlinui.cpp
+++ b/Marlin/src/lcd/marlinui.cpp
@@ -218,6 +218,10 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
 
 void MarlinUI::init() {
 
+  #if HAS_U8GLIB_I2C_OLED && PINS_EXIST(I2C_SCL, I2C_SDA) && DISABLED(SOFT_I2C_EEPROM)
+    Wire.begin(uint8_t(I2C_SDA_PIN), uint8_t(I2C_SCL_PIN));
+  #endif
+
   init_lcd();
 
   #if HAS_DIGITAL_BUTTONS
@@ -274,10 +278,6 @@ void MarlinUI::init() {
     slow_buttons = 0;
   #endif
 
-  #if HAS_U8GLIB_I2C_OLED && PINS_EXIST(I2C_SCL, I2C_SDA) && DISABLED(SOFT_I2C_EEPROM)
-    Wire.begin(int(I2C_SDA_PIN), int(I2C_SCL_PIN));
-  #endif
-
   update_buttons();
 
   TERN_(HAS_ENCODER_ACTION, encoderDiff = 0);

@ellensp
Copy link
Contributor

ellensp commented Nov 11, 2023

Ive created a PR to fix this, so closing this issue

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Jan 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants