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. 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. 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. 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. 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!
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
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
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.
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…
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.
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.
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
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!
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?
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.
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…
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…
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
There is not a Digikey “kit” for this. I purchased the blank aluminum enclosure box from there and designed/drilled out the holes myself. Here is a link to the enclosure: https://www.digikey.com/en/products...jaqw3fRJd2TIkHTi0gIsiJd4CXeS9WxK-6Inmnr_8ZO0z
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... 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. 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.
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...
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!
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.
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!
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).
Figured it. All running now. Tried TSW2 and Zusi and it really is fantastic. Thanks for the inspiration!
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
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.
Slightly different approach Not so generic, as it simulates only two loco types, but that feeling must be unforgettable...
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?
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.
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
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.