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.

Comments

  • Please check uiconfig.h carefully. There is already a flag for SH1106 
    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.
  • Thank you. I've been looking at what I think are the constructor lines in the ui.cpp file. I do not understand your implementation of the u8glib (if that's the correct term) I'm used to using constructors that look like above taken from the u8glib examples. 
  • We can only have one constructor but have different ones to choose from. My var is no constructor just the selector for the right constructor. YOu need to define the pins in macros as well to fill the constructor with your values.
  • That is well out side my understanding. I'll have to shelve this for now. Thank you for your help.
  • Well I'm back at trying to Grok this. I see where there are some corresponding lines of code in the UI.CPP file but none of it makes sense in a way I can wrap my head around.

    I'm assuming this is the specific code you were directing me to in UI.cpp:

    #ifdef U8GLIB_SH1106_SW_SPI
    u8g_InitSPI(&u8g,&u8g_dev_sh1106_128x64_sw_spi,  UI_DISPLAY_D4_PIN, UI_DISPLAY_ENABLE_PIN, UI_DISPLAY_RS_PIN, U8G_PIN_NONE, U8G_PIN_NONE);
    #endif

    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.
  • We don't use the C++ interface for performance reasons. But that initalizes the data structure for your display and takes similar values as the constructor.
    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

  • Ok, I think I get it. 

    I'll do some experimenting later this weekend. Thank you for the explanation.
Sign In or Register to comment.