Jump to content

[KSP 1.10.0] Kerbal Simpit: A KSP serial mod for hardware controllers (1.4.1)


stibbons

Recommended Posts

Can anyone help me debug this? Pretty simple code. I want it to turn on the onboard LED when the SAS button is pressed. At the moment it does not do this. (The example files work however :))

 

#include "KerbalSimpit.h"

KerbalSimpit mySimpit(Serial);

void setup() {
  Serial.begin(115200);
  
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);
  
  while (!mySimpit.init()) {
    delay(100);
  }
  
  digitalWrite(LED_BUILTIN, LOW);
  
  mySimpit.inboundHandler(messageHandler);
}

void loop() {

  mySimpit.update();
}

void messageHandler(byte messageType, byte msg[], byte msgSize) {

  byte actions = msg[0];
  
  if (messageType == ACTIONSTATUS_MESSAGE) {
     if (actions & SAS_ACTION) {

        digitalWrite(LED_BUILTIN, HIGH);
    }
  }
}

 

Edit ** Solved

Edited by TheDicko
Link to comment
Share on other sites

Hi, just got a unity crash.

I wrote an arduino program that toggles Action Group 1 and an LED.

It works fine, but if you leave it for a few minutes without doing anything, and then press the button, it causes a unity crash.

Here is my log file https://www.dropbox.com/s/zcnxc7ju0dzc6m2/Player.log?dl=0

Here is my code https://www.dropbox.com/s/92ekeuhnq6e9p15/toggle_action_1.ino?dl=0

Any help would be appreciated. I feel i'm 1 percent away from this working completely, because as i said it works, unless you leave it idle for a few mins.

 

Edit ** Solved.

Edited by TheDicko
Solved
Link to comment
Share on other sites

  • 3 weeks later...
On 10/24/2020 at 8:33 AM, TheDicko said:

Hi, just started out with what looks to be an amazing mod. Quick question, how do you guys debug code? I was thinking of printing to the serial monitor, but it says port busy, when using ksp.

@TheDicko you won't be able to use Serial Monitor while connected to Kerbal Simpit because the arduino board uses the serial connection to connect to KSP. That's what you're getting a port busy error message.

On 10/25/2020 at 5:38 PM, TheDicko said:

Hi, just got a unity crash.

I wrote an arduino program that toggles Action Group 1 and an LED.

It works fine, but if you leave it for a few minutes without doing anything, and then press the button, it causes a unity crash.

Here is my log file https://www.dropbox.com/s/zcnxc7ju0dzc6m2/Player.log?dl=0

Here is my code https://www.dropbox.com/s/92ekeuhnq6e9p15/toggle_action_1.ino?dl=0

Any help would be appreciated. I feel i'm 1 percent away from this working completely, because as i said it works, unless you leave it idle for a few mins.

 

Edit ** Solved.

@TheDicko noticed that on a couple of your posts you made an Edit and said that you solved it...for the benefit of the rest of us on the forum, could you explain what you found to be the problem and how you fixed it? I'm sure others have run into similar issues and this might help quite a few people. Thanks!

Link to comment
Share on other sites

6 hours ago, PSU_Jedi said:

@TheDicko you won't be able to use Serial Monitor while connected to Kerbal Simpit because the arduino board uses the serial connection to connect to KSP. That's what you're getting a port busy error message.

@TheDicko noticed that on a couple of your posts you made an Edit and said that you solved it...for the benefit of the rest of us on the forum, could you explain what you found to be the problem and how you fixed it? I'm sure others have run into similar issues and this might help quite a few people. Thanks!

Absolutely!

On 10/25/2020 at 9:38 PM, TheDicko said:

Hi, just got a unity crash.

I wrote an arduino program that toggles Action Group 1 and an LED.

It works fine, but if you leave it for a few minutes without doing anything, and then press the button, it causes a unity crash.

Here is my log file https://www.dropbox.com/s/zcnxc7ju0dzc6m2/Player.log?dl=0

Here is my code https://www.dropbox.com/s/92ekeuhnq6e9p15/toggle_action_1.ino?dl=0

Any help would be appreciated. I feel i'm 1 percent away from this working completely, because as i said it works, unless you leave it idle for a few mins.

 

Edit ** Solved.

Anyone who has this problem, remember to add mySimpit.update(); in your arduino loop! 

On 10/24/2020 at 2:50 PM, TheDicko said:

Can anyone help me debug this? Pretty simple code. I want it to turn on the onboard LED when the SAS button is pressed. At the moment it does not do this. (The example files work however :))

 

#include "KerbalSimpit.h"

KerbalSimpit mySimpit(Serial);

void setup() {
  Serial.begin(115200);
  
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);
  
  while (!mySimpit.init()) {
    delay(100);
  }
  
  digitalWrite(LED_BUILTIN, LOW);
  
  mySimpit.inboundHandler(messageHandler);
}

void loop() {

  mySimpit.update();
}

void messageHandler(byte messageType, byte msg[], byte msgSize) {

  byte actions = msg[0];
  
  if (messageType == ACTIONSTATUS_MESSAGE) {
     if (actions & SAS_ACTION) {

        digitalWrite(LED_BUILTIN, HIGH);
    }
  }
}

 

Edit ** Solved

Solution -  remember to register to those channels!

6 hours ago, PSU_Jedi said:

@TheDicko you won't be able to use Serial Monitor while connected to Kerbal Simpit because the arduino board uses the serial connection to connect to KSP. That's what you're getting a port busy error message.

@TheDicko noticed that on a couple of your posts you made an Edit and said that you solved it...for the benefit of the rest of us on the forum, could you explain what you found to be the problem and how you fixed it? I'm sure others have run into similar issues and this might help quite a few people. Thanks!

If i remember correctly it was you who solved the unity crash for me over on reddit. many thanks!

Link to comment
Share on other sites

On 11/13/2020 at 3:27 AM, PSU_Jedi said:

@TheDicko you won't be able to use Serial Monitor while connected to Kerbal Simpit because the arduino board uses the serial connection to connect to KSP. That's what you're getting a port busy error message.

One option, albeit slightly janky, would be to use a couple of cheap Arduino Megas. Just have your debug stuff be spit out of Serial1 on your controller Mega, and read into Serial1 on the debug message repeater. Then just send the stuff read in from serial1 on the message repeater out of the normal serial connection to a serial monitor on your computer.

Link to comment
Share on other sites

  • 3 months later...

Hi,

First of all, @stibbonsthanks very much for making this library, so far it's the only one I got it to work with the latest KSP & Win10.

"Work" might be an overstatement though, I'm trying to test a simple example where a couple of LEDs will light up when clicking on RCS or SAS on the navball, however I'm getting some strange behaviour:

Any of the LEDs will turn on on the first click, however they won't turn off if you click them again, however if you click both (both LEDs on) then you can click again either and switch them off (but only one of them, not both!)

Unfortunately I don't have a second Arduino to try and debug this, here's the code if you'd be kind to have a look:

 

#include "KerbalSimpit.h"
#include <KerbalSimpitMessageTypes.h>
#include <PayloadStructs.h>


const int SAS_LED = 11; 
const int RCS_LED = 12;

KerbalSimpit mySimpit(Serial);

void setup() {
  Serial.begin(115200);

  // Set initial pin states, and turn on the LED
  pinMode(SAS_LED, OUTPUT);
  pinMode(RCS_LED, OUTPUT);
  
  digitalWrite(SAS_LED, HIGH);
  digitalWrite(RCS_LED, HIGH);
  
  // This loop continually attempts to handshake with the plugin.
  // It will keep retrying until it gets a successful handshake.
  while (!mySimpit.init()) {
    delay(100);
  }
  digitalWrite(SAS_LED, LOW);
  digitalWrite(RCS_LED, LOW);

  mySimpit.inboundHandler(messageHandler); // declares the message handler to read incoming messages from Simpit mod
  mySimpit.registerChannel(ACTIONSTATUS_MESSAGE); // subscribes to the Action Status message channel
  mySimpit.registerChannel(SCENE_CHANGE_MESSAGE); // subscribes to the Scene Change message channel
}


void messageHandler(byte messageType, byte msg[], byte msgSize) { // sets up the message handler to receive messages from Simpit
  switch(messageType) {
    case ACTIONSTATUS_MESSAGE: // defines the set of actions for messages coming from ACTIONSTATUS_MESSAGE
    byte actions = msg[0]; // assigns the ACTIONSTATUS_MESSAGE to the variable actions
  
    if (actions & SAS_ACTION) { // checks to see if SAS is turned on
      digitalWrite(SAS_LED, HIGH); // turns on the SAS LED indicator if SAS is on
    } else {
      digitalWrite(SAS_LED, LOW); // set SAS LED indicator off if SAS is off
    }
    if (actions & GEAR_ACTION) { // checks to see if Gear is down
      digitalWrite(GEAR_LED, HIGH); // turns on Gear LED indicator if gear is down
    } else {
      digitalWrite(GEAR_LED, LOW); // set the Gear indicator off if gear is up
    }
    if (actions & LIGHT_ACTION) { // checks to see if Lights are on
      digitalWrite(LIGHTS_LED, HIGH); // turns on Lights LED indicator if lights are on
    } else {
      digitalWrite(LIGHTS_LED, LOW); // set Lights indicator off if lights are off
    }
    if (actions & RCS_ACTION) { // checks to see if RCS is active
      digitalWrite(RCS_LED, HIGH); // turns on the RCS LED indicator if RCS is active
    } else {
      digitalWrite(RCS_LED, LOW); // set RCS indicator off if RCS is inactive
    }
    if (actions & BRAKES_ACTION) { // checks to see if Brakes are on
      digitalWrite(BRAKES_LED, HIGH); // turns on Brakes LED indicator if brakes are on
    } else {
      digitalWrite(BRAKES_LED, LOW); // set Brakes indicator off if brakes are off
    }
    break;
  } 
}


void loop() {
  mySimpit.update(); // necessary updates and loops for called functions
 
}

 

I'm using an Arduino UNO (clone CH340), KerbalSimpit v1.4.1.66 and KSP 1.11.1.03066.

 

Thanks in advance!

Edited by CaptnUndrpnts
Link to comment
Share on other sites

  • 4 weeks later...
On 3/23/2021 at 8:14 AM, Jebadiah Kerman 42 said:

Hi 

I have been reading through this information and it has really helped me I am trying to install the mod though CKAN but when I search for the mod it doesn't turn up.

Could anyone help me. BTW I am using the Mac version through the terminal. 

Thanks 

Hi :)

You can install the old mod manually (I think CKAN will detect it as not compatible depending on what version of KSP you're running), so not sure how well that'd work.

There's a new version of the mod that's being developed by some cool people. No idea about Mac though, but if you swing by the discord channel (KerbalSimPit) you may find some answers :) I'm currently using this new version (still in alpha), but seems to be working fine for the most of it.

 

 

 

Link to comment
Share on other sites

  • 2 months later...
On 3/26/2021 at 5:10 AM, CaptnUndrpnts said:

Hi :)

You can install the old mod manually (I think CKAN will detect it as not compatible depending on what version of KSP you're running), so not sure how well that'd work.

There's a new version of the mod that's being developed by some cool people. No idea about Mac though, but if you swing by the discord channel (KerbalSimPit) you may find some answers :) I'm currently using this new version (still in alpha), but seems to be working fine for the most of it.

 

 

 

What Discord server is this? I can't seem to find it in this forum thread or on Google. Could you maybe post an invite link? If that's not against any forum rules, I wouldn't really know.

Edited by jemhop
Link to comment
Share on other sites

  • 2 months later...

Hello everyone,

We have taken over Simpit with a new version with a lot of improvement (new features and bugfixes). You can find the forum thread here .

We have some users on Mac and the mod worked for them. Our version is now available on CKAN by installing version >2.0 of Simpit.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...