Adding rotary encoder with I2C OLED display

I've been tinkering with the firmware and now have an OLED display working via I2C.  B)

Now I'd like to add a way to use the menus. Hopefully with a rotary encoder. I can connect this in the same pinout as used for the "Smart" controllers. What changes in the firmware configuration do I need to make for the encoder to work?

Comments

  • Check it in ui.h or displaylist.h for 1.0 version. Each controller has a section setting pin numbers and at the end 2 functions handling the keys.
  • edited June 2017
    Thank you Repetier. I'm not too much of a coder and am finding myself confused as to where I may either enable or define the encoder. 1.1 dev is what I think I've downloaded.

    I read both the ui.h and displaylist.h files and see no obvious place for this.

    RAMPS 1.4 board, The encoder is connected as follows:

    Button A 33
    Button B 35
    Click button 37

    Thanks again.
  • how did you set up yor display?
    did you use the uiconfig.h?
  • Yes uiconfig.h

    #define UI_DISPLAY_TYPE 5
    #define U8GLIB_SSD1306_I2C

  • edited June 2017

    so it´s simple to add Encoder.

    in configuration.h 

    set #define FEATURE_UI_KEYS 1

    in uiconfig.h

    uncomment   //  UI_KEYS_INIT_CLICKENCODER_LOW(33,31);  and replace the pin numbers by yours

    do the same for //UI_KEYS_CLICKENCODER_LOW_REV(33,31)

    similar  for button , assign pin number/function

    so at least the part in your uiconfig.h should be

    void uiInitKeys() {
    #if UI_HAS_KEYS!=0
      UI_KEYS_INIT_CLICKENCODER_LOW(33,35); 
      UI_KEYS_INIT_BUTTON_LOW(37); // push button, connects gnd to pin

    #endif
    }
    void uiCheckKeys(uint16_t &action) {
    #if UI_HAS_KEYS!=0

     UI_KEYS_CLICKENCODER_LOW_REV(33,35); 
     UI_KEYS_BUTTON_LOW(37,UI_ACTION_OK); // push button, connects gnd to pin
    #endif
    }



    think that should work for you, if Encoder direction is wrong, just swap the pin numbers

  • Thank you RAyWB. I'll hack on that when I get home from work.
  • edited June 2017
    This works. Thank you so very much.

    (Note to self -- This works better if you actually connect to pins 33, 35, and 37. Not 31, 33, 35.... :blush: )
Sign In or Register to comment.