zitronen

[Hardware, Plugin] Arduino based physical display + serial port io+ tutorial (10-06-17)

Recommended Posts

1 hour ago, zitronen said:

Due on windows 7/8

Good point! If my old ntb will be able to run ksp I ll try since it is w7 machine. I ll report with resultst if I get some!

 

For driving Amp meters looks at  this. It realy explains how to od it.

Share this post


Link to post
Share on other sites

@zitronen Thanks! That was quick :) And I am quick with testing too. On Win7 Due behaves same as on W10. Handshake okay, data reciving, data "send" no ingame response.  Debug log looks like same for W7 and W10. 

Chopped down log with only KSPSerial instances:

Spoiler

[LOG 20:22:07.449] [AddonLoader]: Instantiating addon 'SettingsNStuff' from assembly 'KSPSerialIO'
[LOG 20:22:07.453] KSPSerialIO: Loading settings...
[LOG 20:22:07.468] KSPSerialIO: Default Port = COM3
[LOG 20:22:07.469] KSPSerialIO: Refreshrate = 1
[LOG 20:22:07.469] KSPSerialIO: BaudRate = 57600
[LOG 20:22:07.470] KSPSerialIO: Handshake Delay = 3000
[LOG 20:22:07.470] KSPSerialIO: Handshake Disable = 0
[LOG 20:22:07.471] KSPSerialIO: Pitch Enable = 0
[LOG 20:22:07.471] KSPSerialIO: Roll Enable = 0
[LOG 20:22:07.471] KSPSerialIO: Yaw Enable = 0
[LOG 20:22:07.472] KSPSerialIO: Translate X Enable = 0
[LOG 20:22:07.472] KSPSerialIO: Translate Y Enable = 0
[LOG 20:22:07.473] KSPSerialIO: Translate Z Enable = 0
[LOG 20:22:07.473] KSPSerialIO: Wheel Steering Enable = 2
[LOG 20:22:07.474] KSPSerialIO: Throttle Enable = 2
[LOG 20:22:07.474] KSPSerialIO: Wheel Throttle Enable = 2
[LOG 20:22:07.474] KSPSerialIO: SAS Tol = 0.1

[LOG 20:23:08.064] [AddonLoader]: Instantiating addon 'KSPSerialPort' from assembly 'KSPSerialIO'
[LOG 20:23:08.065] KSPSerialIO: Version 0.18.6a
[LOG 20:23:08.066] KSPSerialIO: Getting serial ports...
[LOG 20:23:08.066] KSPSerialIO: Output packet size: 200/255
[LOG 20:23:08.069] KSPSerialIO: Found 3 serial ports
[LOG 20:23:08.069] KSPSerialIO: trying default port COM3
[LOG 20:23:11.087] KSPSerialIO: Packet Size ERROR - 0/25
[LOG 20:23:11.087] KSPSerialIO: CS PASS - 00-03-01-04-02-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
[LOG 20:23:11.115] KSPSerialIO: Packet Size ERROR - 0/25
[LOG 20:23:11.147] KSPSerialIO: Packet Size ERROR - 0/25
[LOG 20:23:11.180] KSPSerialIO: Packet Size ERROR - 0/25
[LOG 20:23:11.204] KSPSerialIO: found KSP Display at COM3
[LOG 20:23:11.205] [AddonLoader]: Instantiating addon 'KSPSerialIO' from assembly 'KSPSerialIO'

[LOG 20:23:12.922] KSPSerialIO: Packet Size ERROR - 0/25
[LOG 20:23:12.922] KSPSerialIO: Packet Size ERROR - 0/25
[LOG 20:23:12.923] KSPSerialIO: Packet Size ERROR - 0/25
[LOG 20:23:12.923] KSPSerialIO: Packet Size ERROR - 0/25

[LOG 20:23:16.205] KSPSerialIO: Handshake received - 314

[LOG 20:23:16.344] KSPSerialIO: Packet Size ERROR - 0/25
[LOG 20:23:16.345] KSPSerialIO: Packet Size ERROR - 0/25
[LOG 20:23:16.560] KSPSerialIO: Packet Size ERROR - 0/25
[LOG 20:23:16.560] KSPSerialIO: Packet Size ERROR - 0/25
[LOG 20:23:16.561] KSPSerialIO: Packet Size ERROR - 0/25
[LOG 20:23:16.562] KSPSerialIO: Packet Size ERROR - 0/25
[LOG 20:23:16.562] KSPSerialIO: Packet Size ERROR - 0/25

 

Then log is basicly spamed by KSPSerialIO: Packet Size ERROR - 0/25 until com is closed.

 Any idea what can cause this?

Share this post


Link to post
Share on other sites

*c4ooo hopes the arduino mega he will be receiving soon will work on win7 _._

Edited by c4ooo

Share this post


Link to post
Share on other sites

Oh oops I put the error message in the wrong place, so it always says 0/25. Try this version: https://sites.google.com/site/zitronfiles/KSPSerialIO_018_6b.zip

But that suggests the arduino is sending packets that are not the correct length, possibly 8/32bit struct padding problem.

23 minutes ago, c4ooo said:

*c4ooo hopes the arduino mega he will be receiving soon will work on win7 _._

Mine works

Edited by zitronen

Share this post


Link to post
Share on other sites

Now I got number. And not good number :D  Now it is:  KSPSerialIO: Packet Size ERROR - 45/25.  I was curios so I did change  struct __attribute__((__packed__)) ControlPacket {  to old struct ControlPacket { and result is KSPSerialIO: Packet Size ERROR - 48/25. 

With my limited knowlege I guess Due just spits out whole packet in 32b format but that is almost two times bigger then plugin expect. If we tell Due to send it as 8b not 32b then it should "fix it" right? :) 

Share this post


Link to post
Share on other sites

Wow, you're fast.

A noobish question. How to access the debug-output?

Edited by Benji

Share this post


Link to post
Share on other sites
2 hours ago, Mattew said:

With my limited knowlege I guess Due just spits out whole packet in 32b format but that is almost two times bigger then plugin expect. If we tell Due to send it as 8b not 32b then it should "fix it" right? :) 

You want to read the Arduino documentation on ints. And you're right. On the Uno and other ATMega-based boards, an int is 16 bits, while on the Due an int is 32 bits.

The solution is to use the int16_t data type instead of int. And when unsigned int is used, it should be replaced by uint16_t. Pretty straightforward, just modify the ControlPacket definition in your sketch like this

uint16_t ControlGroup;
int16_t Pitch;

and so on.

31 minutes ago, Benji said:

A noobish question. How to access the debug-output?

The plugin logs to the usual KSP logs - KSP.log in the game directory.

  • Like 3

Share this post


Link to post
Share on other sites
25 minutes ago, stibbons said:

You want to read the Arduino documentation on ints. And you're right. On the Uno and other ATMega-based boards, an int is 16 bits, while on the Due an int is 32 bits.

The solution is to use the int16_t data type instead of int. And when unsigned int is used, it should be replaced by uint16_t. Pretty straightforward, just modify the ControlPacket definition in your sketch like this


uint16_t ControlGroup;
int16_t Pitch;

and so on.

The plugin logs to the usual KSP logs - KSP.log in the game directory.

 

Many thanks @stibbons. And like that the DUE works just fine.

@Mattew I tested a bit with two arduinos. As long as it's not bidirectional everything goes smoothly. But you're right. Bidirectional communication is a huge pain. Then I dicovered I can use RX/TX 1,2 and 3 as digital pins. Pin shortage was one point why I thought about two arduinos. But with the communication-pins that's no problem anymore.

Edited by Benji
  • Like 1

Share this post


Link to post
Share on other sites

Okay, okay. I can confirm it is fixed and working so far. Now no more Error packet size messages and I am able see whole packet in log and most important thing are actual controls in game :D   Love you guys, you are awesome :D  Now I am back on track. 

@Benji Yeah I had on my Mk.1 one-way, one-value, comunication for nixie tube driver board, that works nice, but sending more than one value, let alone biderictional, is real rocket science for me :D 

  • Like 2

Share this post


Link to post
Share on other sites

@Mattew I was sending single "characters": 'S' for SAS on, 's' for SAS off, 'R' for RCS on, 'r' for RCS off, and so on. First I thought I had to synchronise the two boards. But spamming just worked fine. Perhaps when doing bidirectional you have to synchronise.

Uhh. The Nixies look super-duper-retro-cool.

Share this post


Link to post
Share on other sites

Hi everyone,

     Just wanted to thank you all for helping me out with this mod. I am away from my family for the holidays and this project has really taken my mind off everything. (well almost). I just got my LCD screens hooked up and going to start mounting it to my "Dashboard" this weekend. (That is if I can borrow a drill from work). Great Mod, and even better community! :P

 

Here's the link to the Monstrosity that I created!!!!

Edited by Freakout242
ooops
  • Like 2

Share this post


Link to post
Share on other sites

I got my joysticks today and all they are is 4 limit switches at the base for direction. Can I use digital input instead of analog? How would I program that?

Share this post


Link to post
Share on other sites
2 hours ago, JoshTheCoward said:

I got my joysticks today and all they are is 4 limit switches at the base for direction. Can I use digital input instead of analog? How would I program that?

Sure. If the "left" switch is closed, set TX to -1000 (or Yaw, or Roll, depending on what you're using the joystick for). If the "right" switch is closed, set it to 1000. And so on.

I'm using digital joysticks on my board, and added a potentiometer to let me set the intensity of movement. With the knob turned up full, the translation controls work at full strength. With the knob set to half way, the translation controls only send 500 instead of 1000. It works a lot better than I expected it would. :)

  • Like 1

Share this post


Link to post
Share on other sites

You need to use something like

if (digitalRead(pin1)) {
	CPacket.Roll = 500;
}
else if (digitalRead(pin2)) {
	CPacket.Roll = -500;
}
else {
	CPacket.Roll = 0;
}

 

  • Like 1

Share this post


Link to post
Share on other sites
On 1/13/2017 at 2:09 AM, stibbons said:

Sure. If the "left" switch is closed, set TX to -1000 (or Yaw, or Roll, depending on what you're using the joystick for). If the "right" switch is closed, set it to 1000. And so on.

I'm using digital joysticks on my board, and added a potentiometer to let me set the intensity of movement. With the knob turned up full, the translation controls work at full strength. With the knob set to half way, the translation controls only send 500 instead of 1000. It works a lot better than I expected it would. :)

What does the code for this look like feels like i've tried everything.

Share this post


Link to post
Share on other sites

@JoshTheCoward It looks very much like what zitronen wrote, each direction has a value in CPacket (Roll, Yaw, Pitch, TX, TY, TZ) that you assign a value when a signal is read from a pin. Start by reading up on code at the Arduino homepage and go through their basic tutorials if you are completely new to coding, debugging KSP controllers is terrible because you have to wait for the game to load to test it out.

Try making a program that will output 1000 on the serial monitor when you pull the joystick. Then, a sketch that outputs the direction. Then mesh that program with the bit of code that zitronen wrote in the post above yours. Ask along the way if you have problems, and when you do paste the code here (use the code tag).

Share this post


Link to post
Share on other sites
5 hours ago, Freshmeat said:

@JoshTheCoward It looks very much like what zitronen wrote, each direction has a value in CPacket (Roll, Yaw, Pitch, TX, TY, TZ) that you assign a value when a signal is read from a pin. Start by reading up on code at the Arduino homepage and go through their basic tutorials if you are completely new to coding, debugging KSP controllers is terrible because you have to wait for the game to load to test it out.

Try making a program that will output 1000 on the serial monitor when you pull the joystick. Then, a sketch that outputs the direction. Then mesh that program with the bit of code that zitronen wrote in the post above yours. Ask along the way if you have problems, and when you do paste the code here (use the code tag).

Don't know what the code tag is.

 

but here is my code.

 

 if (digitalRead(WPIN)){
      CPacket.Pitch = -500;
  }
    else if (digitalRead(SPIN)){ 
      CPacket.Pitch = 500;
  }
    else {
      CPacket.Pitch = 0; 
      } 

 

But it starts out 500 pitch in the one direction. Once you press the opposited direction it goes to 500 the other way but then returns to 500 the other way.

Share this post


Link to post
Share on other sites

Just checking: You use pulldown resistors in your circuit, right? And code tags is the <> button in the toolbar when writing on the forum.

Share this post


Link to post
Share on other sites
3 hours ago, Freshmeat said:

Just checking: You use pulldown resistors in your circuit, right? And code tags is the <> button in the toolbar when writing on the forum.

That is probably it. Is there a way to use the pullups resisters on the Arduino?

 

Sorry again for being a noob.

Share this post


Link to post
Share on other sites

Connect a 10kohm resistor between your input gate and ground. Thus, the signal will be ground until the switch is closed. 10k is enough that the ground connection is ignored when the switch is closed. Wiring goes like this:

PullDownill.jpg

Electrical engineers will put a small capacitor in parallel with the resistor to avoid voltage fluctuating when the connection is made, but this equipment is not life and death, and I have never had problems without it.

Edited by Freshmeat
Added image
  • Like 1

Share this post


Link to post
Share on other sites

Will this work on Linux? (except the COM port detection), or not at all?

Share this post


Link to post
Share on other sites

@Denko666 Unfortunately not. @stibbons is working on an alternative, but it is still not ready for release. You should be able to compile his github source if you are into that kind of stuff.

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