Adding constructor for U8GLIB and SPI display
After getting an I2C OLED display working with Repetier on RAMPS I wanted to also try getting an SPI based OLED display working.
After reading the various choices in the menu in uiconfig.h for U8GLIB based displays I do not see anything that looks like something I can modify for my use. Here's what I have. SPI based SH1106 based 128 x 64 OLED. It's connected to pins 16, 17, 27, 23, 25. For testing I've successfully run this on the RAMPS board with the "hello world" example sketch using the following construct:
U8GLIB_SH1106_128X64 u8g(16, 17, 27, 23, 25); // SW SPI Com: D0 = 16, D1 = 17, CS = 27, RST = 23, DC = 25
I had the bright idea to add the above line to uiconfig.h and of course this failed. After comparing the entries in the uiconfig.h file with the constructs in the U8GLIB examples I'm not sure how to craft a working construct.
Thank you in advance.
After reading the various choices in the menu in uiconfig.h for U8GLIB based displays I do not see anything that looks like something I can modify for my use. Here's what I have. SPI based SH1106 based 128 x 64 OLED. It's connected to pins 16, 17, 27, 23, 25. For testing I've successfully run this on the RAMPS board with the "hello world" example sketch using the following construct:
U8GLIB_SH1106_128X64 u8g(16, 17, 27, 23, 25); // SW SPI Com: D0 = 16, D1 = 17, CS = 27, RST = 23, DC = 25
I had the bright idea to add the above line to uiconfig.h and of course this failed. After comparing the entries in the uiconfig.h file with the constructs in the U8GLIB examples I'm not sure how to craft a working construct.
Thank you in advance.
Comments
U8GLIB_SH1106_SW_SPI
that can be used. You find constructor in ui.cpp if you need to compre more closely. That is also where you need to add new constructors if needed.
I'm assuming this is the specific code you were directing me to in UI.cpp:
While I somewhat understand this I cannot understand how this code (is it a constructor?) translates into what I am used to seeing with the U8GLIB constructors like I posted above. I am assuming I need to define pins somewhere but, really, this is over my head. Seems like it should not be that hard to Grok.
Thank you.
All you need is set
UI_DISPLAY_D4_PIN
UI_DISPLAY_ENABLE_PIN
UI_DISPLAY_RS_PIN
With the correct pin numbers.
Reading uiconfig comments you see even the explaination:
#if UI_DISPLAY_TYPE == DISPLAY_U8G // Special case for graphic displays
// You need to define which controller you use and set pins accodringly
// For software spi assign these definitions
// SCK Pin: UI_DISPLAY_D4_PIN
// Mosi Pin: UI_DISPLAY_ENABLE_PIN
// CD Pin: UI_DISPLAY_RS_PIN
I'll do some experimenting later this weekend. Thank you for the explanation.