zitronen

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

Recommended Posts

Ok... Ive been trying some early experiments with my first arduino today (and learning about resistors!). I've tried wiring up your light demo but I'm not getting it to work.

I think I've wired it up the same (I'm using a Mega2560... I assume the blue wire on yours is plugged into the ground but it looks like it is in the wrong place...) but all that happens is the green led comes on for about 2 or 3 seconds when the game loads in to the main menu. The warning lights aren't working in game and I'm getting the tiny RX led flashing like crazy on the board.

Share this post


Link to post
Share on other sites

Here is a more detailed description. I have no other mods installed.

KSP Loads...

When title screen appears all three leds flicker once (almost imperceptibly).

Green LED then turns on for about 2 seconds - then turns off.

I load a game.

Select a ship and load.

As soon as the scene is loaded in and I'm on the launchpad the tiny LED marked "RX" on the Arduino begins flickering really quickly.

The red, yellow and green warning lights do nothing throughout the flight :/

I also have the log file but I don't know how people post them in those clever scrolling text boxes!

Here is how I have it wired. The resistors are the ones supplied with the LEDs specifically for use with the Arduino.

aKXChu1.jpg

Edited by Mulbin

Share this post


Link to post
Share on other sites

Hmm.. OK your wiring is correct, and if the rx led is flashing it means it's talking to the arduino. It's probably because you need the latest version of the plugin which outputs some more data. I guess I only updated the source code to github and forgot to re-upload the new dll files. Try it again with the 0.11 plugin, same link on the first page.

Share this post


Link to post
Share on other sites

Ok just downloaded again... I'll set up the board again.

Not sure this is the problem though as the file size and dates of the new DLLs are identical to my old ones.

Ok, still not working :( exactly the same as before although I have noticed that I am getting a message on KSP saying something like Starting Port Com1 when the launchpad scene is loaded. Still no lights though other than the green one in the main title menu.

The only differences I can think of are...

I am using an Arduino Mega 2560 rev3

I am using different power LEDS with 220r resistors

Ive just noticed that your serial port.dll still says last edited 25/12/2013 Is that up to date? KSPSerialIO is newer..

Edited by sal_vager

Share this post


Link to post
Share on other sites

The dlls should be correct, I pulled them directly from my ksp folder which I just tested, and I didn't do anything to serialport.dll lately. When you say there are no lights does that mean you are not even getting the rx blinks any more? If you don't see the rx blinks any more then that's quite important.

The correct behaviour of the demo should be:

Start KSP, main menu loads, plugin loads and searches for the arduino, green LED on when it finds it then turns off. (press alt - F2 during loading to see if there are any error messages)

At the launch pad, when the scene loads it should say "Starting serial port X" or "Using serial port X" in the middle of the screen and the green LED should be on. When you launch you should see the warning lights if there's something to warn (G or low fuel).

Share this post


Link to post
Share on other sites
The dlls should be correct, I pulled them directly from my ksp folder which I just tested, and I didn't do anything to serialport.dll lately. When you say there are no lights does that mean you are not even getting the rx blinks any more? If you don't see the rx blinks any more then that's quite important.

RX is blinking, so the plugin is sending data to the board.

The correct behaviour of the demo should be:

Start KSP, main menu loads, plugin loads and searches for the arduino, green LED on when it finds it then turns off. (press alt - F2 during loading to see if there are any error messages)

Check! All fine so far...

At the launch pad, when the scene loads it should say "Starting serial port X" or "Using serial port X" in the middle of the screen...

Check! Still just as you describe...

...and the green LED should be on.

Nope. No green LED (but I know it works from the handshake on the main menu).

When you launch you should see the warning lights if there's something to warn (G or low fuel).

Nope, no lights at all during flight :(

Share this post


Link to post
Share on other sites

I just tried rebooting in windows xp... still not working so not likely to be anything to do with my windows install.

I don't know much about Arduino as it only arrived today, is it possible the KSPIODemo just doesn't work on a mega 2560?

Ahh... there is something in the debug console on the title screen that might be a clue...

[Log]: AddonLoader: Instantiating addon 'KSPSerialPort' from assembly 'KSPSerialIO'

[Log]: KSPSerialIO: Getting serial ports...

[Log]: KSPSerialIO: Found 1 serial ports

[Log]: KSPSerialIO: trying port \Device\USBSER000 - COM1

[Log]: KSPSerialIO: KSP Display not found

It still turns the green light on and off though.

Oh wait, just loaded again and now it says..

[Log]: KSPSerialIO: found KSP Display at COM1

... but its still not working.

Watching the debug in flight, the plugin doesn't seem to be trying to do anything since the menu screen. No log entries at all in flight for KSPSerialIO

RX light still pulsing constantly, without ever stopping until I end the flight.

Edited by sal_vager

Share this post


Link to post
Share on other sites

Didn't work the first time for me, got an access denied error. Turns out, you can't have the arduino IDE's serial debugger open at the same time!

Worked like a charm the 2nd time around. My LEDs and resistors are mis-matched (safely!), but you can see the first one lit here, and the rx LED as well:

wJYvdCZl.jpg

Now I just need to figure out the LedControl library, and figure out a simple sketch to send the data to my two SPI displays.

Share this post


Link to post
Share on other sites

I dont have the debugger open.

Edit - I notice you have more wires plugged in than th OP. Are you running a 5v line through as well?

Edit - nevermind, it doesn't seem to connect to the circuit in any way...

Edit - Does anyone have an example of this working on a Mega 2560?

Edited by Mulbin

Share this post


Link to post
Share on other sites

Sorry for wall of posts!, Xitronen will wake up with plenty to read :)

Just tried it on another computer with exactly the same result, no lights in flight, only the green one in the main menu.

Tested the board on lots of Arduino experiments and seems to be working fine.

Xitronen - Could you tell me exactly what type of LED and resistors you are using? Unlikely to have anything to do with it but worth a shot...

... otherwise I have to report your plugin doesn't work on Megas.

EDIT - I'm seeing quite a few posts online saying that some projects that work fine on an UNO dont work on a MEGA... I don't have the technical knowhow to understand why though :/

EDIT 2 - I don't know if there are any clues here... particularly the line "The Mega2560 differs from all preceding boards in that it does not use the FTDI USB-to-serial driver chip. Instead, it features the ATmega16U2 " http://arduino.cc/en/Main/arduinoBoardMega2560

EDIT 3 - If it is any help here are the schematics for both boards... not sure what it means by "pin functions" (I'm only on day 2 of learning electronics!) but they are different on pins 5,6, and 7 on each board... is this relevant?

aCLNWCG.png

Qpcx5Zl.jpg

Sorry again for the all the bother! Perhaps I can return the favour with advice on enclosure design etc (I'm a designer by trade).

Edited by Mulbin

Share this post


Link to post
Share on other sites
Didn't work the first time for me, got an access denied error. Turns out, you can't have the arduino IDE's serial debugger open at the same time!

Worked like a charm the 2nd time around. My LEDs and resistors are mis-matched (safely!), but you can see the first one lit here, and the rx LED as well:

http://i.imgur.com/wJYvdCZl.jpg

Now I just need to figure out the LedControl library, and figure out a simple sketch to send the data to my two SPI displays.

OK great, at least it's working for someone!!

Mullbin I think there's nothing wrong with your wiring, but just in case I put together a quick test code just to check your LEDs are working:


//pins for LEDs
#define GLED 5
#define YLED 6
#define RLED 7


void setup(){
initLEDS();

LEDSAllOff();
}

void loop()
{
LEDSAllOn();
delay(1000);
LEDSAllOff();
delay(1000);
}



void LEDSAllOff() {
digitalWrite(GLED,LOW);
digitalWrite(YLED,LOW);
digitalWrite(RLED,LOW);
}

void LEDSAllOn() {
digitalWrite(GLED,HIGH);
digitalWrite(YLED,HIGH);
digitalWrite(RLED,HIGH);
}

void initLEDS() {
pinMode(GLED,OUTPUT);
digitalWrite(GLED,HIGH);

pinMode(YLED,OUTPUT);
digitalWrite(YLED,HIGH);

pinMode(RLED,OUTPUT);
digitalWrite(RLED,HIGH);
}

Just make a new sketch and paste it in, it will blink all the LEDs once per second.

There are some differences between the mega and the rest, but I don't have a mega so it's really hard to say what's going on. If your rx led is blinking then that means the plugin is working properly and the arduino is getting the data. But for some reason it's not doing anything with the data.

Edited by zitronen

Share this post


Link to post
Share on other sites

OK here's a stab in the dark. I increased the wait time in the plugin so it will wait a bit longer during the handshake. This is specifically for Mulbin: https://sites.google.com/site/zitronfiles/KSPSerialIO_M1.zip

No idea if it will work or not, but it should make it less likely for you to get "KSPSerialIO: KSP Display not found" error.

Edit:

I would like to add a .cfg file so some of the settings can be adjusted without having to rebuild the dll, anyone know what's the easiest way of doing that with a partless plugin? Trigger?

Edit:

Mulbin can you load this on to the arduino and tell me what happens: https://sites.google.com/site/zitronfiles/KSPIODemoWTF.zip

Edited by zitronen

Share this post


Link to post
Share on other sites
OK here's a stab in the dark. I increased the wait time in the plugin so it will wait a bit longer during the handshake. This is specifically for Mulbin: https://sites.google.com/site/zitronfiles/KSPSerialIO_M1.zip

No idea if it will work or not, but it should make it less likely for you to get "KSPSerialIO: KSP Display not found" error.

Edit:

I would like to add a .cfg file so some of the settings can be adjusted without having to rebuild the dll, anyone know what's the easiest way of doing that with a partless plugin? Trigger?

Edit:

Mulbin can you load this on to the arduino and tell me what happens: https://sites.google.com/site/zitronfiles/KSPIODemoWTF.zip

I think a config file would be great to customizing down the line (if at all possible). I notice right now that the plugin iterates through every COM port. I have two, an unused hardware port, and the Arduino. I can see where someone might have another COM port actually in use, and this handshaking each port to see if an arduino is attached might cause problems. A config file where by default it's set to search each COM port, but leaves the option to hard-code a specific port for those who need it.

Also, looking at your first post I don't see that AGL is an available output. One of the reasons I embarked on this was specifically to get AGL on a display to aid in landing attempts without lithobraking.

Share this post


Link to post
Share on other sites
Mullbin I think there's nothing wrong with your wiring, but just in case I put together a quick test code just to check your LEDs are working:

That works fine, all three LEDs flashing together at 1 second intervals.

OK here's a stab in the dark. I increased the wait time in the plugin so it will wait a bit longer during the handshake.

No change, still have the same problem.

Mulbin can you load this on to the arduino and tell me what happens: https://sites.google.com/site/zitronfiles/KSPIODemoWTF.zip

No change, still have the same problem. :(

EDIT - Here is the log from the point of entering the flight - any clues here?


[WRN 17:50:45.191] [HighLogic]: =========================== Scene Change : From SPACECENTER to FLIGHT =====================
[EXC 17:50:45.211] NullReferenceException
[LOG 17:50:47.846] AddonLoader: Instantiating addon 'KSPSerialIO' from assembly 'KSPSerialIO'
[LOG 17:50:47.891] ------------------- initializing flight mode... ------------------
[LOG 17:50:47.895] Loading ship from file: C:\Users\Joe\Desktop\Simpit KSP\KSP_win\Ships\VAB\Kerbal 2.craft
[ERR 17:50:47.924] Cannot load Module ModuleTripLogger because the associated module on the part doesn't match the saved module
[LOG 17:50:48.059] Kerbal 2 loaded!
[LOG 17:50:53.561] putting ship to ground: 0
[LOG 17:50:53.569] [Kerbal 2]: Ready to Launch - waiting to start physics...
[LOG 17:50:53.578] Crewmember Jebediah Kerman assigned to Mk1-2 Command Pod, seat # 0 (crew seat index: 0)
[LOG 17:50:53.580] Crewmember Bill Kerman assigned to Mk1-2 Command Pod, seat # 1 (crew seat index: 1)
[LOG 17:50:53.582] Crewmember Bob Kerman assigned to Mk1-2 Command Pod, seat # 2 (crew seat index: 2)
[LOG 17:50:53.584] [FLIGHT GLOBALS]: Switching To Vessel Kerbal 2 ----------------------
[LOG 17:50:53.588] setting new dominant body: Kerbin
FlightGlobals.mainBody: Kerbin
[LOG 17:50:53.591] Reference Frame: Rotating
[LOG 17:50:53.636] stage manager resuming...
[LOG 17:50:53.638] Vessel assembly complete!
[LOG 17:50:53.639] stage manager starting...
[LOG 17:50:53.641] all systems started
[LOG 17:51:00.529] [PlanetariumCamera]: Focus: Kerbal 2
[LOG 17:51:00.844] Flight State Captured
[LOG 17:51:00.845] Saving Achievements Tree...
[LOG 17:51:00.859] Game State Saved as persistent
[LOG 17:51:02.460] [Kerbal 2]: ground contact! - error: 0.141m
[LOG 17:51:02.462] Unpacking Kerbal 2
[LOG 17:51:12.608] activating stage 2 - current stage: 3
[LOG 17:51:12.610] [asasmodule1-2]: Activated
[LOG 17:51:12.611] [RCSTank1-2]: Activated
[LOG 17:51:12.612] [fuelTank4-2]: Activated
[LOG 17:51:12.614] [liquidEngine1-2]: Activated
[LOG 17:51:12.615] [winglet3]: Activated
[LOG 17:51:12.617] [winglet3]: Activated
[LOG 17:51:12.618] [winglet3]: Activated
[LOG 17:51:12.629] [launchClamp1]: Activated
[LOG 17:51:12.636] [launchClamp1]: Activated
[LOG 17:51:12.642] [launchClamp1]: Activated
[LOG 17:51:12.643] [RCSBlock]: Activated
[LOG 17:51:12.645] [RCSBlock]: Activated
[LOG 17:51:12.646] [RCSBlock]: Activated
[LOG 17:51:12.648] [RCSBlock]: Activated
[LOG 17:51:12.649] [00:00:00]: Liftoff!!
[LOG 17:51:12.662] [Progress Node Reached]: FirstLaunch
[LOG 17:51:12.665] [Progress Node Complete]: FirstLaunch
[LOG 17:51:15.909] Packing Kerbal 2 Debris for orbit
[LOG 17:51:15.911] Packing Kerbal 2 Debris for orbit
[LOG 17:51:15.912] Packing Kerbal 2 Debris for orbit
[LOG 17:51:21.367] activating stage 1 - current stage: 2
[LOG 17:51:21.374] [00:00:08]: Separation of stage 2 confirmed
[LOG 17:51:21.376] [decoupler1-2]: Activated
[LOG 17:51:25.788] Kerbal 2 Debris Unloaded
[LOG 17:51:25.790] Kerbal 2 Debris Unloaded
[LOG 17:51:25.792] Kerbal 2 Debris Unloaded
[LOG 17:51:35.778] activating stage 0 - current stage: 1
[LOG 17:51:35.779] [Mark1-2Pod]: Activated
[LOG 17:51:35.781] [parachuteLarge]: Activated
[LOG 17:51:43.428] Game Paused!
[LOG 17:51:43.430] Active Vessel is in atmosphere. Cannot save.
[WRN 17:51:47.949] [HighLogic]: =========================== Scene Change : From FLIGHT to SPACECENTER =====================
[LOG 17:51:49.045] [PlanetariumCamera]: Focus: Kerbin
[LOG 17:51:56.221] [Progress Tracking]: Posted anonymous data to server successfully. Server Reply: KSP PROGRESS DATA OBTAINED
[LOG 17:52:00.054] Flight State Captured
[LOG 17:52:00.056] Saving Achievements Tree...
[LOG 17:52:00.067] Game State Saved as persistent
[WRN 17:52:00.068] [HighLogic]: =========================== Scene Change : From SPACECENTER to MAINMENU =====================
[LOG 17:52:02.793] AddonLoader: Instantiating addon 'KSPSerialPort' from assembly 'KSPSerialIO'
[LOG 17:52:02.795] KSPSerialIO: Getting serial ports...
[LOG 17:52:02.796] KSPSerialIO: Found 2 serial ports
[LOG 17:52:02.798] KSPSerialIO: trying port \Device\Serial0 - COM2
[LOG 17:52:07.807] KSPSerialIO: found KSP Display at COM2

Edited by Mulbin

Share this post


Link to post
Share on other sites

Just trying to think outside the box... could I be missing some other essential files like .net framework stuff?

Share this post


Link to post
Share on other sites
I think a config file would be great to customizing down the line (if at all possible). I notice right now that the plugin iterates through every COM port. I have two, an unused hardware port, and the Arduino. I can see where someone might have another COM port actually in use, and this handshaking each port to see if an arduino is attached might cause problems. A config file where by default it's set to search each COM port, but leaves the option to hard-code a specific port for those who need it.

Also, looking at your first post I don't see that AGL is an available output. One of the reasons I embarked on this was specifically to get AGL on a display to aid in landing attempts without lithobraking.

RAlt = AGL, it's radar altitude.

No change, still have the same problem. :(

OK that make no sense because I changed the code so either the green or the other leds should go on.

Share this post


Link to post
Share on other sites

Just double checked, reinstalled KSPIODemoWTF and still exactly the same. Green light comes on for 1 second at the title screen, no lights at all in flight.

Share this post


Link to post
Share on other sites

Debuging over the internet with only 3 LEDs is pretty tricky! I think I found a potential bug that causes the arduino code to lock up if there happens to be garbage on the serial port, may not be related but try the arduino demo code on the first post again, I have re-uploaded the new code.

Share this post


Link to post
Share on other sites
Debuging over the internet with only 3 LEDs is pretty tricky!

Ha, yes, Thanks for trying! I'll give the new code a go and let you know...

Share this post


Link to post
Share on other sites
I think a config file would be great to customizing down the line (if at all possible). I notice right now that the plugin iterates through every COM port. I have two, an unused hardware port, and the Arduino. I can see where someone might have another COM port actually in use, and this handshaking each port to see if an arduino is attached might cause problems. A config file where by default it's set to search each COM port, but leaves the option to hard-code a specific port for those who need it.

That is exactly what I want to do, I know how config files work with partmodules, it's super easy, but I'm not sure how it works with a partless plugin.

Share this post


Link to post
Share on other sites
I think I found a potential bug that causes the arduino code to lock up if there happens to be garbage on the serial port, may not be related but try the arduino demo code on the first post again, I have re-uploaded the new code.

No, sorry, still exactly the same :(

Share this post


Link to post
Share on other sites

I might need to buy an arduino mega to track this one down...

Edit: just did! I will put this on hold for a bit till I get the 2560.

Edited by zitronen

Share this post


Link to post
Share on other sites
I might need to buy an arduino mega to track this one down...

Edit: just did! I will put this on hold for a bit till I get the 2560.

I was just thinking I might have to buy an UNO just to get started on my project lol.

If you want to try the exact one I have, this is it, Funduino Mega 2560. http://www.ebay.com/itm/Funduino-Mega-2560-R3-Arduino-Compatible-ATMage16U2-with-USB-Cable-/291048141694?pt=LH_DefaultDomain_0&hash=item43c3d2337e

EDIT - I just ordered a cheap UNO which should be here next week. Will know for certain then if I can run it on an UNO or if there is some other problem.... I can't think what though as I have tried now on two different computers with fresh ksp installs and a total of 3 operating systems.

Edited by Mulbin

Share this post


Link to post
Share on other sites

Ok some other general questions about your plugin!

I'm still in the very early stages of learning Arduino... but am I right in thinking the only bit I'd really need to edit to add more lights / dials etc to run off the existing fields would be Utilities? - adding similar parameter to caution +, warning + etc. The rest (kspiodemo, handshake, serialcoms) looks like stuff I probably shouldn't touch or I'll break the plugin...

Also... I picked this up with the hope that I can eventually get it to run as a dial using the plugin, any advice on how to safely wire it up? Do I need to run this in series with a resistor on the gnd like with an LED?.. don't want to put it near the arduino until I'm sure it won't fry my board!

ZhAbkQS.jpg

Sorry for the noobish questions, you are the best source of info on ksp simulator panels I've found!

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.