Recommended Posts

So I'm working on a project to create a custom home made controller for KSP using an arduino mega but I am very new to using an arduino and with talking to the game so I was wondering if anyone could help me with getting a single switch when flipped to progress to the next stage of a rocket (in my eyes this is on the easier end of controls to figure out but I'm a moron and even from my research I have been getting confused. I think I need to use  zitronen's KSPSerialIO mod but I'm not sure this is what I need again I'm just looking for help with one switch to change one thing on the game (the switch is a off - momentary on type of switch so a "push button")

Please and thank you.

Share this post


Link to post
Share on other sites

Hi EccentricTea and welcome to the forum. :)

Your thread has been moved to the Fan Works area, where you will find and be found by several other people who have worked on similar projects. Good luck with it. 

Share this post


Link to post
Share on other sites

Hi EccentricTea, and welcome to the forum

A stage button is  manageable to do from KSPSerialIO, and a good place to start. I recommend doing it in steps if you are new.

First of all, try to do the tutorials on the arduino webpage, section 1 and section 2 until debounce. That will give you the basics of how to connect components and write code for the Arduino. Bookmark the reference section while your at it, you will come to know it intimately over the next period of time if you want to make your own controller.

Second, install KSPSerialIO as you would any other mod. The big hitch here is that it only works out of the box on Windows, excluding Windows 10. There is a Mac/Linux port by Stibbons, linked here. Windows 10 is pretty much hit and miss depending on your exact hardware, as the original Arduinos and most copies use a USB chip that does not talk to Unity.

Thirdly, the demo code included has a tab called output. In this file, the function controls() shows how to alter a state from a button:

    if (digitalRead(SASPIN))  //--------- This is how you do main controls
      MainControls(SAS, HIGH);
    else
      MainControls(SAS, LOW);

in the above SASPIN just means 8 and SAS means 7, as zitronen uses defined constants to make things easier to remember. Maincontrols is a function that changes state of the bit you tell it to. You want to change the state of the bit STAGE, so you can pick a digital pin, for example 2 (0 and 1 are reserved) and connect a button. Then change above piece of code to:

    if (digitalRead(2))  // Read digital pin 2
      MainControls(STAGE, HIGH);
    else
      MainControls(STAGE, LOW);

Then you will stage by pressing a button connected to digital pin 2. Be sure to upload a picture or a small video of it working so we can see it and applaud.

Once you are that far, you definitely want to connect a throttle if you have not got one on a joystick. It is the single best improvement in control scheme you can have. Feel free to ask more questions either here or in the KSPSerialIO thread, where people are extremely helpful.

Slight word of warning though: Controllers can fast become a separate time consuming and quite expensive hobby. I started knowing nothing three years ago, now collecting parts for another major rebuild, an have sunk well over a hundred euro into the project by now because I keep getting new ideas about what could be cool to have. Buy components from China over Ebay to keep the cost down.

Share this post


Link to post
Share on other sites
Posted (edited)
16 hours ago, Freshmeat said:

First of all, try to do the tutorials on the arduino webpage, section 1 and section 2 until debounce. That will give you the basics of how to connect components and write code for the Arduino. Bookmark the reference section while your at it, you will come to know it intimately over the next period of time if you want to make your own controller.

The only addition I could make to @Freshmeat's excellent overview is that you'll also need to be familiar with how the Blink Without Delay example sketch works. You'll need to be able to do your debouncing and other stuff without using the delay function.

EDIT: Ooops, looks like blink without delay is already covered before debouncing. I'll just crawl back in to serial testing cave.

Edited by stibbons

Share this post


Link to post
Share on other sites

@Freshmeat and @stibbons 

Thank you for the help, you have given me enough information and direction for me to hopefully figure things out now. I'll definitely keep you guys posted we have the wooden beta version of the control panel pretty much figured out I can get some photos to show you guys once I figure out how to upload photos here if not we have a website (that needs updating) that we try and post statuses up there.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now