Jump to content

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


zitronen

Recommended Posts

Or if you are lazy, can just use 2 buttons to increase/decrease SASMode.

Yeah and

CPacket.SASMode = SMOFF;

is not normally needed, you can can turn off SAS using the orginal SAS controls.

Edited by zitronen
Link to comment
Share on other sites

Hmm, looking at https://github.com/zitron-git/KSPSerialIO/blob/master/KSPSerialIO/KSPIO.cs#L935 it seems that SASMode remain set to the last value, and wont reset to zero when SAS is dissabled. Similarly, by looking at https://github.com/zitron-git/KSPSerialIO/blob/master/KSPSerialIO/KSPIO.cs#L1114 , setting CPacket.SASMode = SMOFF; wont actualy dissable SAS, but would be ingored.

(In my orignal code, setting the SAS control byte to zero would not change anything, but the sas state sent to the arduino would revert to zero when SAS is turned off)

Just wanted to point this out, as i think it may cause problems. 

Edited by c4ooo
Link to comment
Share on other sites

2 hours ago, Mattew said:

One detail I just find out. Can we get way to change "vector reference" ? I mean if prograde/retro is relative to orbit or surface or target. That would be awesome then.

So, what you're asking for is a switch to change between 'surface' and 'target' modes, yeh? :)  

Link to comment
Share on other sites

Hello! I made a thing :) wanted to share.

It's been about 2 years since I built this project, but I've finally gotten around to posting it! Thank you zitronen, for making this possible. You inspired me greatly :D 

G1Oz0HN.jpg

If you want to see more pictures, I put some up on imgur: http://imgur.com/a/GFKPg

And a video: https://www.youtube.com/watch?v=Nv8L_1PuXVM&t=19s

Link to comment
Share on other sites

Thanks @c4ooo, I will make a post on Mulbin's forum :)

@zitronen, I wanted to ask you a question - I find that rarely, my Arduino is losing connection every now and then with the computer. I saw your suggestion to increase the Arduino Serial buffer, which I increased from 64 to 256 (both RX and TX). However, I am still experiencing the problem.

Do you think it could be that I am overpowering my Arduino, and it is shutting down from too much current draw? After the loss of connection, it always manages to re-establish a connection within about 1-2 handshake delay intervals. Thanks for your input!

Link to comment
Share on other sites

53 minutes ago, mountaineerman said:

Thanks @c4ooo, I will make a post on Mulbin's forum :)

@zitronen, I wanted to ask you a question - I find that rarely, my Arduino is losing connection every now and then with the computer. I saw your suggestion to increase the Arduino Serial buffer, which I increased from 64 to 256 (both RX and TX). However, I am still experiencing the problem.

Do you think it could be that I am overpowering my Arduino, and it is shutting down from too much current draw? After the loss of connection, it always manages to re-establish a connection within about 1-2 handshake delay intervals. Thanks for your input!

You can do the maths to be exact - but that could be a possibility (with that much stuff connected to the board). 
Do you have external power running to the 'duino? If not, start with this.

Further, you can also increase the baud rate; I run mine at 115200, and have set my refresh to "0.3" - and I found this helped with the random cut-outs. I also modified the board settings in my Arduino program files to have a 256 buffer size (like you have).

Give these a shot :)

Link to comment
Share on other sites

I had the same problem due to processing overload - did too much math on my Mega. You can try to go through your panel and see if there are some indicators that only need an update every half second, or even less. That solved the problem for me.

Link to comment
Share on other sites

I've been meaning to build a KSP simpit for a long time, but the first thing I wanted was a navball. What is a simpit without a navball? So I made one. This is a cheap 3.2" TFT LCD arduino mega shield display at 320x480 colour. I can get about 10 frames per second and that seems usable. I still need to modify the plugin to add node information, but this looks like a start. The latency is also not too bad.

Here's a video clip of the navball in operation :KSP LCD Navball

The code is all on github: github.com/mmoller2k/tft_navball

Enjoy and thanks for the plugin.

x3lvFgu.jpg

Edited by boostme
fixed image link
Link to comment
Share on other sites

Edit: the orignal version of this post had a question that i figured out :)

I added navball speed modes. They use the upper nibble of SASMode (autopilot vector). "If the navball is in Surface mode and SAS is set to AntiNormal, SASMode will equal TARGET + SMAntinormal = 48 + 5 = 52. ". To get the SASMode (auto pilot vector) on arduino, do (SASMode & 0x0F), and (SASMode & 0xF0) to get the navball speed mode.

Navball speed mode definitions: 

#define ORBIT 16
#define SURFACE 32
#define TARGET 48
Spoiler

SASMode (autopilot vector) definitions:


#define SMOFF           0
#define SMSAS           1
#define SMPrograde      2
#define SMRetroGrade    3
#define SMNormal        4
#define SMAntinormal    5
#define SMRadialIn      6
#define SMRadialOut     7
#define SMTarget        8
#define SMAntiTarget    9
#define SMManeuverNode  10

 

Heres some example code for arduino:

    if((VData.SASMode & 0x0F) == SMRetroGrade){ //if the SAS is set to RetroGrade...
      CPacket.SASMode = SMPrograde; //set to Prograde
    }else{
      CPacket.SASMode = 0; //reset
    }

    if((VData.SASMode & 0xF0) == ORBIT){ //If navball in orbit mode...
      CPacket.SASMode = CPacket.SASMode | TARGET;  //Set to target mode. (Notice the bitwise-or with the SAS autopilot vector
    }

 

Edited by c4ooo
Link to comment
Share on other sites

11 hours ago, JoshTheCoward said:

Do you think there will be a fix for the no inputs for windows 10 at some point or should I install a copy of 7 again?

The problem is driver based, so the plugin cannot fix it. A workaround is to purchase a USB to TTL converter based on a different chip and connect tx, rx to Dig0 and Dig1, and +5V and GND to Vin and GND instead of USB to Arduino.

Link to comment
Share on other sites

14 hours ago, c4ooo said:

I added navball speed modes.

Oh that is cool. Thank you! That will come handy :) Already working on plans and schematics for that. But code looks kind of advanced for me :D Ah, i ll figure it out. Long winter evenings comes anyway :D

 

I would like advice on issue with my Mk.2 build. It is planed as module system, like one Atmega will handle comunication with PC, second all inpust (joystick, switches), third one all outputs (leds, indicators), fourth is for nixie tubes, fifth one is Due for 7" TFT.   All will comunicate using I2C or SPI bus. An as you see ATmega328 will be master sending and reciving data from all other processors. My question is if it will better to use DUE (with its 84Mhz clock) as Master that will handle PC <--> Control panel comunication, send data to other procesors and recive back AND still handle 7" TFT smoothly.  What you think?  

Link to comment
Share on other sites

On 28/11/2016 at 8:43 AM, mountaineerman said:

Thanks @c4ooo, I will make a post on Mulbin's forum :)

@zitronen, I wanted to ask you a question - I find that rarely, my Arduino is losing connection every now and then with the computer. I saw your suggestion to increase the Arduino Serial buffer, which I increased from 64 to 256 (both RX and TX). However, I am still experiencing the problem.

Do you think it could be that I am overpowering my Arduino, and it is shutting down from too much current draw? After the loss of connection, it always manages to re-establish a connection within about 1-2 handshake delay intervals. Thanks for your input!

You could also try changing

boolean KSPBoardReceiveData() {
  if ((rx_len == 0)&&(Serial.available()>3)){

To

boolean KSPBoardReceiveData() {
  if ((rx_len == 0)&&(Serial.available()>6)){

In SerialCOMS tab

Increasing baud rate also helps, in fact I think it's about time for us to use 115200 as default instead of 38400.

 

@c4ooo I don't have a lot of time right now, will try to test your new code later this week. Thanks!

Edited by zitronen
Link to comment
Share on other sites

I've converted my TFT navball from a Mega2560 to an Arduino Due. It is significantly faster, but I cannot get it to connect to KSP.

I've tried both the ports without success. The LEDs on the programming port start flashing when I launch a vessel, but the Due sees no connection.

Am I screwed? Is it back to the Mega? Anyone with any ideas?

Link to comment
Share on other sites

Somebody talk about that several pages back. Mega2560 is 8-bit and SAM3X on Due is actualy 32-bit mCu. There are required some changes in code to make it work I think.

Found it.

Critical thing for anybody moving to 32 bit CPUS is that you need to add

struct __attribute__((__packed__)) VesselData

To your message structure definition in the Arduino code, otherwise all the bytes in the message get mixed together.

I get it what problem is going on but i dont get it how to fix it :D

Link to comment
Share on other sites

13 hours ago, boostme said:

Thanks! That would explain it. I'll give it a try tonight.

Initial testing shows that I might be able to fill the wireframe with the Due and still get more than 10 FPS.

Is the bottleneck the fact that an arduino cant really drive an LCD or is it your 3D drawing code?

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