Custom Buttons with UI_KEYS_BUTTON_HIGH/LOW

Good Morning,

my name is Stefan and i experience a little problem. I have tried to add
some keys to my printer which i will use for milling. I have an RAMPS
1.4 with an MEGA.
The producer is Sainsmart. I have that Display: LCD
12864. That is the Kit:
http://www.sainsmart.com/arduino/arduino-kits/3d-printkits/ramps-1-4-a4988-mega2560-r3-endstop-lcd-12864-kit-for-reprap-3d-printer.html

In
the configurator i have choos that Display: RepRapDiscount Full Graphic
Smart Controller 128x64, RAMPS, RUMBA, Megatronics 2 & RAMBO

I have add that code in the uiconfig.h:

#define UI_HAS_KEYS 1

void uiInitKeys() {
#if UI_HAS_KEYS!=0

// Keypad, connect 5V to Pin x  Pin 11, 57, 58 are empty
  UI_KEYS_INIT_BUTTON_HIGH(0); // Zero all
  UI_KEYS_INIT_BUTTON_HIGH(1); // Zero Z
  UI_KEYS_INIT_BUTTON_HIGH(4); // slow X
  UI_KEYS_INIT_BUTTON_HIGH(5); // slow Y
  UI_KEYS_INIT_BUTTON_HIGH(6); // Babysteps Z
  UI_KEYS_INIT_BUTTON_HIGH(63); // Left
  UI_KEYS_INIT_BUTTON_HIGH(59); // Right
  UI_KEYS_INIT_BUTTON_HIGH(40); // forward
  UI_KEYS_INIT_BUTTON_HIGH(64); // backward
  UI_KEYS_INIT_BUTTON_HIGH(42); // up
  UI_KEYS_INIT_BUTTON_HIGH(44); // down
  UI_KEYS_INIT_BUTTON_HIGH(65); // Home all
  UI_KEYS_INIT_BUTTON_HIGH(66); // Emergency stop / Or disconnect current??

#endif
}

void uiCheckSlowKeys(uint16_t &action) {
....
....
...
...
...
  // ----- End RGB shield ----------
  */
 
#endif

  //UI_KEYS_MATRIX(32,47,45,43,41,39,37,35);
 
  // Keypad, puch button, connects 5V to pin
  UI_KEYS_BUTTON_HIGH(0,UI_ACTION_SET_ORIGIN); // Zero all
  UI_KEYS_BUTTON_HIGH(1,UI_ACTION_SET_Z_ORIGIN_BUTTON); // Zero Z defined in ui.ccp and ui.h
  UI_KEYS_BUTTON_HIGH(4,UI_ACTION_XPOSITION); // slow
  UI_KEYS_BUTTON_HIGH(5,UI_ACTION_YPOSITION); // slow
  UI_KEYS_BUTTON_HIGH(6,UI_ACTION_Z_BABYSTEPS); // slow
  UI_KEYS_BUTTON_HIGH(63,UI_ACTION_Y_UP); // Left
  UI_KEYS_BUTTON_HIGH(59,UI_ACTION_Y_DOWN); // Right
  UI_KEYS_BUTTON_HIGH(40,UI_ACTION_X_UP); // forward
  UI_KEYS_BUTTON_HIGH(64,UI_ACTION_X_DOWN); // backward
  UI_KEYS_BUTTON_HIGH(42,UI_ACTION_Z_UP); // up
  UI_KEYS_BUTTON_HIGH(44,UI_ACTION_Z_DOWN); // down
  UI_KEYS_BUTTON_HIGH(65,UI_ACTION_HOME_ALL); // Home all
//  UI_KEYS_BUTTON_HIGH(66,UI_ACTION_EMERGENCY_STOP); // Emergency stop / Or disconnect current??
}

#endif
#endif

The problem i get is:

The Buttons doing absolutely nothing oO
Can anyone tell me what is going wrong?

Another short question:
In that part:
case UI_ACTION_SET_Z_ORIGIN_BUTTON:
           GCode::executeFString(PSTR("G92 Z0"));
           break;
is it also possible to send a M command?

I hope for a fast response and sorry for my bad english.

Kind regards
Stefan

Comments

  • 1. what type of Switches do you use ?  n.c. or n.o?

    2. M command is possible the same way

    greetings from munich ;-)


  • Hey, thx for the answer.
    Yes Munich, correctly ;)

    I use n.o switches. They connect 5V while i am pushing the Button (Taster).

    Kind regards
    Stefan
  • edited April 2016

    does your Rotary Encoder work?

    how is Display connected? Looks like double use of Pins...


    I´m not familiar with the config tool , while I´m doing Settings Manual .

    maybe you can take a look at  configuration.h at line around1600 which Controller is set

  • Hey,
    sorry i have only 988 lines ;)

    I've found that two lines (perhaps you need to tell me the option):
    #define FEATURE_CONTROLLER 11
    "uiController": 0,

    The Display has an Rotary Encoder and 3 Switches (Encoder, Stop/Reset, Light for Display)
    Here is everything working fine and i did not get any problems.

    I have take a look on the RAMPS 1.4 shematic. That are the Digital Pins of Servos, Aux1 and Aux2:
    http://reprap.org/mediawiki/images/thumb/c/ca/Arduinomega1-4connectors.png/800px-Arduinomega1-4connectors.png

    I didn't think that i have a double use.
  • is there something written about uikeys in your config.h?

    like:

    #define FEATURE_UI_KEYS 0

    if yes, set it to one


  • Hey, thx for the repley.
    yes i get it:
    #define FEATURE_UI_KEYS 0

    is that the error?
  • think so , set it to 1 , that will activate the buttons
  • where did you add the code ? in uiconfig.h  or in ui.h?

    uiconfig only works if you set Feature_Controller 1.

    so you have to set Pins for Display also in uiconfig. h



    Settings for Controller 11  are located in ui.h , also the init and check the keys.


    i suggest you should define the keys and Display manually in uiconfig in order of not changing

    the Standard Settings.

    so check ui.h from line 645 to 677 for display

    and for your ramps line 834 to 854 for pin Settings

    move that Settings to uiconfig.h  , so that should work





  • Hey,
    sorry ich verstehs nicht..

    so i have take a look in the ui.h.
    (Only for testing)
    I have set from line 642 (void uiInitKeys() ) my key init:
    void uiInitKeys() {
      // Keypad, connect 5V to Pin x  Pin 11, 57, 58 are empty
      UI_KEYS_INIT_BUTTON_HIGH(0); // Zero all
      UI_KEYS_INIT_BUTTON_HIGH(1); // Zero Z
      UI_KEYS_INIT_BUTTON_HIGH(4); // slow X
      UI_KEYS_INIT_BUTTON_HIGH(5); // slow Y
      UI_KEYS_INIT_BUTTON_HIGH(6); // Babysteps Z
      UI_KEYS_INIT_BUTTON_HIGH(63); // Left
      UI_KEYS_INIT_BUTTON_HIGH(59); // Right
      UI_KEYS_INIT_BUTTON_HIGH(40); // forward
      UI_KEYS_INIT_BUTTON_HIGH(64); // backward
      UI_KEYS_INIT_BUTTON_HIGH(42); // up
      UI_KEYS_INIT_BUTTON_HIGH(44); // down
      UI_KEYS_INIT_BUTTON_HIGH(65); // Home all
    //  UI_KEYS_INIT_BUTTON_HIGH(66); // Emergency stop / Or disconnect current??
      }

    And i have set in line 660:
    void uiCheckSlowKeys(uint16_t &action) {
        // Keypad, puch button, connects 5V to pin
      UI_KEYS_BUTTON_HIGH(0,UI_ACTION_SET_ORIGIN); // Zero all
      UI_KEYS_BUTTON_HIGH(1,UI_ACTION_SET_Z_ORIGIN_BUTTON); // Zero Z
      UI_KEYS_BUTTON_HIGH(4,UI_ACTION_XPOSITION); // slow
      UI_KEYS_BUTTON_HIGH(5,UI_ACTION_YPOSITION); // slow
      UI_KEYS_BUTTON_HIGH(6,UI_ACTION_Z_BABYSTEPS); // slow
      UI_KEYS_BUTTON_HIGH(63,UI_ACTION_Y_UP); // Left
      UI_KEYS_BUTTON_HIGH(59,UI_ACTION_Y_DOWN); // Right
      UI_KEYS_BUTTON_HIGH(40,UI_ACTION_X_UP); // forward
      UI_KEYS_BUTTON_HIGH(64,UI_ACTION_X_DOWN); // backward
      UI_KEYS_BUTTON_HIGH(42,UI_ACTION_Z_UP); // up
      UI_KEYS_BUTTON_HIGH(44,UI_ACTION_Z_DOWN); // down
      UI_KEYS_BUTTON_HIGH(65,UI_ACTION_HOME_ALL); // Home all
    //  UI_KEYS_BUTTON_HIGH(66,UI_ACTION_EMERGENCY_STOP); // Emergency stop / Or disconnect current??
      }

    I have a RAMPS so i have take a look to line 867:
    Here is defined:
    #else  // RAMPS
    #undef BEEPER_PIN
    #define BEEPER_PIN             37
    #define UI_DISPLAY_RS_PIN      16
    #define UI_DISPLAY_RW_PIN      -1
    #define UI_DISPLAY_ENABLE_PIN  17
    #define UI_DISPLAY_D0_PIN      23
    #define UI_DISPLAY_D1_PIN      25
    #define UI_DISPLAY_D2_PIN      27
    #define UI_DISPLAY_D3_PIN      29
    #define UI_DISPLAY_D4_PIN      23
    #define UI_DISPLAY_D5_PIN      25
    #define UI_DISPLAY_D6_PIN      27
    #define UI_DISPLAY_D7_PIN      29
    #define UI_ENCODER_A           33
    #define UI_ENCODER_B           31
    #define UI_ENCODER_CLICK       35
    #define UI_RESET_PIN           41
    #endif

    Here i have add
    #define UI_ACTION_HOME_ALL     65
    but i didn't do anything.

    Can you explain your steps?
  • Hey,

    i get it. I defined that one in the ui.h:
    #else  // RAMPS
    ....
    ....
    ....
    #ifdef UI_MAIN
    void uiInitKeys() {
      UI_KEYS_INIT_CLICKENCODER_LOW(UI_ENCODER_A, UI_ENCODER_B); // click encoder on pins 47 and 45. Phase is connected with gnd for signals.
      UI_KEYS_INIT_BUTTON_LOW(UI_ENCODER_CLICK); // pushbutton, connects gnd to pin
      // Keypad, connect 5V to Pin x  Pin 11, 57, 58 are empty
      UI_KEYS_INIT_BUTTON_LOW(0); // Zero all
      UI_KEYS_INIT_BUTTON_LOW(1); // Zero Z
      UI_KEYS_INIT_BUTTON_LOW(4); // slow X
      UI_KEYS_INIT_BUTTON_LOW(5); // slow Y
      UI_KEYS_INIT_BUTTON_LOW(6); // Babysteps Z
      UI_KEYS_INIT_BUTTON_LOW(63); // Left
      UI_KEYS_INIT_BUTTON_LOW(59); // Right
      UI_KEYS_INIT_BUTTON_LOW(40); // forward
      UI_KEYS_INIT_BUTTON_LOW(64); // backward
      UI_KEYS_INIT_BUTTON_LOW(42); // up
      UI_KEYS_INIT_BUTTON_LOW(44); // down
      UI_KEYS_INIT_BUTTON_LOW(65); // Home all
    //  UI_KEYS_INIT_BUTTON_LOW(66); // Emergency stop / Or disconnect current??
    #if UI_RESET_PIN > -1
      UI_KEYS_INIT_BUTTON_LOW(UI_RESET_PIN); // Kill pin
    #endif
    }
    void uiCheckKeys(uint16_t &action) {
    #if FEATURE_CONTROLLER == CONTROLLER_BAM_DICE_DUE
      UI_KEYS_CLICKENCODER_LOW_REV(UI_ENCODER_B, UI_ENCODER_A); // click encoder on pins 47 and 45. Phase is connected with gnd for signals.
    #else
      UI_KEYS_CLICKENCODER_LOW_REV(UI_ENCODER_A, UI_ENCODER_B); // click encoder on pins 47 and 45. Phase is connected with gnd for signals.
    #endif
      UI_KEYS_BUTTON_LOW(UI_ENCODER_CLICK, UI_ACTION_OK); // push button, connects gnd to pin
        // Keypad, puch button, connects 5V to pin
      UI_KEYS_BUTTON_LOW(0,UI_ACTION_SET_ORIGIN); // Zero all
      UI_KEYS_BUTTON_LOW(1,UI_ACTION_SET_Z_ORIGIN_BUTTON); // Zero Z
      UI_KEYS_BUTTON_LOW(4,UI_ACTION_XPOSITION); // slow
      UI_KEYS_BUTTON_LOW(5,UI_ACTION_YPOSITION); // slow
      UI_KEYS_BUTTON_LOW(6,UI_ACTION_Z_BABYSTEPS); // slow
      UI_KEYS_BUTTON_LOW(63,UI_ACTION_Y_UP); // Left
      UI_KEYS_BUTTON_LOW(59,UI_ACTION_Y_DOWN); // Right
      UI_KEYS_BUTTON_LOW(40,UI_ACTION_X_UP); // forward
      UI_KEYS_BUTTON_LOW(64,UI_ACTION_X_DOWN); // backward
      UI_KEYS_BUTTON_LOW(42,UI_ACTION_Z_UP); // up
      UI_KEYS_BUTTON_LOW(44,UI_ACTION_Z_DOWN); // down
      UI_KEYS_BUTTON_LOW(65,UI_ACTION_HOME_ALL); // Home all
    //  UI_KEYS_BUTTON_LOW(66,UI_ACTION_EMERGENCY_STOP); // Emergency stop / Or disconnect current??
    #if UI_RESET_PIN > -1

    Should i copy that in the uiconfig.h? If yes what i should copy?

    Another question:
    At the moment it drive 1mm and stops. Then it drives 1mm and stops (so lang as i press the button) is there
    a possibility to "smooth" that?
    With which Action i will only drive 0.1 mm or less? (Can i set a command or G code to switch in a "slow" mode)

  • regarding uiconfig sent you a german message...

    for moving smaller steps you have to write a ui_action.
    handling can be done like this :

    case UI_ACTION_Y_UP01:
    if(!allowMoves) return action;
    GCode::executeFString(PSTR("G91\n G1 Y 0.1 F200 \n G90\n"));
    break;

    or another way:
    (thats the way original move is done)
    case UI_ACTION_Y_UP01:
    case UI_ACTION_Y_DOWN01:
    if(!allowMoves) return action;
    PrintLine::moveRelativeDistanceInStepsReal(0, ((action == UI_ACTION_Y_UP01) ? 1.0 : -1.0) * Printer::axisStepsPerMM[Y_AXIS]/10, 0, 0, JOGRATE, false,false);
    break;

    it´s just typing;-)

  • Good Morning :)
    so have i take that lines in the uiconfig.h:

    // Special pins for some u8g driven display
    ....
    ....
    ....
    ....
    ....

    // Defined for RAMPS from ui.h
    #undef BEEPER_PIN
    #define BEEPER_PIN             37
    #define UI_DISPLAY_RS_PIN      16
    #define UI_DISPLAY_RW_PIN      -1
    #define UI_DISPLAY_ENABLE_PIN  17
    #define UI_DISPLAY_D0_PIN      23
    #define UI_DISPLAY_D1_PIN      25
    #define UI_DISPLAY_D2_PIN      27
    #define UI_DISPLAY_D3_PIN      29
    #define UI_DISPLAY_D4_PIN      23
    #define UI_DISPLAY_D5_PIN      25
    #define UI_DISPLAY_D6_PIN      27
    #define UI_DISPLAY_D7_PIN      29
    #define UI_ENCODER_A           33
    #define UI_ENCODER_B           31
    #define UI_ENCODER_CLICK       35
    #define UI_RESET_PIN           41
    #define UI_DELAYPERCHAR 50
    #if FEATURE_CONTROLLER == CONTROLLER_BAM_DICE_DUE
    #define UI_ENCODER_SPEED 2
    #endif
    #ifndef UI_INVERT_MENU_DIRECTION
    #define UI_INVERT_MENU_DIRECTION 0
    #endif


    /** \brief Are some keys connected?

    0 = No keys attached - disables also menu
    1 = Some keys attached
    */
    #define UI_HAS_KEYS 1

    Was that right? I didn't commend anything out. I didn't get an error while i'm compiling

    A great Tip for all others: Don't use the keys with HIGH, Use the Keys with LOW and connect them to ground.....

    I think i would use that version becouse i understand it:
    case UI_ACTION_Y_UP01:
    if(!allowMoves) return action;
    GCode::executeFString(PSTR("G91\n G1 Y 0.1 F200 \n G90\n"));
    break;

    Is there a possibility to set an Switch with that function:
    I set the Switch to LOW and while it is LOW all axes will drive with 0.01 mm?

    Another point is that:
    I have created that keys:
      UI_KEYS_BUTTON_LOW(59,UI_ACTION_Y_UP); // Left
      UI_KEYS_BUTTON_LOW(63,UI_ACTION_Y_DOWN); // Right
      UI_KEYS_BUTTON_LOW(40,UI_ACTION_X_UP); // forward
      UI_KEYS_BUTTON_LOW(64,UI_ACTION_X_DOWN); // backward
      UI_KEYS_BUTTON_LOW(44,UI_ACTION_Z_UP); // up
      UI_KEYS_BUTTON_LOW(42,UI_ACTION_Z_DOWN); // down

    When i drive with the keys the printer will do 1mm, stop, 1mm, stop, 1mm, stop, and so on.
    Is there a possiblity to smooth that, that the printer will drive the way without stops ever 1mm?

    A lost question to your last post:
    Wy you are useng that command?:
    GCode::executeFString(PSTR("G91\n G1 Y 0.1 F200 \n G90\n"));

    Becouse that will work too:
    GCode::executeFString(PSTR("G1 Y 0.1"));
    is that the point to make it more smooth?

    Greetings
    Stefan :)
  • Hi Stefan,

    please send me your uiconfig.h  by e-Mail i´ll check it for you.

    Quote:

    A lost question to your last post:
    Wy you are useng that command?:
    GCode::executeFString(PSTR("G91\n G1 Y 0.1 F200 \n G90\n"));

    Becouse that will work too:
    GCode::executeFString(PSTR("G1 Y 0.1"));
    is that the point to make it more smooth?

    NO it´s not the same

    GCode::executeFString(PSTR("G91\n G1 Y 0.1 F200 \n G90\n")); 

    G91: sets move to relative positioning

    G1 Y 0.1 F200  moves x by 0.1mm to + direction

    G90 goes back to absolute positioning

    for example : machine is at Position x=10mm   it will move to Position10.1mm


    if you don´t use the G91/G90

      for example : machine is at Position x=10mm   it will move to Position 0.1mm

    that´s the difference

    F says just the Speed(F for feedrate) and 200 means 200 mm/min what is quite slow

    Greetings

    Robert





Sign In or Register to comment.