Jump to content

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


zitronen

Recommended Posts

Hey guys and girls, any news on W10 issue? It realy sad not to use my control panel since even with handshake disabled it wont work (connect, disconnect, connect disconnect...). I Didnt found any solid information about usb win10 problems, only found out that MANY ppl with arduino and other custom hardware using usb for communication have big problems with connection. 

Link to comment
Share on other sites

It's not a driver issue. Short version is that the plugin is able to marshal data out the serial connection, but packets inbound are never processed. The plugin registers a handler for the System.IO.Ports.SerialPort.DataReceived event but since Windows 10 that event just... doesn't seem to fire. For what it's worth, it's never, ever worked on Linux or OS X.

This is probably exacerbated by the fact that KSP doesn't include the Unity libraries for serial comms so we're relying on assorted third party C# implementations. But seeing as Unity uses a pretty crusty version of mono I'm not quite convinced building KSP with the full .NET suite will help.

I've got a fork of this plugin that works fairly well on Linux and OS X by doing two things:

I've stress-tested my fork pretty heavily on Linux (it ran for a solid eight hours of constant launches during the maker faire in Sydney last month without crashing), and I've run it for short periods on OS X, but I don't really test it in Windows at all.

@Mattew, you could give my fork a try at http://spacedock.info/mod/850/KSP Serial IO (cross platform). But I honestly have no idea if it'll work for you or not. Sure would be interested to see somebody try it out though. :)

1 hour ago, Mattew said:

It realy sad not to use my control panel since even with handshake disabled it wont work (connect, disconnect, connect disconnect...).

And for what it's worth, I half suspect this is because your arduino code is assuming it's disconnected because it never gets a successful handshake. If you're basing your code on zitronen's example sketch, it's probably worth making sure you've disabled any conditionals that check for a connection.

Link to comment
Share on other sites

37 minutes ago, stibbons said:

It's not a driver issue.

I just remembered this may not be entirely accurate. A few pages back somebody claimed to have gotten this plugin working properly in Windows 10 using Arduino compatible boards with a different serial chipset, therefore a different driver. See

So it might be something like a weird interaction between the C# library and the standard Arduino serial driver. If you happen to have some spare cash it might be worth tracking down an Arduino board with a WCH340 chip on them. But, again, I have no idea if it'll actually work or not sorry. :)

Edited by stibbons
Link to comment
Share on other sites

6 hours ago, stibbons said:

And for what it's worth, I half suspect this is because your arduino code is assuming it's disconnected because it never gets a successful handshake. If you're basing your code on zitronen's example sketch, it's probably worth making sure you've disabled any conditionals that check for a connection.

Well that maybe it since I just disable HandShake in config file of pluggin itself and not bother with code at all.  I ll try that. 

I can do some testing, I ll check it out and see it that will work, since it looks like some good solution is faaar away. 

5 hours ago, stibbons said:

I just remembered this may not be entirely accurate. A few pages back somebody claimed to have gotten this plugin working properly in Windows 10 using Arduino compatible boards with a different serial chipset, therefore a different driver.

So it might be something like a weird interaction between the C# library and the standard Arduino serial driver. If you happen to have some spare cash it might be worth tracking down an Arduino board with a WCH340 chip on them. But, again, I have no idea if it'll actually work or not sorry. :)

Well it maybe go somewhere, since today when i was googling for issue i came over this video Windows USB Serial COM port driver bug and guy there did some tests where UNO r3 with its ATmega16U2 as USB-to-serial have issues but Duemilanove with FTDI USB-to-TTL works fine. Maybe WCH340 works too since its "hardware" convertor opposite ATmega16U2 "software" based convertor?  I assume that basic USB-to-TTL convertor based on WCH340 or similar chip connected to arudino TX RX lines and bypassing its original ATmega16U2 in theory could do the trick. Thinking of buying it and testing it. Or Uno with WCH340, but  its 3 week for something to come from ebay xD

Edit: Found this thing on Ebay CH340G USB-TTL Convertor . Cheap too.

Edited by Mattew
Link to comment
Share on other sites

On a completely different subject, I was wondering a bit about the VData. Specifically, whether it would be worth the trouble to use integers for a bunch of the stuff. For example, the fuel levels, latitude/longitude, roll/pitch/heading, inclination and eccentricity. Desired precision could be achieved by measuring in deci- or milliunits. I know that this would break a lot of existing codebase, but as I understand it, floats are a drag on the Arduino. Right now I copy a bunch of the values to uint_32t before doing further calculations, but i would prefer not to.

This is of course on the basis that the time savings are worth it, which I don't know enough about the Arduino to be qualified to say. Just speculating.

Link to comment
Share on other sites

4 minutes ago, Freshmeat said:

On a completely different subject, I was wondering a bit about the VData. Specifically, whether it would be worth the trouble to use integers for a bunch of the stuff. For example, the fuel levels, latitude/longitude, roll/pitch/heading, inclination and eccentricity. Desired precision could be achieved by measuring in deci- or milliunits. I know that this would break a lot of existing codebase, but as I understand it, floats are a drag on the Arduino. Right now I copy a bunch of the values to uint_32t before doing further calculations, but i would prefer not to.

This is of course on the basis that the time savings are worth it, which I don't know enough about the Arduino to be qualified to say. Just speculating.

 

Possibly, most of the things are meant to be easy to directly sent to a display with a simple dtostrf() which gives you a easy method to choose how to format the number. Floats are slow, but maybe not as slow as you might think: http://forum.arduino.cc/index.php?topic=40901.0

10 - 40us per operation, you can do 25000-100000 floating point calculations a second. So unless you are doing some serious maths it really shouldn't be a problem.

Link to comment
Share on other sites

In the thread, I saw that a sin(x) was rather expensive. I need both acos and sqrt for some parts of my controller infoscreens. Oh well, I have ordered a Due anyway for the keyboard functions, it gains me a five time increase in CPU speed. And all the headaches of 3.3V to 5V level shifting, but you can't have everything, I suppose.

Link to comment
Share on other sites

You know, @Freshmeat...
An Arduino with a faster CPU like a Duemiwhatsitcalled, and with lots of ports, like a Mega2560... And INTEGRAL LEVEL SHIFTING would be an absolute killer device:D
Maybe an easier name too... :rolleyes:
Why can't this be a thing that exists! :confused:

In the mean time, there's this thing: Level Shifter Shield. It looks like that particular model from that particular vendor had to be reworked. They say it works 100%, but since it had to basically be fixed after manufacturing, they're selling them for about $5. Not sure if it's what you need, but it might help, and it's cheap. It's not able to directly drive LEDs and other devices that require higher levels of current, but it makes all I/O 5 volt tolerant. You can use transistors to drive current, if you need to directly drive anything.

Edited by richfiles
Link to comment
Share on other sites

7 hours ago, zitronen said:

You can also go all out and get a teensy 3 like @stibbons, which I think is 5V tolerant on digital pins.

Minor point of order, it's only the Teensy 3.1 and 3.2 that are 5V tolerant. The 3.0 is not. I'm using a 3.2 on an I2C bus with a 5V master with no problems.

7 hours ago, zitronen said:

They are kickstarting a new one with a 180MHz ARM...

The new boards also have an FPU. The only mild downside is that the 180MHz version loses the 5V tolerance. I've backed the kickstarter, looking forward to trying the new boards out.

Link to comment
Share on other sites

Hy everyone,

i have a few Questions. I´m trying to build my own KSP Cockipt. Now i have some problems and hope you can help me.

First i wanted that my Display shows "Waiting for KSP" until it the variable Connected is true.

The Display show the text but when i go to the Lunch Pad the Text still stand there an the green light won´t turn on.

 if (Connected == false)
{
      lcd.setCursor(0, 0);
      lcd.print("Waiting for KSP");
      for ( int i; i <= 15 ; i++)
      {
      lcd.setCursor(i, 1);
      lcd.print(".");
      delay (1000);
      }
}

The other thing that i don´t understand is, i have a button which should start a startcheck after that a countdown should count to zero and the rocket should start.

But when i push the button the display shows the information i wanted but ignore the for loop and restart the whole prozedure and the green light turn of and looped it as long as i uploaded the same code or restart the arduino uno.

void startcheck ()
{
  if ( start == true)
  {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("KSP Start Check");
      delay(500);
      //RCS Check
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("***RCS Check****");
      delay(1000);
      //RCS Einschalten
      lcd.setCursor(0,1);
      lcd.print("Checked");
      delay(1000);
      //SAS Check
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("***SAS Check****");
      delay(1000);
      //SAS Einschalten
      lcd.setCursor(0,1);
      lcd.print("Checked");
      delay(1000);
      //Fuel Check
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("***Fuel Check***");
      delay(1000);
      //Fuel Auslesen
      lcd.setCursor(0,1);
      lcd.print(VData.LiquidFuelTot);
      delay(1000);
            //MonoP Check
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("***MonoP Check**");
      delay(1000);
      //MonoP Auslesen
      lcd.setCursor(0,1);
      lcd.print(VData.MonoPropTot);
      delay(1000);
      //Power Check
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("*E Charge Check*");
      delay(1000);
      //Echarge Auslesen
      lcd.setCursor(0,1);
      lcd.print(VData.ECharge);
      delay(1000);
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Ready to start");
      delay(1000);
      for (int t = 10; t = 0; t--)
      {
        lcd.setCursor(7,1);
        lcd.print(t);
        delay (1000);
      }


  }

My KSPIODemo13 loop looks like:

void loop()
{
  input();
  output();
  dsplay();
  startcheck();
}

 

The last Question, ist there any posibiliy that i can start the rocket whithout keyboard input and readout target speed and distance?

I hope you can help me.

Thanks

 

Link to comment
Share on other sites

In both of your for loops, you have the wrong syntax, the first one:

for ( int i; i <= 15 ; i++)

is wrong, you probably meant

for ( int i = 0; i <= 15 ; i++)

 

The second one:

for (int t = 10; t = 0; t--)

is also wrong, you probably meant

for (int t = 10; t <= 0; t--)

 

Link to comment
Share on other sites

If the loop delays the process for to long, the board goes idle as defined in input.ino. If you want a countdown sequence, you need to use a check against time instead of delay commands, and print the appropriate message when a certain time has passed. Something like this:

In setup:

starttime = millis();

In startchk:

now = millis();
if (starttime - now > than 1000) {first second of countdown code}
else if (starttime - now > 2000) {second second of countdown code}

And so forth. In the tenth second (countdown = zero), the last command would be to set the stage bit high in CPacket. That ought to do the trick, but I am not entirely certain.

Second, you will get this sequence every time you switch vessel, so it might not be an entirely good idea. Some suitable checks against velocity and position might be able to identify a starting vehicle, but rovers are still a problem. You might want to only initiate start sequence on a button.

This project might require a few false starts, feel free to experiment and ask for help.

Link to comment
Share on other sites

Hy,

thanks for your posts, i get it work but not as i wanted.

But first here a few pictures of my cockpit

I have build here 3 different input types: Joystick, Keyboard and arduino

The Joystik controls Pitch and Yaw, Firebutton is Stage, then switch map SAS and RSC activate/deaktivate and controls view

The Linear Poti with the red cap controls the Throttle. The big hole there was a mistake but later it will cool the Hand with a Computer fan.

Then we have the three LEDs, The Display and the poti under the display is to switch the display. Actually 4 Modes. 1 AP and EP 2. Altitude 3. MonoP and Electric Charge 4. Time to Node and DeltaV

The small Joystik on the left Controls Translation Up,Down,Left,Right. The two red buttons control the Roll Axis. The small button under the Joystik Controls RCS Foward and Backward.

20160913_142028.jpg

 

20160913_142039.jpg

Here is a video from the start.

As you can see the start works nearly correctly. With two exceptions. RCS and SAS won´t go active. (At home SAS and RCS went active after the for loop)  And the stage should be switched after countdown goes to 1.

 if ( start == HIGH)
{
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("KSP Start Check");
      delay(500);
      //RCS Check
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("***RCS Check****");
      delay(1000);
      //RCS Einschalten
      CPacket.MainControls |= (1 << 6);       
      lcd.setCursor(0,1);
      lcd.print("Checked");
      delay(1000);
      //SAS Check
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("***SAS Check****");
      delay(1000);
      //SAS Einschalten
    CPacket.MainControls |= (1 << 7);      
      lcd.setCursor(0,1);
      lcd.print("Checked");
      delay(1000);
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("****LED Check***");
      digitalWrite(GLED,HIGH);
      delay(1000);
      digitalWrite(YLED,HIGH);
      delay(1000);
      digitalWrite(RLED,HIGH);
      delay(1000);
      digitalWrite(GLED,LOW);
      delay(1000);
      digitalWrite(YLED,LOW);
      delay(1000);
      digitalWrite(RLED,LOW);
      lcd.setCursor(0,1);
      lcd.print("Checked");
      //Fuel Check
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("***Fuel Check***");
      delay(1000);
      //Fuel Auslesen
      lcd.setCursor(0,1);
      lcd.print(VData.LiquidFuelTot);
      delay(1000);
            //MonoP Check
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("***MonoP Check**");
      delay(1000);
      //MonoP Auslesen
      lcd.setCursor(0,1);
      lcd.print(VData.MonoPropTot);
      delay(1000);
      //Power Check
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("*E Charge Check*");
      delay(1000);
      //Echarge Auslesen
      lcd.setCursor(0,1);
      lcd.print(VData.ECharge);
      delay(1000);
      lcd.clear();
      for ( int t = 10 ; t >= 0 ; t--)
      {
        if(t |= 0)
        { 
         lcd.setCursor(0, 0);
         lcd.print("Ready to start");
         lcd.setCursor(0,1);
         lcd.print(t);
         delay(1000);
         lcd.clear();
       }
        else
        {
          CPacket.MainControls |= (1 << n);       
          lcd.setCursor(0,0);
          lcd.clear();
          lcd.print("*****Engage*****");
          delay(2000);
       }
  }
    start = LOW;
  lcd.clear();
}

}

if i set start = low it won´t restart anymore.

For the "Waiting for KSP" Loop i have actually no solution.

 

With target i mean if you select an other Vehicle for Docking etc KSp schow you the distance an relative speed to the target. I want this informations on my display.

 

Edited by svarne
Code
Link to comment
Share on other sites

OK you have a few mistakes in the code:
 

if(t |= 0)

should be

if(t != 0)


and

CPacket.MainControls |= (1 << n); 

should be

CPacket.MainControls |= (1 << 0); 

because "n" does not exist anywhere in your code.

 

I don't know why you are changing the bits manually and not using the simple function

MainControls(RCS, HIGH);

 

The reason why SAS and RCS only comes on after the for loop is because during your start sequence no packet is sent to KSP. Only after the sequence does normal communications start. Arduino can only do one thing at a time. You can fix this the proper way by doing what @Freshmeat is suggesting, or if you don't care about fixing it properly you can force a packet to be sent by using

KSPBoardSendData(details(CPacket));

After your SAS and RCS checks.

 

Really cool looking control panel though!

 

I think target distance and speed are good suggestions. I will look into adding them after the 1.2 update shows up.

 

 

 

Link to comment
Share on other sites

Zitronen

All in fair warning, I've got quite little coding experience, but i've written some serial communications between a java client and an Arduino before. I wanted to try build a hardware controller for ksp, as per many others. I've also done a bit of C# in my past as well. As I already owned an arduino mega i wanted to use that. In due course i discovered your plugin, however I've already made the jump to Windows 10 :/ you see where this is going. From previous comments it seems like you have no interest in fixing a windows 10 version so I set about having a go. I tried to use your plugin to get an idea of the response the client attempt to connect the handshake light come on but then goes off before the ship has even loaded. 

I then tried the de-bugger made my KingLuxor, which to my surprise worked. From my cursiory glance at the difference between the two sources your SerialIO seems to be custom however the debugger seems to use a windows stock code, could that indicate that the fault finding could beggin between spotting differences in how the two interact with the arduino's. I should note that i tried this code with an Arduino Mega 2560 and Arduino Uno R3. 

Obviously this isnt something i'm gunna solve straight away but i knew enough to get in and have a look under the hood. I thought i'd just drop in state what i found, as it hadnt been mentioned before, im gunna go away and practice my C and serail comms as well as KSP plugins before i try and actually get truely involved in a constructive problem solving conversation. I hope in some way this information is usefull, and even if it isnt, thanks for your code. Its given me a project to do over the next few months!

 

Cheers

Link to comment
Share on other sites

OK, I probably need to compile a list about windows 10, since the useful info is scattered all around the thread. I am using a crappy serial library because KSP (Unity, mono) does not include it, and there are no any other options. Yes indeed if we can figure out what is the difference between the crappy library and the proper C# library (used by KingLuxor) then maybe we can fix it. But that requires some knowledge how windows and serial drivers and such work, which is beyond what I can do.

 

There are currently 3 possible "workarounds" :

  1. Don't use windows 10
  2. Disable handshake in config file, manually set COM port (currently suggested option)
  3. There are unconfirmed reports that some arduino copies with different USB-Serial chips work just fine for some reason

 

I am very interested in fixing the windows 10 problem, many of us have tried for months. What I don't have any interest in is getting a new windows 10 computer just to find a fix.

 

Link to comment
Share on other sites

On 15. 9. 2016 at 6:18 PM, zitronen said:

I am very interested in fixing the windows 10 problem, many of us have tried for months. What I don't have any interest in is getting a new windows 10 computer just to find a fix.

Just sit tight with me and have fingers crossed. I ordered from ebay  that USB-TTL module with CH340 chip and REALY hoping it will work. I am guessing 10-14 days until it arrives so lets wait. 

 

EDIT:

So today i got a little surprise from ebay. That USB-TTL module actualy come TODAY! unbeliveable. But sadly i am not home and cant do serious testing. Buuuut i made quick test (Uno with KSPIODemo13) and comunication was handled by CH340 convertor insted of Uno`s on board Atmega16U2. And guess what? IT WORKS ABSOLUTLY PERFECT! Yes, KSP IO pluggin is working under Win10 with no issues (kind of). I got communication both ways, in and out. I got throttle from uno board even when there werent any controler (probably getting false signals on unconnected analog input) and it was seen in game on actual throttle. From those few short test I didnt lost comunication with board and seem absolutly fine. I will get home tomorow and ll be able to run some full test, especialy connect my full control panel using CH340 and see how it goes. Probably run some quick Mun mission and see if it will held up whole time with no issues (I guess it will be ok). 

So long story short, Win10 have issues comunicate over Atmega16U2 but CH340 run fine.  I hope it will some of you more experianced guys (or girls) some idea how to fix code insted of telling ppl to go buy CH340 TTL module. 

Edited by Mattew
No need for double posting
Link to comment
Share on other sites

Okaaay. Just finished tests with my control panel + CH340. I had no issues so far, everything works as expected. Connection is fine. Recived and transmited data are okay too.  I think we can say that problem is in Atmega16U2 chip or its drivers. That isn my expertise so I cant say why is that.

If anyone strugling in Win10 with his or hers custom control panel and dont want wait for fix (or maybe it wont be even possible to fix) you can get same USB-TTL-Thing as me. 

Link to comment
Share on other sites

 

3 hours ago, Mattew said:

Okaaay. Just finished tests with my control panel + CH340. I had no issues so far, everything works as expected. Connection is fine. Recived and transmited data are okay too.  I think we can say that problem is in Atmega16U2 chip or its drivers. That isn my expertise so I cant say why is that.

If anyone strugling in Win10 with his or hers custom control panel and dont want wait for fix (or maybe it wont be even possible to fix) you can get same USB-TTL-Thing as me. 

What drivers did you use (I just ordered the module that you linked)

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...