KerbalController: a Custom Control Panel for Rocket Game Kerbal Space Program

57,829

343

97

About: I always like to learn something new, but rarely finish what I start.

Why build a KerbalController?

Well, because pushing buttons and throwing physical switches feels so much more substantial than clicking your mouse. Especially when it's a big red safety switch, where you have to open the cover first, flick the switch to arm your rocket, start the countdown and 3 .. 2 .. 1 .. we have liftoff!

What is a KerbalController?

A KerbalController, also referred to as a Control Panel, Simpit (simulated cockpit), DSKY (display keyboard) or custom joystick, is a customized input device for controlling the popular rocket-building-and-flying-and-hopefully-not-exploding game Kerbal Space Program combined with optional output from the game, such as status lights, telemetry displays and/or fuel gauges.

This specific build includes inputs such as rotation and translation controls through joysticks, a throttle slider, loads of buttons with status lights, LED fuel gauges and a telemetry LCD display with multiple modes.

This guide will include everything you need to build an identical copy, or make adjustments and improvements along the way, as you see fit. Included are:

  • a parts list
  • digital design drawings ready for lasercutting
  • wiring instructions
  • Arduino code
  • Code for the accompanying KSP plugin
  • Lots of pictures

Ready for takeoff? Let's go!

Step 1: The Tools

The most important tool you need to have for this build is a soldering iron. That includes some solder, a metal cleaning sponge to clean the tip of the soldering iron and a "third hand".

Other tools are a wire stripper, a wire cutter, tweezers and some small size screwdrivers.

Step 2: Parts and Basic Layout

Making the best possible controller for you means selecting exactly which buttons and switches you want to implement. Because everybody plays the game differently. Some people fly planes and build SSTO's (single-stage-to-orbit). Others prefer rovers of space stations. And some just want things to spectacularly explode!

It helps to draw all the parts in their approximate size and drag them around in a vector drawing program (like Affinity Designer or Inkscape) or 3D drawing program (like SketchUp).

If you want an easier build, you can just copy my controller and get the parts listed on the attached parts list.

Step 3: Create a Prototype (optional)

If you are copying my controller, you can skip this step.

If you are going for a custom layout, I recommend using a shoe box first to create a working prototype with the main controls. It really helps to fine tune the position of the main controls. It's also nice to get the confidence you can get it to work before you continue to invest time and money in the final build. I actually played the game for quite a while with my shoe box controller. Isn't it the Kerbal way to use salvaged parts to hack something together?

Step 4: Tips on Wiring

When creating a prototype, don't solder all your buttons in unless you want to de-solder them when you get to the final enclosure. I soldered some wires to the buttons and used a solderless breadboard to make the temporary connections to the Arduino.

When connecting all electronics to the final faceplate, you can reduce clutter by creating loops for 5V and ground. You don't connect all ground pins directly to the Arduino, but rather connect ground on one button to ground on the next button and loop all around. Finally, you connect to the Arduino.

After creating loops for power and ground, all the connections to the Arduino pins remain. I recommend getting some strips of header pins and soldering the wires to those. You can use these as a big connector, so you can still unplug your Arduino for testing.

The length of the wires is a balancing act between short enough to keep the enclosure free of excess tangles of wire (which might prevent you from being able to close the box) and long enough to be able to move parts out of the way to solder other parts in, tighten screws and poke around with your multimeter while debugging.

Step 5: Getting the Faceplate Lasercut

Achieving a clean, professional look is very hard when sawing and painting by hand. Luckily, laser cutting is not very expensive any more. It allows for extreme precision, as long as your design is accurate.

Attached is my faceplate design, in formats appropriate for Affinity Designer and other vector drawing programs like the free InkScape.

I had the faceplate lasercut in The Netherlands at Lichtzwaard. They have since closed and activities have been taken over by Laserbeest, where I had the box laser cut. Every shop may have different requirements for the design, so check with your shop before submitting. They also almost always offer design help at an hourly rate.

Important things to keep in mind:

  • Everything must be vector based. That's why the logo in my faceplate design didn't get etched. Note this is not fixed in the designs attached.
  • Even text has the be vector based. So convert those letters into curves!
  • Measure. Measure. Measure. I failed to take into account the size required for mounting the joysticks and had to hack it. Turned out fine, luckily. Note this is fixed in the attached designs.

After checking everything thoroughly, send it to the lasercutting shop. Expect to pay 40-50 euros in The Netherlands and get this beautiful result in the mail the next day!

Step 6: Hooking Up Buttons and Switches

Most switches and buttons have the connectors labeled C, NO, NC, +, -. Here's how to hook them up to the Arduino.

Simple switch or pushbutton:

  • Ground --> C (common)
  • Arduino digital pin --> NO (normally open)

We will configure the digital pin as INPUT_PULLUP, which means the Arduino will keep the pin at 5V and detect when the pin gets grounded and treat that as an input. The NO connector on the switch or button is Normally Open, so the circuit is not connected. When you push the button or toggle the switch, the circuit gets closed and the pin gets grounded.

Pushbutton with LED:

The button part is the same as above. For the LED, you attach additional wires:

  • Ground --> - (negative)
  • Arduino digital pin --> + (positive)

This part is pretty straightforward. We will use the Arduino pin in normal OUTPUT mode.

Safety switches with LED:

These are a bit different and do not allow control over the LED independent from the switch position. The LED will always only light up when the switch is toggled on. They have a +, - and signal connector.

  • Ground --> - (negative)
  • 5V --> + (positive)
  • Arduino digital pin --> S (signal)

We will use the Arduino pin in INPUT mode. When the switch is toggled on, the LED lights up and the signal pin goes high.

Step 7: Hooking Up Joysticks and the LCD

LCD

The LCD is very simple. It just needs power, ground and serial.

  • 5V --> VDD
  • Ground --> GND
  • Arduino Tx PIN --> RX

You can use a JST connector or solder the wires to the board directly.

Joysticks

The joysticks might look daunting at first, but they are quite easy to connect. There are three axis that are connected in the same way. Two of them are using the connectors on the bottom of the joystick. The third uses some wires.

  • Ground
  • Wiper --> Arduino analog input pin
  • 5V

The connectors can be attached in this order. Don't worry about getting it backwards, the wiper is always the middle one. If power and ground are swapped, we can flip the axis around in the Arduino code later.

The wires might have a different colouring scheme on your joystick, but in general: the two wires with identical colours are for the button on top. Red or orange is 5V, Black or brown is Ground. The remaining wire is the wiper.

Step 8: LED Bar Fuel Gauges

Okay. This is the hardest part of the entire build. Feel free to skip this on your first build, or improve it and let me know!

I got these great LED bars I want to use as fuel gauges. The top LED is blue, then some green, then orange and finally red. If we can light one LED at a time, we can let it represent the fuel level on our spacecraft.

I initially ordered driver IC's with them. They work great! You can select dot mode or bar mode and it will display an analogue input voltage as a single LED (dot) or a range of LEDs (bar). But an Arduino does not output an analogue voltage! And the PWM feature that allows you to dim a LED by sort of emulating an analogue voltage, does not work with these driver IC's.

On to plan 2: shift registers. You get to work with these in every Arduino starter kit. And you can learn more about them here: https://www.arduino.cc/en/Tutorial/ShiftOut

The plan is to somehow convert the fuel levels into the proper string of bits that will represent the fuel levels on the LED bars. With 5 fuel gauges, all fuel levels filled up would need to be 10000000001000000000100000000010000000001000000000. With monopropellant empty, it would become: 10000000001000000000100000000010000000000000000001.

Sound simple enough. There are some complications. The shift registers have 8 pins, while the LED bars have 10 LEDs. I use 7 shift registers to get 56 outputs. When wiring them in, I skipped an IC pin somewhere (we'll fit that in code). And I wiring one LED bar in starting at the other end (we'll fix that in code). Oh and Arduino math that we need sometimes uses floating point arithmetic which causes rounding errors (we'll fix that in code). Note that I share the code in a later step.

My final build did not match the attached wiring diagram, so if you rebuild this controller, some updates are required to the code. Comment below if you need assistance.

Every LED requires it's own resistor. Try some different values in order to match the brightness. Green appears much brighter than red with the same resistors, so it helps to balance that out.

End result: instead of 50 digital pins required to power the 5 LED bars, that is reduced to 3: a clock signal, a latch signal and a data signal.

Step 9: Building the Enclosure

Time to get my revenge with those logo's!

I converted the logo's to proper vector drawings so they get etched just fine. This time, I have a different issue. The screw holes are not in the right places for proper assembly of the box. I used 6mm MDF for the box. Unfortunately, screwing of nailing into the edges causes them to split. I hacked it together with additional wood scraps and glue. Lot's of glue.

For those of you that are better with wood, glue and/or nails, I have attached a version of the designs without the screw holes altogether.

Despite the difficulties, the end result is quite slick.

Step 10: Software and Testing

Download the following software to make the controller work with Kerbal Space Program:

KSP plugin: https://github.com/hugopeeters/KSPSerialIO

The ZIP file is the compiled plugin. The rest is source code you can use to modify the plugin and compile your own version. Unpack the plugin into the GamaData directory.

Arduino Code: https://github.com/hugopeeters/KerbalController

Use the Arduino IDE to upload the code onto the Arduino Mega in your controller.

Look at the bottom right of the Arduino IDE to figure out which serial port the controller is on (e.g. /dev/cu.usbmodem1421). Open the config.xml file from the plugin directory and make sure your port is filled in. Now you are good to go!

You can use debug mode by putting the small on/off switch top left into the ON position. The LCD should display a string of letters. Each letter represents a button or switch and switches between lower and upper case when you press the button or toggle the switch. Setting the xyz switches into Xyz (on/off/off) will also display the throttle slider values. xYz displays joystick values for the Translation (left) joystick. xyZ for the Rotation (right) joystick.

LCD Modes

The following display modes can be selected for display on the LCD by using the x, y and z switches.

TakeOff Mode:     Suface Velocity / Acceleration (G)   
Orbit Mode:       Apoapsis + Time to Apoapsis / Periapsis + Time to Periapsis
Maneuver Mode:    Time to next maneuver node / Remaining Delta-V for next node
Rendezvous Mode:  Distance to target / Velocity relative to target
Re-Entry Mode:    Percentage overheating (max) /   Deceleration (G)
Flying Mode:      Altitude / Mach number
Landing Mode:     Radar Altitude / Vertical Velocity
Extra Mode:       not implemented (yet)

To see the different modes in action, look at the video at the end of the instructable.

Step 11: To the Moon!

Fire up KSP, load your favourite vessel, or build a new one and off you go!

Tips:

  • Use custom action group 5 for your ladders
  • Use custom action group 6 for your solar panels
  • Use custom action group 7 for parachutes or drogue chutes
  • Assign the launch escape system and the appropriate decouplers to the Abort action group
  • Don't forget you need to Arm the Staging button
Arduino Contest 2017

Runner Up in the
Arduino Contest 2017

First Time Author Contest 2018

Runner Up in the
First Time Author Contest 2018

Epilog Challenge 9

Participated in the
Epilog Challenge 9

Share

    Recommendations

    • Sensors Contest

      Sensors Contest
    • Sew Tough Challenge

      Sew Tough Challenge
    • Growing Beyond Earth Maker Contest

      Growing Beyond Earth Maker Contest

    97 Discussions

    0
    None
    mightyevo

    Question 3 months ago on Step 8

    Hi.
    i was hoping you could update us to what you have done with the shift registers. am mid build and realise i dont fully "get" this part. thanks

    1 answer
    0
    None
    hugopeetersmightyevo

    Answer 4 days ago

    Sorry for the late reply. I understand that is the hardest part. I messed up the wiring in a few places and adjusted for that in my code. You will have to adjust the code a bit to your own cabling. Let me know what exactly you need help with and I'll try to explain better.

    0
    None
    zardiax3

    Question 5 months ago on Step 4

    où peut-on avoir le schéma de cablage svp

    0
    None
    Crowsjunker

    7 months ago

    HugoPeters! Incredible job with this. You (and the countless other KSP modders) inspired me make my own! I was working with the same joysticks you use in this and I was banging my head against the wall trying to figure out why the Z axis was eternally wonky! I took a step back and began sifting through your code and stumbled on this.

    if(analogRead(pRZ) <= 40){CPacket.Roll = constrain(map(analogRead(pRZ),0,40,-1000,0),-1000,0);}
    else if(analogRead(pRZ) >= 60){CPacket.Roll = constrain(map(analogRead(pRZ),60,500,0,1000),0,1000);}
    else {CPacket.Roll = 0;}

    Seeing this, I realized that the Z axis seems like it was just as wonky for you! I decided to test a second joystick and found the same thing. a wonky z-axis! I was doubtful that between you and I we had gotten 4 defective sticks.
    I took stick apart, hoping that there was something impacting the Z-pot - but found nothing - UNTIL I realized that it was wired wrong! (read: I had it wired wrong). It goes against logic (at least in mind) - but the z axis pot is wired so that BLACK is the wiper, not white!

    I changed my wiring and presto - my z-axis produces results just like X or Y!
    It just so happens that I took a close up look at the pictures you posted and, like I did initially, you used white as the wiper (wiper--->analog input pin)! It looks like it's a pain to change, but FWIW, I'll bet if you make black the wiper - it will no longer be wonky for you!


    TLDR: For those joysticks, black is the z-axis wiper, not white!

    Love the controller! Thanks again for the inspiration!!!

    1 reply
    0
    None
    RobertoG124

    Question 8 months ago

    hi hugopeeters
    excuse my English.
    I'm building your project, i like your job.
    I have a problem, after loading the arduino code and launching KERBAL, (wiht or without the Joysticks connected) the x, y and z axes display are not zero, they display flipping values move and the kerbal ship derive from corect path. I think it is possible to solve this problem by acting on the code but I do not understand how to do it.
    Please help me, I tried to change the arduino board by buying a new one but the problem continues.

    1 answer
    0
    None
    hugopeetersRobertoG124

    Reply 8 months ago

    Every joystick will have slightly different resistance values and deadspace. You need to tweak the numbers in the define_controlpacket.ino file. For example:
    if(analogRead(pRX) >= 530){CPacket.Yaw = constrain(map(analogRead(pRX),1023,530,-1000,0),-1000,0);}
    else if(analogRead(pRX) <= 470){CPacket.Yaw = constrain(map(analogRead(pRX),470,0,0,1000),0,1000);}
    else {CPacket.Yaw = 0;}

    This indicates my values on this axis center around 500 and I added 30 plus and minus as dead space, because it jitters between 470 and 530.
    0
    None
    kerbal9

    Question 9 months ago on Step 3

    You've inspired me to try making a small controller. I've had an Uno sitting in a drawer for years and I've dusted it off and just got Unojoy working. I'm really new when it comes to the wiring side of things. Do you have any schematics I could follow as an example? I see the instructable has the code, but without knowing what is wired where, I don't know how to use it.

    Thanks!

    1 answer
    0
    None
    hugopeeterskerbal9

    Answer 8 months ago

    That's cool! Step 6 has info on wiring individual buttons and switches. When wiring multiple, you can daisy-chain all the ground connections together to limit the cable mess.

    0
    None
    joedude

    Question 10 months ago

    Great project!

    I've been playing with this project but unfortunately it seems I fried my Mega2560... My new plan is to make the project work with a Uno or Nano and some 74HC165 shift registers. My shift registers are interfacing with the arduinos, but I can't seem to get the Arduino Uno or Nano to talk to KSP.... is there something in the sketch that I could change to make it work?

    1
    None
    carl_burton82

    10 months ago

    This is incredible. I am a total novice and learning as I go along. Thanks for all the guidance. I am struggling with the arduino code and testing certain functions of the controls. Is there a way to monitor the commands? I have been trying to use the serial monitor, but can't get any data to plot up on there. Im not sure if I'm just wiring the stuff up wrong. I basically wanted to mock up each button separately on a bread board and test its signal to arduino, (similar to the started lessons the give you) does the code require the power buttons to be also built into the system, or will it only work with all pins. If you have any more pictures of the completed wiring that would be amazing. By the way, it is by far the best one I have seen on the the internet. So huge hats off to you on a. Taking the time to make it for yourself, and b. being really kind and sharing all of your hard work. Thanks

    1 reply
    0
    None
    hugopeeterscarl_burton82

    Reply 10 months ago

    Hi Carl, thanks for the compliments! If you are unsure of the wiring of a button or switch, I woudl recommend you start with a simple new Arduino sketch like this: https://learn.adafruit.com/adafruit-arduino-lesson... If you follow this example, the final part talks about using the Serial Monitor.

    Since the final controller also uses software serial to talk to the KSP plugin, it becomes more difficult to use the serial monitor for debugging.

    0
    None
    AlphaFireBeast.

    Question 1 year ago

    i cut out the base of the box but it was so small it didnt fit the lid of the box what are the bottom boxes dimensions?

    1 answer
    0
    None
    hugopeetersAlphaFireBeast.

    Answer 1 year ago

    The vector drawing includes a 10x10mm square you can use for scaling. The width of the base should be 300mm if I recall correctly.

    0
    None
    hugopeetersAlphaFireBeast.

    Answer 1 year ago

    I don't. Are the instructions per button in steps 6 and 7 clear enough for you? You can use a breadboard and jumper wires at first to test each button and output individually before you solder things permanently. If you have a specific question about connecting one of the components, let me know and I'll try to clarify.

    0
    None
    WillB119

    Question 1 year ago

    I am using the exact same joysticks as listed in the excel sheet. My board slowly (in the matter of about 5 seconds)powers down and reboots if either joystick is twisted along the z axis clockwise only. Did you have this issue?

    2 answers
    0
    None
    Hati_spWillB119

    Answer 1 year ago

    Had the same problem. For my joysticks, the internal wiring of the z-axis was done wrong by the manufacturer (black was the wipper and white the ground). I simply opened them and resoldered the wires. Or you could just change the wiring in your controller. Hope this helps!

    0
    None
    hugopeetersWillB119

    Answer 1 year ago

    Yes. When you twist them too far clockwise, the resistance drops too far. You should be able to solve that by putting a resistor in series with that axis.

    how much would it cost to have someone else make it and buy it from them?