How to make a pc controller to send commands to a specific game

I started playing Ship Simulator Extremes, and I got to thinking about what it would take to make a custom controller for it. At one point a device called the ShipDriver was produced, but it has been discontinued, doesn't do exactly what i want, and it's more fun to build than to buy.

What I'm thinking: A controller that should fit on your lap with things like two azimuth thrusters, rudder wheel, side engine thruster throttles, etc. It would also ideally communicate to the PC via bluetooth, since I play on the TV while sitting on the sofa. Buttons and flashy lights are a given.

I only have experience building the projects in the Arduino starter kit, so I know I have a lot to learn, but the big thing that seems like a mystery to me is how you would interface with the game. For example, how to tell it that the value coming from this potentiometer should should set the right engine throttle.

With a little bit of Googling it seems like the UnoJoy is a good way to present the controller to the PC, I'm just not sure how to "talk" to the game. (And how to build those azimuth throttles, but that's another question.)

Thanks for the help and the resources!

Have the arduino be a USB keyboard (I believe the Leonardo is the choice for this), and then remap the game controls to the USB keyboard, or have the arduino emulate the keystrokes required.

Marmotjr: Have the arduino be a USB keyboard (I believe the Leonardo is the choice for this), and then remap the game controls to the USB keyboard, or have the arduino emulate the keystrokes required.

Thanks for the reply Marmotjr!

That seems like it would be a good and simple way of handling the digital side of things, but what about all of the analog input for a game like this?

For example, a throttle lever: You would want pushing the throttle lever up to 50% to set the in-game throttle to 50%. Or you may want to mount a single thumbstick for manipulating the camera view.

That's what sensors and inputs are for.

Bow thruster? Two way switch under a lever. Rudder control? Rotary encoder on a wheel. Throttle? Pots on an arm.

Then the code interprets each input, processes it into keystrokes, and outputs the appropriate signal to the PC. I'm not familiar with the Leonardo and this application, but I have done quite a bit with USB keyboard emulators, take a look at nostromos loadout manager. I wonder if that could be adapted for this application.

As this is a custom job, you'll probably want custom controls made, and having a 3d printer helps. If you don't, you could make some from what you have lying around or go buy some, or check out a place like 3dhubs to have somebody print stuff out for you.

Thanks a ton for your help! I see what you mean. I think from here what I need to figure out is how to configure the game itself with analog inputs (I haven't seen that in the configuration settings so far).

If I can do that, the gist I get is that you push 50% forward on the throttle, the arduino reads the pot, interprets the value as 50% throttle, and then hands that information to the game. It's that last part that I'm fuzzy on, but I bet that's something game-configuration specific that I need to look up.

I plan on making whatever I can by hand. The controls seem fairly straightforward, as you mentioned, save for the azimuth thrusters which will need to be carefully combined (like a lever+pot for the throttle mounted on a wheel for the azimuth control).

I have played this game, but it's been a while, but it's more like if you want 40% throttle, there would be a key stroke (4 perhaps?) that would set the throttle to 40%. The arduino would read the sensors, and then output the 4 key to the PC. You would be turning a bunch of wheels and levers and switches into a keyboard.

See, that's what I'm trying to avoid. The throttle controls / engine rotation are analog in game. You can manipulate them freely by click-dragging them with the mouse, placing them wherever you like. The ShipDriver that used to be available recreated the real-life feel of the controls. Here's a youtube video of it in action.

I'm wanting to recreate that (with my own artistic liberties).

Edit: Here's a video with the game itself.

Then you would have the arduino emulate mouse clicks and drags at certain X,Y coordinates on the screen.

Eh. That seems highly undesirable (not handling screen resolution changes, imprecise, needing to be configured completely differently for different ships, nearly impossible to configure), and I highly doubt that's how the ShipDriver did things (It advertises as being able to be used for a variety of ship sims, and within this game seems to be plug-and-play for various ships).

It seems more likely to me that there is a way to configure analog input to various functions within the game.

That's what lead me to looking up things like the UnoJoy. They have various projects and state that it can be used to map both buttons and joysticks. While that alone alone takes me so far, my hope was that the analog support could be used for the mapping I would need for this project.

Based on this page:

http://www.shipdriver.com/support/

The "ship driver" appears to the PC as a couple (or more) USB HID devices - at minimum, a joystick/pad and a keyboard.

So, you would need to emulate -both- of those.

It appears from the sample code of UnoJoy, that it already supports analog sticks, in addition to the digital buttons. You should review those examples carefully.

For the keyboard, there is this library:

http://arduino.cc/en/Reference/MouseKeyboard

There might be others out there as well.

The trick will be to combine both the keyboard and unojoy (or whatever other joystick emulator library) you use together. They may or may not work well together. It might turn out ok - or you might find yourself needing to wade through both library's code bases, and coming up with something custom.

I would concentrate on getting one side, then the other operating independently; for instance, start with the UnoJoy library, and try to get it to take the input of a potentiometer, and have it output to the PC, looking like a HID joystick - and use some kind of testing program on the PC to see how it is working (don't try to use the game in the beginning). Then build up from there.

Once you have the number of controls needed (analog inputs from potentiometers, and button inputs) for the joystick side of things working and verified, go to the keyboard side.

Save a copy of your joystick code, then reload the arduino with your keyboard code, taking other inputs/buttons and mapping them to keypresses; again - don't use the game, instead open up notepad or something and have the output appear there.

Once you have something on both sides working in a test mode, then try each out with the game. Make sure they are working ok, and fix anything you find at this stage.

Then - work on combining your codebases and the libraries together; this might be the most difficult part of the project, or it might be the simplest. One thing you might run into, is memory issues; for the number of inputs you need, though, you'll probably have to go with a Mega anyhow.

Thanks for the input cr0sh! That's very helpful.

I think I'll start (as you said) by loading up UnoJoy onto my arduino, connecting a pot, and getting that working with some test code. From there, I'll probably then move to seeing if I can get the game configured with that input. I figure if I can turn the pot itself and have that operate the rudder, or set the throttle, etc., that's enough to know I can at least make a decent set of controls.

From there I'll look at integrating UnoJoy with a keyboard library for keystrokes. I do believe I'll be going with an Arduino mega, and the author of UnoJoy has a similar project - MegaJoy - just for that. Between two engine throttles + rotation, fore and aft thrusters, and rudder, I'm seeing at least 7 joystick axes.