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. paulopsx2

    paulopsx2 Active Member

    Joined:
    Apr 2, 2016
    Messages:
    613
    Location:
    brasil
    Balance:
    616Coins
    Ratings:
    +163 / 2 / -0
    My Motion Simulator:
    2DOF, Arduino, Motion platform
    well.. this project, its exaclty the same i use on 2012, for physical changes on my f1 add for t500rs. works perfect, but wires between platform and wheel still a great problem... some idea how to wirelless project??
  2. paulopsx2

    paulopsx2 Active Member

    Joined:
    Apr 2, 2016
    Messages:
    613
    Location:
    brasil
    Balance:
    616Coins
    Ratings:
    +163 / 2 / -0
    My Motion Simulator:
    2DOF, Arduino, Motion platform
    some pics how to

    Attached Files:

  3. TOPMO3

    TOPMO3 Active Member

    Joined:
    May 12, 2015
    Messages:
    133
    Location:
    Russia
    Balance:
    890Coins
    Ratings:
    +201 / 0 / -0
    • Like Like x 1
  4. paulopsx2

    paulopsx2 Active Member

    Joined:
    Apr 2, 2016
    Messages:
    613
    Location:
    brasil
    Balance:
    616Coins
    Ratings:
    +163 / 2 / -0
    My Motion Simulator:
    2DOF, Arduino, Motion platform
  5. Nick Moxley

    Nick Moxley Well-Known Member

    Joined:
    Dec 13, 2013
    Messages:
    2,779
    Occupation:
    Owner/Operator- Moxleys Rantals
    Location:
    Winnipeg Manitoba Canada
    Balance:
    17,054Coins
    Ratings:
    +2,504 / 30 / -2
    My Motion Simulator:
    2DOF, 3DOF, DC motor, JRK
    Easiest Bluetooth setup to do is the BlueHID. its relatively cheap, its dead nuts easy to setup, the only real downside is the size of the board.
    • Like Like x 1
    • Informative Informative x 1
  6. TOPMO3

    TOPMO3 Active Member

    Joined:
    May 12, 2015
    Messages:
    133
    Location:
    Russia
    Balance:
    890Coins
    Ratings:
    +201 / 0 / -0
    Didn't try yet..
    Input lag is probably higher than wired, but can't say how much
  7. HoiHman

    HoiHman Active Member

    Joined:
    Feb 1, 2015
    Messages:
    211
    Occupation:
    Mechanic
    Location:
    The Netherlands
    Balance:
    330Coins
    Ratings:
    +143 / 1 / -0
    I bought a couple of arduino micro pro's and used the last joystick sketch. Pretty with it and the small size is perfect for building steering wheels.

    Everything works perfect except my CTS rotary encoders. First i had to turn them four steps to register one click, then i switched to " half step" which improved, but it still takes two steps for the rotary to register 1 click.
    So i probably need a "quarter step" setting for my CTS encoders, but i have really no idea how to edit this in the sketch.

    I hope that somebody can help me out here.
  8. Rupe

    Rupe New Member

    Joined:
    Jun 22, 2018
    Messages:
    3
    Location:
    Spain
    Balance:
    166Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    Arduino
    I have the same problem. Can someone help me?
  9. Nick Moxley

    Nick Moxley Well-Known Member

    Joined:
    Dec 13, 2013
    Messages:
    2,779
    Occupation:
    Owner/Operator- Moxleys Rantals
    Location:
    Winnipeg Manitoba Canada
    Balance:
    17,054Coins
    Ratings:
    +2,504 / 30 / -2
    My Motion Simulator:
    2DOF, 3DOF, DC motor, JRK
    Try Chained for encoders, There is a small bug in the build somewhere on encoders....going to chained fixed it.
  10. Rupe

    Rupe New Member

    Joined:
    Jun 22, 2018
    Messages:
    3
    Location:
    Spain
    Balance:
    166Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    Arduino
    What do you mean with chained?¿? I'm a newby.
    Thx
  11. Nick Moxley

    Nick Moxley Well-Known Member

    Joined:
    Dec 13, 2013
    Messages:
    2,779
    Occupation:
    Owner/Operator- Moxleys Rantals
    Location:
    Winnipeg Manitoba Canada
    Balance:
    17,054Coins
    Ratings:
    +2,504 / 30 / -2
    My Motion Simulator:
    2DOF, 3DOF, DC motor, JRK

    Options for Encoders are Single or Chained, Set them up in chained the same way you would single. That should solve it for you I would hope.
  12. Rupe

    Rupe New Member

    Joined:
    Jun 22, 2018
    Messages:
    3
    Location:
    Spain
    Balance:
    166Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    Arduino
    Ok that's perfect but... what do you mean with chained¿?¿¿
    Something like this??
    [​IMG]
  13. sel

    sel New Member

    Joined:
    Jun 24, 2018
    Messages:
    2
    Location:
    uk
    Balance:
    252Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    Arduino
    Hi, I'm trying to get started with this and have limited Arduino experience.
    My current issue is the Joystick library, I've placed it in the library folder but that's as far as I get as it doesn't show in the menu or Library Manager.

    There is an error message

    Invalid library found in N:\Program Files (x86)\Arduino\libraries\ArduinoJoystickLibrary-master: N:\Program Files (x86)\Arduino\libraries\ArduinoJoystickLibrary-master

    I also tried using Add zip Library but it still won't show and same error.

    Any Ideas on this one as I'm stumped.
  14. sel

    sel New Member

    Joined:
    Jun 24, 2018
    Messages:
    2
    Location:
    uk
    Balance:
    252Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    Arduino
    Never mind I sorted the problem, wrong library.
  15. Henrik

    Henrik New Member Gold Contributor

    Joined:
    Aug 13, 2017
    Messages:
    18
    Location:
    Sverige
    Balance:
    104Coins
    Ratings:
    +15 / 0 / -0
    I messed up the matrix, did not pay attantion to the instruktions "sry"
    Before i cut everything up, is there an way to define button presses by.
    Example: Pin10+pin14=Button12, Pin10+pin21=Button14, in the code?
    Because then i can make it without cutting.
    I got it working with 5 rotaries :)
  16. Henrik

    Henrik New Member Gold Contributor

    Joined:
    Aug 13, 2017
    Messages:
    18
    Location:
    Sverige
    Balance:
    104Coins
    Ratings:
    +15 / 0 / -0
    Never mind, it seams to be to complicated for me, after looking in the keypad library.
    So i resoldered 4 of the buttons and now all of them work.
  17. evolaco

    evolaco Member

    Joined:
    Sep 27, 2015
    Messages:
    260
    Location:
    Spain
    Balance:
    1,070Coins
    Ratings:
    +29 / 0 / -0
    My Motion Simulator:
    3DOF
    Can 6 encoder be used?
  18. JonBakhol

    JonBakhol Active Member

    Joined:
    Mar 16, 2018
    Messages:
    107
    Location:
    Netherlands harderwijk
    Balance:
    442Coins
    Ratings:
    +46 / 1 / -0
    My Motion Simulator:
    2DOF, DC motor, JRK
    Hi @Henrik ,

    I was wondering what sketch you are using for the 5 rotaries. This is because I'm busy with an F1 Steering also with 5 encoders and 25 buttons.
    Wheel like attached and using the matrix (also attached)
    RB13 Vrijgemaakt.jpg button layout-1.jpg

    I also attached my code, hopefully you can take look at it?

    Many thanks for now,

    Bakhol

    Code:
    //BUTTON BOX
    //USE w ProMicro
    //Tested in WIN10 + Assetto Corsa
    //AMSTUDIO
    //20.8.17
    
    #include <Keypad.h>
    #include <Joystick.h>
    
    #define ENABLE_PULLUPS
    #define NUMROTARIES 5
    #define NUMBUTTONS 16
    #define NUMROWS 4
    #define NUMCOLS 4
    
    
    byte buttons[NUMROWS][NUMCOLS] = {
      {0,1,2,3},
      {4,5,6,7},
      {8,9,10,11},
      {12,13,14,15},
     
    };
    
    struct rotariesdef {
      byte pin1;
      byte pin2;
      int ccwchar;
      int cwchar;
      volatile unsigned char state;
    };
    
    rotariesdef rotaries[NUMROTARIES] {
      {0,1,16,17,0},
      {2,3,18,19,0},
      {4,5,20,21,0},
      {6,7,22,23,0},
      {8,9,24,25,0},
    };
    
    #define DIR_CCW 0x10
    #define DIR_CW 0x20
    #define R_START 0x0
    
    #ifdef HALF_STEP
    #define R_CCW_BEGIN 0x1
    #define R_CW_BEGIN 0x2
    #define R_START_M 0x3
    #define R_CW_BEGIN_M 0x4
    #define R_CCW_BEGIN_M 0x5
    const unsigned char ttable[6][4] = {
      // R_START (00)
      {R_START_M,            R_CW_BEGIN,     R_CCW_BEGIN,  R_START},
      // R_CCW_BEGIN
      {R_START_M | DIR_CCW, R_START,        R_CCW_BEGIN,  R_START},
      // R_CW_BEGIN
      {R_START_M | DIR_CW,  R_CW_BEGIN,     R_START,      R_START},
      // R_START_M (11)
      {R_START_M,            R_CCW_BEGIN_M,  R_CW_BEGIN_M, R_START},
      // R_CW_BEGIN_M
      {R_START_M,            R_START_M,      R_CW_BEGIN_M, R_START | DIR_CW},
      // R_CCW_BEGIN_M
      {R_START_M,            R_CCW_BEGIN_M,  R_START_M,    R_START | DIR_CCW},
    };
    #else
    #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},
    };
    #endif
    
    byte rowPins[NUMROWS] = {21,20,19,18};
    byte colPins[NUMCOLS] = {15,14,16,10};
    
    Keypad buttbx = Keypad( makeKeymap(buttons), rowPins, colPins, NUMROWS, NUMCOLS);
    
    Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
      JOYSTICK_TYPE_JOYSTICK, 25, 0,
      false, false, false, false, false, false,
      false, false, false, false, false);
    
    void setup() {
      Joystick.begin();
      rotary_init();}
    
    void loop() {
    
      CheckAllEncoders();
    
      CheckAllButtons();
    
    }
    
    void CheckAllButtons(void) {
          if (buttbx.getKeys())
        {
           for (int i=0; i<LIST_MAX; i++)   
            {
               if ( buttbx.key[i].stateChanged )   
                {
                switch (buttbx.key[i].kstate) { 
                        case PRESSED:
                        case HOLD:
                                  Joystick.setButton(buttbx.key[i].kchar, 1);
                                  break;
                        case RELEASED:
                        case IDLE:
                                  Joystick.setButton(buttbx.key[i].kchar, 0);
                                  break;
                }
               }   
             }
         }
    }
    
    
    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
      }
    }
    
    
    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 == DIR_CCW) {
          Joystick.setButton(rotaries[i].ccwchar, 1); delay(50); Joystick.setButton(rotaries[i].ccwchar, 0);
        };
        if (result == DIR_CW) {
          Joystick.setButton(rotaries[i].cwchar, 1); delay(50); Joystick.setButton(rotaries[i].cwchar, 0);
        };
      }
    }
    • Like Like x 2
  19. dualin

    dualin Member

    Joined:
    Jul 11, 2012
    Messages:
    31
    Location:
    Cáceres - Spain
    Balance:
    - 41Coins
    Ratings:
    +4 / 2 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino
    Anyone can explain what is chained for the encoders? I make work the rotarys perfectly but the cst288 don't work fine. I can get only one pulsation every four.

    Regards
  20. ozkan memisoglu

    ozkan memisoglu New Member

    Joined:
    Sep 10, 2018
    Messages:
    2
    Balance:
    87Coins
    Ratings:
    +0 / 0 / -0
    How did you connect your Arduino Pro Micro to Arduino Leonardo. Can you show with diagrammatize thank you so much sorry for my english.