Jump to content

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


zitronen

Recommended Posts

If these are the same displays that I'm planning on using (they might not be exactly the same of course) then you need to check that the Dout pin (24) is not connected to the +V line. It's a common fault on these boards and eventually fries them. Apologies if you already know this.

Hi, I'm just about to get started on a physical panel for my ksp. To introduce myself: I am an electronics engineer working in the film/TV biz, I have a lot of experience as a result so I might be able to help with any electronics problems or questions you may have. Obviously though, I do not know everything there is to know!

Edited by Claw
multipost
Link to comment
Share on other sites

Progress! The sketch now uploads to the Arduino. Com port is working fine and KSPserial is detecting the device but...

All that happens is the display shows 0000000 leaving the last digit unlit. I'm assuming from the code that it should be showing Altitude?

Tried both MrOnak's original version and Freshmeat's edit (keen to be efficient as will be running 2 daisy chains each with 8 Max chips... so a total 128 digits!), both codes have the same effect.

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

- - - Updated - - -

Also, just dug this up from earlier in the thread by Zitronen if it's any help! (all greek to me ;) )

Have you tried replacing VData.Alt with '12345678'? When I try to get something to work, I start by making it display a fixed value for debugging. Alternativly, start by writing a dedicated program that just displays stuff, and then import the code into the plugin. I assume you checked the wiring throughtly.

In other news, display driver chips are in route from China. Got fed up with 75HC959 and all the work you have to do manually. More important, two doors will arive this weekend, so I finally complete my garage to workshop conversion. Yeah for not freezing my butt off when I want to solder something :D

Link to comment
Share on other sites

Okay the reason why the right-most digit doesn't light up is because I changed the loop from 0-8 to 1-9 due to my use of pow() but I forgot to adapt the use of i in setDigit() :(. Don't drink and code, I guess hehe.

If you replace your loop() function with the one below (fixed version of freshmeats alternative) they all should light up.

That said, it is odd that you say KSPIO confirms to have found the Arduino but the numbers stay zero. I'll do some thinking but spontaneously I'm at a loss.


void loop()
{

// update KSP data
input();

// fetch current altitude as long value, not as floating point
alt = (long) VData.Alt; // casting to long is needed to be able to fetch individual digits I believe

// update displays - for loop staring at 1 to make pow() work

int digitPlace = 1;

for(int i = 0; i < 8; i++) {
// this isolates the i-th digit
digit = (alt / digitPlace) % 10;
digitPlace = digitPlace *10;

lc.setDigit(0, i, digit, false);
}

delay(70); // roughly matches the default update frequency of KSPIO
}

Link to comment
Share on other sites

Holy crap so much happening I can't keep up!

@Zitronen: Any specific reason for setting the default baud rate to 38400?

There's no reason for having default baud rate at 38400. Back when we started it seemed like a good number, since we only had 40 bytes to send, now we have 180 maybe we should increase it. You can change it in the config and see if it causes any problems, I doubt it would!

I understand where you're coming from. If I may, I'd then suggest adding a "force sync" to the ControlPacket, so you could get immediate sync after an undock. It is a bit stressful to loose throttle and RCS during these maneuvers.

On the bug I wrote about, I think the issue is fuel lines. My pod has fuel lines linked directly to the engine, and the fuel in these tanks is not counted.

What if we only synced RCS, SAS and maybe some other "important" stuff on vessel switching? Maybe that will be a better fix? What can possibly go wrong? Have it as an option as well.

Yeah fuel lines... The resource code I stole from mechjeb only looks for things attached through nodes, I wouldn't know where to begin to fix that (unless someone can find better code I can steal!).

@Zitronen: Am I right that the Arduino side of your plugin is not on your github?

Reason why I'm asking is because I've applied a useful patch to my AVR-c "fork" of your code that adds a return value to kspio_input() and I believe that might be useful for your official code as well. My kspio_input() function matches your input().

The return value allows to run code that depends on vesselData numbers to be run only when the numbers actually have changed.

See my latest commit in my branch for details:

https://github.com/MrOnak/avr_KSPIO/commit/6d3c1bb5d483c28d6feb542f67f1b07ed9a99ce4

If I'm not mistaken your code with this patch would be this (changes in bold):


[B][COLOR="#FF0000"]int[/COLOR] [/B]input() {
now = millis();
[B] [COLOR="#FF0000"]int returnValue = -1;[/COLOR][/B]

if (KSPBoardReceiveData()){
deadtimeOld = now;
[B] [COLOR="#FF0000"]returnValue = id;[/COLOR][/B]

switch(id) {
case 0: //Handshake packet
Handshake();
break;
case 1:
Indicators();
break;
}

//We got some data, turn the green led on
digitalWrite(GLED,HIGH);
Connected = true;
}
else
{ //if no message received for a while, go idle
deadtime = now - deadtimeOld;
if (deadtime > IDLETIMER)
{
deadtimeOld = now;
Connected = false;
LEDSAllOff();
}
}

[B][COLOR="#FF0000"]return returnValue;[/COLOR][/B]
}

In case you're interested in a bit of collaboration, I'll try and send you pull requests whenever I find useful changes / additions and your Arduino code is on github :)

Yeah that makes sense, and it really should be on github. All these different demo versions is getting pretty silly. I will remember to put it up before we hit version 9000.

I'll be back in a week or so, don't break anything :D! Also welcome back Mulbin, looks like you are on track to getting your 7 segs working, thanks everyone for helping!

Link to comment
Share on other sites

@Zitronen:

I'll be able to test higher baudrates in 2 weeks or so, will report back. I actually managed to physically break my soldering iron (the plastic handle snapped... don't ask) so I'm out of action for the time being ;)

Also, I'll keep an eye on your github for that Arduino code :)

Link to comment
Share on other sites

What if we only synced RCS, SAS and maybe some other "important" stuff on vessel switching? Maybe that will be a better fix? What can possibly go wrong? Have it as an option as well.

You said it loud, we're doomed ;) Anyway, great solution.

Link to comment
Share on other sites

Okay the reason why the right-most digit doesn't light up is... -snip-

Yep, that got all 8 lit up, but still stuck on 00000000

Have you tried replacing VData.Alt with '12345678'? When I try to get something to work, I start by making it display a fixed value for debugging

Good idea... something isn't right, when I replace VData.Alt with 12345678 it actually displays _7_45678, it's not the chip/leds though, I've tested it on 4 separate LED modules now and they all do the same thing. Wiring is also fine and other generic arduino 7 segment sketches work fine, so something not right with the code...

jHYB5YP.jpg

Link to comment
Share on other sites

@Mulbin:

Can you try:

void loop()
{

// update KSP data
input();

// fetch current altitude as long value, not as floating point
//alt = (long) VData.Alt; // casting to long is needed to be able to fetch individual digits I believe

//int digitPlace = 1;

for(int i = 0; i < 8; i++) {

lc.setDigit(0, i, i, false);
}

delay(70); // roughly matches the default update frequency of KSPIO
}

That should print the digit position in the actual digit, so result should be 76543210, if I am reading the documentation correct.

Link to comment
Share on other sites

Yep, that works. As soon as I upload the sketch I get 76543210

Must be the way MrOnak chose to isolate digits then. Try this:

void loop()
{

// update KSP data
input();

// fetch current altitude as long value, not as floating point
//alt = (long) VData.Alt; // casting to long is needed to be able to fetch individual digits I believe

alt = 1234567;

int digitPlace = 1;

for(int i = 0; i < 8; i++) {
// this isolates the i-th digit
digitTemp = long((alt / digitPlace));
digit = digitTemp % 10;
digitPlace = digitPlace *10;

lc.setDigit(0, i, digit, false);
}

delay(70); // roughly matches the default update frequency of KSPIO
}

No idea if it works, but that would be my next try.

Edit: % (modulo) does not work on floats, what kind of var is alt?

Edited by Freshmeat
Link to comment
Share on other sites

That throws up this...

KSPIODemo8.ino: In function 'void loop()':

KSPIODemo8:155: error: 'digitTemp' was not declared in this scope

Sorry

void loop()
{

// update KSP data
input();

// fetch current altitude as long value, not as floating point
//alt = (long) VData.Alt; // casting to long is needed to be able to fetch individual digits I believe

alt = 1234567;

int digitPlace = 1;
long digitTemp;

for(int i = 0; i < 8; i++) {
// this isolates the i-th digit
digitTemp = long((alt / digitPlace));
digit = digitTemp % 10;
digitPlace = digitPlace *10;

lc.setDigit(0, i, digit, false);
}

delay(70); // roughly matches the default update frequency of KSPIO
}

Link to comment
Share on other sites

I'm the one who should be sorry for all the questions :)

Ok, uploaded the sketch and it's acting strangely again. As soon as it uploads the display reads _2_34567

Then it is the modulo that f*ck up the reading. Well, try doing it this way:

void loop()
{

// update KSP data
input();

// fetch current altitude as long value, not as floating point
//alt = long(VData.Alt); // casting to long is needed to be able to fetch individual digits I believe. Note that this destroys the number as it is printed, if you want to reuse alt elsewhere you need to get it from VData.Alt again.

long alt = 1234567;

int tens;
int digit;

for(int i = 7; i > -1; i--) { //we need to start lowest digit first
// this isolates the i-th digit
tens = alt / 10;
digit = alt - (10*tens)
alt = tens;

lc.setDigit(0, i, digit, false);
}

delay(70); // roughly matches the default update frequency of KSPIO
}

Link to comment
Share on other sites

Ok... I took a guess that what it means the code should look like this, with the ";" after (10*tens)?

tens = alt / 10;

digit = alt - (10*tens);

alt = tens;

But the code is still not right, the display now shows 7____000

Link to comment
Share on other sites

Did you get a datasheet with your displays? If so, please upload it somewhere and link it.

Reason I'm asking is I'd like to know what input causes a digit to display an underscore. The code that "extracts" single digits from a long value - the (alt / digitPlace) % 10 part - is tried and proven, that is not the problem.

In theory I can imagine some floating point issues but that would only lead to wrong digits ranging from 0-9, not something completely invalid. Aside from that, I'm displaying the altitude from a float just fine on a testrig that is using the same digit-math so... floating points going out of whack seem unlikely since it works for me.

Link to comment
Share on other sites

So the way I've been using my 7 segs is by converting the number to a string first using dtostrf(), then writing the string to the LEDs. This way you have better control of the formatting and you can also display letters and symbols.


char SSLED[9] = "--------";

...
byte decimal = 9; //decimal is where you want the decimal point, set it to >9 if you don't want it.

dtostrf(round(###put value here###),8,0,SSLED);
write7Segment(display, SSLED, decimal);


void write7Segment(byte display, char value[9], byte decimal)
{
for (byte j = 0; j<8; j++) {
lc.setChar(display,j,value[j],decimal==j);
}
}

I have a whole convoluted function for moving the decimal point around and displaying the unit on the lcd (see video in first post), I would post it here but it's kind of hard coded to use only 6 digits.

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