Jump to content

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


zitronen

Recommended Posts

@Darkblade: For slide pots, high resistance is good. 50k is excellent, I use 10k myself, and have used a 1K in a pinch (not recommended). The limiting factor is the max current draw from the Arduino, and 50K would be 0,1 mA out of 500 mA available from the +5V pin.

Link to comment
Share on other sites

@Darkblade: For slide pots, high resistance is good. 50k is excellent, I use 10k myself, and have used a 1K in a pinch (not recommended). The limiting factor is the max current draw from the Arduino, and 50K would be 0,1 mA out of 500 mA available from the +5V pin.

Excellent; now to figure out how to connect it up and get it to work in KSPIO :)

Link to comment
Share on other sites

Just a quick coding question (to see if I am making this overly complicated).

I have two switches (STAGELOCK and STAGE) as well as an LED. The behaviour I want is as follows:

When STAGELOCK is toggled, turn on LED.

When STAGELOCK is toggled and STAGE is triggered, launch the rocket.

Both STAGELOCK and STAGE are using internal pull-up resistors, so this means they normally read HIGH.

I have the following code for the first part.


if (digitalRead(STAGELOCKPIN)) //pull-up resistor is used so this pin is normally high
digitalWrite(GLED, LOW);
else
digitalWrite(GLED, HIGH); //once key lock is toggled, turn on LED

For the second part, I am not sure if it is necessary to define all the cases. There are 4 cases and my desired actions:

1) STAGELOCKPIN is high (due to pull-up resistor), STAGEPIN is high = rocket does not launch

2) STAGELOCKPIN is low (toggled), STAGEPIN is high = rocket does not launch, but LED is turned on (taken care of above)

3) STAGELOCKPIN is high, STAGEPIN is low (this is the case where you try to press the launch button without disarming the safety) = rocket does not launch

4) Both STAGELOCKPIN and STAGEPIN are low (both switches toggled) = rocket launches

I have the first 3 cases coded as follows, but I am not sure if it is necessary to explicitly stage cases 2 and 3 (also, the fact I am inverting the boolean logic is quite messy). I am unsure what would happen if I do not define case 2 and 3.


// HIGH && HIGH || HIGH && LOW || LOW && HIGH
if ((digitalRead(STAGELOCKPIN) && digitalRead(STAGEPIN)) || (digitalRead(STAGELOCKPIN) && !digitalRead(STAGEPIN)) || (!digitalRead(STAGELOCKPIN) && digitalRead(STAGEPIN))) 
MainControls(STAGE, LOW);
else
MainControls(STAGE, HIGH); //LOW && LOW

Edited by Darkblade48
Link to comment
Share on other sites

You can do all of that simply by checking for case 4 in your list. The outcome of all of the other cases is the same. Something like this should be all you need.

if (!digitalRead(STAGELOCKPIN) && !digitalRead(STAGEPIN)) {
MainControls(STAGE, HIGH);
} else {
MainControls(STAGE, LOW);
}

Link to comment
Share on other sites

You can do all of that simply by checking for case 4 in your list. The outcome of all of the other cases is the same. Something like this should be all you need.

if (!digitalRead(STAGELOCKPIN) && !digitalRead(STAGEPIN)) {
MainControls(STAGE, HIGH);
} else {
MainControls(STAGE, LOW);
}

Oh of course!

I don't know why I was making it so complicated by defining out all the cases I didn't want the rocket to stage and then just putting the one case as part of the 'else' statement. :D

Edit:

Quick question regarding pin assignment; since the Arduino uses TX and RX to communicate, I assume that we cannot assign these pins (pins 0 and 1 on an Uno) for use?

Edited by Darkblade48
Additional question
Link to comment
Share on other sites

Where is the best place to send output to an LCD panel?

I can only get it to function in the main loop, but it seems to cause some stuttering issues on my 7 segs when burning to really high orbit.

Placing the code in "void indicators ()" doesn't seem to do anything.

  
lcd.setCursor(8,0);
lcd.print(VData.G);
lcd.setCursor(10,1);
lcd.print(VData.TAp);

Nevermind.... I needed to place brackets around the code :)

Edited by T.A.P.O.R.
Link to comment
Share on other sites

In theory it's only worth updating the LCD when you get a new VesselData packet. In the KSPIODemo sketch, the original Indicators() method in utilities.ino is called whenever a valid VesselData is received from the game. You should be able to just update your LCD in that, rather than spend the extra time calling it in every iteration of loop().

Link to comment
Share on other sites

In theory it's only worth updating the LCD when you get a new VesselData packet. In the KSPIODemo sketch, the original Indicators() method in utilities.ino is called whenever a valid VesselData is received from the game. You should be able to just update your LCD in that, rather than spend the extra time calling it in every iteration of loop().

Yep, it is behaving better now.

Link to comment
Share on other sites

Still waiting for the weather to get good enough for soldering without freezing my fingers off, but in the meantime I have managed to hook up a secondary display from an old car DVD using the TV-OUT library. I am very tempted to use this instead of soldering a bunch of 7 seg LEDs.

Link to comment
Share on other sites

Still waiting for the weather to get good enough for soldering without freezing my fingers off, but in the meantime I have managed to hook up a secondary display from an old car DVD using the TV-OUT library. I am very tempted to use this instead of soldering a bunch of 7 seg LEDs.

You can get some cheap <$10 3 or 4 inch composite video LCDs on Ebay for that as well.

Link to comment
Share on other sites

You can get some cheap <$10 3 or 4 inch composite video LCDs on Ebay for that as well.

Aww now you're both just making me want to spend more money!

After a few glasses of fermented grape juice last week I bid on a bunch of old VU meters.

It turns out that they're enormous!

Marzubus style OlED for comparison on the bottom right.

IMG_0429.JPG

Link to comment
Share on other sites

@TAPOR: They are beautiful. I keep wanting to ditch some of the old voltmeters at school "for taking up storeroom", but I really cannot bring myself to press on with my colleagues. The real problem with that meter is the voltage, you will have to mess with it to bring it down to 5 V.

@Zitronen: Free is cheaper than $10. Especially since the dollar rose just enough to make $10 uncomfortably close to the magic 80 dkr when import tax kicks in with 25% plus administration fee of ~£20. :confused:

While we're at it, I have given some thoughts to external power for my leds. The display comes with a 9V supply and plenty of power. I wondered if I could use a 7805 to tap +5V from it as well. The main worry I have is common ground. In Denmark we don't have seperate grounding for appliances, so I worry if the ground of the display PSU is the same as the ground in the Arduino. Is it safe to connect them, maybe with a resistor between? And how big is the tolerance, are we talking mV or tens of mV?

Edited by Freshmeat
More questions
Link to comment
Share on other sites

@TAPOR: They are beautiful. I keep wanting to ditch some of the old voltmeters at school "for taking up storeroom", but I really cannot bring myself to press on with my colleagues. The real problem with that meter is the voltage, you will have to mess with it to bring it down to 5 V.

@Zitronen: Free is cheaper than $10. Especially since the dollar rose just enough to make $10 uncomfortably close to the magic 80 dkr when import tax kicks in with 25% plus administration fee of ~£20. :confused:

While we're at it, I have given some thoughts to external power for my leds. The display comes with a 9V supply and plenty of power. I wondered if I could use a 7805 to tap +5V from it as well. The main worry I have is common ground. In Denmark we don't have seperate grounding for appliances, so I worry if the ground of the display PSU is the same as the ground in the Arduino. Is it safe to connect them, maybe with a resistor between? And how big is the tolerance, are we talking mV or tens of mV?

Yeah, I'm prepared for that.

There are 3 terminals on the back, one is marked + one is 10 and the other is blank.

I'm assuming that the blank is either 20v or GND.

Which kind of leads into your point about common ground.

In my experience and coming from an audio perspective, different grounds can cause problems with noise on the line.

If you want to protect your Arduino, you might want to look into using a Zener diode (say 4.7v or 5.1v).

Here's an example from MusicFromOuterSpace which is intended for an analogue synthesizer, but would work equally well here (I think)

protectcvinputs.gif

Replace ext CV with your positive supply and VC Summer OpAmp with your + rail on the Arduino.

Link to comment
Share on other sites

While we're at it, I have given some thoughts to external power for my leds. The display comes with a 9V supply and plenty of power. I wondered if I could use a 7805 to tap +5V from it as well. The main worry I have is common ground. In Denmark we don't have seperate grounding for appliances, so I worry if the ground of the display PSU is the same as the ground in the Arduino. Is it safe to connect them, maybe with a resistor between? And how big is the tolerance, are we talking mV or tens of mV?

Depending on your Arduino, you won't even need a 7805. Standard Uno and Mega boards have an on board regulator that can handle from 7V up to 20, but they recommend no higher than 12. You can supply 9V either through the barrel jack on the board, or via the VIN pin, and it will run with no problems. I bought a 9V power supply to run my arduino, because I needed more power for the motorised throttle slider, and it supplies a fair bit more current for LEDs and things than I'd get powered from USB alone.

Link to comment
Share on other sites

@TAPOR & Stibbons: Thanks for the reply, it did not occur to me that you could use the barrel connection while you where connected on USB. The specs on the +5V are the same as I could get using an external regulator. I can easily throttle the output of the MAX7219 to be something like 10-15 mA per pin, leaving me plenty of current to drive 4 ic's within budget.

And I am sorry for your loss, TAPOR. It was truly a beauty.

Link to comment
Share on other sites

@TAPOR & Stibbons: Thanks for the reply, it did not occur to me that you could use the barrel connection while you where connected on USB. The specs on the +5V are the same as I could get using an external regulator. I can easily throttle the output of the MAX7219 to be something like 10-15 mA per pin, leaving me plenty of current to drive 4 ic's within budget.

And I am sorry for your loss, TAPOR. It was truly a beauty.

Thanks Freshmeat,

I'll resurrect it someday.

I have a new dilemma. Too many data displays and don't know what to display on them all :)

My panel has 6 x 8 digit 7 segment leds and I can only think of what to do with four.

  • Apoapsis
  • Periapsis
  • Sea Level Altitude
  • Radar Altitude
  • ???
  • ???

I've also added 2 x 4 digit 7 segment clock modules:

  • Time to Apoapsis
  • Real world time

There is also a 20x4 LCD in transit, plus the teeny weeny oled.

Any suggestions for what to display on the last two 7 segs and LCD would be most welcome.

Edited by T.A.P.O.R.
Link to comment
Share on other sites

Any suggestions for what to display on the last two 7 segs and LCD would be most welcome.

Depends on what you want to do, for launch, all you need is AP, PE, inclination, time to AP and eccentricity to get to a perfect circular orbit without looking at the map. You can also display altitude and orbital speed, but they are already in the game anyway. G force is also nice. For landing, you may want rate of decent, fuel, oxidizer etc. For precise orbits like geostationary, you may want semi major&minor axes, orbital period.

Link to comment
Share on other sites

And finally the weather got warm enough for an extended stay in the workshop. My hardware has gone through an extensive repair and upgrade. It started with my roll potmeter drifting, I was using far to much current so the voltage dropped. Further, resistors in parallel did not work out to sort switches, as the tolerance needed to be down to 2%. So my light was constantly flickering. And the coding had to make an entry for each value, quite horrible.

So I have since my first attempt learned about shift-in and MAX7219 ic's, headers, veroboards, shrink tubing, and proper soldering techniques. The result is a controller that can do the same as the old controller did, but with a much cleaner layout of circuits, possibility of expanding, and far simpler code. This means I actually get to play again, after a forced hiatus since just after New Year :)

Once I get more time, I still plan on a major rebuild. The LCD tv ought to be incorperated, and I want to add a couple of proper joysticks (one analog, one digital) to the Arduino instead of using the mounted Logitech controller. The reason is I want to be able to exchange roll and yaw controls in game for either planes or rockets. And get relevant flight data on the screen so I can ditch KER HUD.

Edit: OK, testing is done. At the same time I discovered a couple of bugs in my old code that made it skip some security checks. There is room for improving my landing assist system, getting a LED to blink should keep me entertained for a while.

Edited by Freshmeat
Testing done
Link to comment
Share on other sites

I'm having trouble getting the tutorial code to work from the first post. When I go to the launch pad, the RX LED on the arduino will start rapidly blinking. It says "Starting serial port COM3" at the bottom right corner of the screen and the log says: KSPSerialIO: Handshake received - 314. But none of the 3 LEDS ever turn on.

This is how it's connected up:

SrPqLGs.jpg

I've confirmed all 3 LEDs work using the basic Blink arduino sketch.

Any ideas what's going on?

Link to comment
Share on other sites

Hey Welcome to the forum & good luck with KSPIO :)

I'm having trouble getting the tutorial code to work from the first post. When I go to the launch pad, the RX LED on the arduino will start rapidly blinking. It says "Starting serial port COM3" at the bottom right corner of the screen and the log says: KSPSerialIO: Handshake received - 314. But none of the 3 LEDS ever turn on.

This is how it's connected up:

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

I've confirmed all 3 LEDs work using the basic Blink arduino sketch.

Any ideas what's going on?

The green light should be on (and stay on) once handshake is connected.

Did you have a successful upload of the sketch?

Try increasing the baud rate from the default to 115200, this has helped with a couple of my boards.

Serial.begin(115200);

I also had a lot of ports clogged up, so even though It would upload sketches, KSP sometimes refused to connect.

Don't forget to re-start KSP every time you unplug the board or change the configure file.

Edit:

I've had another look, and it all looks like it's wired up correctly.

I'm guessing that it's an issue between KSP & your com port.

Edited by T.A.P.O.R.
Link to comment
Share on other sites

The green LED comes on for two or three seconds and then turns off. It seems that the board is resetting a second or two after the handshake goes through. The sketch is uploaded fine and increasing the baud rate doesn't make a difference. :huh:

edit: It seems that the arduino is resetting just before the green LED comes on as well.

During loading the launch pad:

Arduino resets

Green LED turns on for 2 seconds

Green LED turns off

Arduino resets

Finishes loading, RX light starts blinking

Any ideas?

edit edit:Tried putting a capacitor across the RESET and GND pins which successfully stops the arduino from resetting but hasn't made a difference otherwise. LED still only coming on for a couple of seconds.

Changing IDLETIMER in the Arduino sketch determines how long the Green LED will come on for, so I guess after the initial handshake it's not receiving any data.

Edited by Cell
Link to comment
Share on other sites

I'm having trouble getting the tutorial code to work from the first post. When I go to the launch pad, the RX LED on the arduino will start rapidly blinking. It says "Starting serial port COM3" at the bottom right corner of the screen and the log says: KSPSerialIO: Handshake received - 314. But none of the 3 LEDS ever turn on.

This is how it's connected up:

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

I've confirmed all 3 LEDs work using the basic Blink arduino sketch.

Any ideas what's going on?

I had something similar earlier on, I think it had something to do with the xml config file in KSP.

If you like you can PM me the code from your sketch and I'll compare it with mine, but I still have a feeling that its something to do with the serial/usb port.

Link to comment
Share on other sites

Well now I feel really dumb. It seems that CKAN isn't using the latest version (only 16.1). Updating to the latest version from the OP has fixed it and every thing is working now. :)

Link to comment
Share on other sites

Well now I feel really dumb. It seems that CKAN isn't using the latest version (only 16.1). Updating to the latest version from the OP has fixed it and every thing is working now. :)

Sweet, glad you got it sorted :)

Good luck with your build and remember to search this thread if you get stuck.

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