Jump to content

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


zitronen

Recommended Posts

Have you re-downloaded the demo 8 code lately (since 10 says ago)? If not you need to do that. There was a version mismatch since I uploaded the wrong code.

If you have problems with indicators it seems like you have the wrong version.

You can easily check: the struct VesselData in the first arduino tab should have 45 elements in the new version.

That was exactly it. Actually i re-downloaded, but i still had the previous version in my download folder and extracted that instead.

So a big pebcak there from me :)

In addition: when i refactored my arduino code, i moved the initTxPackets() function, still with CPacket.id = 1; instead of = 101; :)

So there were two mismatches. It's working now and i can go back to further implement my buttons.

Thanks for the quick help, everyone :)

Link to comment
Share on other sites

Can you use multiple arduinos at the same time if so how many? Thanks

The ksp plugin only supports 1 serial connection, but you can connect multiple arduinos by using one as the hub and distributing the data to others (or some other network topology). The protocol was made to support it, and someone in this thread has been doing that. However, there is no example code and this will require some quite complicated coding. So not recommended for beginners. If you are running out of pins for things, it's easier to just buy an arduino mega for ~$10 on ebay.

For those who prefer to work with Atmel microprocessors directly and without the overhead of the Arduino GUI, I've ported Zitronen's Demo8 to native AVR C:

https://github.com/MrOnak/avr_KSPIO

Enjoy

Added to first post!

Link to comment
Share on other sites

Any issues with me hacking up your code to make a Netduino version?

Just in case you're refering to my ported code, go ahead. The code is released as Creative Common Attributions. As long as you keep a reference to me and Zitronen you're good to go.

However be aware the UART code I used is released under GPL, this affects the licensing that you can put your port under (no commercial products, etc). Just so you know.

Link to comment
Share on other sites

Can you use multiple arduinos at the same time if so how many? Thanks

Like Zitronen said, you can have multiple Arduinos talk to each other via SPI or I²C but to be honest that's not really worth it. If you're simply running out of pins I highly recommend checking out how shift-registers work (74*595 if you need lots of outputs, 74*165 if you need lots of inputs). Those are cheaper than "moar Arduinos" and essentially can be talked to with the SPI protocol.

Maybe if you outline why you want to use more than one Arduinos in the first place I can give you an idea of how you might get around that :)

Edited by MrOnak
Link to comment
Share on other sites

Just in case you're refering to my ported code, go ahead. The code is released as Creative Common Attributions. As long as you keep a reference to me and Zitronen you're good to go.

However be aware the UART code I used is released under GPL, this affects the licensing that you can put your port under (no commercial products, etc). Just so you know.

Great! I'll post here when I get it working.

Link to comment
Share on other sites

If you guys have any problems/suggestions with my code let me know. There are probably many bugs since I just hacked it together. It's a bit scary seeing people using it as some kind of standard, I'm not even a software person!

Ah... don't worry too much about it, the code is alright to show what can be done. Anyone using it in a project will very likely adapt it to his / her own style anyway. :D

Link to comment
Share on other sites

I know the video... its alright and it does explain shift registers okay, but honestly, using the 595's to control inputs is just plain wrong ;) the 165's are so much easier for that.

I have never played with those, but now I want to :D

Do you have a source for these? Sparkfun does not carry them anymore, and the only other source I could find was in the EU.

Link to comment
Share on other sites

I have never played with those, but now I want to :D

Do you have a source for these? Sparkfun does not carry them anymore, and the only other source I could find was in the EU.

Hmm frankly speaking every electronic shop should have them, they're bread and butter ICs. That said Sparkfun and the likes will be much too expensive for simple components like that unless you're lucky.

I got a pack of 50 74595's from ebay (seller from Hongkong, free shipping) for very little money. If you can wait a few weeks for the delivery to arrive I'd say check there, its usually worth it (not always). In the case of the 50 74595's, they were cheaper than 10 ICs of the same kind if I had bought them locally. I doubt I'll ever need 50 pieces but hey... I can now afford to fry a few.

Check radioshack or your local equivalent if you can't find anything on ebay or you don't want to wait a few weeks. I've also had good experience with more specialized shops for some components although I'm not sure about shift-registers (but you'll find transistors, resistors, condensators and the like very cheap in car-hifi supplier shops for example).

Note that virtually any *74*595 and *74*165 will do (595 for outputs, 165 for inputs). The letters before the "74" simply denote the manufacturer and the letters in between the numbers denote the manufacturing proces (TTL variants).

Regarding the manufacturing process, if you can get "HC" or "HCT" variants, they're preferable (faster switching, less voltage sensitive) but in the end it won't matter much.

Edited by MrOnak
Link to comment
Share on other sites

Re: SOI

I've finally gotten around to poking at this project again, and just updated myself on all the new comments. I saw someone do some rough calculations to extract the SOI from orbital parameters; looking through the API, I think we can get the SOI directly fairly easily. From the API documentation:

CelestialBody Class

[TABLE=class: wikitable]

[TR]

[TH=bgcolor: #F2F2F2, align: center]Inherits[/TH]

[TH=bgcolor: #F2F2F2, align: center]Implements[/TH]

[/TR]

[TR]

[TD]UnityEngine.MonoBehaviour[/TD]

[TD]ITargetable, IDiscoverable[/TD]

[/TR]

[/TABLE]

A CelestialBody represents a planet, moon, or star that acts as a source of gravity and has some sphere of influence. You can find the CelestialBody whose sphere of influence you are currently in with the vessel.mainBody field.

We should be able to get to it by having another field in KSPSerialIO:

// Early on in the code, define a dictionary with all the possible spheres of influence
Dictionary<string, int> celestialBodies = new Dictionary<string, int>()
{
{"Kerbol", 0},
{"Kerbin", 1},
{"Mun", 2},
{"Minmus", 3}
// etc.
};
// Add a field to the packet definition, maybe force an 8-bit value here?
public int SOI;

In the packet packing section, add


[COLOR=#000000][FONT=sans-serif]KSPSerialPort.VData.SOI =  celestialBodies[ActiveVessel.mainBody.name];[/FONT][/COLOR][COLOR=#000000][FONT=sans-serif]
[/FONT][/COLOR]

I'm a Python guy, not much experience with C#, so I may have done some of this up incorrectly. We'd also have to check to be sure we're getting the correct strings as used in mainBody.name, and perhaps add some logic to include a {"No SOI", -1} pair (what does mainBody.name hold when not in any SOI? Is that even possible in KSP?) Anyone with some C# knowledge want to look into this and see if it works?

:: forum is insisting on adding an extra CODE /CODE pair... no idea why. ::

Edited by drmag
Link to comment
Share on other sites

Yeah quite a few people have wanted a SOI thing. My original thinking was to use a 16 bit uint. So a value like 10300 means 1(Kerbol)03(planet 3, Kerbin)00(moon 0 or not near moon). I could pack it all into a byte, but this is more human readable and makes it easier if squad decide to add more bodies later.

Link to comment
Share on other sites

Hello

I have a small issue with this plugin - input from Arduino isn't working, but my displays are working perfectly.

I tried updating plugin and data structs in program, but it's still not working.

Any ideas?

Link to comment
Share on other sites

I really like this mod, and I build a controller for it, but it doesn't work in .24. (it worked fine in .23.5) I have the latest version of the KSP side of the mod, and my Arduino code is a modified version of your code. I already added the pitch, heading, and roll float values to the vesselData struct, but it doesn't do anything in the game. Are there any other changes I need to make to the Arduino code besides that?

Link to comment
Share on other sites

kOS is providing access to the current SOI - you might be able to borrow some code from there :)

Thanks for the "intelligence" :cool:. Since 0.25 is coming out soon, I'll wait till it comes out and see if there are any problems. If it works fine in 0.25 I will look into adding SOI output.

I really like this mod, and I build a controller for it, but it doesn't work in .24. (it worked fine in .23.5) I have the latest version of the KSP side of the mod, and my Arduino code is a modified version of your code. I already added the pitch, heading, and roll float values to the vesselData struct, but it doesn't do anything in the game. Are there any other changes I need to make to the Arduino code besides that?

You may need to look at the "handshake" tab, since things have changed. It should look like this

// Handshake

void Handshake(){
digitalWrite(GLED,HIGH);

HPacket.id = 0;
HPacket.M1 = 3;
HPacket.M2 = 1;
HPacket.M3 = 4;

KSPBoardSendData(details(HPacket));
//Serial.println(F("KSP;0"));
//delay(1000);
}

Also check your

struct ControlPacket

is the same as the demo8 code, and lastly under "ultilities" check initTxPackets, should be

void InitTxPackets() {
HPacket.id = 0;
CPacket.id = 101;
}

If that doesn't work post your debug log here.

Edited by zitronen
Link to comment
Share on other sites

You may need to look at the "handshake" tab, since things have changed. It should look like this

// Handshake

void Handshake(){
digitalWrite(GLED,HIGH);

HPacket.id = 0;
HPacket.M1 = 3;
HPacket.M2 = 1;
HPacket.M3 = 4;

KSPBoardSendData(details(HPacket));
//Serial.println(F("KSP;0"));
//delay(1000);
}

Also check your

struct ControlPacket

is the same as the demo8 code, and lastly under "ultilities" check initTxPackets, should be

void InitTxPackets() {
HPacket.id = 0;
CPacket.id = 101;
}

If that doesn't work post your debug log here.

Ok thanks for that, I'm trying it out now!

EDIT--Things are working now... Everything except throttle. I'll see if I can work it out myself.

Edited by jandcando
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...