Arduino Controller Build

Discussion in 'General Discussion' started by Whitsim, Sep 10, 2021.

  1. Whitsim

    Whitsim Member

    Joined:
    Dec 26, 2020
    Messages:
    53
    Likes Received:
    62
    Hi all,
    Long time TS user but a bit of a lurker when it comes to the forums. I just wanted to share the controller setup that I just finished building based on an Arduino Micro.
    [​IMG]
    I designed it to be a somewhat generic cab layout to be used with pretty much any stock type rather than a specific model. The throttle, brake, and horn switches are known as joystick switches which are sprung single axis switches that send the corresponding keystroke. You can either get a single keystroke by briefly pressing it or holding it down acts just like holding a key on a regular keyboard. While it would be nice to have actual moving levers and notches, the immersion factor works quite nicely. Most of the basic train operation functions are now used without touching the keyboard.
    [​IMG]
    The Arduino Micro basically sends key commands based on switch input just like a normal keyboard would. Most of the hardware was bought off of Amazon and a huge online electronics parts store called Digi-Key. The most expensive component was the aluminum enclosure which was $40 USD. Overall, everything was under $150 USD.
    [​IMG]
    The actual code is relatively simple “Keyboard Library” that sends key presses when a switch is activated. The fact that it’s generic allows it to be compatible with basically every piece of stock. I can easily modify the code to rewrite the buttons with minimal effort to change their function.
    [​IMG]
    Starting at the top, going left to right I’ve programmed up the following:

    Top Row
    Red - Load/Unload (T)
    Yellow - Close Doors (R)
    Black Rotary - DRA (Y)
    Joystick Switch - Loco Brake ( [ / ] )
    Blue - Guard Signal (C)

    Next Row:
    Black Rotary - Reverser (W/S)
    Joystick Switch - Throttle (A/D)
    Green - Sander (X)
    Joystick Switch - Hi/Low Horn (B/Space)
    Yellow Mushroom - AWS (Q)
    Joystick Switch - Train Brake ( ; / ‘ )

    I’m pretty savvy with electronics but this was my first real experience playing with an Arduino and doing some very basic coding. I was hesitant to get started but I’m glad I did. It was a fun project and the finished project completely changes the immersion level for me. I recommend others give it a go!
     
    Last edited: Sep 10, 2021
    • Like Like x 17
    • Helpful Helpful x 1
  2. paul.pavlinovich

    paul.pavlinovich Well-Known Member

    Joined:
    Aug 21, 2020
    Messages:
    1,684
    Likes Received:
    1,994
    I'm impressed with your workmanship and its a little cheaper than Raildriver if you don't count your time. Nice one.

    You don't need to send characters btw. TS has an API foTS2021 r external controllers. This might give you some ideas
    This one only reads from TS https://github.com/alios/raildriver (ignore the name, it works regardless of whether you have an actual Raildriver or not and this one can also write back https://github.com/lilopkins/libraildriver and you might find this one the most use of all https://www.railsimulator.net/wsif/entry/677-ts2017-raildriver-and-joystick-interface/

    Paul
     
    • Like Like x 1
  3. ntypeman

    ntypeman Well-Known Member

    Joined:
    Jun 19, 2018
    Messages:
    1,052
    Likes Received:
    269
    Whitsim...

    very impressed... I'd like to do something similar... Not sure about coding though...

    I'd love to see working gauges / instruments at some point...

    Eric
     
    • Like Like x 1
  4. Whitsim

    Whitsim Member

    Joined:
    Dec 26, 2020
    Messages:
    53
    Likes Received:
    62
    Thanks Paul for that info. It may be something to tinker with one day.

    It was easier than you think, Eric. It basically was the same basic few lines of code for each button function just copied and pasted. I can gladly share the whole thing if you ever decide to give it a go.
     
    • Like Like x 1
  5. DIFFLOCK

    DIFFLOCK Active Member

    Joined:
    Jan 27, 2021
    Messages:
    276
    Likes Received:
    107
    Impressive controller you have there! :cool:
     
    • Like Like x 1
  6. Whitsim

    Whitsim Member

    Joined:
    Dec 26, 2020
    Messages:
    53
    Likes Received:
    62
    Just an update, I was having some issues with momentary key commands on a few locos with braking and sand. After some time investigating, it turns out that the HID Keyboard was actually sending rapid repeat keypresses rather than one long momentary keypress. After lots of experimentation, I reprogrammed the Arduino Micro as an HID Joystick and am using JoyToKey now to send the keys. It works absolutely flawlessly including all AP stock. No issues at all. Down the road I might experiment with the Raildriver interfaces mentioned above.
    I can’t even imagine ever going back to a keyboard at this point…
     
    • Like Like x 2
  7. paul.pavlinovich

    paul.pavlinovich Well-Known Member

    Joined:
    Aug 21, 2020
    Messages:
    1,684
    Likes Received:
    1,994
    Sounds like you're having fun there Whitsim using a controller of any fashion blows away the keyboard totally. Based on your success I'm contemplating building an Alerter button and set of PZB buttons. I kind of think I might cheat though and use a big button programable keyboard for this. They're sometimes used on cash registers and similar so hopefully won't be too hard to find.
     
    • Like Like x 1
  8. ntypeman

    ntypeman Well-Known Member

    Joined:
    Jun 19, 2018
    Messages:
    1,052
    Likes Received:
    269
    Whitsim...

    How much were your horn / "joystick" controllers please???

    Eric
     
  9. Whitsim

    Whitsim Member

    Joined:
    Dec 26, 2020
    Messages:
    53
    Likes Received:
    62
    I got my switches off eBay but I’ve also seen them on Amazon too. The common term is “Joystick Switch”. The ones I got and you see online are essentially cheaper knockoffs of expensive industrial switches. The universal part number is XD2PA22CR regardless of brand so look that up. I’m pretty sure they eBay/Amazon ones are all the same exact switch, probably from the same factory, but just a different label depending on distributor. Just make sure you get 2-way “momentary” or “non-latching”. The latch ones will not spring back to center. I paid about $11.00USD each from a US seller, but I’ve seen them as low as $5.00USD each if you want to wait for shipping from China.
     
    • Like Like x 1
  10. ntypeman

    ntypeman Well-Known Member

    Joined:
    Jun 19, 2018
    Messages:
    1,052
    Likes Received:
    269
    Thanks Whitsim...

    Much appreciated...

    Eric
     
  11. paul.pavlinovich

    paul.pavlinovich Well-Known Member

    Joined:
    Aug 21, 2020
    Messages:
    1,684
    Likes Received:
    1,994
    Have a look at your local electronics or electrical retailer too, those kind of switches are commonly available and even non knockoff ones are usually decently priced. Even nice metal light up ones :)
    These examples are from Australia but there will be some kind of retailer wherever you are from. Arduino and other similar single board computers combined with covid lockdowns have given these little electronic shops a breath of new life.
    https://www.jaycar.com.au/green-19m...os=4&queryId=e854949172ef53b2776c996438a5ec73
    or more basic ones for half the price
    https://www.jaycar.com.au/red-momen...os=2&queryId=e117c61bddabf516552750d4174b7349
     
  12. Whitsim

    Whitsim Member

    Joined:
    Dec 26, 2020
    Messages:
    53
    Likes Received:
    62
    I made a quick video showing the basic operation and how the joystick switches operate.
     
    • Like Like x 2
    • Helpful Helpful x 1
  13. rover75

    rover75 New Member

    Joined:
    Sep 6, 2021
    Messages:
    12
    Likes Received:
    4
    Very nice
     
    • Like Like x 1
  14. paul.pavlinovich

    paul.pavlinovich Well-Known Member

    Joined:
    Aug 21, 2020
    Messages:
    1,684
    Likes Received:
    1,994
    Grand work Whitsim you should think about selling them :)
     
    • Like Like x 1
  15. Whitsim

    Whitsim Member

    Joined:
    Dec 26, 2020
    Messages:
    53
    Likes Received:
    62
    I barely have time to actually use it much less build more. I’ll stick to being a DIY controller motivator and consultant for now!
     
    • Like Like x 2
  16. DTG Jamie

    DTG Jamie Staff Member

    Joined:
    Aug 24, 2020
    Messages:
    1,426
    Likes Received:
    5,353
    Well done, looks brilliant.
     
    • Like Like x 1
  17. 749006

    749006 Well-Known Member

    Joined:
    Dec 10, 2016
    Messages:
    8,420
    Likes Received:
    2,675
    When you opened the power controller do you have to do one notch at a time and the same when you shut off?
    And how does it work for diesel locos that don't have a notched controller?
     
  18. Whitsim

    Whitsim Member

    Joined:
    Dec 26, 2020
    Messages:
    53
    Likes Received:
    62
    It works the same way as a regular keyboard would on notchless throttles or brakes. The length of time you hold down the switch would be identical the time a keyboard button was held. You can slam the throttle fully on or off by holding down the switch. The same for the brakes. Also, holding the horn will make as long of a tone as you want.
     
    • Like Like x 1
    • Helpful Helpful x 1
  19. 749006

    749006 Well-Known Member

    Joined:
    Dec 10, 2016
    Messages:
    8,420
    Likes Received:
    2,675
    Thanks - very helpful
     
  20. Whitsim

    Whitsim Member

    Joined:
    Dec 26, 2020
    Messages:
    53
    Likes Received:
    62
    I just put together a very quick video using an AP Class 37 to show how it works with notchless throttle and brakes.



    Now time for a cold one and a proper drive…
     
    • Helpful Helpful x 2
    • Like Like x 1
  21. Whitsim

    Whitsim Member

    Joined:
    Dec 26, 2020
    Messages:
    53
    Likes Received:
    62
    I’m not normally one for a Class 101 drive but I gave it a go tonight using the controller. I cloned the JoyToKey profile specifically for the 101 to use the loco brake lever as the gear lever. What a difference when changing gears, dare I say it was manageable.

    Here’s a quick demo video showing the basic features in action…

     
    • Like Like x 1
    • Helpful Helpful x 1
  22. malikrthr

    malikrthr Well-Known Member

    Joined:
    Mar 1, 2019
    Messages:
    764
    Likes Received:
    1,260
    That is an impressive creation. Great job on constructing an Arduino based controller for Train Simulator. I remember utilizing the Arduino UNO microcontroller during my undergraduate studies. I would be interested in constructing this as a hobby project for use in Train Simulator. Interesting to note that Digi-Key electronics has a kit to start this project
     
    • Like Like x 2
  23. paul.pavlinovich

    paul.pavlinovich Well-Known Member

    Joined:
    Aug 21, 2020
    Messages:
    1,684
    Likes Received:
    1,994
    It looks great in your video :)
     
    • Like Like x 1
  24. ntypeman

    ntypeman Well-Known Member

    Joined:
    Jun 19, 2018
    Messages:
    1,052
    Likes Received:
    269
    Have you a link to this please???

    Eric
     
  25. Whitsim

    Whitsim Member

    Joined:
    Dec 26, 2020
    Messages:
    53
    Likes Received:
    62
  26. Whitsim

    Whitsim Member

    Joined:
    Dec 26, 2020
    Messages:
    53
    Likes Received:
    62
    [​IMG]
    A few weeks ago I stumbled across an AWS reset button assembly on eBay from a company that was scrapping Class 313s and picked it up as the latest thing to tinker with. It arrived in amazingly good shape as on this type it was mounted below the console with only the metal button protruding above the cab panel. I also purchased a small aluminum enclosure to use as a base to mount the unit. Behold the latest addition to my little setup...
    [​IMG]
    I still had an empty pin on the Arduino Micro so I decided to use a 3.5mm headphone jack and plug as a way to interface this standalone module to the rest of the panel. For now, I’m using the old yellow mushroom on the main panel as DSD. Should I decide to pack it up or move it around, I can simply unplug the AWS unit from the main console.
    [​IMG]
    I’m happy with the way it came out and the modular extension part of it has me wondering what may be next. Plus, I have a nice little piece of history still doing what it was meant to do, albeit virtually.
     
    • Like Like x 4
    • Helpful Helpful x 1
  27. ntypeman

    ntypeman Well-Known Member

    Joined:
    Jun 19, 2018
    Messages:
    1,052
    Likes Received:
    269
    Whitsim...

    Can you tell me the company is or who the seller is on ebay please???

    Eric
     
  28. Whitsim

    Whitsim Member

    Joined:
    Dec 26, 2020
    Messages:
    53
    Likes Received:
    62
    Jags222
     
    • Like Like x 1
  29. ntypeman

    ntypeman Well-Known Member

    Joined:
    Jun 19, 2018
    Messages:
    1,052
    Likes Received:
    269
    Thanks Whitsim...
     
  30. Whitsim

    Whitsim Member

    Joined:
    Dec 26, 2020
    Messages:
    53
    Likes Received:
    62
    [​IMG]

    Just an update, I’ve made a few additional hardware changes and additional Joy-To-Key profiles...

    First, I replaced the DRA rotary switch that was in the top row center with a yellow pushbutton to be used as a “Guard signal”. While the DRA was an interesting interface, it was rarely used and otherwise space on my setup that could be better utilized. Back to using the mouse for that now...

    Second, I also swapped out two of the other pushbuttons with different colors to closer replicate typical door control colors. This basically allows for separate right and left “doors open” (red) and “doors close” (blue). On stock with simplified door operation, the right and left doors aren’t typically separated so they are both simply programmed to the standard “load/unload” T-key. However, on more advanced AP and JT stock simulating DOO, I cloned and created an additional Joy-To-Key profile to map the left “doors open” button to the T/U-keys and right “doors open” button to the T/O-keys. The blue button is “doors close” R-key.

    So now I basically have 3 Joy-To-Key profiles. The first version is for typical stock with simple door operations . The second version is for 1st generation DMUs with a geared throttle in lieu of the loco brake. The third one is for AP/JT stock with advanced DOO door operation mentioned above.

    As always, I hope this inspires others to give creating some DIY hardware a go. The immersion takes it to a whole new level...
     
    • Like Like x 2
    • Helpful Helpful x 1
  31. LCYCowboy

    LCYCowboy Member

    Joined:
    Aug 23, 2021
    Messages:
    71
    Likes Received:
    77
    I'm really interested in building one of these. I've found the joysticks and the Arduino controller and breakout board, but could you possible point me in the direction of the buttons and rotary switches you have used? Also, where did you get the enclosure from?

    Thanks for any Help!
     
  32. Whitsim

    Whitsim Member

    Joined:
    Dec 26, 2020
    Messages:
    53
    Likes Received:
    62
    Hi,
    Scroll above and you’ll see detailed info on the Actuator Switches and Enclosure.

    The actuator switches I got off eBay at a better price but you can also get them from Amazon. The enclosure and some miscellaneous items like board standoffs and USB jacks was from DigiKey. The rest of the push buttons and rotaries were off Amazon, nothing fancy.

    Taiss / 3pcs 22mm 10A 440V 1NO... https://www.amazon.com/dp/B07GPJ6876?ref=ppx_pop_mob_ap_share

    APIELE (Pack of 2) 22mm 3... https://www.amazon.com/dp/B091B62D6W?ref=ppx_pop_mob_ap_share

    Hope this helps.
     
    Last edited: Jan 30, 2022
  33. LCYCowboy

    LCYCowboy Member

    Joined:
    Aug 23, 2021
    Messages:
    71
    Likes Received:
    77
    RIght, I've ordered all the bits! I'm going for a more German setup. AFB, Throttle, Brakes, Dynamic brakes and loc brakes on the joystick, then a SIFA acknowledge button, two door buttons and three PZB toggles. I'm hoping it will all go well. I've got all the internals including the micro board and the breakout bars. The only thing I am really nervous about is the programming. I haven't touched code since I programmed a game in Basic on my ZX Spectrum 40 years ago!!!!! I might ask politely if you can help me! I am so looking forward to this. I'll be able to use the controller for Zusi as well (currently I have my Saitek/warthog mapped to it, but Zusi just mimics keyboard inputs too, so this should work well). Thanks for the inspiration!
     
  34. LCYCowboy

    LCYCowboy Member

    Joined:
    Aug 23, 2021
    Messages:
    71
    Likes Received:
    77
    I've finally recieved all my parts today and built the controller (which I really enjoyed). I was wondering, could I borrow your HID joystick sketch so that I could modify it (I don't really have a clue how it all works). WhatsApp Image 2022-02-28 at 15.40.05.jpeg WhatsApp Image 2022-02-28 at 15.40.04.jpeg
     
    • Like Like x 1
  35. LCYCowboy

    LCYCowboy Member

    Joined:
    Aug 23, 2021
    Messages:
    71
    Likes Received:
    77
    Figured it. All running now. Tried TSW2 and Zusi and it really is fantastic.

    Thanks for the inspiration!

    signal-2022-02-28-202952_001.jpeg signal-2022-02-28-202952_002.jpeg
     
    • Like Like x 5
  36. Whitsim

    Whitsim Member

    Joined:
    Dec 26, 2020
    Messages:
    53
    Likes Received:
    62
    Great job, looks awesome! :)
     
  37. Philbo

    Philbo New Member

    Joined:
    Jun 28, 2023
    Messages:
    15
    Likes Received:
    7
    Nice job. No wonder you have won me over. I was going with a different shape but I see now that your design is sensible.
    Now that the dust has settled are you happy with the button count and types used?
    Which is better, 4 or 5 joystick switches?
    I like the master switch on yours but I also like the short paddle switches on lccowboys unit.
    (please excuse if I got that username wrong.)
    [edit]
    Oh, almost forgot... would you be happier with more real estate to rest your hands/forearms?
    philbo
     
    Last edited: Jun 28, 2023
  38. dolanbaker

    dolanbaker Active Member

    Joined:
    Dec 29, 2022
    Messages:
    115
    Likes Received:
    69
    Great projects, I went a slightly different route a couple of years ago and used the module from an old keyboard and simply brought out wires directly connected to switches and buttons. I also built an arduino based controller with analogue dials for speed RMM etc, but it was too bulky to use so went back to the basic keyboard controller. console.jpg
     
  39. kiski

    kiski Member

    Joined:
    Apr 27, 2018
    Messages:
    86
    Likes Received:
    54
    Slightly different approach ;)



    Not so generic, as it simulates only two loco types, but that feeling must be unforgettable...
     
    • Like Like x 1
  40. dolanbaker

    dolanbaker Active Member

    Joined:
    Dec 29, 2022
    Messages:
    115
    Likes Received:
    69
    Looks like he managed to get the dash from a real loco, I would like to know how he got the simulator to run over two screens.
    Is that possible on TSC?
     
  41. kiski

    kiski Member

    Joined:
    Apr 27, 2018
    Messages:
    86
    Likes Received:
    54
    Indeed it is from real loco, damaged after an accident and not able to be repaired again. In CZ/SK there are many loco graveyards where you can get those, price is always a matter of discussion.
    About those two monitors - I do not know, maybe it is possible from the beginning.
     
    • Like Like x 1
  42. Philbo

    Philbo New Member

    Joined:
    Jun 28, 2023
    Messages:
    15
    Likes Received:
    7
    I hope I am your level Whitsim; decent at electronics but no programming since my Turbo Pascal days aka looong time ago. Soon find out I guess. Can you tell me the name of the breakout board, the one that sits next to the Micro. I can't find that configuration and it seems I should use the same. Also, when I look up Train Sim on Steam I get lots of TSW3 stuff. Please, what is the exact name of the simulator that Paul says actually has an API? Is TS aka Train Simulator Classic?
    Thanks in advance,
    phil
     
    • Helpful Helpful x 1
  43. noaholivet#7296

    noaholivet#7296 New Member

    Joined:
    Oct 28, 2023
    Messages:
    1
    Likes Received:
    0
    hello everyone, i bought everything to make a controller like yours. but i'm having a bit of trouble with the code, could you please share it with me so i can take a cue from it.
     

Share This Page