1. Do not share user accounts! Any account that is shared by another person will be blocked and closed. This means: we will close not only the account that is shared, but also the main account of the user who uses another person's account. We have the ability to detect account sharing, so please do not try to cheat the system. This action will take place on 04/18/2023. Read all forum rules.
    Dismiss Notice
  2. For downloading SimTools plugins you need a Download Package. Get it with virtual coins that you receive for forum activity or Buy Download Package - We have a zero Spam tolerance so read our forum rules first.

    Buy Now a Download Plan!
  3. Do not try to cheat our system and do not post an unnecessary amount of useless posts only to earn credits here. We have a zero spam tolerance policy and this will cause a ban of your user account. Otherwise we wish you a pleasant stay here! Read the forum rules
  4. We have a few rules which you need to read and accept before posting anything here! Following these rules will keep the forum clean and your stay pleasant. Do not follow these rules can lead to permanent exclusion from this website: Read the forum rules.
    Are you a company? Read our company rules

DIY Arduino Buttonbox

Discussion in 'DIY peripherals' started by TOPMO3, Mar 28, 2016.

  1. TOPMO3

    TOPMO3 Active Member

    Joined:
    May 12, 2015
    Messages:
    133
    Location:
    Russia
    Balance:
    893Coins
    Ratings:
    +201 / 0 / -0
    Hi @Lightman

    I can't see you wiring, but I think you can use exactly the same pins as for Micro - 10, 16, 14, 8, 9 for matrix columns and 15, 18, 19,20, 21 for rows.
    If any of columns or rows will not work - let me know Im sure we'll fix it :)
  2. Lightman

    Lightman New Member

    Joined:
    Feb 28, 2017
    Messages:
    4
    Location:
    Germany
    Balance:
    196Coins
    Ratings:
    +1 / 0 / -0
    My Motion Simulator:
    Arduino
    I have to the blue numbers held.

    Attached Files:

  3. TOPMO3

    TOPMO3 Active Member

    Joined:
    May 12, 2015
    Messages:
    133
    Location:
    Russia
    Balance:
    893Coins
    Ratings:
    +201 / 0 / -0
    yes, use blue (digital) numbers
  4. Lightman

    Lightman New Member

    Joined:
    Feb 28, 2017
    Messages:
    4
    Location:
    Germany
    Balance:
    196Coins
    Ratings:
    +1 / 0 / -0
    My Motion Simulator:
    Arduino
    Hello I have got the board and now everything connected 25 buttons.

    If I now want to compile the butten simpjoy_02c I get an error.

    Can you help me

    Code:
    Arduino: 1.8.1 (Windows 10), Board: "Arduino Leonardo"
    
    C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Lightman\Documents\Arduino\libraries -fqbn=arduino:avr:leonardo -vid-pid=0X2341_0X8036 -ide-version=10801 -build-path C:\Users\Lightman\AppData\Local\Temp\arduino_build_127589 -warnings=none -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\Lightman\Documents\Arduino\libraries\Joystick\examples\buttsimpjoy_02c\buttsimpjoy_02c.ino
    C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Lightman\Documents\Arduino\libraries -fqbn=arduino:avr:leonardo -vid-pid=0X2341_0X8036 -ide-version=10801 -build-path C:\Users\Lightman\AppData\Local\Temp\arduino_build_127589 -warnings=none -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\Lightman\Documents\Arduino\libraries\Joystick\examples\buttsimpjoy_02c\buttsimpjoy_02c.ino
    Using board 'leonardo' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
    Using core 'arduino' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
    Detecting libraries used...
    "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10801 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR  -DUSB_VID=0x2341 -DUSB_PID=0x8036 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="Arduino Leonardo"' "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\leonardo" "C:\Users\Lightman\AppData\Local\Temp\arduino_build_127589\sketch\buttsimpjoy_02c.ino.cpp" -o "nul"
    "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10801 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR  -DUSB_VID=0x2341 -DUSB_PID=0x8036 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="Arduino Leonardo"' "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\leonardo" "C:\Users\Lightman\AppData\Local\Temp\arduino_build_127589\sketch\buttsimpjoy_02c.ino.cpp" -o "C:\Users\Lightman\AppData\Local\Temp\arduino_build_127589\preproc\ctags_target_for_gcc_minus_e.cpp"
    C:\Users\Lightman\Documents\Arduino\libraries\Joystick\examples\buttsimpjoy_02c\buttsimpjoy_02c.ino:21:20: fatal error: Keypad.h: No such file or directory
    
    #include <Keypad.h>
    
                        ^
    
    compilation terminated.
    
    exit status 1
    Error compiling for board Arduino Leonardo.
  5. TOPMO3

    TOPMO3 Active Member

    Joined:
    May 12, 2015
    Messages:
    133
    Location:
    Russia
    Balance:
    893Coins
    Ratings:
    +201 / 0 / -0
    Do you install keypad library?

    go to Sketch -> Include Library -> Manage Libraries

    Untitled3.png

    then type keypad in search and then choose "Keypad by Mark Stanley, Alexander Brevig" and then click Install

    Untitled4.png
    • Informative Informative x 1
  6. Lightman

    Lightman New Member

    Joined:
    Feb 28, 2017
    Messages:
    4
    Location:
    Germany
    Balance:
    196Coins
    Ratings:
    +1 / 0 / -0
    My Motion Simulator:
    Arduino
    Ok thank you really so a simple mistake it now works Perfect all 25 buttons

    Topmo you're the best I thank you.
    • Winner Winner x 1
  7. Evan Rowlands

    Evan Rowlands EMR Industries

    Joined:
    Jan 22, 2017
    Messages:
    190
    Occupation:
    business owner/ EMR industries
    Location:
    Melbourne Australia
    Balance:
    - 82Coins
    Ratings:
    +33 / 0 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform
    hi mate im having alittle trouble the code wont verify it comes up error exit 1 cant comply to board any ideas im using the stardard script and a r3 uno
  8. Pelice

    Pelice New Member

    Joined:
    Jan 5, 2017
    Messages:
    2
    Location:
    Italy
    Balance:
    167Coins
    Ratings:
    +1 / 0 / -0
    i think you need an Arduino Pro Micro because they are a bit different from Arduino Uno (different chip).
  9. Evan Rowlands

    Evan Rowlands EMR Industries

    Joined:
    Jan 22, 2017
    Messages:
    190
    Occupation:
    business owner/ EMR industries
    Location:
    Melbourne Australia
    Balance:
    - 82Coins
    Ratings:
    +33 / 0 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform
    ok sweet im having the same issue with a dash im trying verify
  10. deividiblake

    deividiblake New Member

    Joined:
    Apr 18, 2017
    Messages:
    1
    Location:
    brasil
    Balance:
    156Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    Arduino
    Olá a todos, Estou tendo um problema, eu instalei o scatch no arduino pro micro board eo ultmio econder rotary não está desaparecendo. Aparente.
  11. Esirius

    Esirius New Member

    Joined:
    Apr 18, 2017
    Messages:
    2
    Location:
    Netherlands
    Balance:
    182Coins
    Ratings:
    +0 / 0 / -0
    Hey all,

    Im having sometroubles with this, i got a pro micro, installed the old joystick lib installed the keypad lib as specified,

    How ever i cant get the buttons to work, the rotary's work like a charm, is there an older lib i should use for keypad ? or

    Greetz, Eric
  12. Evan Rowlands

    Evan Rowlands EMR Industries

    Joined:
    Jan 22, 2017
    Messages:
    190
    Occupation:
    business owner/ EMR industries
    Location:
    Melbourne Australia
    Balance:
    - 82Coins
    Ratings:
    +33 / 0 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform
    gday mate im going to buy the board today ill let you no how i going
  13. Evan Rowlands

    Evan Rowlands EMR Industries

    Joined:
    Jan 22, 2017
    Messages:
    190
    Occupation:
    business owner/ EMR industries
    Location:
    Melbourne Australia
    Balance:
    - 82Coins
    Ratings:
    +33 / 0 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform
    im still tring to get the dash going
  14. Evan Rowlands

    Evan Rowlands EMR Industries

    Joined:
    Jan 22, 2017
    Messages:
    190
    Occupation:
    business owner/ EMR industries
    Location:
    Melbourne Australia
    Balance:
    - 82Coins
    Ratings:
    +33 / 0 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform
    ive started and online course so im hoping to be able to help more guys out soon
  15. Evan Rowlands

    Evan Rowlands EMR Industries

    Joined:
    Jan 22, 2017
    Messages:
    190
    Occupation:
    business owner/ EMR industries
    Location:
    Melbourne Australia
    Balance:
    - 82Coins
    Ratings:
    +33 / 0 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform
    im hoping to make some new products also like an anti roll bar box
  16. Esirius

    Esirius New Member

    Joined:
    Apr 18, 2017
    Messages:
    2
    Location:
    Netherlands
    Balance:
    182Coins
    Ratings:
    +0 / 0 / -0
    I figured out that with the keypad it goes wrong, as soon as i use the analog ports it stops working, am using a 3,3v Pro Micro.

    It seems that the A0 to A3 ( 19 / 21 ) ports will be un usuable for me, wich kinda doesnt makes sence, anyone got an idea ?
  17. TOPMO3

    TOPMO3 Active Member

    Joined:
    May 12, 2015
    Messages:
    133
    Location:
    Russia
    Balance:
    893Coins
    Ratings:
    +201 / 0 / -0
    Hi all

    sketch is adapted to V2 joystick library, also fixed issue with 4th encoder.
    New sketch's version buttsimpjoy_02d.zip uploaded in the OP
    • Like Like x 2
  18. Jocelyn Lauzière

    Jocelyn Lauzière New Member

    Joined:
    Jun 12, 2017
    Messages:
    4
    Location:
    Drummondville, Quebec, Canada
    Balance:
    288Coins
    Ratings:
    +1 / 0 / -0
    Hi
    I have use your sketch to make my Button box with 30 buttons and 4 rotaries encoders on a Leonardo.

    There is my code.
    Code:
    /*bottonbox
    *Supports up to 30 buttons and up to 4 encoders
    *By Jocelyn Lauziere
    *
    *A modified version of version 0.1 by TOPMO3
    *https://www.xsimulator.net/community/threads/diy-arduino-buttonbox.8302/
    *
    *For Atmega32U4 based board - ie Leonardo
    *Arduino IDE 1.6.6 (or above) !
    *
    *Leonardo pinout, https://www.pinterest.com/pin/513762269976514845/
    *
    *Joystick library from  Matthew Heironimus, https://github.com/MHeironimus/ArduinoJoystickLibrary
    *
    *Encoders code from Ben Buxton
    *More info: http://www.buxtronix.net/2011/10/rotary-encoders-done-properly.html
    *
    *Thank you guys! :)
    */
    
    #include <Keyboard.h>
    #include <Keypad.h>
    #include <Joystick.h>
    Joystick_ Joystick;
    
    #define ENABLE_PULLUPS
    #define NUMROTARIES 4
    #define NUMBUTTONS 30
    #define NUMROWS 6
    #define NUMCOLS 5
    
    
    //define the symbols on the buttons of the keypads
    byte buttons[NUMROWS][NUMCOLS] = {
      {0,1,2,3,4},
      {5,6,7,8,9},
      {10,11,12,13,14},
      {15,16,17,18,19},
      {20,21,22,23,24},
      {25,26,27,28,29},
    };
    
    
    struct rotariesdef {
      byte pin1;
      byte pin2;
      int ccwchar;
      int cwchar;
      volatile unsigned char state;
    };
    
    rotariesdef rotaries[NUMROTARIES] {
      {0,1,KEY_RIGHT_ARROW,KEY_LEFT_ARROW,0},
      {2,3,KEY_DOWN_ARROW,KEY_UP_ARROW,0},
      {4,5,KEY_PAGE_UP,KEY_PAGE_DOWN,0},
      {6,7,KEY_HOME,KEY_END,0},
    };
    
    
    
    #define DIR_CCW 0x10
    #define DIR_CW 0x20
    
    #define R_START 0x0
    #define R_CW_FINAL 0x1
    #define R_CW_BEGIN 0x2
    #define R_CW_NEXT 0x3
    #define R_CCW_BEGIN 0x4
    #define R_CCW_FINAL 0x5
    #define R_CCW_NEXT 0x6
    
    const unsigned char ttable[7][4] = {
      // R_START
      {R_START,    R_CW_BEGIN,  R_CCW_BEGIN, R_START},
      // R_CW_FINAL
      {R_CW_NEXT,  R_START,     R_CW_FINAL,  R_START | DIR_CW},
      // R_CW_BEGIN
      {R_CW_NEXT,  R_CW_BEGIN,  R_START,     R_START},
      // R_CW_NEXT
      {R_CW_NEXT,  R_CW_BEGIN,  R_CW_FINAL,  R_START},
      // R_CCW_BEGIN
      {R_CCW_NEXT, R_START,     R_CCW_BEGIN, R_START},
      // R_CCW_FINAL
      {R_CCW_NEXT, R_CCW_FINAL, R_START,     R_START | DIR_CCW},
      // R_CCW_NEXT
      {R_CCW_NEXT, R_CCW_FINAL, R_CCW_BEGIN, R_START},
    };
    
    
    byte rowPins[NUMROWS] = {21,20,19,18,15,22}; //connect to the row pinouts of the keypad
    byte colPins[NUMCOLS] = {14,16,10,9,8}; //connect to the column pinouts of the keypad
    
    //initialize an instance of class NewKeypad
    Keypad buttbx = Keypad( makeKeymap(buttons), rowPins, colPins, NUMROWS, NUMCOLS);
    
    
    
    void setup() {
      Keyboard.begin();
      Joystick.begin();
      rotary_init();
    }
    
    
    
    void loop() {
    
      CheckAllEncoders();
    
      CheckAllButtons();
    
    }
    
    
    void CheckAllButtons(void) {
          if (buttbx.getKeys())
        {
           for (int i=0; i<LIST_MAX; i++)   // Scan the whole key list.
            {
               if ( buttbx.key[i].stateChanged )   // Only find keys that have changed state.
                {
                switch (buttbx.key[i].kstate) {  // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
                        case PRESSED:
                        case HOLD:
                                  Joystick.setButton(buttbx.key[i].kchar, 1);
                                  break;
                        case RELEASED:
                        case IDLE:
                                  Joystick.setButton(buttbx.key[i].kchar, 0);
                                  break;
                }
               }  
             }
         }
    }
    
    
    //Call this once in setup().
    void rotary_init() {
      for (int i=0;i<NUMROTARIES;i++) {
        pinMode(rotaries[i].pin1, INPUT);
        pinMode(rotaries[i].pin2, INPUT);
        #ifdef ENABLE_PULLUPS
          digitalWrite(rotaries[i].pin1, HIGH);
          digitalWrite(rotaries[i].pin2, HIGH);
        #endif
      }
    }
    
    
    /* Read input pins and process for events. Call this either from a
    * loop or an interrupt (eg pin change or timer).
    *
    * Returns 0 on no event, otherwise 0x80 or 0x40 depending on the direction.
    */
    unsigned char rotary_process(int _i) {
       unsigned char pinstate = (digitalRead(rotaries[_i].pin2) << 1) | digitalRead(rotaries[_i].pin1);
      rotaries[_i].state = ttable[rotaries[_i].state & 0xf][pinstate];
      return (rotaries[_i].state & 0x30);
    }
    
    void CheckAllEncoders(void) {
      for (int i=0;i<NUMROTARIES;i++) {
        unsigned char result = rotary_process(i);
        if (result) {
          Keyboard.write(result == DIR_CCW ? rotaries[i].ccwchar : rotaries[i].cwchar );
        }
      }
    }
    Like you can see, I have add a row to obtain 30 joystick buttons and ended up using keyboard keys for the rotaries (4) due to the 32 maximum buttons on a joystick. It works very well but I would prefer to use only the joystick and no keyboard keys. I've tried to use a hat switch instead of the keyboard but I just can figure out how. Using two hat switches would allow me up to 16 buttons (each having 8 directions) or 8 rotaries encoders on a single joystick. It would be a good next version :) .
    Any chance you can help me run this new version of your code?
    Thanks a lot for all your work, without your sketch, I would still be learning to carry out my project, but with your sketch, I already have fun with my buttons box.

    Attached Files:

    • Like Like x 1
  19. TOPMO3

    TOPMO3 Active Member

    Joined:
    May 12, 2015
    Messages:
    133
    Location:
    Russia
    Balance:
    893Coins
    Ratings:
    +201 / 0 / -0
    Hi Jocelyn

    Check the latest sketch version 02d. In the initialization of joystick library you can define number of buttons. These lines:
    //initialize an Joystick with 34 buttons;
    Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
    JOYSTICK_TYPE_JOYSTICK, 34, 0,
    false, false, false, false, false, false,
    false, false, false, false, false);

    Change 34 to number of buttons you need. But please note that "game controller properties" can show only 32 buttons, so if you have more you should use some other app, for example this one http://www.planetpointy.co.uk/joystick-test-application/
  20. Jocelyn Lauzière

    Jocelyn Lauzière New Member

    Joined:
    Jun 12, 2017
    Messages:
    4
    Location:
    Drummondville, Quebec, Canada
    Balance:
    288Coins
    Ratings:
    +1 / 0 / -0
    I do the switch to the 02d sketch version, work perfectly.
    Thanks a lot!