zitronen

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

Recommended Posts

On 8/31/2019 at 12:03 AM, tsaven said:

Is there documentation anywhere of how many decimal points are sent for each floating point variable?  I'm having a heck of a time getting my Mach readout to work and I think I've been formatting it wrong, but it's hard to tell when I don't know how big (in terms of characters) the incoming variable is.

It would also be useful to have documented somewhere what structure the other variables are sent in, especially the time-related ones.  Seconds, minutes, hours, etc?

What floating point data are you talking about to be exact? You might have to convert them to integers or something for them to work correctly with the API for your readout. Otherwise, the formatting of the structures is found in the original post.

Edited by c4ooo

Share this post


Link to post
Share on other sites

Slowly pecking away at my project. I have two videos for show and tell (both shot in portrait mode sorry)

These show my very rough work in progress KSP controller project. Progress is quite slow and I've been on and off at it for years now. It'll still take a while to get to something more than a breadboard. I've had to learn all sorts of things to get this far, but it's been quite fun 'working the problem'.

Still a long while off, but I figured someone might be interested in the progress so far. The last month of my most recent tinkering has rewarded me well with these two elements that seem to be actually working. Debugging continues.

Video 1: External ASET Prop (RPM) CRT display test. With @NavyFish PDAI integration for port renaming / selecting.

Buttons in order: UP, DOWN, ENTER, ESCAPE, SORTMODE

 

Video 2: ASET Prop (RPM) DSKY software logic test before hardware implementation. Copied the lau script logic from @MOARdV

Buttons implemented:
AP/PE buttons: Orbit, Tgt, Rndz, Mnvr
Time buttons: Ap, Pe, An, Dn, Mnvr, Lnch (no code for this one as yet)
DeltaV buttons: Total, Stage, Mnvr, Trnf

Additional code snagged from @alexustas from multiple mods. I've managed to get all the Annunciators from the ALCOR lander can working (in software) and registered on the Arduino. However, I still need to create a test page to verify I've got all that logic straight.

Also a big shout out to @linuxgurugamer for the Logger mod. It's an excellent mod to get the data out of KSP/Unity so it's usable for something other than shoving down the serial line of this mod. Allowed me to update a text file as required. This is then read by an independent WPF application that watches for file updates. That app just reads the updated file and formats the text using the same fonts from the ASET mod pack for the display on a small separate monitor. I've got a 800x600 monitor on order that will be it's proper display. Doesn't work as well on a widescreen.

Oh - and can't forget a big thanks to @zitronen  for making this mod in the first place. Note: you do NOT want to see what I've done to your code to get it to this point. At last count I'm pushing about 400+ bytes across 5 different structs through my serial connection and the Teensy 3.6 is keeping up fine. It's split across various timings,  some are updated periodically, others are 4 times a second, still others are faster.

Current plan is to have a layout like the Mk1 lander can. I still think I can use LGGs custom resolution mod to expand the screen across two monitors, stack those monitors vertically, then add the LGG camera mod, which should allow me to have a fwd and down facing 'window' like the Mk1 Lander Can.

Edited by cyberKerb

Share this post


Link to post
Share on other sites

Hi all, 

Due to my own incompetence I am currently not even able to get Serial IO working with KSP. I have installed the KSP Serial IO folder to the Plugin Data folder as was implied within the github zip file structure. Is this correct?  From videos I have seen of this mod on youtube upon startup at the launchpad green text should appear confirming connected to com port x or something similar which I do not get so I assume it is not running. In addition when i try to upload a sketch to the Uno when it should be connected to KSP it uploads fine implying the serial port was not being used.

Could someone let me know where to install the current version of KSP Serial IO and what I should expect on startup please.  In addition, if I know my Uno always connects on COM3 is this what I should change to within the config file for KSPSerial IO? 

Many thanks in advance.

Share this post


Link to post
Share on other sites

I have checked page 2 and understand what to expect during a good startup now.

This is from Mulbin on page 1  "So let me get this straight (I have very limited knowledge of this stuff)... you just drop the KSPSerialIO folder into... gamedata? And then KSP will send all these values to the serial? Just like that??" 

does anyone know if this Is this still the same procedure? Its just having a plugin data folder inside I thought it might go there.

Share this post


Link to post
Share on other sites
On 9/2/2019 at 12:19 PM, cyberKerb said:

Oh - and can't forget a big thanks to @zitronen  for making this mod in the first place. Note: you do NOT want to see what I've done to your code to get it to this point. At last count I'm pushing about 400+ bytes across 5 different structs through my serial connection and the Teensy 3.6 is keeping up fine. It's split across various timings,  some are updated periodically, others are 4 times a second, still others are faster.

 

Haha nice. This is also why I'm not sharing the code I use for my personal display, it's a huge mess! :D

4 hours ago, Torbus said:

Hi all, 

Due to my own incompetence I am currently not even able to get Serial IO working with KSP. I have installed the KSP Serial IO folder to the Plugin Data folder as was implied within the github zip file structure. Is this correct?  From videos I have seen of this mod on youtube upon startup at the launchpad green text should appear confirming connected to com port x or something similar which I do not get so I assume it is not running. In addition when i try to upload a sketch to the Uno when it should be connected to KSP it uploads fine implying the serial port was not being used.

Could someone let me know where to install the current version of KSP Serial IO and what I should expect on startup please.  In addition, if I know my Uno always connects on COM3 is this what I should change to within the config file for KSPSerial IO? 

Many thanks in advance.

No you put the folder in GameData, like all other mods, not in PluginData. You can also use CKAN to install it automatically, since it was updated recently. Also yes you can change the default port in the config file. If the plugin can't find the default port it will check other available ports on your PC.

Share this post


Link to post
Share on other sites
On 8/31/2019 at 4:20 AM, zitronen said:

Uh.. floats have a variable number of decimal points, that's why they are called "floating" point. Mach number is a sent as a float. Arduinos only support 32bit floats, they have about 7 significant digits (M=1.235678, M=12.345678 M=123.45678, etc.), times are always in seconds, but some are signed (int) because they can be negative and some are unsigned (UInt). The only time related variable that is a float is "deltaTime" which is the time interval in seconds since last serial packet was sent from KSP, used for calculating derivatives.

 

On 9/1/2019 at 6:06 PM, c4ooo said:

What floating point data are you talking about to be exact? You might have to convert them to integers or something for them to work correctly with the API for your readout. Otherwise, the formatting of the structures is found in the original post.

Sorry for phrasing my question so stupidly, but that was the answer I was looking for;  exactly how many digits I would need to deal with.  In terms of getting the variable displayed on a 7-segment display, I've gotten familiar with the "dtostrf" function and have been using it to great effect.  I've got my velocity & mach readouts working, including a button to switch the velocity between Orbital, Surface and Target.

The time-based items I'm still having a hell of a time with though (such as time-to-AP).  About half the time they'll display properly, but then sometimes they'll seemingly get stuck for about a minute before starting to update again.  My next step is to throw a 4x20 LCD onto the breadboard for troubleshooting, so I can output different variables to it as they're going through the calculation process to figure out where I'm garbling my data up.

Edited by tsaven

Share this post


Link to post
Share on other sites
23 hours ago, zitronen said:

Haha nice. This is also why I'm not sharing the code I use for my personal display, it's a huge mess! :D

No you put the folder in GameData, like all other mods, not in PluginData. You can also use CKAN to install it automatically, since it was updated recently. Also yes you can change the default port in the config file. If the plugin can't find the default port it will check other available ports on your PC.

Thanks for the quick reply Zitronen.  I now have Demo 4 installed to an Arduino uno and connection to com 3 is confirmed on startup at the launchpad. As i understand it If I connect LEDs to the pins listed as RCSLEDs or SASLEDs within the skectch then the LEDs should display the relevant state of either of those systems. Is this correct?  

Sorry for the stupid questions and thank you for providing what looks like a fantastic tool (when I eventually get my tiny pea brain around it all). 22cdafc0-98d2-11e2-a853-00144feabdc0?fit

Edited by Torbus
to edit my post

Share this post


Link to post
Share on other sites

No wait there is no SASLED. what the f am i talking about. That's in demo 17. If in demo 17 I use your code and amend it to 

      if (getSASMode() == SMSAS) { //--------- This is how you read SAS modes
         digitalWrite (SASLED, HIGH);
       }

I should get the SAS led turning on when the SAS is on right? Everything else in the sketch is as I downloaded it. 
 

Edited by Torbus
solved

Share this post


Link to post
Share on other sites

I figured others here might like to see the slow progress I'm making.  I've gotten most of the quirks of writing I2C data to all of my 7-segment displays worked out, including how to split the longer numbers over multiple displays.  Right now it's all running on my breadboard, but due to the ease of hooking up dozens of I2C devices it's going to be easy to have it all working once I figure out a layout and a frame that I like.

Right now I have the red 7-segments displaying Velocity, and the blue one displaying heading.  Halfway through you can see me pressing some buttons that change the Velocity readout; these buttons switch it between displaying Surface, Orbital, and Target relative velocity.  The bottom LEDs will eventually be labeled and will indicate exactly which velocity readout is being displayed.

*edit* Come to think of it, maybe I should have taken a video of a rocket launch or a plane that will actually exceed 999m/s to show off the fact that the other red 7-seg display actually works for that...

Edited by tsaven

Share this post


Link to post
Share on other sites

which library and chipset (max7219 ?) do you use for the 7segments? 

if so, basicly i can do it with an 8x8 matrix displays.

Share this post


Link to post
Share on other sites
8 minutes ago, sec3 said:

which library and chipset (max7219 ?) do you use for the 7segments? 

if so, basicly i can do it with an 8x8 matrix displays.

They're the Serial 7-Segment Display from Sparkfun.  It's actually an entire ATMega328 dedicated just to running the 4-charecter display, but because of this it's got a bunch of other features that make them way easier to deal with than having to multiplex and eat up a zillion I/O pins.  I'm planning on using ~20 of these 4-charecter 7-segment displays in my final controllor, so being able to use I2C instead of Serial is going to make the wiring way easier and reduce the load on my Arduino(s).

Share this post


Link to post
Share on other sites

tnx. wow; for multiplexing  i didn´t expect  an 328 on there ...   this one is pre-burned with an RX-Receiver?  or do you need to burn initial code on it?
the sparkfun doc only says another uno or something serial device has to communicate. thats really simple; wire.write them... 

can you send me via PN some code snippets from your setup to study the code ? 

 

 

Share this post


Link to post
Share on other sites
On 9/8/2019 at 6:45 AM, sec3 said:

tnx. wow; for multiplexing  i didn´t expect  an 328 on there ...   this one is pre-burned with an RX-Receiver?  or do you need to burn initial code on it?
the sparkfun doc only says another uno or something serial device has to communicate. thats really simple; wire.write them... 

can you send me via PN some code snippets from your setup to study the code ?

You don't need to put any code on it; it comes pre-loaded and configured.  The only thing you'll possibly want to do (if you're using a lot of them via I2C) is to change the address, which is easy with a few commands.  Then you can daisy-chain up to 128 of them together and address/control them all just using the SCA/SCL pins on the Arduino.

The Sparkfun hookup guide has very detailed instructions on hooking it up and getting it working with whichever communication method you chose, including sample code: https://learn.sparkfun.com/tutorials/using-the-serial-7-segment-display/all

Share this post


Link to post
Share on other sites

Hello everyone!

Im struggling with this Mod. I have managed to actualy see the data coming out of the serialport but i dont know how to convert this data so i can use it. I have used a virtual Serialport, a Terminal-program and this debugging tool to just see whats going on. So in the debugging tool i just changed the amount of liquid fuel to 1000 and watched whats happening in the data. So 4 nummbers are changing to "7A 44". Now the question: How on earth do i convert "7A 44" back into 1000? I have tried everything that the windows calculator can give me but ther is no 1000!! The problem is that i dont use Arduino so i cant use the Examples! or even read them. I am desperate. I dont need mutch data and i dont want to control something (i doing it a different way). Would be nice if someone can explain me this. I think i can do everything except this converting stuff. THX

 

Share this post


Link to post
Share on other sites
4 hours ago, Predator32767 said:

Hello everyone!

Im struggling with this Mod. I have managed to actualy see the data coming out of the serialport but i dont know how to convert this data so i can use it. I have used a virtual Serialport, a Terminal-program and this debugging tool to just see whats going on. So in the debugging tool i just changed the amount of liquid fuel to 1000 and watched whats happening in the data. So 4 nummbers are changing to "7A 44". Now the question: How on earth do i convert "7A 44" back into 1000? I have tried everything that the windows calculator can give me but ther is no 1000!! The problem is that i dont use Arduino so i cant use the Examples! or even read them. I am desperate. I dont need mutch data and i dont want to control something (i doing it a different way). Would be nice if someone can explain me this. I think i can do everything except this converting stuff. THX

 

Fuel data is stored as 32-bit floats. (zitronen why? >_> ) 1000 as a 32-bit float is 0x447a0000, according to this website, so your value makes perfect sense.

On an aside, how are you planning on using this mod without an arduino? 

Share this post


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

Fuel data is stored as 32-bit floats. (zitronen why? >_> ) 1000 as a 32-bit float is 0x447a0000, according to this website, so your value makes perfect sense.

Yes i already found that calculator but i cant figure it out to do this calculation. My english isnt bad but i am not a mathematician and so it is hard to understand.

EDIT: I found a tiny little button to switch to German on this Website so i will read this again step by step tomorrow!

 

Quote

On an aside, how are you planning on using this mod without an arduino? 

Well i said this a little bit wrong. I am not using the language that an Arduino uses but the same microprozessor. The language i am working with is Bascom. I found out that a "float" is called "single" in Bascom but as i said i dont know how to handle it. I just need some sort of a formula: 0x447a0000 -> 1000.

Edited by Predator32767
little update

Share this post


Link to post
Share on other sites

Is there a guide somewhere to how to add controls?  I am looking to add other stuff over time...  3-axis joysticks for rotation and translation, a couple of Nextion displays, etc....  I have some sample code from other peoples projects for comparisons, but i dont think i can do much copy and paste without screwing things up....

 

baby steps / walk before you run / that sort of thing.

 

I am using the Arduino sketch posted on /r/kerbalcontrollers by a guy who goes by wurmi00 because i want to use the nextion display setup that he did.  However, i am not getting any response from the plugin that way.

I think i need some config help.  I may be using a mismatched version of the plugin or something.  The arduino lights blink showing that data is tx and rx.  but not all that fast,.   When i run the demo code, things work and that light blinks really rapidly.  Any input is welcome.

.jx624va5gom31.jpg?width=576&auto=webp&s=

Edited by BamBam

Share this post


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

Well i said this a little bit wrong. I am not using the language that an Arduino uses but the same microprozessor. The language i am working with is Bascom. I found out that a "float" is called "single" in Bascom but as i said i dont know how to handle it. I just need some sort of a formula: 0x447a0000 -> 1000.

Um so... 0x447a0000 *IS* 1000, just in a special format. One thing to understand about low level programming is that data is just raw numbers, and gets its meaning from the context it is used in, if that makes sense. 


What you are trying to do is convert the float into an integer. Almost all languages have a built an int() function to do this for you. One thing to be aware though is that int() truncates the float, you need to be aware of this if you require the numbers after the decimal. 

That being said though, if your language is any good you should be able to do all your calculations using the orignal floating point number, however float math is slower than integer math, especially on old CPU / MCUs.

Share this post


Link to post
Share on other sites

I can do what i want. It will not work. The only number i became is 1148846080.0 .There is an int() function but this just seems to "delete whats behind the dot":

Quote

The fraction is the right side after the decimal point of a single.

The integer is the left side before the decimal point.

 

But i have another idea: I can use this number to calculate the percentage between Max an Current of the liquid fuel. If this will not work i give up.

Share this post


Link to post
Share on other sites
6 hours ago, Predator32767 said:

There is an int() function but this just seems to "delete whats behind the dot":

Isn't this what you want? If you want to use an integer but still express some of the values behind the dot, all you have to do is multiply the float by 10^x or 2^x, then convert to int, then remember that your integer is actually 10^x or 2^x times smaller then its raw value.

Share this post


Link to post
Share on other sites
12 hours ago, c4ooo said:

Isn't this what you want?

no! as i said 447A 0000 is in decimal 1148846080.0. if i use this int() i become 1148846080 just without the ".0". But i have wasted the hole Weekend to find out how to calculate from 447A 0000 back to 1000 and it finaly works! Its a gigantic calculation behind this but it works. So i have to go from Hex to Decimal to Binary, Split this in 3 parts and calculate the Sign, the Exponent and the Mantissa in decimal and then i can use this 3 numbers to calculate back to 1000. I try to use some different numbers and it is pricise enough for this. Now i just have to manage the serial communication and the Spliting of the hole Package into single informations so i can use them for my "KSP-control-center". THX for the help!

Share this post


Link to post
Share on other sites

@zitronen, I have to give mad props to you for creating and maintaining a mod that has such capabilities.  I'm farther along in my controller than I ever expected to be and I'd never have been able to do it if your demo code hadn't spelled things out so clearly and easily.  Thank you, thank you for documenting and commenting the code out as well as you have.

I'm integrating more and more functions into my controller every day!

 

Share this post


Link to post
Share on other sites
10 hours ago, Predator32767 said:

no! as i said 447A 0000 is in decimal 1148846080.0. if i use this int() i become 1148846080 just without the ".0". But i have wasted the hole Weekend to find out how to calculate from 447A 0000 back to 1000 and it finaly works! Its a gigantic calculation behind this but it works. So i have to go from Hex to Decimal to Binary, Split this in 3 parts and calculate the Sign, the Exponent and the Mantissa in decimal and then i can use this 3 numbers to calculate back to 1000. I try to use some different numbers and it is pricise enough for this. Now i just have to manage the serial communication and the Spliting of the hole Package into single informations so i can use them for my "KSP-control-center". THX for the help!

Once again, if you wanted to preserve the numbers after the decimal, you need to multiply your float by 10 or 100 or 1000, then when you cast it to integer you will still have the numbers after the decimal. However I don't even see why you need to cast from float to int, any competent programming language will just allow you to use the floats directly. 

Good job reinventing the wheel with your own casting function though ¯\_(ツ)_/¯

 

Edit: it sounds like you are reading the data *as an integer* and casting it to integer, you need to read the data *as a float* and cast it to integer.

Edited by c4ooo

Share this post


Link to post
Share on other sites
On 9/15/2019 at 1:48 AM, BamBam said:

Is there a guide somewhere to how to add controls?  I am looking to add other stuff over time...  3-axis joysticks for rotation and translation, a couple of Nextion displays, etc....  I have some sample code from other peoples projects for comparisons, but i dont think i can do much copy and paste without screwing things up....

 

baby steps / walk before you run / that sort of thing.

 

I am using the Arduino sketch posted on /r/kerbalcontrollers by a guy who goes by wurmi00 because i want to use the nextion display setup that he did.  However, i am not getting any response from the plugin that way.

I think i need some config help.  I may be using a mismatched version of the plugin or something.  The arduino lights blink showing that data is tx and rx.  but not all that fast,.   When i run the demo code, things work and that light blinks really rapidly.  Any input is welcome.

First of all, welcome around controller building.

It is a bit hard for me to understand what your problem is, but if I understand correctly, the demo code runs, but not your own code. To help, we will need to see you own code. Please, do not paste it in a post, but upload it to somewhere we can download and look. I do recall wurmis name, but not any particulars of his project. If it is old, you might have to update the VesselData and ControlPacket structs with the new entries. Also, a sketch is keyed to a specific hardware setup, so unless you have the exact equivalent setup and wiring the sketch will not do anything useful.

Share this post


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

First of all, welcome around controller building.

It is a bit hard for me to understand what your problem is, but if I understand correctly, the demo code runs, but not your own code. To help, we will need to see you own code. Please, do not paste it in a post, but upload it to somewhere we can download and look. I do recall wurmis name, but not any particulars of his project. If it is old, you might have to update the VesselData and ControlPacket structs with the new entries. Also, a sketch is keyed to a specific hardware setup, so unless you have the exact equivalent setup and wiring the sketch will not do anything useful.

ok, so i have belatedly come to realize that i cannot simply copy somebody's code without having their exact setup.  So, I will be starting from the Demo17 code.  That Demo17 code works just as it should.

 

Here is my rough plan...  I have a USB-HID interface board that I will be using for the actual input into the game.  that lets me keep the input functionality separate and simple.  I plan to use serialIO to drive my indicator LEDs and a set of 7 segment / 8 digit displays to show altitude, apoapsis, periapsis, velocity.  and some analog guages to show fuel levels, and atmosphere density.  It means that i will have to have two USB cables connected but that is no big deal.

 

So, instead of somebody to solve my problem for me, what i need is a really basic tutorial on how to make the starter code in Demo17 to do what i tell it.  My programming skills are all from 1994 when we did Turbo Pascal in High School.  Since then i have not done anything more than write batch files and a few really simple if/then operations.  So I have basically zero experience with Arduino.  My 3D printer ran briefly on Marlin but even that code was already setup and you just had to define a few variables.

 

Dipping into some major wishful thinking here, I saw on this or maybe on the subreddit /r/kerbalcontrollers that somebody had made a sort of DSKY display that used a small LCD panel.  That was beautiful, and if I could figure out how that was implemented that would be a major upgrade to my sort of simplistic plan at the moment.

 

 

 

Edited by BamBam

Share this post


Link to post
Share on other sites

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.