Arduino Button Box And Lever Control For Console

Discussion in 'Creators Club' started by Stephen Crofts, Apr 5, 2021.

  1. Stephen Crofts

    Stephen Crofts Well-Known Member

    Joined:
    Aug 24, 2020
    Messages:
    859
    Likes Received:
    890
    A year or so ago I made myself an arduino button box for car racing games on a PS4. This year I’ve tried to adapt it for TSW2 by adding potentiometers to make lever controls like those on a BR blue era diesel.

    The impetus for this project was trying to drive hud-less. With the buttons on the PS4 controller I couldn’t tell what notch the throttle or brake was in, so I was looking for a way to roughly physically tell me what percentage throttle or brake was being applied.

    I wanted throttle, train and loco brake and reverser to be on levers. The recent keyboard binds for doors have made the button box so much more immersive, and binding one button to take rail fan shots has taken away the delay of holding the square button on the PS4 controller, which often missed a good shot through its delay. Now it’s instant!

    I’m not an electronics or diy genius so what I’ve got here are adaptations built on the code and ideas of others. But I’ve been pleasantly surprised at how reasonable it is at giving good control for tsw.

    I’ve set up 2 arduinos. One is a pure button box made with a tiny bit of diy effort. The other hosts the levers on an admittedly shoddy plastic box which has played the role of proof of concept test-bed until I have time to set up something better.

    The arduinos needed for this are the Leonardo or the older pro-micro, both of which have the controllers embedded onboard to act as a usb keyboard which can talk to the PS4 or Xbox very happily.

    One of the arduinos controls a keypad matrix. The matrix is 21 buttons, in a 3x7 arrangement. The matrix currently is as is, without diodes protecting each component (I learnt about key-press ghosting well after soldering this board up), but it really shouldn’t be hard to add those in and doesn't cause much issue without them as normally we only use one button at a time.

    Separate from the keypad matrix are some rotary encoders used for the car game. They have limited usefulness in tsw, but I’ve got them in use, so the code for controlling these is included.

    The first arduino's circuit is split over 2 board either side of a carracing wheel. The circuits are joined by 3.5mm audio jack and sockets.

    The 2nd arduino controls the levers, and a second keypad.
    The potentiometers are 10kOhm 6mm shaft.
    Lastly I had an old PS3 analog control stick mounted onto a control board lying around, so I set that up to use as a 2 tone horn in one direction and to change gear on the class 101 in the other direction. The horn function responds well, even getting over the delay between tones when using an ordinary keyboard. However, I can’t get the gear shift to work on the 101, despite the code looking sound.
    As I’m using 6 analog inputs on this circuit so the arduino needs to be the Leonardo, other types have only 4 analog pins.

    Attached are some circuit diagrams for anyone interested and the code I used for each arduino.

    There are others with more finesse in electronics than I that can add their knowledge, but I share this for the fun it provided me and as a example of how simulation as a hobby can extend one’s skills in others areas too.

    NB. There are limitations with this lever system:
    The levers are detecting a change in resistance which the code translates into a series of ‘notch’ numbers.
    Each ‘notch’ sends a keyboard button press from the arduino to the console. There are no physical notches, but the number of ‘notches’ can be changed in the code to change the sensitivity of the lever.
    The downside is that for a loco that only needs a little input (eg the Javelin) there is a lot of lever movement left over that won’t do anything, meaning that if the lever is moved further, the in game lever position and the arduino lever position won’t necessarily be in the same place each time. However, on other locos the number of ‘notches’ I’ve programmed is about right and even for those with needing less sensitivity, it isn’t unplayable.
    I’m going to look into setting up some more switches to change the sensitivity of the levers for specific locos at some point.

    The only other thing I would change if I re-wire at any point would be to get potentiometers with much much more friction in the shaft. I thought these were tight enough, but they are actually quite fluid with the levers attached.

    It’s rough and ready, but I now have something a step closer to mimicking rail driver like controls for a console, and it’s meeting my intention of trying to drive without the hud! Driving the class 20 into the ore terminal on TVL by lever is thoroughly enjoyable, and a little closer to the real driver’s skill of driving by feel rather button.

    Thanks for reading this far!

    78d0ae7feed56c95e1e8d6ac69827063.jpeg 986ba6c0c698f976e7ae23f837247cf9.jpeg b982b20e1fbe2c8f0b57404c993b3823.jpeg
     

    Attached Files:

    • Like Like x 1
  2. Stephen Crofts

    Stephen Crofts Well-Known Member

    Joined:
    Aug 24, 2020
    Messages:
    859
    Likes Received:
    890
    Here is the file for the circuit diagrams for anyone that's interested.
     

    Attached Files:

  3. Stephen Crofts

    Stephen Crofts Well-Known Member

    Joined:
    Aug 24, 2020
    Messages:
    859
    Likes Received:
    890
    I’ve recently updated the code for both button boxes and added controls for changing the sensitivity of the levers.
    For those interested in the doing something similar the updated code is attached below.

    Changes for Box A code include:
    Cab camera button now additionally controls the centre dot when you are in the cab.
    The task list button will change to a rail fan shot button when you choose an outside camera.
    The reset camera button now has a long press mode that brings up the task list
    The Free cam button, once pressed now has a long press that activates the shift key. Using the controller, you can now fly around quickly by holding this button down.
    AWS button, now has a long press function that releases the emergency brake valve.

    Changes for Box B (the lever box) include:
    • Apart from the Emergency valve function, all the above buttons have been recoded to match box A.
    • 2 simple dpst switches to control the sensitivity of the throttle and brake levers on the fly are now wired into the last 3 available pins on the Arduino Leonardo.
    One switch chooses throttle or brake, the other switches the chosen lever from low, default or high sensitivity.
    Useful for locos with only a few notches like the javelin or a control wheel witch many graduations.
    As a guide BR blue locos work well with the default sensitivity. It isn't perfect but it is an improvement.

    Unfortunately the gear change for the class 101 still won’t work, but for other locos it does seem to act on the throttle notch by notch. I’ve no idea why as the logic in the code shouldn’t be letting it!!
     

    Attached Files:

Share This Page