Jump to content

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


zitronen

Recommended Posts

I see a lot of the posts for hardware but I think I am missing where code is placed in the posts. I would just like to get a look at it to see how it is formatted and how it is structured. At most I have dabbled in various coding but the only thing I spent a fair amount of time with is html (Not much of a coding language but it gave a decent basis on formatting). The arduino starter guide that came with the kit is nice and all but it tries to cover the whole range of parts included when all i want to do is get to work on my own controller :)

Link to comment
Share on other sites

I see a lot of the posts for hardware but I think I am missing where code is placed in the posts. I would just like to get a look at it to see how it is formatted and how it is structured. At most I have dabbled in various coding but the only thing I spent a fair amount of time with is html (Not much of a coding language but it gave a decent basis on formatting). The arduino starter guide that came with the kit is nice and all but it tries to cover the whole range of parts included when all i want to do is get to work on my own controller :)

Hey there!

If you're stuck, feel free to send me a PM. I've been working with the code the past 24 hours and have a fairly solid grasp of it all.

I'm also planning on creating / releasing some videos + documentation that de-mystifies the code, and how to link in external libraries / make different things work :)

RE: Pull Down Resistors --

Thanks again to Zitronen for providing the link to

explaining floating circuits.

I think I followed a crappy guide to buttons, because I put all my resistors in series. The momentary push-buttons didn't work (until I wired in the resistor + 5v properly, as per the video).

However, my toggle switches are working fine; anybody got any idea on why that could be? :huh:

[Marzubus / Stibbons / TAPOR -- you guys participated in some of this discussion in depth, I'm hoping one of you can answer this one :) ]

Many thanks!

Link to comment
Share on other sites

If you're using pull-up resistors as described in the video, multiple buttons should be wired like this:

ea6JOb3.png

Using pull-down resistors is the same, just swapping VCC and GND.

But I'm not sure what you mean by wiring your resistors in series. There's two options I can think of. If you do it like this:

PMHkiCv.png

then you're shorting all of your input pins together - pushing one button will result in all of the inputs being low.

On the other hand, doing it like this:

FuWGogN.png

means that all of your input pins are still floating, and all bets are off. It's entirely possible that a setup like this will result in one group of identical switches not working, and another group of identical switches working. Depending on air temperature and humidity, phase of the moon and the last time you saw a brindle goat.

And finally, because I know somebody else will point it out if I don't, the Atmel microcontrollers in Arduino Uno and Mega boards have built-in pull-up resistors. That means you can save yourself some wiring and use a layout like this:

tyy6Sih.png

But if you choose to do this, then you need to tell the Arduino that you want to enable the internal pullup, by setting the pin mode to INPUT_PULLUP.

pinMode(Switch1_Pin, INPUT_PULLUP);

There. I hope that makes things... um... slightly less confusing?

Link to comment
Share on other sites

There. I hope that makes things... um... slightly less confusing?

Believe it or not, you have! Thank you so much! :D

So using a mega, it's got the internal pull-up.

Any thoughts as to why the 'input_pullup' wouldn't work on my SPST / momentary on buttons?

I had to modify them to have a pull-up resistor as per the video. That works - but going by this diagram, my original wiring should've worked too!

Edited by Sputnix
Link to comment
Share on other sites

I can only think of one or two possible explanations. Obviously, if you don't set the pinMode to INTERNAL_PULLUP, then it won't work. Alternatively, if you're using a cheaper arduino clone board, it's possible it has a different processor or a counterfeit Atmel chip with wonky or nonexistent internal pullups.

Link to comment
Share on other sites

Could it be a problem with contact bounce? Was it "not working at all" or "working erratically"? Personally, I always pull my inputs down externally instead of using internal pull, just to be sure. It also reduces the possibility of a bug in my code by one.

Link to comment
Share on other sites

I can only think of one or two possible explanations. Obviously, if you don't set the pinMode to INTERNAL_PULLUP, then it won't work. Alternatively, if you're using a cheaper arduino clone board, it's possible it has a different processor or a counterfeit Atmel chip with wonky or nonexistent internal pullups.
Could it be a problem with contact bounce? Was it "not working at all" or "working erratically"? Personally, I always pull my inputs down externally instead of using internal pull, just to be sure. It also reduces the possibility of a bug in my code by one.

It is a 'clone-duino' - the toggle switches worked fine, but the momentary SPST switches weren't. All inputs were were defined as 'input_pullup'. So I suspect there is an internal pullup resistor in this thing.

However, I think I worked out what I did. When I was putting everything back together, I think I reconnected the 'gpio data' line to the wrong connector on the button :blush:

So, I'm sorry for the wild goose chase. On the plus - I got a lot more learning and understanding through it :)

Many thanks again!!

Link to comment
Share on other sites

I'm pretty sure the parachute thing is based on indicated air speed or Mach, which are already in the packet. Anyone want to do some experiments? :)

I've done some testing. I believe it's the orbital speed. If it's greater than 310, it's unsafe; less than 310 it's safe.

This could also be based on atmospheric pressure; since each planet will have a different value.

However, until I travel to these other celestial bodies, I won't be able to confirm this.

I displayed Air Speed, Orbital Speed, Vertical Velocity, Gees. and Air Density on the LCD;

I then had an assistant take a photo of the display as the 'safe/unsafe' indicator changed. In both instances (allowing for slight delay from the photographer) it looks that around ~300 is the magical number

Parachute_1.png

Edited by Sputnix
Link to comment
Share on other sites

I've done some testing. I believe it's the orbital speed. If it's greater than 310, it's unsafe; less than 310 it's safe.

This could also be based on atmospheric pressure; since each planet will have a different value.

However, until I travel to these other celestial bodies, I won't be able to confirm this.

I displayed Air Speed, Orbital Speed, Vertical Velocity, Gees. and Air Density on the LCD;

I then had an assistant take a photo of the display as the 'safe/unsafe' indicator changed. In both instances (allowing for slight delay from the photographer) it looks that around ~300 is the magical number

http://pfpfree.net/images/ksp/july/Parachute_1.png

Did you look at Indicated Airspeed (IAS)? IAS is not the same as surface speed (which is True Airspeed or TAS), it takes into account of pressure. The parachute will create the same amount of drag at 30m/s IAS no matter how high or what planet you are on, but will have totally different drag at 30m/s TAS depending on air density.

This video explains it: https://vimeo.com/26488181

Also air density goes from 1.225kg/m^3 to 0kg/m^3 on Kerbin, so you might want to add some decimal points.

Link to comment
Share on other sites

Did you look at Indicated Airspeed (IAS)? IAS is not the same as surface speed (which is True Airspeed or TAS), it takes into account of pressure. The parachute will create the same amount of drag at 30m/s IAS no matter how high or what planet you are on, but will have totally different drag at 30m/s TAS depending on air density.

This video explains it: https://vimeo.com/26488181

Also air density goes from 1.225kg/m^3 to 0kg/m^3 on Kerbin, so you might want to add some decimal points.

Yeah, I was using IAS for the 'air speed' tab.

Thanks for that video, too. Highly informative! You've always got something incredibly useful to share!

As for the data -- I've outputted every variable that could be of use; You may be right, that it's a combo of variables / values -- but I'm still analysing it.

Anybody else that feels like they might have something to add, feel free to check it out below.

There's 2 unsafe points.

1. Ascending with engines lit.

2. Descending, free-falling to the surface.

.

V2 below (Faster refresh, can see values better) --

Edited by Sputnix
Link to comment
Share on other sites

Yeah, I was using IAS for the 'air speed' tab.

Thanks for that video, too. Highly informative! You've always got something incredibly useful to share!

As for the data -- I've outputted every variable that could be of use; You may be right, that it's a combo of variables / values -- but I'm still analysing it.

Anybody else that feels like they might have something to add, feel free to check it out below.

There's 2 unsafe points.

1. Ascending with engines lit.

2. Descending, free-falling to the surface.

.

V2 below (Faster refresh, can see values better) --

Nice, very useful test. Looks like Mach 0.8 is the magic number. Would be interesting to test it somewhere with a denser atmo, so Mach 0.8 can mean > 250 IAS.

Link to comment
Share on other sites

Nice, very useful test. Looks like Mach 0.8 is the magic number. Would be interesting to test it somewhere with a denser atmo, so Mach 0.8 can mean > 250 IAS.

Heh. Thanks (You can pat yourself on the back for the heavy lifting work ;):P )

Once I've got myself off planet, I'll do similar tests, and posts the results here :)

* * *

As an aside, can anyone point me in the direction as to how to convert / cast the times (Time to AP, Time to PE, and Mission time - first two being Int's, and the Mission being UInt32) so as to work with an 8 digit, 7-segment display?

I've tried googling; but either my google-fu is borked, or it's not possible [easily].

Thanks :)

Edited by Sputnix
Link to comment
Share on other sites

Forgive me if I'm overlooking something obvious... I downloaded this plugin, put it into the GameData folder, hooked up and loaded the sketch onto my Arduino Uno with three LEDs / 1k resistors hooked up per the tutorial.

Everything worked fantastic! LEDs lit up when they were supposed to (for the warning alarm little tut) --

HOWEVER. My throttle control is out of whack? I can't throttle down the entire way - using LeftControl OR "X" key. The throttle goes down to 25% and parks there. This was working fine about an hour ago when I was playing for fun... only difference was installing this plugin.

Is this a somewhat common issue? Is it in the DLL files / configs for the plugin? Did I even put the plugin into the right folder? Haha thanks guys. A little intimidating since you all seem way smarter than me. I just thought I would try it out since I have a couple of spare Arduino boards and lots of LEDs sitting around.

Link to comment
Share on other sites

Forgive me if I'm overlooking something obvious... I downloaded this plugin, put it into the GameData folder, hooked up and loaded the sketch onto my Arduino Uno with three LEDs / 1k resistors hooked up per the tutorial.

Everything worked fantastic! LEDs lit up when they were supposed to (for the warning alarm little tut) --

HOWEVER. My throttle control is out of whack? I can't throttle down the entire way - using LeftControl OR "X" key. The throttle goes down to 25% and parks there. This was working fine about an hour ago when I was playing for fun... only difference was installing this plugin.

Is this a somewhat common issue? Is it in the DLL files / configs for the plugin? Did I even put the plugin into the right folder? Haha thanks guys. A little intimidating since you all seem way smarter than me. I just thought I would try it out since I have a couple of spare Arduino boards and lots of LEDs sitting around.

I think that's because you are not connecting a throttle to the arduino. If that is the case, you need to disable throttle control in the .cfg file, or remove the arduino code that reads analog input. See the first post for the cfg file options.

Link to comment
Share on other sites

Thanks for the quick and informative reply!

I'm still very much getting use to programming/coding so I'm not quite good at looking through lines of code so critically.

Thank you again!

Link to comment
Share on other sites

Thanks for the quick and informative reply!

I'm still very much getting use to programming/coding so I'm not quite good at looking through lines of code so critically.

Thank you again!

I am in the same boat as you! I am slowly learning my way so I can apply it to a custom controller. If you have any questions, feel free to ask. It helps me to cement what I learn by helping others through it as well, and it has the added benefit of learning about something I don't know by helping track down an answer.

Link to comment
Share on other sites

As an aside, can anyone point me in the direction as to how to convert / cast the times (Time to AP, Time to PE, and Mission time - first two being Int's, and the Mission being UInt32) so as to work with an 8 digit, 7-segment display?

I've tried googling; but either my google-fu is borked, or it's not possible [easily].

Thanks :)

In case anyone is interested - I have worked this one out. I'll detail the information in my worklog tomorrow!

Link to comment
Share on other sites

I know this is "super noob" territory, but does anyone here want to spend some time and help me out / explain things to me? I tried using the demo code and removing the input coding to create a simple LED display... Lights on with RCS/SAS/Gear ect. However I keep getting errors upon compiling and I'm not too sure what I'm doing wrong and which parts of the code are "expendable" for what I want to do with it.

I'll keep researching arduino tutorials and language ect but I was just wondering if someone here might be able to help explain it more in laymans terms to me.

Link to comment
Share on other sites

However I keep getting errors upon compiling and I'm not too sure what I'm doing wrong and which parts of the code are "expendable" for what I want to do with it.

I'll keep researching arduino tutorials and language ect but I was just wondering if someone here might be able to help explain it more in laymans terms to me.

Qst 1 - What are the errors?

Qst 2 - Have you gone through the Arduino Tutorials?

They're a great place to start to get your head around the hardware, coding, and functionality of the devices.

Also, you should add things little by little (usually one at a time) to make sure everything is working, and to make troubleshooting / debugging a whole lot easier! :)

Link to comment
Share on other sites

I'm trying to connect my Raspberry Pi to the Plugin using C#. I can receive and display data from KSP but I can't send the ControlPacket to control my vessel. - answering the handshake is working of course.

When pressing a button, the Pi should send the ControlPacket for turning lights on.

The ControlPacket looks the following: 190 239 45 101 32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 104

But nothing happens. Has the ControPacket any Errors or where could I be wrong?

Link to comment
Share on other sites

I'm trying to connect my Raspberry Pi to the Plugin using C#. I can receive and display data from KSP but I can't send the ControlPacket to control my vessel. - answering the handshake is working of course.

When pressing a button, the Pi should send the ControlPacket for turning lights on.

The ControlPacket looks the following: 190 239 45 101 32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 104

But nothing happens. Has the ControPacket any Errors or where could I be wrong?

Using my Matrix reading ability :D, it looks like you have packet length = 45 instead of 25. You might have byte packing issues?

Link to comment
Share on other sites

Using my Matrix reading ability :D, it looks like you have packet length = 45 instead of 25. You might have byte packing issues?

I think an integer is 4 Bytes long not 2 or is the Arduino only 16Bit? The ControlPacket has 10 integers an 5 Bytes => 25 Bytes (16Bit-Mode) or 45 Bytes (32Bit-Mode)

I will try it tomorrow with Int16, thanks.

Link to comment
Share on other sites

I think an integer is 4 Bytes long not 2 or is the Arduino only 16Bit? The ControlPacket has 10 integers an 5 Bytes => 25 Bytes (16Bit-Mode) or 45 Bytes (32Bit-Mode)

I will try it tomorrow with Int16, thanks.

Yeah int on arduino is 16 bit, long is 32bit. Bit of a trap if you are using other platforms.

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