PDA

View Full Version : Can Link2FS & Arduino do this . . . ????



Tom_G_2010
10-10-2012, 08:02 AM
I'm part way into a build using a combination of Leo Bodnar cards for inputs and a couple Phidgets cards for outputs. In general all is going well but I've run into a few hick ups that are maddening. I just discovered this part of the forum and am now starting to explore whether Link2FS might help solve the issues I'm running into. So here are some initial questions as I start to read up on Link2FS and Arduino cards.

1. I read that Link2FS can work with non Arduino cards. Has anyone attempted to use it with Phidgets cards? I have a Phidgets LED 64 and a Phidgets Servo controller adn it would be good not to loose the investment in them.

2. Can I build logic in the code? For example can I read various FSX outputs and based on some set of thresholds or logic trigger an annunciator lamp? For example monitor altitude, gear position, and airspeed then set off a warning lamp if airspeed drops below 100n or altitude below 200 AGL and gear are not down.

3. Is there any way to drive 7 segment LEDs using Link2FS and an Arduino? I have still not finalized how I'm going to build some of my avionics stack and being able to drive 7 segment LEDs for the freq display etc. is one of the issues. I am looking at other options like putting a face plate mask over a pc monitor, but I would really rather have actual 7 segment LEDs and my reading on some of the other solutions seem to be leading to coding complexity and money that are nor within reach at this time.

Well, those are the first of the questions I came up with. I'm sure there are more to follow... THANKS!!!

zulucat
10-10-2012, 10:56 PM
1. I read that Link2FS can work with non Arduino cards. Has anyone attempted to use it with Phidgets cards? I have a Phidgets LED 64 and a Phidgets Servo controller and it would be good not to loose the investment in them.

I'm not familiar with Phidgets products but it looks like they use a USB interface. This will be a problem for an Arduino board. It may be possible to interface to Phidgets boards but its going to require additional hardware and custom software.


2. Can I build logic in the code? For example can I read various FSX outputs and based on some set of thresholds or logic trigger an annunciator lamp? For example monitor altitude, gear position, and airspeed then set off a warning lamp if airspeed drops below 100n or altitude below 200 AGL and gear are not down.

The Arduino is an 8-bit microprocessor board which is programmed in the C Programming Language. Using LINK2FS you can get FSX data and then process that data. It would be a fairly simple task to set off a warning lamp based on plane conditions. However, it would be up to you to do the software. How are your C programming skills?


3. Is there any way to drive 7 segment LEDs using Link2FS and an Arduino?

Yes. A problem arises if you need more than one or two 7-segement displays. It's the number of pins required to control a single digit directly (7 pins plus 7 resistors to limit the current running through each segment). There are solutions to this problem -- see below.


ARDUINO INFO
=============

The Arduino comes in a number of variation but the two primary ones ate the UNO and Mega2560. The UNO runs around $30 and the Mega2560 generally sells for $65. However, Mouser carries the Mega2560 for under $40. The arduino homepage is: Arduino - HomePage (http://arduino.cc/en/)

Adafruit and SparkFun are two companies that carry a lot of Arduino related products (including the UNO & Mega2560.
Adafruit also has a great series of tutorials covering most of the products they carry or manufacture.
http://www.adafruit.com (http://adafruit.com)
SparkFun Electronics (http://www.sparkfun.com)

Adaifruit carries a 4-digit 7-segment display that uses an I2C interface. Eight of the boards can be connected to the same interface.
Adafruit 0.56 4-Digit 7-Segment Display w/I2C Backpack - Red ID: 878 - $9.95 : Adafruit Industries, Unique & fun DIY electronics and kits (http://www.adafruit.com/products/878)

SparkFun has USB breakout boards that might be the solution to interfacing to the Pidgets boards.
https://www.sparkfun.com/products/718

Mega2560 at Mouser
A000067 Arduino | Mouser (http://www.mouser.com/ProductDetail/Arduino/A000067/?qs=sGAEpiMZZMt0re6d%252b2Rx9v%252bc%252bQEIaOW9)

Software development tools are free and can be downloaded from the Arduino web site. Versions for Windows, Mac OSX and Linux are available.
Arduino - Software (http://arduino.cc/en/Main/Software)

Jim NZ
10-11-2012, 01:12 AM
Tom, your sim looks to be a real winner. I very nearly went down that same road but shells of aircraft are really rare in NZ. We tend to keep them flying until the rivits corrode away and bits fall off !!! :) and of course,,, by then it's too late to find a complete, undamaged cockpit.

Flightsim and the Arduino ,,, I've never seen the Arduino as a threat to purpose made interface cards that seem to be everywhere now. I do how-ever see them as a very good alternative to the expensive cards where some-one wants to experiment with interfacing into (or out of) flightsim
Arduino users tend to be the type of Guy (or Gal) that want to do everything themselves ,, the interface card must be cheap ,,, they do the coding ,,, and they do the construction of the unit (Auto pilot / radio's / motion platform etc) It's the personal challenge, rather than just going out and buying.
These "experimenters" can interface a modest cockpit with Arduinos. Even some "high end" cockpits have Arduinos doing the odd-ball stuff which can be difficult with bought cards. This comes about because you can program the Arduino itself to do what you want.

So to answer you questions Tom ,,,
1/...
No the Link2fs stuff wont interface with Phidgets cards.

2/...
You can install code into an Arduino that will do just that but it would be a pain ,,, you will need to reload the Arduino every time you changed planes.
An easier option is to have the desktop software do it for you ,,, close to what you are talking about is in my (real early) ,,
FSX arduino mega arduino duemilanove Uno flight simulator (http://www.jimspage.co.nz/uno1_interface.htm)
On the agenda is a project that has 14 annunciators that the triggers are mostly set by the user ,, 1 click plane change and 1 click install.
When or if this is ever released is anyone's guess.

3/...
Yes ,, Have a look in these threads ,,,,
http://www.mycockpit.org/forums/arduino-cards-link2fs/24715-my-pde-autopilot-controls-using-rotary-encoders-tm1640-displays.html
http://www.mycockpit.org/forums/arduino-cards-link2fs/22636-arduino-com-nav-led-display-fsx.html
http://www.mycockpit.org/forums/arduino-cards-link2fs/24818-wanted-urgent-example-3-digit-7-segment-led-fsx-link2fs-sketch.html
Basically have a dig thru the Arduino sub-forums here in mycockpits.

To sum up ,,,
Use Leo's BU0836X for the inputs (Excellent card for inputs)
Unless you are into coding and "do it yourself" stuff ,, stick with Phidgets cards or some other purpose made card that are made for the job.
You look to be planning an advanced simulator and with the limitations of the Arduino coupled with the limited software for them (at the moment) it may cause you frustrations.

Jeeze ,, I'm writting a book here !!!
Cheers Tom ,,, Jim

Tom_G_2010
10-11-2012, 01:57 AM
Zulucat and Jim,

Thanks for the feedback. Jim, I'm going to investigate the 7 segment solutions that you posted links to further as they appear to be within my reach both technically and in terms of cash outlay. The phidgets cards are in many ways no more purpose built that the Arduino cards, well, maybe a bit more, but in the end it still takes coding or at least scripting to get them to play ball with FSX. I have been using Alan Dyer's FS2Phidget interface app and have managed to get several things working.

I have not however been able to solve for the 7 segment LEDs via that route. And my research into OC and SOIC says it requires more cash and coding than I might be up for just to run the 7 segment displays. In the end I still need to decide whether I'll build the avionics units with 7 Segment displays or go the route of doing a faceplate mask over an LCD monitor. But, knowing I have a possible 7 Segment solution within reach gives me one more factor in my decision process.

Again, Thanks!

Jim NZ
10-11-2012, 03:40 AM
Good stuff Tom ,,, I was a bit worried that you may have been expecting a "super fix" for everything but if all you want is to drive 7 segment LEDs then it's a piece of cake ,,, especially the "serial" driven ones that require very little code on the Arduino and only use a couple of pins.

OK ,, happy researching Tom ,,, Jim

milobars
11-04-2012, 05:08 AM
Hi All,

Firstly, thank you to Jim for supplying all this information and getting lots of people going with Arduino and his fantastic programs.
I tackled the display issues with some experimentation with LCD screens, but after much research stumbled upon a site called DealExtreme - Cool Gadgets at the Right Price - DX Free Shipping Worldwide (http://www.dx.com) (deal extream). Here they have Arduino compatible products extreamily cheap. Arduinio Mega is about $120 here (Australia) - I bought a Mega for $17 including postage!

Anyway ... they have dual 4x serial segment displays. Extreamily easy to get going, and with minimal code.
Here is what I have done so far:

7226 each board can drive 8x 7 segment displays.

7227 Only needs 3 pins from an Arduinio, and you can drive up to 8 of these 8x7 segment displays with only 3 pins!

7228 Here is the COM1 Radio frequency and standby frequency display for my radios. The first 8 digits (from the left) is being driven by one board, the last 3 digits are being driven by a 2nd board (connected to the first board with +5v, Gnd and the same three pins from the Arduino).

This means I can display the entire radio stack frequencies with only 3 pins from the arduino! I am going to use another set of pins to drive the entire set of displays for my auto pilot. The best thing is, these boards are $5 from DX.com including postage!!

Here is the sketch I'm mucking around with ... it's taken from Jims examples, and uses link2FS_inout program (Thanks Jim!).

//We always have to include the library
#include "LedControl.h"

/*
Now we need a LedControl to work with.
***** These pin numbers will probably not work with your hardware *****
pin 12 is connected to the DataIn
pin 11 is connected to the CLK
pin 10 is connected to LOAD
*/

LedControl lc=LedControl(12,11,10,2);
int xx; //sets up a variable for the data
int yy; //altitude
String AP;
int i;

/* we always wait a bit between updates of the display */
unsigned long delaytime=250;

void setup() {
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
*/
lc.shutdown(0,false);
lc.shutdown(1,false);
/* Set the brightness to a medium values */
lc.setIntensity(0,8);
lc.setIntensity(1,8);
/* and clear the display */
lc.clearDisplay(0);
lc.clearDisplay(1);
Serial.begin(115200); // sets up the baud rate for the serial coms.


for(int i=0;i<8;i++)
{
lc.setDigit(0,i,8,false); // This does a quick test of all the segments
lc.setDigit(1,i,8,false);
delay(delaytime);
}

for(int i=8;i>0;i--)
{
lc.setChar(0,i,' ',false);
lc.setChar(1,i,' ',false);
delay(delaytime);
}

{lc.clearDisplay(0);
lc.clearDisplay(1);}
delay(delaytime);
}


void loop() {
// scrollDigits();


if (Serial.available() > 0) { //if there is a charator in the serial receive buffer then ,,,,
xx = Serial.read(); // read it.


if (xx == 'd'){ // Found Com 1 Radio Freq
delay (11); // It seems to need a delay here
//digitalWrite(13, HIGH);
yy = char(Serial.read()); //Read the first charactor sent
lc.setChar(0,7,yy,false);
delay (11);
yy = char(Serial.read()); //Read the first charactor sent
lc.setChar(0,6,yy,false);
delay (11);
yy = char(Serial.read()); //Read the first charactor sent
lc.setChar(0,5,yy,true);
delay (11);
yy = char(Serial.read()); //DONT READ THE DOT
delay (11);
yy = char(Serial.read()); //Read the first charactor sent
lc.setChar(0,4,yy,false);
delay (11);
yy = char(Serial.read()); //Read the first charactor sent
lc.setChar(0,3,yy,false);
yy = char(Serial.read()); //read last digit but dont display
}


if (xx == 'e'){ // Found Com 1 S/B Freq
delay (11); // It seems to need a delay here
//digitalWrite(13, HIGH);
yy = char(Serial.read()); //Read the first charactor sent
lc.setChar(0,0,yy,false);
delay (11);
yy = char(Serial.read()); //Read the first charactor sent
lc.setChar(1,7,yy,false);
delay (11);
yy = char(Serial.read()); //Read the first charactor sent
lc.setChar(1,6,yy,true);
delay (11);
yy = char(Serial.read()); //DONT READ THE DOT
delay (11);
yy = char(Serial.read()); //Read the first charactor sent
lc.setChar(1,5,yy,false);
delay (11);
yy = char(Serial.read()); //Read the first charactor sent
lc.setChar(1,4,yy,false);
yy = char(Serial.read()); //read last digit but dont display
}

if (xx == 'p'){ // Found AP Altitude set
delay (11); // It seems to need a delay here
//digitalWrite(13, HIGH);
yy = char(Serial.read()); //Read the first charactor sent
lc.setChar(1,3,yy,false);
delay (11);
yy = char(Serial.read()); //Read the first charactor sent
lc.setChar(1,2,yy,false);
delay (11);
yy = char(Serial.read()); //Read the first charactor sent
lc.setChar(1,1,yy,false);
delay (11);
yy = char(Serial.read()); //Read the first charactor sent
lc.setChar(1,0,yy,false);
delay (11);
}


}}
-----------------------------------------------------------------------
Driving the displays is really easy

lc.setChar(a,b,c,d);

a = select board 0 -7 [You can drive up to 8 of these board on three arudino pins]
b = select segment display position 0 - 7 [there are 8 7segment display per board]
c = data to display [0-9]
d = true = display "." false = no decimal point
Thats it!

Tom_G_2010
11-04-2012, 07:48 PM
That looks great! And, something I think I will have to pursue for my sim project! I am looking for space in the budget to purchase teh card and hope to start on it perhaps next month. Again, thanks all for the input, info, and ideas!!!


Of course, since then I have come up with a couple more interesting ideas and I am wondering if there might be a solution via the Arduino route.

STALL WARNING HORN
I want to enable a stall warning horn that is mounted in the proper location in my cockpit. (Cessna 172 so in the wing root mounting plate next to the outside air vent on the pilots side) I would prefer not to hear the stall warning coming over the sim pit speakers but I don't think I can prevent that. However er I do want to have it clearly heard from the normal mounting location.

Can I pick up an indication of the Stall Warning, better yet the intensity of it, in order to control a variable voltage output form the card which will drive an electronic stall horn?

OUTSIDE AIR TEMP
I managed to snag a Cessna logo'd dial type outside air temp thermometer on e-bay. It mounts in the end of one of the pull out wing root air vents. I will be hacking into the back of it to attach it to a small servo motor. I am hoping to get the outside air temp value from either FSX or from my weather software (AS2012 at this time but may be switching to Opus) to drive that servo motor and display the air temp on the thermometer face.

So, a slightly different flavor of the same basic question: Can I pick up an indication of the outside air temp in order to control a servo motor via the Arduino card?

If I get pointed in the right direction and can figure this out maybe I can return the good will and post some sketches myself in the future...

Again, Thanks for the help and direction thus far I am hoping to get a lot of mileage out of it.

zulucat
11-04-2012, 10:05 PM
A couple of ideas come to mind. You could use a Piezo Buzzer to generate your warning. It's simple to do with an Arduino. The (-) lead goes to ground and the (+) lead goes to a pin on the Arduino. You can then use the tone() and noTone() functions to the turn the buzzer on and off. The drawback is that you can change the pitch but not the volume of the buzzer.

http://www.adafruit.com/products/160

The second idea is more complicted. Record (or get a recording) of the actual 172 stall warning. If necessary, convert the recording to WAV format. Play the recording back using an Arduino WAV Shield.

http://www.ladyada.net/make/waveshield

Another option would be to attach a digital-to-analog (DAC) converter and use that to drive a small audio amplifier. This would require some programming effort but might be the way to go.

https://www.adafruit.com/products/935

https://www.adafruit.com/products/987

Jim NZ
11-05-2012, 03:35 AM
Thanks for your post there Milobars. It's great to see projects getting posted.
One thing tho ,, I'm not sure if it's just me or not but the attachment links don't work ,, I get ,,
"Invalid Attachment specified. If you followed a valid link, please notify the administrator"
Is anyone else seeing the attachments ????
Once I can see them ,, I'll have a deeper study of your whole setup.


Tom ,, Yes ,, I run a piezo for warnings and your right ,, it makes a big difference the sound coming from the actual panel rather than from the speakers.
I did put a resistor in circuit with it ,,, cant remember why but it would have to do with the sound obviously. Maybe lowered the pitch / volume ?? cant remember I'm afraid.
Although I didn't do it ,,, a bit of insulation tape over the piezo "hole" quietens it down considerably.
There is actually a piezo in the "Uno 1" project on my site.

Lets know if those attachments work please Guys or is at my end. ??

Thanks guys ,,, Jim

zulucat
11-05-2012, 04:39 AM
Lets know if those attachments work please Guys or is at my end. ??
The attachment links don't work for me either.

milobars
11-05-2012, 05:22 AM
Ok, I've put the pics in the back of my website, so the links might work better. Not sure what happened. Try having a go at these:

www.cheapalarmparts.com.au/sim/2x7segments.JPG
This is the front of the board bought from dx .com

www.cheapalarmparts.com.au/sim/theboard.JPG
This is the back of the board.

www.cheapalarmparts.com.au/sim/radio.JPG
This the board running via the Arduinio.

Hope that works!

Milobars.

milobars
11-05-2012, 05:26 AM
Ok, I've put the pics in the back of my website, so the links might work better. Not sure what happened. Try having a go at these:

www.cheapalarmparts.com.au/sim/2x7segments.JPG (http://www.cheapalarmparts.com.au/sim/2x7segments.JPG)
This is the front of the board bought from dx .com

www.cheapalarmparts.com.au/sim/theboard.JPG (http://www.cheapalarmparts.com.au/sim/theboard.JPG)
This is the back of the board.

www.cheapalarmparts.com.au/sim/radio.JPG (http://www.cheapalarmparts.com.au/sim/radio.JPG)
This the board running via the Arduinio.

Hope that works!

Milobars.

Tom_G_2010
11-05-2012, 09:40 AM
With regards to the Stall Warning, Good to know there are some options. I know the volume on a piezo speaker is fixed, but I wonder if you could deal with that in the same way you do dimming an LED which is fixed in brightness, via pulse modulation??? So, after I obtain the arduino I'll be experimenting with this.

Any thoughts on the Outside Air Temp data and driving a servo motor?

zulucat
11-05-2012, 11:59 AM
Adafruit has a board which can drive up to 16 servos. You need just two wires going to the Arduino (not including power and ground).

http://www.adafruit.com/products/815

Adafruit also carries a remote temperature sensor which might work for you.

http://www.adafruit.com/products/381

I was wrong. You CAN vary the volume of the piezo -- volume depends on the frequency you use to drive the piezo! You would need to look at the datasheet for the piezo to figure what freq to use.

Tom_G_2010
11-05-2012, 12:35 PM
Adafruit has a board which can drive up to 16 servos. You need just two wires going to the Arduino (not including power and ground).

Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface [PCA9685] ID: 815 - $14.95 : Adafruit Industries, Unique & fun DIY electronics and kits (http://www.adafruit.com/products/815)

Good to know and something I can look into.


Adafruit also carries a remote temperature sensor which might work for you.

Waterproof DS18B20 Digital temperature sensor + extras ID: 381 - $9.95 : Adafruit Industries, Unique & fun DIY electronics and kits (http://www.adafruit.com/products/381)

I'm not looking to sense any real world temps. What I want to do is read FSX's "simulated" Outside Air Temp. If I can not get that value out of FSX then maybe I can get it from my weather app which at the moment is Active Sky, but may be changing to Opus in the near future. So, the questions are:



Can I read the Outside Air Temp value from any of those sources? And,
If I snag the temp data from one of them can I then use that to drive a servo via the arduino?


It sounds like from your info the answer to the servo drive is yes. So the big question is how to pull that temp data.


I was wrong. You CAN vary the volume of the piezo -- volume depends on the frequency you use to drive the piezo! You would need to look at the datasheet for the piezo to figure what freq to use.

So, in effect, yes, it can be controlled in a similar way to an LED. An off the shelf piezo like those I purchased at the local electronics hobby shop recently is in it's most basic use typically powered by a DC source. Those could be fed an ac sig of varying freq. or a pulse width modulated signal of varying pulse width/freq to control the volume.

More good to know info as I ponder how to accomplish this.

Jim NZ
11-06-2012, 05:20 AM
Just a quickie Tom ,,, you would be using a small servo on your gauge which ,, most of the smaller gauges can be driven directly from the Arduino so there would be no need for a "add-on" board if you are using only a few.

I think the outside temperature in FSX is available ,, I'll check and let you know.

Milobars ,,, Yes ,,, Thanks for the Pix ,,, I'll chase up why the attachments wont work though ,, it seems a common problem here.


Cheers ,, Jim.

Tom_G_2010
11-24-2012, 11:42 AM
Jim.

I acquired an Arduino Uno (translate that pulled it out of one of my kids old projects) and have started to read the language and library stuff from the official Arduino web site, and all the info your web site. I'll eventually have to by a Mega, but the Uno is great for experimenting on the test bench.

Earlier in this thread I mentioned some of what I want to accomplish. Here's the list as of now:



7 segment displays for the avionics stack
Outside Air Temp Gauge
Stall Warning Horn
Flap position indicator
Whiskey Compass (ordering a continuous 360 servo)
Auto Pilot Elevator Trim drive
Annunciator Panel(s)


Like most, I'm trying to teach myself by reverse engineering some sketch samples and reading up on the code. I've dabbled in VB, VBA, LUA, and a few odd others, but I'm not a programmer. I was able to get a servo up and running to represent the flap position, and a basic stall warning horn. But despite my reading so far, some of what that code does is not totally clear to me. I was hoping perhaps I could get a little more explanation about a couple things.

Here's my code so far:

#include <servo.h> Servo myservoFlap;


int j1;
String Flap, FlapOld;
String Stall, NoStall;


void setup()
{
myservoFlap.attach(9);


Serial.begin(115200);
}


void loop()
{
if (Serial.available() > 0) {
j1 = Serial.read();
if (j1 == 'M'){
delay (1);
Flap = "";
Flap += char(Serial.read());
Flap += char(Serial.read());
Flap += char(Serial.read());
Flap += char(Serial.read());
Flap += char(Serial.read());
Flap += char(Serial.read());
if (Flap != FlapOld){
char carray[7];
Flap.toCharArray(carray, sizeof(carray));
int n = atoi(carray);
n = map(n, 0, 57, 133, 60);
myservoFlap.write(n);
FlapOld = Flap;
}
}
if (j1 == 'L'){
delay (1);
Stall = "";
Stall += char(Serial.read());
Stall += char(Serial.read());
Stall += char(Serial.read());
Stall += char(Serial.read());
Stall += char(Serial.read());
Stall += char(Serial.read());
char carray[7];
Stall.toCharArray(carray, sizeof(carray));
int n = atoi(carray);
if (n == 1){
delay(1);
analogWrite(6, 15);//Activate Stall Horn
}
else {
analogWrite(6, 0);//Silence Stall Horn
}
}
}
}

I take it the multiple "+= char(Serial.read())" lines are converting the serial data received into a string of 6 characters, yes? I noticed one persons code sample only used three lines like this???

Regarding the next few lines, I have read through the Arduino reference several times and either I'm being thick headed or this is more creative than what the docs cover. Could you give me a better idea of what these lines are accomplishing:


char carray[7];
Flap.toCharArray(carray, sizeof(carray));
int n = atoi(carray);

I understand that it is some form of conversion from a character sting to a number but I'm just not getting how it does that... :(

In general I would like to better understand the data format that Link2FS is sending to the card and the manipulations that take place so I can start to visualize my own code.

A couple refinements I will also be working on include: smoothing out the servo action on the flap control; and creating some variation in the stall warning.

By cutting back the delay value I was able to smooth out the servo some, but there's still a noticeable jitter to it that I wasn't seeing through Phidgets control card. I suspect the Phidget card being a dedicated servo controller has some form of smoothing hard coded that I would have to somehow recreate in the Arduino Sketch if possible.

It appears that FSX only has an on/off state for the stall warning. While my real world flight time is somewhat limited I did a fare amount of stall practice in 152's and 172's. The stall horn varies greatly in intensity as a stall condition develops. I will be experimenting with ways to at least fake that build up to stall if I can figure it out...


Oh, one last question, did you ever find that outside air temp value?


Thanks again for a great program and web site!!!</servo.h>

zulucat
11-24-2012, 02:40 PM
I take it the multiple "+= char(Serial.read())" lines are converting the serial data received into a string of 6 characters, yes? I noticed one persons code sample only used three lines like this???
The "+=" appends the char just read to data already in String. You should be reading only 3 chars not 6. If you take a look at Jim's documentation the "Flaps Position" checkbox has 3 chars to left. This indicates that Link2FS sends 3 chars after the "M" to indicate flap position. Similarly, the Stall Warning command (L) sends just a single char. You should update your code to reflect that fact.

NOTE: "+=" normally adds to a variable, not appends. However, String is a C++ class and the use of "+" has been redined to do an append for that class. Here's an example of normal usage:



int val;
val = 5;
val += 7; // adds 7 to 5


Regarding the next few lines, I have read through the Arduino reference several times and either I'm being thick headed or this is more creative than what the docs cover. Could you give me a better idea of what these lines are accomplishing:


char carray[7];
Flap.toCharArray(carray, sizeof(carray));
int n = atoi(carray);
The code is using a C library function (atoi) to convert a C string to an integer. Flap.toCharArray() is converting data in the Flap object to a standard C string.


A couple refinements I will also be working on include: smoothing out the servo action on the flap control; and creating some variation in the stall warning. By cutting back the delay value I was able to smooth out the servo some,
I'm wondering if your servo problem could be caused by reading too many chars?


It appears that FSX only has an on/off state for the stall warning.
I think I mentioned in an earlier post that Stall Warning could only be a 1 or a 0. In reality it could be in the range of 0 to 9. Maybe Jim can straighten us out on this one!

Tom_G_2010
11-25-2012, 11:45 AM
Zulucat,

Thanks for the additional information. Yes, you did mention the stall 0 to 9, but I am only seeing 0 or 1 out of Link2FS hence my coding based on that.

As for the = then += the code won't compile unless I use += on each line.

I have removed the unneeded lines per you explanation above. Thanks!

I need to do some more reading on the char function since I can't figure out what the [7] is doing after the carray in that line. On the way out the door now so I guess that'll be this evenings reading... Same for the array. I use arrays in spreadsheet and database coding at work but don't do a lot with them in coding. More to read and learn.

zulucat
11-25-2012, 02:25 PM
As for the = then += the code won't compile unless I use += on each line.
I assume that you are referencing the = in the code sample I provided. The = is a standard C assignment operator which places the value of 5 in the int named val. Sorry for the confusion.


I need to do some more reading on the char function since I can't figure out what the [7] is doing after the carray in that line.
The [7] defines the number of chars reserved for the array.

ALSO: In an eariler post you mentioned you might end buying a Mega to replace the UNO. I can recommend Mouse Electroincs for your purchase. The have, by far, the best price on a Mega 2560 that I've found. That's where I bought mine.

Jim NZ
11-26-2012, 04:00 AM
Tom ,, Zulucat has covered most of your queries but I thought I'd dive in about that stall thing.

The stall warning that shows is either On or Off.

I'm at the moment I'm doing a wee mod to the program to suit the non-english copies of FSX and FS9 and I'll have a look at including the outside air temperature and also the stall variable ,, "stall alpha" ,, I don't know what it does but I suppose I'm about to find out. It may or may-no be of any use to you.

I done a quick wee "hack" yesterday and it's actually quite interesting watching the temperature change with different weather and altitude etc. ,, nice ,, so get that servo and gauge all sorted out Tom. :)

Cheers ,,, Jim

AK Mongo
11-26-2012, 07:27 AM
Jim,

Any chance you could get at some engine info out if you are "hacking"?

It would be very helpful to have the EGT, Fuel Flow, oil temp, oil pressure, and suction It looks like the simconnect names are:

GENERAL ENG OIL PRESSURE:index
GENERAL ENG EXHAUST GAS TEMPERATURE:index
GENERAL ENG OIL TEMPERATURE:index
ENG FUEL FLOW GPH:index
SUCTION PRESSURE

Reid

Tom_G_2010
11-26-2012, 09:46 AM
Jim,

Thanks much!!! I am stumbling through learning the code and some of it is clicking right away other things not.

I already have some 180 servos that I'm using for things like the flap gauge, but no 360s. So I am going to be ordering a couple 360 servos. One to drive the thermometer needle since it needs about 300 degrees of rotation and I won't have any space inside the airvent for gears, the other to drive the Whiskey compass which of course needs 360 continuous rotation.

I got the piezo stall horn to mimic the build up and drop off of a stall horn with a for loop that ramps up or down the pwm value, but if you're able to expose that stall alpha and it works like I hope it does that will be even more realistic.

My next stumbling block came last night when I attempted to read a variable that had two characters. Reading the "M" or "L" values for flap position and stall works great, when I try to read a two character value like ">x" I get nothing. More reading and head scratching tonight... Hoping to find another code sample floating out on the forum.

I hadn't thought about the variables that Reid mentioned above. I have had the debate about mechanical gauges or LCD gauges so many times my head hurts. At the moment I'm leaning towards LCD, but that may change after my next nightmare about the issue... So the more variables exposed in Link2FS the better.

Again, Thanks for Link2FS and all your help on this!!! I know it's a lot of work for nothing more than the gratitude of a bunch of crazy sim pit builders, but you have that from many of us in abundance!

AK Mongo
11-26-2012, 11:17 AM
Tom,

Where are you finding 360 servos, and are you sure that is what you want?

Most 360 servos remove the positional sensor, and in effect makes them bi-directional motors without position feedback. This forum:http://www.mycockpit.org/forums/cockpit-parts-motion-platforms/24131-how-convert-real-cessna-altimeter-sim-use.html has some options for using a dc motor and a multi-turn pot with servo guts. It may be worth a look. If you have found something else, I would love to hear about it. For the Whiskey compass, a stepper may be a better option, unless you have a plan to track the continuous servo's position.

Reid

AK Mongo
11-26-2012, 11:19 AM
Jim,

Again, Thanks for Link2FS and all your help on this!!! I know it's a lot of work for nothing more than the gratitude of a bunch of crazy sim pit builders, but you have that from many of us in abundance!

I could not agree more, Jim.

Reid

Tom_G_2010
11-27-2012, 02:00 AM
Tom,

Where are you finding 360 servos, and are you sure that is what you want?

Most 360 servos remove the positional sensor, and in effect makes them bi-directional motors without position feedback. This forum:http://www.mycockpit.org/forums/cockpit-parts-motion-platforms/24131-how-convert-real-cessna-altimeter-sim-use.html has some options for using a dc motor and a multi-turn pot with servo guts. It may be worth a look. If you have found something else, I would love to hear about it. For the Whiskey compass, a stepper may be a better option, unless you have a plan to track the continuous servo's position.

Reid

Reid, you are spot on. There are several 360 or continuous rotation servos but none that I have looked at in detail since that last post have position sensors. So I have started looking at stepper motors as well. My challenge there is still the same though, detecting position. At start up of the sim the plane could be pointed in any direction so there needs to be a way to sync up the Whiskey Compass. After it is in sync the rest seems straight forward from a known starting point.

I would think there are some commercially made position sensors that could be added to them, but I haven't gone that far in my reading yet. More to look at tomorrow...

AK Mongo
11-27-2012, 03:13 AM
I want to say that I have seen steppers that used an optical device to calibrate. There is an led that shines through a hole in a rotating plate that is only aligned at a known position and this sets the start point for the counter. Upon initializing the instrument it rotates to that known position and then moves to the correct heading using the voodoo that runs a stepper. Is it called an Optical Interrupter? maybe? I think it is in Mike Powell's Instrument book. I have tomorrow off, so I will try and look it up for you.

Reid

Jim NZ
11-27-2012, 05:11 AM
Thanks for the comments Guys ,,,
Just a quick wee update (it's getting late here) to prove things are actually happening here.

I've finished the "non-english" stuff.
Added more extractions (all gauge related) to both the FSX side and also the FS9 side.

It goes well and I have just got to get some bugs fixed it and fully test it on both sims.
Probably about 3 days if all goes well.

Cheers ,,, Jim

Jim NZ
11-30-2012, 03:53 AM
Yesterday I uploaded the updated program for testing. It is just the exe file and needs to be put into the same folder that Link2fs_inout_v2 is in.
It will use you present ini file so there is no need to "re-program" all the settings.

Unfortunately I never had time to really thrash the testing stage so we will see how she goes.
I already see a change I need to do ,,, The fuel pressure reading has allowed for 4 digits !!!! :)

Fixed the "non English" thing.
Added 17 more extractions that are mainly only suitable for gauge builders.

See how it goes and if any fiddles are needed I'll do them quickly and get this out of the way.

It's at the bottom of this page ,,,,,
Your looking for version 3
http://www.jimspage.co.nz/link2fs_inout.htm
(You may have to hit refresh to see the new entry.)

It's great to see lots of activity in GA pit building again ,,, very refreshing. :)

Happy testing Guys ,,, Jim

Tom_G_2010
11-30-2012, 08:43 AM
Jim, THANKS! Your work on this is greatly appreciated!

Or should I say:

/*
THANKS!
Your work on this is greatly appreciated!
*/

I know, bad :roll: but I couldn't help myself...

I saw the Outside Temperature C and Stall Alpha I'll be messing with them this weekend for sure.
If anything quirky pops up with the Beta I'll let you know.

Jim NZ
11-30-2012, 03:54 PM
Tom the "stall alpha" may be a disappointment for you.
It brings out a fixed figure and only changes when you change planes but doesn't change while flying.

I presume it needs to be "mixed" with other flight parameters to get a certain figure ,, which would be difficult to do within the Arduino but not impossible I suppose.

If you find a useful "mix" let me know and I can add that manipulation of that figure within my program.

Happy testing ,,, Jim

Jim NZ
11-30-2012, 04:32 PM
Tom ,, sorry I forgot to answer an earlier question about "dual identifiers".

There is a help file on that subject in the Link2fs_inout_v2.zip file.

Basically you check for single identifiers and then check for dual identifiers ,, quite easy when the "picture" pops into your head.

See ya ,, Jim

Tom_G_2010
11-30-2012, 06:04 PM
Tom ,, sorry I forgot to answer an earlier question about "dual identifiers".

There is a help file on that subject in the Link2fs_inout_v2.zip file.

Basically you check for single identifiers and then check for dual identifiers ,, quite easy when the "picture" pops into your head.

See ya ,, Jim

Jim, No problem, and thanks for the follow up. I figured it out since having posted and forgot to update the post. Not sure if there's a more efficient way, but I built a pair of if statements that look for the ">" or "=" and have if's nested under them to look at the second character. I'll be sure to look at the help file when I get home.

Skipping the unrelated stuff here's what I'm basically doing



if (Serial.available() > 0) {
j1 = Serial.read();
if (j1 == '>'){
delay (11);
j1 = Serial.read();
if (j1 == 'a'){
// do something
}
if (j1 == 'b'){
// do something else
}
}
if (j1 == '='){
j1 = Serial.read();
if (j1 == 'a'){
// do another thing
}
if (j1 == 'b'){
// do something different
}
}
}

Jim NZ
11-30-2012, 09:11 PM
You've got it Tom :) ,,, Jim

Tom_G_2010
01-29-2013, 01:44 AM
Hi All,
Firstly, thank you to Jim for supplying all this information and getting lots of people going with Arduino and his fantastic programs.
I tackled the display issues with some experimentation with LCD screens, but after much research stumbled upon a site called DealExtreme - Cool Gadgets at the Right Price - DX Free Shipping Worldwide (http://www.dx.com) (deal extream). Here they have Arduino compatible products extreamily cheap. Arduinio Mega is about $120 here (Australia) - I bought a Mega for $17 including postage!

Anyway ... they have dual 4x serial segment displays. Extreamily easy to get going, and with minimal code.
Here is what I have done so far:

7226 each board can drive 8x 7 segment displays.

7227 Only needs 3 pins from an Arduinio, and you can drive up to 8 of these 8x7 segment displays with only 3 pins!

7228 Here is the COM1 Radio frequency and standby frequency display for my radios. The first 8 digits (from the left) is being driven by one board, the last 3 digits are being driven by a 2nd board (connected to the first board with +5v, Gnd and the same three pins from the Arduino).

This means I can display the entire radio stack frequencies with only 3 pins from the arduino! I am going to use another set of pins to drive the entire set of displays for my auto pilot. The best thing is, these boards are $5 from DX.com including postage!!

Here is the sketch I'm mucking around with ... it's taken from Jims examples, and uses link2FS_inout program (Thanks Jim!).

----------------------------------------------------------------------------------
code removed from quote for brevity. See post #6 from milobars for the posted code
----------------------------------------------------------------------------------
Driving the displays is really easy

lc.setChar(a,b,c,d);

a = select board 0 -7 [You can drive up to 8 of these board on three arudino pins]
b = select segment display position 0 - 7 [there are 8 7segment display per board]
c = data to display [0-9]
d = true = display "." false = no decimal point
Thats it!

milobars, THANKS!

I ordered a display and a few other odds and ends from Deal Extreme. The amount of time it took for it to arrive after they shipped it was a bit drawn out, but everything I ordered got here.

Your code example was straight forward and after I installed the LED Control library everything worked like a charm. So know I'm off to finish my hardware design so I can order the correct count of displays for my avionics stack.

I added the code to make the display shut down when the avionics bus voltage dropped and I am about to work on the code for a display dimmer. To conserve on displays I am going to order a few single 7 segment displays for the fixed "1" digit of each freq display and use the dual 4 digit units for the active digits.

Again, Thanks!
Tom G.

NeoMorph
02-03-2013, 06:24 AM
Can you send values to Link2FS and set the radios in FSX for example. I can see you can send switches but what about radio freqs?

You may have an arduino program that lets you save various freqs so you can press a button and it automatically selects that freq in FSX. I'm trying to build a Collins CTL-32 radio for use in my ATR-72 you see and those have mem features. The flight 1 ATR has the mem but I want to put it into an external piece of firmware so that I can use other aircraft with the mem features as well.

Jim NZ
02-04-2013, 04:56 AM
No my program wont do that ,, it manipulates the frequencies within FSX itself and doesn't "hold" them.

Sammy-E
02-04-2013, 05:53 AM
Just a thought.. ... You could use variables on in the arduino to store frequencies and with a pushbutton store the selected frequency into those variables.. If the active frequency changes due to recalling the stored frequency, send an update to FSX through Link2FS?

EDIT: After re-reading the post, I'm pretty sure this (send frequency) is not possible with current version of Link2FS. It cannot "send data" to FSX, it sends key's.

NeoMorph
02-04-2013, 06:07 AM
Grrr... what is with this forum... post and half the time it says "Token has expired" and then loses my post and then there is no way to restore it even though it says its auto saving.

Ok try yet AGAIN...

Jim, I think you got what I want back to front (my post wasn't too clear after I had spent all night trying to track down a dumb current leakage). I want to store the frequencies in the Arduino program... then I press a button and that freq gets sent to the serial port. Possibly as "h109.500" like it comes down from your program. Your program then passes it on to FSX. Simple as that.

Your program already handles the switches so it should be easy peasy to just act as courier to the frequencies I would have thought.

Tom_G_2010
02-04-2013, 08:58 AM
NeoMorph,

I had the same question in the back of my mind for a later point in my coding efforts, but have not gone far enough to attempt to solve for it or put up any questions. You beat me to it. I was hoping to do two things, one setup a VFR button that flips my transponder to 1200 regardless of present and two provide a series of programmable freq. presents for my Comm and Nav radios.

I fly on line with Boston Virtual Air Traffic Control and am often flying planned routes such that I know in advance all the freq's I'll need. What I had in mind was to be able to punch in the freq's on the radios and store them just as you do presets on a car radio so I could call them up quickly with a single button press as the flight progressed.

I have some thoughts gathering in the back of my mind on how to do the store and recall code but had not yet considered how to send the stored freq. back to FSX.

Hopefully Link2FS can inject the freq's back into FSX directly, but if not I am pondering another idea. Link2FS can read the current freq's from FSX, I am using that to drive radio displays, so that means I can capture the freq easily to store it. I can also use that to read the current freq and compare it to a stored preset freq and then send the needed increment or decrement steps back to FSX to alter the freq. That's not nearly as clean or eloquent and it may also be prone to some errors so I am hoping Link2FS can inject the freq directly.

Tom G.

NeoMorph
02-04-2013, 03:36 PM
Well I dug out my copy of VB6 today and used Jim's program (not the source of course) as inspiration and was amazed how easy it was to get it working. I'm not using SimConnect though... just plain old FSUIPC because although Jim's program is awesome I think it has to be on the same PC as FSX and I want to distribute the load somewhat.

I am also planning on making my ATR 72 modular like a real plane is (ie I can unscrew the stuff and remove it all from the cabin without having to dig in the back) and using Arduino's as driver boards is really simple. I was going to use PIC's up to now and even bought a load of them. Now though... one Ardy UNO per module and maybe a mega for more complicated stuff.

Oh yeah and why go back to VB6... because I hate VB.NET with a vengeance! For me it became WAYYYYY too complicated for what I wanted to do. VB6 is the essence of simplicity with the complicated there in the back waiting.

Jim NZ
02-05-2013, 02:23 AM
Yes ,, I took it up wrong ,,, well there's good news ,,, once I get the "Multi" settled the next step is to bring in Simconnect inputs, so that means you will be able to "inject" a complete radio frequency.

With the chit chat about this ,,, it wouldn't be too big a mission to add a page with "user fills them in" sort of thing and the Arduino sends a set code that would send "user filled in" (say) "*A" to FSX ,, hard to explain whats in my head but it would save having to re-code the Arduino everytime you wanted to alter it. It's all held in the "multi" for you.

Let me reword that ,,
There's a page in the multi with a whole lot of drop-down boxs and textboxs in it you can fill in.
In the one maked (say) "*A" ,,
In the dropdown you sellect Com1
Then in the textbox beside it you fill in 123.450
Soooo ,, when your arduino sends "*A" then my "Multi" will send the 123.450 to Com1 in FSX.
There ,, even I can understand that :) :)
The data entered would be saved along with your profile so it's never lost.
But I need to get the present core of "multi" stable and finished ,, then bring in all the simconnect inputs stuff that's of use to us.

Neomorph ,, yea I know what you mean and it's a real pain the newer programing tools ,, VB6 is great but M$ seem **** bent on getting it out of the system ,, so sharing programs using VB6 now is a nightmare with all the operating systems out there now.
Anyway ,, good luck with your mission.

Cheers guys ,, Jim

Tom_G_2010
02-05-2013, 09:47 AM
Jim,

It sounds like with Multi I could enter some freq values into a user defined table and then call them up as needed, yes, no??? Does that mean I would need to interact with Link2FS manually to do this or could I accomplish this with interaction via the arduino?

What I am hoping to do is code the arduino to capture the currently extracted freq and save it as a variable that I later recall and send to FSX to change radio freq's. Very much like you set the radio presents on a car radio. The code on the arduino to do this is fairly easy to write it's just a matter of whether Link2FS present or multi could then send that stored info back to FSX to change the radio freq.

Example:

I'm on the ramp at KBOS with Flight plan in hand headed to KJFK so I know I'll need to make no less than 9 freq changes throughout my flight. With my two radios I can set the first four freq in advance but for the rest I would normally need to dial them in on the fly so to speak.

What I want to do is sit on the ramp and load freq's 5 thru 9 into present buttons by dialing up the freqs on the radio one at a time and then pressing and holding the present buttons (maybe six user present buttons) one at a time. The code on the arduino would see the long button press and would read the last extracted freq and store it in that preset buttons defined variable.

Later in the flight when I need the freq I click of the button and that action is read by the arduino as a short button press and triggers the recall freq code which reads the variable previously set and sends that freq back to FSX to tune the radio.

I could then at KJFK look at my next flight leg and repeat the action to load up the next set of needed freq's and so on.

Jim NZ
02-05-2013, 08:59 PM
No, I was looking at what you Guys were talking about and came up with an idea that may have been useful but with what you've just said ,, no it wont work so I've canned the idea.

I'm close to releasing this rebuild and once that is settled I'll start adding the other stuff.
The thing needs to be stable and trouble free (proven) before I add anything to it.
Once it's proven ,, the first thing to be added will be the "simconnect input" which will enable you to inject a complete radio frequency into FSX plus a whole heap of other things you can "inject".

Cheers ,,, Jim