Jump to content

[Hardware, Plugin] Arduino based physical display + serial port io+ tutorial (24-11-19)


zitronen

Recommended Posts

2 hours ago, Kerbal007 said:

Hi all and a big hug to @zitronen

I have been mucking around with this and struggling enjoyably and read that on windows 10 input was no longer accepted yet my pot is working! Is this because it is analog as opposed to digital?

I have not wired a button up yet :) #noob #learningcode

EDIT 2: I got it! this is the best day ever

The issue is with a specific IC chip on the arduino or wrong driver on your PC as far as I know. So you just got lucky in terms of what IC was used by the designer of your specific arduino (I think genuine ones don't work while knockoff Chinese ones work a lot of the time?) . As for analog vs digital, all the data is converted to digital anyways when being sent over the Serial interface, so it doesn't matter ;)

Edited by c4ooo
Link to comment
Share on other sites

Oh, thanks for the feedback. I know my arduino does not like keyboard.h but its nothing special, I picked it up at jaycar in a starter kit XC3902. 

Now that I have some "essential functions" im going to dive into how the mod works :). 

Link to comment
Share on other sites

22 hours ago, Kerbal007 said:

Can someone point me to a source where i can understand why we #define vs const in the sketch please?

"#define" defines a macro that gets replaced by the preproccessor before your code even gets to the compiler. Macros are really just dumb text replacements and should be treated as such, but that's not to say they aren't handy. "const" is a language feature that gets interpreted by the compiler, and has type safety and other features just like any other variable. Both are equally useful for defining stuff like I/O pin numbers, but #define macros can also be used for compile-time #if#else blocks.

 

Edited by c4ooo
Link to comment
Share on other sites

First of all thanks @zitronen. I really Like this project.

Based on this project I have created an ethernet based version of KSPSerialIO with an Android client running on any mobile phone. With that all those who don't have the electrical equipment to build an Arduino input device can now simply use their mobile phones.

In the next step I want to extend the App and also create a RaspberryPi client.

If you are interested take a look at

Maybe it's possible to add the link to the original post?

Link to comment
Share on other sites

Built a console with this plugin a few years ago. Haven't played in a while (had a kid) and built a new computer. Can't seem to get it working again. I don't even get the message on the launch pad that it is looking for a com port. Does the plugin work with 1.9 with breaking ground installed? I'll admit I haven't installed a plugin in a while, so I might not have done that correctly. I wish it had a "readme" in the folder saying copy this folder into your <whatever> location...

Link to comment
Share on other sites

  • 2 weeks later...

the bare minimum works well on  new PC; Win10; V 1.9.1; COM3.   

BUT the mod doesn´t appear in the  miniAVC-window or i´m too dumb in readin´ ;-)
btw. the KSP starts in notime with 81 ! mods - or was it a failure to install on SSD ´cause of the Unity-Cache write-process ? 

- great job, finding the issue with the COMports after all this years!  

Edited by sec3
Link to comment
Share on other sites

  • 2 weeks later...

Hello everyone!

Since some weeks ago I'm working in my own controller. @zitronen thank you for the work done and for sharing it here!

Programming and building hardware is not new for me but it's the first time that I work in an Arduino project used as an interface with a PC program/game. I hope to start my own thread soon and show you my progress.

So far I have a prototype code which implements almost all functions that I want to implement in my controller. But I'm completely stuck in setting the SAS Modes! I've tried several iterations of the base code, but I'm not able to select any other mode than just the "SAS" one. I've been reviewing all the pages of this post since this feature was implemented in the Plugin and with the directions given by @c4ooo but I still haven't found what I'm missing to make it work.

In my code I have the code showed below, it's basically the baseline code but adapted to implement an additional SAS Mode. Anyone knows what I'm doing wrong? I'm sure that I'm failing in a very basic thing!

This is defined in the main tab


//pins for input
#define PROGRADEPIN 12
  
//Input enums
#define PROGRADE 8

Code in the output tab:

void controls() {
  if (Connected) {

    if (digitalRead(SASPIN)) { //--------- This is how you do main controls
      MainControls(SAS, HIGH);
      setSASMode(SMSAS); //setting SAS mode
    }

    //Tested also standalone (without the previous lines and just with an "IF")
    else if (digitalRead(PROGRADEPIN)){ //same estructure as above
      MainControls(PROGRADE, HIGH); //Input enum for PROGRADE SAS Mode
      setSASMode(SMPrograde); //Setting SMPrograde 
    }
    
    else {
      //setNavballMode(NAVBallTARGET);
      MainControls(SAS, LOW);
    }

    KSPBoardSendData(details(CPacket));
  }
}

Controls are also initialized:

void controlsInit() {

  pinMode(PROGRADEPIN, INPUT_PULLUP);

}

Thank you for the help in advance Kerbonauts!

Link to comment
Share on other sites

Ah I think it's because you are using

MainControls(PROGRADE, HIGH); 

If you set MainControls(PROGRADE = 8) you are actually turning on action group 3. The list of things that can be controlled by MainControls() are

//Action group statuses
#define AGSAS      0
#define AGRCS      1
#define AGLight    2
#define AGGear     3
#define AGBrakes   4
#define AGAbort    5
#define AGCustom01 6
#define AGCustom02 7
#define AGCustom03 8
#define AGCustom04 9
#define AGCustom05 10
#define AGCustom06 11
#define AGCustom07 12
#define AGCustom08 13
#define AGCustom09 14
#define AGCustom10 15

What you should do is

else if (digitalRead(PROGRADEPIN)){ //same estructure as above
      MainControls(SAS, HIGH); //Input enum for PROGRADE SAS Mode
      setSASMode(SMPrograde); //Setting SMPrograde 
    }
    
    

 

Link to comment
Share on other sites

Hello Zitronen,

Thank you for your quick answer.

I think that I've tried this before but I've just tried again to check what happens but the result is the same.

With your code above, what happens is that once I activate the assigned pin the SAS activates, but not the prograde mode :(

EDIT: I'm trying to simplify the problem by just forcing a value in the setSASMode Control Packet. But the result it's the same. If I remove the "MainControls" line nothing occurs (SAS or any other modes are not activated). It was a long shot :|

void controls() {
  if (Connected) {

    if (digitalRead(PROGRADEPIN)){
      MainControls(SAS, HIGH); //Tested with and without this line
      setSASMode();     
    }
   
    else {
      //setNavballMode(NAVBallTARGET);
      MainControls(SAS, LOW);
    }

 

void setSASMode() {
//  CPacket.NavballSASMode &= B11110000;
//  CPacket.NavballSASMode += m;
  CPacket.NavballSASMode &= B11110011; //Forcing a value different to default value
}

 

Edited by OKB_Carba
Additional info added
Link to comment
Share on other sites

On 11/24/2019 at 9:50 PM, zitronen said:

Update 0.19.2:

Changes:

  • Fixed very old bug of auto detection and connection with high number (>10) COM ports, thanks to detective work from @Jimbofarrar

Plugin download link:

https://sites.google.com/site/zitronfiles/KSPSerialIO_019_2.zip

Arduino code dowload:

https://sites.google.com/site/zitronfiles/KSPIODemo17.zip

Could you update or share your source code please. I would like to add some soi numbers for JNSQ Mod on the latest source.

Link to comment
Share on other sites

I found a bug regarding the stages LiquidFuel and Oxidizer.

When I use any kind of radial engine like RV-1 or Mk-55, the values of LiquidFuelS and LiquidFuelTotS are always 0.

When I use a classic engine under the fuel tank it works well.

Link to comment
Share on other sites

On 3/10/2020 at 8:12 PM, Wurmi said:

Could you update or share your source code please. I would like to add some soi numbers for JNSQ Mod on the latest source.

This is already on github, please check first post.

Link to comment
Share on other sites

On 3/10/2020 at 6:30 PM, OKB_Carba said:

Hello Zitronen,

Thank you for your quick answer.

I think that I've tried this before but I've just tried again to check what happens but the result is the same.

With your code above, what happens is that once I activate the assigned pin the SAS activates, but not the prograde mode :(

EDIT: I'm trying to simplify the problem by just forcing a value in the setSASMode Control Packet. But the result it's the same. If I remove the "MainControls" line nothing occurs (SAS or any other modes are not activated). It was a long shot :|


void controls() {
  if (Connected) {

    if (digitalRead(PROGRADEPIN)){
      MainControls(SAS, HIGH); //Tested with and without this line
      setSASMode();     
    }
   
    else {
      //setNavballMode(NAVBallTARGET);
      MainControls(SAS, LOW);
    }

 


void setSASMode() {
//  CPacket.NavballSASMode &= B11110000;
//  CPacket.NavballSASMode += m;
  CPacket.NavballSASMode &= B11110011; //Forcing a value different to default value
}

 

Hi @OKB_Carba

I figured out what's wrong. Changing SAS mode only works when SAS is already on! Completely forgot about this. It was designed to be used with more than one switches, one to turn SAS on, and others to change mode. So if you have two pins, you can do this:

 

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

    if (digitalRead(CG1PIN))  
      setSASMode(SMPrograde); //setting SAS mode to prograde
    else
      setSASMode(SMSAS); //setting SAS mode to normal

If you only want to use a single switch you will have to manually code something in the if statement like (not tested, but should work):

if (inputpin == high)
{
	MainControls(SAS, HIGH);

	if ((ControlStatus(AGSAS) == True) && (getSASMode() != SMPrograde)) //if control group SAS is on and not in prograde mode
		setSASMode(SMPrograde)
	else 
		...
}
else
	...

Sorry about the confusion.

 

 

On 3/18/2020 at 7:01 PM, Tabb said:

I found a bug regarding the stages LiquidFuel and Oxidizer.

When I use any kind of radial engine like RV-1 or Mk-55, the values of LiquidFuelS and LiquidFuelTotS are always 0.

When I use a classic engine under the fuel tank it works well.

Unfortunately, because the fuel code I stole from mechjeb only works by traversing through connection nodes, surface attached engines don't work.

I have no idea how to fix this, I had to copy stuff from more competent people just to get fuel working.

Edited by zitronen
Link to comment
Share on other sites

Hi All,

Thanks for working on this plugin and providing plenty of examples. I got my first arduino and started building a controller a couple of months ago now- it's been a fun hobby to explore and have learned a lot. I have been able to incrementally add /debug controls and displays but am recently finding some frustrating problems that seem to be on the KSP end. I have tried using KSP 1.7 and 1.9 and have the same problems.

1. I just recently got my joystick in the mail and have it hooked up to control attitude. The joystick works great, however my problem is with the SAS- it turns on and off around the SASTol threshold, however, it doesn't actually do anything when it's on. The pitch/yaw/roll indicators in the bottom left stay at 0 unless I'm using the joystick.

2. The throttle control action group doesn't work. With the Breaking Ground DLC parts you can assign motor RPM or blade pitch etc. to increase with throttle, but this won't work while I'm using my controller throttle. The throttle indicator on the navball still goes up and down, and any regular engines throttle, but somehow that isn't being communicated to the action group. I think this is also the case with the pitch/yaw groups.

Has anyone had similar problems or have any ideas? I've read through most of this thread at and haven't seen these problems.

Edited by Bearskinz
Link to comment
Share on other sites

On 3/30/2020 at 5:39 PM, Bearskinz said:

Hi All,

Thanks for working on this plugin and providing plenty of examples. I got my first arduino and started building a controller a couple of months ago now- it's been a fun hobby to explore and have learned a lot. I have been able to incrementally add /debug controls and displays but am recently finding some frustrating problems that seem to be on the KSP end. I have tried using KSP 1.7 and 1.9 and have the same problems.

1. I just recently got my joystick in the mail and have it hooked up to control attitude. The joystick works great, however my problem is with the SAS- it turns on and off around the SASTol threshold, however, it doesn't actually do anything when it's on. The pitch/yaw/roll indicators in the bottom left stay at 0 unless I'm using the joystick.

2. The throttle control action group doesn't work. With the Breaking Ground DLC parts you can assign motor RPM or blade pitch etc. to increase with throttle, but this won't work while I'm using my controller throttle. The throttle indicator on the navball still goes up and down, and any regular engines throttle, but somehow that isn't being communicated to the action group. I think this is also the case with the pitch/yaw groups.

Has anyone had similar problems or have any ideas? I've read through most of this thread at and haven't seen these problems.

The SAS thing unfortunately is the only way I can get axes to work. Not an optimal solution, I recommend using an arduino leo in USB HID joystick mode and directly bind them in KSP input options. This might also solve your second problem as well.

 

Link to comment
Share on other sites

  • 1 month later...

First of all, @zitronen thank you vey much for your excellent job.
KSPSerialIO is amazing. I'm trying to make a Kerbal Controller, and I enjoy a lot playing with that plugin ans testing new ways to use it.

I know there are some mods for KSP that allows to use more than 10 action groups (Action Groups Extended, Action Groups ReExtended...). Is there any way to use it with KSPSerialIO?

I don't know how to include more info in the ControlPacket sent to KSP.

Is there anyone that has made it?

Thanks.

See you in space...

Link to comment
Share on other sites

7 hours ago, Carrot7 said:

Does 2-way communication work with windows 10?

Yes. I have Windows 10 Pro, and it's working in both directions:

In exampe, I can light LEDs or show data in LCS screens with information sent from KSP to Arduino, and I also can use buttons and switches to send information from Arduino to KSP.

Link to comment
Share on other sites

5 hours ago, sandroxil said:

Yes. I have Windows 10 Pro, and it's working in both directions:

In exampe, I can light LEDs or show data in LCS screens with information sent from KSP to Arduino, and I also can use buttons and switches to send information from Arduino to KSP.

Thank You sandroxil, much appreciated.

Link to comment
Share on other sites

On 5/15/2020 at 6:24 PM, sandroxil said:

First of all, @zitronen thank you vey much for your excellent job.
KSPSerialIO is amazing. I'm trying to make a Kerbal Controller, and I enjoy a lot playing with that plugin ans testing new ways to use it.

I know there are some mods for KSP that allows to use more than 10 action groups (Action Groups Extended, Action Groups ReExtended...). Is there any way to use it with KSPSerialIO?

I don't know how to include more info in the ControlPacket sent to KSP.

Is there anyone that has made it?

Thanks.

See you in space...

Unfortunately not right now. I think we talked about it back in the days. Getting more info in the controlpacket is easy, but getting things working with other mods will be annoying, you have to worry about which version of KSPSerialIO supports which version of AGE, for which version of KSP. When KSP updates you have to make sure both mods are updated. Then also you have to make sure things don't break for people who don't use AGE...

An easier work around is just to use an Arduino Leo in keyboard emulation mode and bind the keys to AG(R)E.

Edited by zitronen
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...