Welcome to Cockpitbuilders.com. Please login or sign up.

April 27, 2024, 08:33:48 PM

Login with username, password and session length

PROUDLY ENDORSING


Fly Elise-ng
449 Guests, 0 Users
Members
  • Total Members: 4,154
  • Latest: xyligo
Stats
  • Total Posts: 59,641
  • Total Topics: 7,853
  • Online today: 514
  • Online ever: 582
  • (January 22, 2020, 08:44:01 AM)
Users Online
Users: 0
Guests: 449
Total: 449

COUNTDOWN TO WF2022


WORLDFLIGHT TEAM USA

Will Depart in...

Recent

Welcome

flap indicator interface with Fs9

Started by Mach7, August 03, 2023, 04:23:14 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Mach7

You are correct, it is not necessary to calibrate the resistor to ensure the gauge goes to "100", due to the fact that I only need it to go to slightly above "80", or in other words 8120.

I will download this program and report back.

Jim

_alioth_

#126
Hi,

Why not using a multiturn pot?


If you get about 100% range with a 600ohm, just use a 1k multiturn pot in series.
The you can setup to achieve de max value you want (10.000 ot 8000 or whatever you want), sending 255 pwm output and turning screw to get that value.

Later, code everything knowing 255pwm gets that max value you want.
One advantage is you can calibrate the needles in future without coding.


This is the way I use for my galvanometer gauges:

Gauges.jpeg

multiturnPots.jpeg

About the code, there is a very useful function in Arduino:

pwmValue = map( SIMNeedleValue, needleValueMin, needleValueMax, minPwm, maxPwm);

needleValueMin = 0
needleValueMax = 8000
minPwm = you need to find this value, testing the gauge, as Ame already suggests.
maxPwm = 255
This works great if the movement is lineal but there is no 0,0 in origin..
If the scale or movement is not lineal, then I like finding a function that fits all values range. I use excel or www.mycurvefit.com

then you can limit values with  constrain

pwmValue = constrain (pwmValue, 0, 255);

And in case there is no main bus voltaje, the needle is not in 0, but full left (no voltage).

If (mainBusVoltage < MINVoltage) pwmValue = 0;

Then write the pwm value:

analogWrite (FuelGaugePIN, pwmValue);


Arturo.

Mach7

Thanks Artro,

This puts an interesting idea into the mix. I like the multiturn post install and I actually might have one in my  electrical junk box. I will look today.

So basically are you saying if I can get the needle to move through it's full extent I could avoid trying to find the in between values so the gauges maintain accuracy with fs9 (fuel qty) inputs?

In other words, with the resister installed, I am getting 90 percent of the needle movement using the "fade" program, and because of this, the values will have to be manipulated in the code to accommodate the (link2fs) fuel qty inputs (?). If the code is not modified then when the (FS9) fuel quantity indicates 4000 lbs then the gauge may  (will) read something different (?).

Am I close or correct in this assumption?

Jim

Mach7

#128
@ame,

I downloaded the program and ran the gauge. I tried selecting the serial plotter and monitor, both through the icon at the top right corner, and through the tools menu. It did not display anything.

Regardless, this program seems to show the gauge going to full travel now with the resister(s) installed.

Here is a clip, (running the program created by David Mellis).

https://www.youtube.com/watch?v=BeX5Hp5oCZA

I will keep trying to find the data...not sure why I cannot read the monitor.

_alioth_

#129
Quote from: Mach7 on August 21, 2023, 03:00:10 AMSo basically are you saying if I can get the needle to move through it's full extent I could avoid trying to find the in between values so the gauges maintain accuracy with fs9 (fuel qty) inputs?

In other words, with the resister installed, I am getting 90 percent of the needle movement using the "fade" program, and because of this, the values will have to be manipulated in the code to accommodate the (link2fs) fuel qty inputs (?). If the code is not modified then when the (FS9) fuel quantity indicates 4000 lbs then the gauge may  (will) read something different (?).

Am I close or correct in this assumption?

Jim

What I say is it is a good idea to have the multiturn pot because:

1- you can set the 255pwm output to the value in the gauge you want. it would be normal to have it at 100% of the range of the gauge.

2.- you can calibrate the gauge in future if you need, without change and upload the code again. I have seen multiples professional Frasca cockpit gauges and all of them have a pot to calibrate them.

But you must look for the correlation beetwen pwm output and values.

The way I do this is.

I code the sketch in a way I send a value from 0 to 255 in the serial monitor, and analogWrite the value in the gauge pin. (this is what Ame is saying you to do). It can be done using the same type of data you will have to code in future. (or a new sketch that just only received the number and write it in the analogWrite, or a sketch that does is automatically and you read the data in serial monitor, as Ame suggest. For example:
<H000
<H012 (as example, looking for a value that indicates 0 in the gauge)
<H100
<H150
<H200
<H255
Then write these values in the analogWrite and make a chart with the value in the needle with your pwm values:
PWM -  Gauge
12  __  0
50  __  1.550
100 __  3.600
150 __  5.700
255 __  10.000

You can use the values you want, just note the correlation and make a chart.

Then go to mycurvefit or excel or whatever you want to find the function that works with this correlation:
mycurve03.jpg

mycurve04.jpg
This chart fits a line, and mycurvefit says the function is  PWMoutput = 0.02426791 * fuelReadinSIM + 12.12281

Then, use the function in your code:

PWMoutput = 0.02426791 * fuelReadinSIM + 12.12281;  // the function we found to correlation gauge value and pwm
PWMoutput = constrain (PWMoutput, 0, 255);  // making sure we don't write out range.
if (there is no voltage in master bus) PWMoutput = 0;  //if there is no voltage in master bus, we want the needle to be dead.
analogWrite (gaugePIN, PWMoutput);  // output the analogwrite to move the needle


The beauty of this, is you can find very complex correlations (second or third degree curves) and you resolve the problem with just one line in the code.

The most important thing now is you understand the way everything works so you can code whatever you need in your sim. Or if Ame takes holidays..  ;D

Arturo.

Mach7

Thanks for the info Arturo,

I am still having some difficulty getting the info from the serial monitor...so until I do that I will not know the variables.

Going to try and re-install the drivers...maybe that is the issue.

Jim

ame

Here is some information about the serial monitor tool.

https://docs.arduino.cc/software/ide-v2/tutorials/ide-v2-serial-monitor

It's unlikely that you need to reinstall any drivers. More likely that I made an error in the code I gave you. I didn't actually test it, and I can't test it right now. Maybe later.

It's also possible that the baud rate in use is incorrect. There is a drop-down box at the bottom of the serial monitor. The baud rate must match the rate specified in the Arduino program. In this case 115200.

_alioth_

Quote from: Mach7 on August 21, 2023, 07:59:51 AMThanks for the info Arturo,

I am still having some difficulty getting the info from the serial monitor...so until I do that I will not know the variables.

Going to try and re-install the drivers...maybe that is the issue.

Jim

Can you post a pic of the Serial monitor window?

2 critical points:
-Select the correct com port in IDE menu
-Choose in the serial monitor the same baud rate you have written in the code

In the Ame code:
void setup() {
  Serial.begin(115200);
}

So, be sure you select "115200" in the serial monitor window

Mach7

@Arturo,

I figured it out!

I will run some values and post here in a bit...i am assuming we are looking for the 0-255 values that correspond with the needle location?

Jim

ame

Yes. Watch the output on the serial monitor, and watch the gauge. Make a note of the reported value for each graduation on the gauge scale, i.e. 0 to 10.

Then you can establish a formula for the relationship between PWM value and where the needle is pointing.

Mach7

Ok guys, here are my values..I also have a link to the video I took when tabulating the numbers;

I found the needle remains below zero until a value of "75" is reached on the serial monitor as it is increasing. at this point (75) the needle on the gauge then moves to the "0" mark...(or at least this is when the power is sufficient to move the needle to zero).

I found some variances in value from needle increase to decrease, there might be a couple of reasons for this, it may be due to my tabulation speed, or, due to the lag of the needle going up or down...hard to say. Like I said, I will publish a link to the video, and if there is any question on my math then this link should clear it up.

Here are the values as the needle is INCREASING;

Needle / Monitor value

    0 = 70
  10 = 95
  20 = 115
  30 = 130
  40 = 150
  50 = 170
  60 = 190
  70 = 210
  80 = 230
  90 = 250
  95 = 255 (gauge needle does not go all the way to 100
            mark due to resistor installation).

Here are the values with the needle DECREASING. Note I found some variances at the higher numbers, but they seemed to (somewhat) sync in alignment with the increasing values around the (gauge needle) 60 mark.

I have identified the values that differ from the increasing numbers with an asterisk.

  95 = 255
  90 = 245 *
  80 = 225 *
  70 = 205 *
  60 = 190
  50 = 170
  40 = 150
  30 = 130
  20 = 110 *
  10 = 90 *
    0 = 75

Here is the link to the video;

https://www.youtube.com/watch?v=yrbliurCPhI

_alioth_

put a longer delay (2000 or something like that), because Im not sure the coil+neddle are fast enough to the 500 milis delay, and it could be the reason to read different values going up and down.

Mach7


Mach7

Increasing the delay from 500 to 2000 on the program allowed me to obtain some more accurate numbers..especially at the higher values.

I found as the needle is decreasing it would land at exactly the 90..80..70..and 60 marks on the gauge which gave me a confirmation that the decreasing values were the most accurate.

so..

Increasing and decreasing values are exactly the same,
to review following the increase in delay code, here are the solid values;

  0 = 75
 10 = 95
 20 = 110
 30 = 130
 40 = 150
 50 = 170
 60 = 190
 70 = 205
 80 = 225
 90 = 245
 95 = 255


_alioth_

You could test this code:

Then just write in the Serial monitor
A=0 (send, or enter)  to send pwm 0 to pin 9
A=100  (send, or enter)  to send pwm 100 to pin 9
etc...

In this way you can send a pwm value, look peacefully the needle and note the needle value.


Quote#define MAX_STRING_LEN  32
String cadenaCharEntrada = "";
char vectorChar[MAX_STRING_LEN];
bool finCadena = false;

int pwmPIN = 9;

void setup() {
  cadenaCharEntrada.reserve(MAX_STRING_LEN);
  pinMode(pwmPIN, OUTPUT); 
  Serial.begin(115200);
}

void loop() {
 
  if (finCadena) {                           
    finCadena = false;                                 
    cadenaCharEntrada.toCharArray(vectorChar, MAX_STRING_LEN); 
    String key = subStr(vectorChar, "=", 1);
    int value = atoi(subStr(vectorChar, "=", 2));
    int value2 = atoi(subStr(vectorChar, "=", 3));
    cadenaCharEntrada = "";

    if (key == "A") {
      analogWrite(pwmPIN, value);
    }
   
  }

  // do things


}  //loop end


void serialEvent() {
  while (Serial.available()) {             
    char CaracterEntrada = Serial.read(); 
    cadenaCharEntrada += CaracterEntrada; 
    if (CaracterEntrada == '\n') {         
      finCadena = true;                 
    }
  }
}


char* subStr (char* str, char *delim, int index) {
  char *act, *sub, *ptr;
  static char copy[MAX_STRING_LEN];
  int i;
  strcpy(copy, str);
  for (i = 1, act = copy; i <= index; i++, act = NULL) {
    sub = strtok_r(act, delim, &ptr);
    if (sub == NULL) break;
  }
  return sub;
}


_alioth_

So with values you noted:
0 = 75
10 = 95
20 = 110
30 = 130
40 = 150
50 = 170
60 = 190
70 = 205
80 = 225
90 = 245
95 = 255

I have gone to mycurvefit, and they are quite lineal:

OMuqs0c.png

and the function you need for your code is:

pwmValue = 1.893 * FuelSimValue + 74;

so... for every each value of needle (from 0 to 95), you get the correct pwm value from this function.








Mach7

Ok...will try that as well...thanks!!

Mach7

they are all giving me the same values...

_alioth_

Quote from: Mach7 on August 21, 2023, 10:38:26 AMthey are all giving me the same values...

I suposed that, but you can test every value you want taking all the time you need. And the code can be quickly mod to add more gauges, so:
A=100 means pwm 100 in pin 9
and with a few lines  B=120 sends 120 to pin 10....
etc..

_alioth_



Look..
Just with these few lines you can connect two gauges, and test both, one sending A=xxx and the second one sending B=xxx


Quote#define MAX_STRING_LEN  32
String cadenaCharEntrada = "";
char vectorChar[MAX_STRING_LEN];
bool finCadena = false;

int pwmPIN = 9;
int pwmFuelLeftPIN = 10;

void setup() {
  cadenaCharEntrada.reserve(MAX_STRING_LEN);
  pinMode(pwmPIN, OUTPUT);
  pinMode(pwmFuelLeftPIN, OUTPUT);
  Serial.begin(115200);
}

void loop() {
 
  if (finCadena) {                         
    finCadena = false;                               
    cadenaCharEntrada.toCharArray(vectorChar, MAX_STRING_LEN);
    String key = subStr(vectorChar, "=", 1);
    int value = atoi(subStr(vectorChar, "=", 2));
    int value2 = atoi(subStr(vectorChar, "=", 3));
    cadenaCharEntrada = "";

    if (key == "A") {
      analogWrite(pwmPIN, value);
    }
   
    if (key == "B") {
      analogWrite(pwmFuelLeftPIN, value);
    } 



  }

  // do things


}  //loop end


void serialEvent() {
  while (Serial.available()) {           
    char CaracterEntrada = Serial.read();
    cadenaCharEntrada += CaracterEntrada;
    if (CaracterEntrada == '\n') {       
      finCadena = true;               
    }
  }
}


char* subStr (char* str, char *delim, int index) {
  char *act, *sub, *ptr;
  static char copy[MAX_STRING_LEN];
  int i;
  strcpy(copy, str);
  for (i = 1, act = copy; i <= index; i++, act = NULL) {
    sub = strtok_r(act, delim, &ptr);
    if (sub == NULL) break;
  }
  return sub;
}


Mach7

Would this be what the code would somewhat look like, then controlled by link2fs?

If that is the case then A would could equal the left fuel gauge, B the center, and C the right fuel gauge(?)

_alioth_

It could be quite similar
It accepts "A", or "<A", or whatever you want.
And it takes the number, it does not matter if it is one, two or 3 digits...
but:
-Link2fs does not send a \n (enter) after every send value. I think It can be done in the main page where you connect Arduinos, but I am not sure. This code needs a (enter) after every sent value. Can you test this?
-my code needs a "=" between the characters and number, and link2fs does not send this "="

So, some mods would be needed to work with link2fs.
I can not use link2fs now, so I can not test..

I can try in future, but Ame code based in link2fs examples works, so..

Arturo

_alioth_

The <enter> can be sent in every command with this I think:

return.png

Mach7

oK...i am going to wait for ame to come back online and look at our discussions....we have made quite a bit of progress so far with the values...all the gauges should work the same and now that we have confirmed they are linear. My assumption is that it should be quite straight forward, (for you guys anyway) when we are talking about coding, and connecting. Link2fs should be able to supply the data needed from fs9 to display the left, right, and center tank quantities with all three gauges using various outputs form arduino.

I think we can connect all 4 gauges up as well, (3 fuel gauges and one flap gauge), by adding code to the flap program(?)


_alioth_

#149
yes.. arduino Uno has 6 pwm capable pins (3,5,6,9,10,11)
So you can connect until 6 galvanometer type gauges in the same way you have seen.

You will have to send data from link2fs of:
-3 fuel gauges
-flap gauge
-Master bus voltage!!! Remember, you will want to kill those needles if there is no bus voltage in the plane!!


Like the Website ?
Support Cockpitbuilders.com and Click Below to Donate