1. 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 Download Package Now!
  2. 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
  3. 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 here. Do not following these rules will lead to permanent exclusion from this website: Read the forum 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:
    771Coins
    Ratings:
    +195 / 0 / -0
    Hi all!

    I know, a lot of diyers use Teensy for building buttonboxes, but more choices is better, right? :)
    So I decided to share my ard's sketches.

    1st version is standard universal buttonbox. The sketch supports up to 25 buttons and up to 4 encoders.

    DSC_0335.JPG

    I use:
    - Arduino Pro Micro
    - 4 switches like this
    - 4 buttons like this
    - 3 encoders like this
    - box from local supplier

    Wiring is quite simple:

    scheme_buttsimp (1).jpg

    You can use any number of buttons up to 25 and any number of encoders up to 4 - no sketch modification is needed!
    For example, I use only 15 buttons (4 switches + 4 buttons + 3 encoders buttons), so my matrix is 4x4 and I wired it`s rows to 21, 20, 19, 18 pins and columns to 14, 16, 10, 9 pins


    Buttonbox acts as standard keyboard, it send chars which are defined in struct "buttons"
    char buttons[NUMROWS][NUMCOLS] = {
    {'q','w','e','r','t'},
    {'y','u','i','o','p'},
    {'a','s','d','f','g'},
    {'h','j','k','l','z'},
    {'x','c','v','b','n'},
    };
    You can change it to different chars if you needed.


    Also, in order to minimize possible interference with already assigned buttons I send keypressed with LEFT_CTRL + LEFT_ALT, so buttonbox send 3 keys combinations like LEFT_CTRL + LEFT_ALT + 'a' , LEFT_CTRL + LEFT_ALT +'w' , etc


    Encoder`s "keys" are defined in struct "rotaries":
    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},
    };
    I.e. first encoder acts like right arrow key when CCW rotation and left arrow key when CW rotation , etc




    ADDED 25.04.2016
    Also I wrote sketch which allows a buttonbox acts as joystick instead of keyboard. Wiring, capabilities, etc are the same, but windows sees device as Joystick
    You have to download Joystick library for it:
    https://github.com/MHeironimus/ArduinoJoystickLibrary
    And please be sure you are using Arduino IDE version 1.6.6 or above

    ADDED 03.11.2016
    Uploaded version 02b of joystick sketch. Virtual buttons are pressed for a duration of real buttons presses now.

    ADDED 28.01.2017
    Uploaded version 02c of joystick sketch. Added support of halfstep encoders, if you have those, uncomment the following line in the sketch
    //#define HALF_STEP

    ADDED 31.05.2017
    Uploaded version 02d of joystick sketch. Sketch adapted to V2 joystick library, also fixed issue with 4th encoder

    Attached Files:

    • Like x 16
    • Informative x 3
    • Winner x 2
    • Agree x 1
    • Useful x 1
    Last edited: May 31, 2017
  2. Ads Master

    Ads Master

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
  3. TOPMO3

    TOPMO3 Active Member

    Joined:
    May 12, 2015
    Messages:
    133
    Location:
    Russia
    Balance:
    771Coins
    Ratings:
    +195 / 0 / -0
    2nd version of buttonbox was build for iRacing pitting service. Idea is to form pit combo by special switches/encoders and then just push button and viola - pit combo was send!

    DSC_0322.JPG


    Short description:
    - red ON-OFF switches used for request to change tires - front (top one) and rear (bottom one)
    - green ON-OFF switches used for request to clear windscreen (left one) and fast repair (right one)
    - bottoms encoders acts like right & left arrow keys (left one) and up & down arrow keys (right one)
    - 2 spring return switches on right side used to request to increase/decrease tire`s pressure
    - encoder on the top-right used to indicating how much fuel to add
    - red button serves to send pit combo to iRacing


    Also I added led screen to view and check what pit combo will be. So on the pic above it shows (from left to right):
    - decrease both front & rear tires pressure by 7
    - change both & rear tires, clear windscreen and made fast repair
    - add 10 litres of fuel
    On the pic you can see corresponded pit combo sended to the game

    Wiring:

    scheme_buttpit11.jpg




    I use:
    - 4 ON-OFF switches
    - 3 encoders
    - 2 spring return switches
    - 1 max7219 based display (like this)
    - 6 1kOm resistors (used for OneWireKeyboard)

    Sketch is attached, you need to download RotaryEncoders library

    Attached Files:

    • Like Like x 8
    • Informative Informative x 2
    Last edited: Apr 16, 2016
  4. TFOU57

    TFOU57 Member

    Joined:
    Mar 30, 2009
    Messages:
    146
    Location:
    57100 Thionville ( France )
    Balance:
    5,828Coins
    Ratings:
    +15 / 1 / -0
    My Motion Simulator:
    3DOF, AC motor, Arduino, 4DOF
    interesting topic!
    Last edited: Jan 12, 2017
  5. michto35

    michto35 Member

    Joined:
    Jan 31, 2014
    Messages:
    98
    Location:
    france
    Balance:
    75Coins
    Ratings:
    +53 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino
    can you upload your photos because you no longer see them on the forum?
    I am interested in your project
    • Agree Agree x 1
  6. TOPMO3

    TOPMO3 Active Member

    Joined:
    May 12, 2015
    Messages:
    133
    Location:
    Russia
    Balance:
    771Coins
    Ratings:
    +195 / 0 / -0
    Hi @michto35 ,

    sorry for broken links, corrected them!
    • Like Like x 2
    • Winner Winner x 1
  7. michto35

    michto35 Member

    Joined:
    Jan 31, 2014
    Messages:
    98
    Location:
    france
    Balance:
    75Coins
    Ratings:
    +53 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino
  8. Claudemir

    Claudemir Member Gold Contributor

    Joined:
    Oct 22, 2012
    Messages:
    167
    Balance:
    138Coins
    Ratings:
    +32 / 1 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, Motion platform
    good afternoon ... @TOPMO3

    This botton if I understand well functions as a keyboard right?
    Very cool your project, congratulations!
    I have a question!
    as would cause the controller to be recognized automatically by Windows as unojy?
    I enjoyed the second version of its controller, but would very much like the second version had more push buttons.
    I would like to modify your design for this?

    20 push buttons
    2 Rotary Encoder
    1 potentiometer
    3 keys on / of
    I await a response Thank You!
  9. TOPMO3

    TOPMO3 Active Member

    Joined:
    May 12, 2015
    Messages:
    133
    Location:
    Russia
    Balance:
    771Coins
    Ratings:
    +195 / 0 / -0
    Hi @Claudemir , thanks for kind words

    Yes, its recognized by windows as standard keyboard

    Do you mean you prefer that the device acts as "Game Controller" instead of keyboard? I have a plan to make 2nd version of sketch which will allow device to act as a joystick, but its not realized yet.

    Here we have a problem that only 3 pins of arduino are left unused. its one of reasons why I made two BB instead of one and one of reasons why I was forced to implement "Analog" keyboard (with resistors) in 2nd version.
    You can use 2 of those 3 unused pins (18 and 19 pins becouse they are Analog, but 15 is not!) to connect additional analog wires (say 2 x 4 buttons), or use any 2 of those 3 pins to connect 1 encoder, but thats all
    I recommend you to make 2 separate BB (as I did), one for pits and 2nd for other actions. Or you can try bigger Ard like Due, but I expect you have to adapt the sketch to it.
    • Like Like x 1
    • Informative Informative x 1
    Last edited: Apr 18, 2016
  10. Claudemir

    Claudemir Member Gold Contributor

    Joined:
    Oct 22, 2012
    Messages:
    167
    Balance:
    138Coins
    Ratings:
    +32 / 1 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, Motion platform
    ola @TOPMO3
    I could be using one Arduino r3?
    I tried to use the codgo in one arduino but of an error in both versions!
    I will take a picture and show you ok?
  11. Claudemir

    Claudemir Member Gold Contributor

    Joined:
    Oct 22, 2012
    Messages:
    167
    Balance:
    138Coins
    Ratings:
    +32 / 1 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, Motion platform
    upload_2016-4-19_11-59-2.png










    buttpit.ino:1:24: error: LedControl.h: No such file or directory
    buttpit:57: error: 'Rotary' does not name a type
    buttpit:58: error: 'Rotary' does not name a type
    buttpit:59: error: 'Rotary' does not name a type
    buttpit:85: error: 'LedControl' does not name a type
    buttpit.ino: In function 'void setup()':
    buttpit:95: error: 'lc' was not declared in this scope
    buttpit:112: error: 'Keyboard' was not declared in this scope
    buttpit.ino: In function 'void ProcessPitCombo()':
    buttpit:141: error: 'Keyboard' was not declared in this scope
    buttpit:176: error: 'KEY_RETURN' was not declared in this scope
    buttpit.ino: In function 'void ShowPressures()':
    buttpit:189: error: 'lc' was not declared in this scope
    buttpit:195: error: 'lc' was not declared in this scope
    buttpit:202: error: 'lc' was not declared in this scope
    buttpit:209: error: 'lc' was not declared in this scope
    buttpit.ino: In function 'void CheckButtons()':
    buttpit:225: error: 'Keyboard' was not declared in this scope
    buttpit:225: error: 'KEY_ESC' was not declared in this scope
    buttpit:230: error: 'Keyboard' was not declared in this scope
    buttpit:230: error: 'KEY_TAB' was not declared in this scope
    buttpit:235: error: 'Keyboard' was not declared in this scope
    buttpit.ino: In function 'void CheckChangeEncoder()':
    buttpit:257: error: 'r3' was not declared in this scope
    buttpit:259: error: 'Keyboard' was not declared in this scope
    buttpit:259: error: 'DIR_CCW' was not declared in this scope
    buttpit:259: error: 'KEY_LEFT_ARROW' was not declared in this scope
    buttpit:259: error: 'KEY_RIGHT_ARROW' was not declared in this scope
    buttpit.ino: In function 'void CheckFuelEncoder()':
    buttpit:266: error: 'r1' was not declared in this scope
    buttpit:268: error: 'DIR_CCW' was not declared in this scope
    buttpit:269: error: 'DIR_CW' was not declared in this scope
    buttpit.ino: In function 'void CheckControlEncoder()':
    buttpit:275: error: 'r2' was not declared in this scope
    buttpit:277: error: 'Keyboard' was not declared in this scope
    buttpit:277: error: 'DIR_CCW' was not declared in this scope
    buttpit:277: error: 'KEY_UP_ARROW' was not declared in this scope
    buttpit:277: error: 'KEY_DOWN_ARROW' was not declared in this scope
    buttpit.ino: In function 'void ShowNumber(int, byte)':
    buttpit:288: error: 'lc' was not declared in this scope
    buttpit.ino: In function 'void ProcessSwitches()':
    buttpit:328: error: 'lc' was not declared in this scope
  12. TOPMO3

    TOPMO3 Active Member

    Joined:
    May 12, 2015
    Messages:
    133
    Location:
    Russia
    Balance:
    771Coins
    Ratings:
    +195 / 0 / -0
    Hi @Claudemir ,

    sorry, but you cant use UNO.
    You need Atmega32U4 based board - ie Leonardo, Micro, Esplora, Yun or Due and Zero. Only these Adrs can appear as a native Mouse and/or Keyboard to a connected computer.
    • Like Like x 1
    • Informative Informative x 1
  13. Claudemir

    Claudemir Member Gold Contributor

    Joined:
    Oct 22, 2012
    Messages:
    167
    Balance:
    138Coins
    Ratings:
    +32 / 1 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, Motion platform
    @TOPMO3 thanks for rapidas friend answers!:cheers
    I will buy a pro mini Atmega32U4, and make your project and very cool!hug:
    sorry so many questions!
    I do not understand the programming my grain of study and much less I thank a lot to help us cronstruir their projects.
    I work in the industrial mechanical aria and I am fascinated by electronics and what it can provide.
    this project from what I saw! has a protection for that not conflict with the keyboard I right?

    descupe'm using google translator !.;)
  14. TOPMO3

    TOPMO3 Active Member

    Joined:
    May 12, 2015
    Messages:
    133
    Location:
    Russia
    Balance:
    771Coins
    Ratings:
    +195 / 0 / -0
    Hi @Claudemir ,

    please take a note Pro Mini also doesn't work! Because its based on ATmega328, not ATmega32U4. You need Arduino Micro or Sparcfun Pro Micro

    Personally I use cheep version from our Chinese friends, but I can't recommend it to novice users, because very often those chinese boards arrived with some "strange" bootloader. The strangeness lies in the fact that after power on board works 4x slower than expected, but after RESET it works as it should. It can be cured by flashing original Micro bootloader to the board. And I have no idea, why they flashing such bad bootloaders.
    On the other side, because you already have UNO, you can reflashing bootloader quite easily, there are many tutorials on the web, take a look on this for example (Option 2: Using the Arduino as a Programmer)
    Or you can just wire additional button (on pins RESET and GND) and just press it every time when your PC is power oned.

    Added:
    There are no conflicts between your keyboard and arduino. Windows just see two keyboards and you can use both of them
    • Informative Informative x 4
    • Like Like x 1
    Last edited: Apr 20, 2016
  15. Claudemir

    Claudemir Member Gold Contributor

    Joined:
    Oct 22, 2012
    Messages:
    167
    Balance:
    138Coins
    Ratings:
    +32 / 1 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, Motion platform
    isso serve-me amigo?
    http://produto.mercadolivre.com.br/MLB-756659998-arduino-pro-micro-atmega32u4-cabo-usb-_JM Its main features are: - Microcontroller: ATmega32U4 (SMD); - USB Interface: The very ATmega32U4; - Operating Voltage (Chip): 5 VDC; - Power Supply (Recommended): 7 to 12 VDC (PINO RAW); - Supply Voltage (limits): 6 to 20 VDC (PINO RAW); - Supply Voltage (limits): 4.5 to 5.5 VDC (PINO RAW); - Pin I / O Digital: 12 (5 have PWM by hardware); - Analog Pins: 4 (10 Bit / 0 to 5 VDC); - DC current per pin I / O: 20mA; - DC current for 3.3V pin: 50mA; - Flash Memory 32KB (ATmega32u4) (4KB used by bootloader); - SRAM: 2.5 KB (ATmega32u4); - EEPROM: 1KB (ATmega32u4); - Clock Speed: 16MHz;
  16. TOPMO3

    TOPMO3 Active Member

    Joined:
    May 12, 2015
    Messages:
    133
    Location:
    Russia
    Balance:
    771Coins
    Ratings:
    +195 / 0 / -0
    Yes, its fine
  17. MAYA One

    MAYA One Member

    Joined:
    Jul 7, 2015
    Messages:
    36
    Location:
    china
    Balance:
    385Coins
    Ratings:
    +15 / 0 / -0
    My Motion Simulator:
    2DOF, SCN5
    Thank you, it is worth learning.
  18. TOPMO3

    TOPMO3 Active Member

    Joined:
    May 12, 2015
    Messages:
    133
    Location:
    Russia
    Balance:
    771Coins
    Ratings:
    +195 / 0 / -0
    If someone, for some reason prefer emulating game controller instead of keyboard, here's "joystick" sketch for 1st version.
    also added it to 1st post

    Attached Files:

    • Like Like x 2
  19. MAYA One

    MAYA One Member

    Joined:
    Jul 7, 2015
    Messages:
    36
    Location:
    china
    Balance:
    385Coins
    Ratings:
    +15 / 0 / -0
    My Motion Simulator:
    2DOF, SCN5
    2nd version of buttonbox only for iracing?
    I want to use it in the Dirt Rally.
  20. TOPMO3

    TOPMO3 Active Member

    Joined:
    May 12, 2015
    Messages:
    133
    Location:
    Russia
    Balance:
    771Coins
    Ratings:
    +195 / 0 / -0
    Hi @MAYA One ,

    yes, currently its only for iracing, because its highly depends on how game allows to act with it.
    For example, there are such thing as "pitting combo" in iracing,
    ie if you type #lf in chat - it means you want to change left tyre
    #lf rf - left and right tyres
    #lf +10 rf +10 - change left & right tyres and also add 10 clicks pressure
    and so on.
    So, sketch just emulates yours possible keyboard inputs. When you push "PIT" button, at first arduino sends "t" char to PC, thus involving text char, then it sends text string (your pit combo), once again just emulating keyboard inputs.

    I haven't Dirt Rally, so I don't know how pit service realized in it. If its somehow similar to iracing, then it would be not hard to adapt sketch to Dirt Rally
  21. TFOU57

    TFOU57 Member

    Joined:
    Mar 30, 2009
    Messages:
    146
    Location:
    57100 Thionville ( France )
    Balance:
    5,828Coins
    Ratings:
    +15 / 1 / -0
    My Motion Simulator:
    3DOF, AC motor, Arduino, 4DOF