Header OpenCockpits
Page 1 of 10 12345 ... LastLast
Results 1 to 10 of 99
  1. #1
    150+ Forum Groupie
    Join Date
    Apr 2011
    Location
    United States of America
    Posts
    228
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Arduino COM / NAV LED display - FSX

    Well...I have a success story. A small one, but a success story none-the-less.

    I have completed the COM1 freq display (beta) by using (4) seven segment LED blocks and Charlie-plexing the anodes; therefore, I am only using only 11 outputs to drive the entire COM1 display (...add another output to drive the leading MHZ "1" and trailing KHZ "0" and decimal pt). I am also using (4) inputs to increase/decrease the MHZ/KHZ freq according to the B737 display. I estimate I will be able to use COM1&2 and NAV1&2 on a single 2560 bd using a 5ms loop for an undetectable flicker rate and little bleed to the unlit segments - leaving room to use the analog inputs if I need.

    My problem will arise when I incorporate the rotary encoders; Since the loop will already be at 5ms, I believe I will need to use my second 2560 to handle the encoders and xmit data to the other 2560 "LED COM/NAV" display bd to prevent loop lag generated by the encoder read/translation.

    I admit that I am a novice. If I am on the wrong track, please do hesitate to offer alternatives.

  2. #2
    500+ This must be a daytime job Jim NZ's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    656
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Arduino COM / NAV LED display - FSX

    Hi James,,, Well done with the progress,,, neat stuff what you have acheived in such a short time and you will be looking forward to getting it to a usable state. Charlie-plexing ,,, very cunning approach.

    Now the rotary encoder thingy ,,, As you know I like pulse switchs but at the end of the day everyone gets rotary encoders. I have (and still am) digging into this dreaded corner and there are 2 ways to interface rotary encoders into Arduinos.
    1... Direct pin reading and sort it out internally or externally from there.(With or without an internal library)
    2.. Use interupts and sort it out internally or externally.

    Of the methods I have played with using the cheap mechanical rotary encoders, I found the following ,,,
    Direct input was the most consistant performer using the BOUNCE libray, but it still had direction/pulse errors and wasnt that fast ,, although you could "build in" acceleration.

    The interupt method was definately quicker but because of that, it really showed up dirty contacts with the wiping of the contacts in the switch, hence more direction/pulse errors. You can externally "debounce" the encoders contacts with capacitor/resistor arrangement but that puts you back to the speed of the direct read method,, more or less.

    Optical encoders would really perform with the interupt method. (I think ,, but I dont have any)

    Now,, That 5ms loop,, I wouldnt worry about it ,,, a "debounce" can be that long at anyrate so give it a go on the same card and see what happens.

    If you have good quality encoders you could use iether method,,, but if you have the cheapies,,, use the direct read method with the "bounce" library.

    I've been playing around with another method of handling rotary encoders and I'm Sooooo close to cracking it,, its frustrating. !!! A clean read with acceleration ,,, Soooo close. !!

    I seem to be writing a book here,,, but I've passed on what I know.... Hopefully some-one else with more knowledge might pop in and help you James.

    Again,, well done to get to where you are at ,,,, Jim
    www.jimspage.co.nz
    All this and Liz still loves me ! !

  3. Thanks JMeller, Joe Cygan thanked for this post
  4. #3
    150+ Forum Groupie
    Join Date
    Apr 2011
    Location
    United States of America
    Posts
    228
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Arduino COM / NAV LED display - FSX

    Thanks Jim for the kind words and insight.

    Because I have a "new" set of eyes and have not developed (as of yet) a "set in stone" programming technique, I am going to toss this out there:
    The code I have written has only one delay (5ms) and that is to prevent the loop from running TOO fast. It prevents the current from leaking over to the unlit LED segments. To debounce the inputs, code was written to recognize that when any input goes high, a variable is incremented +1 at the end of the loop. This variable continues to increment so long as the input is HIGH. When the variable == 20, the display changes accordingly. When the variable == 40, the variable is reset to 0 and cycle repeats. If at anytime the input goes LOW, the variable resets to 0 - waiting for any input to go HIGH to begin it's cycle again. This allows the loop to run as fast as it can while allowing the switch to settle into place - - and also increment the display in a readable/predictable manner if I continue to hold in the button. I don't know if this perspective from a novice is useful, but I thought I would throw it out there anyway. Of course, mods to the code will needed with rotary encoders since A or B can hold their state at the next detent.

    As for the rotary encoders, I plan to purchase a moderately priced "grey code" encoder to reduce the aggravation of bouncing. Any recommendations are appreciated. I am also interested in the following post from Oleg (you probably have read this already) : http://www.circuitsathome.com/mcu/re...der-on-arduino
    However, I will need to get myself up to speed on truly understanding his code.

    I am anxiously awaiting the day when you share you success with encoders!

    Marching forward,
    James

  5. #4
    150+ Forum Groupie
    Join Date
    Apr 2008
    Location
    Graham, WA
    Posts
    292
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Arduino COM / NAV LED display - FSX

    Instead of eating one more output for the leading 1 and trailing 0, why not just tie them to Vcc and recover the input?

    You might be better served in transmitting the freq up/dn commands to the host and let the COM1 Arduino pick up the change form the host instead of from another Arduino. (this is how I would do it, ymmv)

    Switch contacts have been known to bounce for as long as 25ms. I didn't know about the BOUNCE library - I'll have to dig into that!

    g.

  6. #5
    150+ Forum Groupie
    Join Date
    Apr 2011
    Location
    United States of America
    Posts
    228
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Arduino COM / NAV LED display - FSX

    Thanks Jim for the kind words and insight.
    Gene, Vcc for the leading and trailing numbers - great catch; I'll do that.

    Because I have a "new" set of eyes and have not developed (as of yet) a "set in stone" programming technique, I am going to toss this out there:
    The code I have written has only one delay (5ms) and that is to prevent the loop from running TOO fast. It prevents the current from leaking over to the unlit LED segments. To debounce the inputs, code was written to recognize that when any input goes high, a variable is incremented +1 at the end of the loop. This variable continues to increment so long as the input is HIGH. When the variable == 20, the display changes accordingly. When the variable == 40, the variable is reset to 0 and cycle repeats. If at anytime the input goes LOW, the variable resets to 0 - waiting for any input to go HIGH to begin it's cycle again. This allows the loop to run as fast as it can while allowing the switch to settle into place - - and also increment the display in a readable/predictable manner if I continue to hold in the button. I don't know if this perspective from a novice is useful, but I thought I would throw it out there anyway. Of course, mods to the code will needed with rotary encoders since A or B can hold their state at the next detent.

    As for the rotary encoders, I plan to purchase a moderately priced "grey code" encoder to reduce the aggravation of bouncing. Any recommendations are appreciated. I am also interested in the following post from Oleg (you probably have read this already) : http://www.circuitsathome.com/mcu/re...der-on-arduino
    However, I will need to get myself up to speed on truly understanding his code.

    I am anxiously awaiting the day when you share you success with encoders!

    Marching forward,
    James

  7. #6
    150+ Forum Groupie
    Join Date
    Apr 2011
    Location
    United States of America
    Posts
    228
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Arduino COM / NAV LED display - FSX

    Another success story!!!! Rather than use a rotary ENCODER, I had a 12pos 2pole rotary SWITCH in my parts bin (available from your over-priced Radio-Shack). Although it takes one more input than a rotary ENCODER, it works very well. After verifing the basic code operation, I inserted the code into my COM / NAV LED display code - with a few modifications (reducing the loop cycle to 4ms and to read on the 2ms.) It works PERFECTLY! As a test, I turned the rotary 3X faster than I would in flight - no misses!

    Jim,
    Will you help you help to point me in the direction of how to create/modify the software to interface with FSX, i.e. LinkFS ???

    If interested, I will post the code which can also be viewed by the Serial Monitor.

    Pumped!
    -James

  8. #7
    500+ This must be a daytime job Jim NZ's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    656
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Arduino COM / NAV LED display - FSX

    Congradulations James ,, thrilled for you, and yes, the rotary switch is a good solid way to go.
    The "in and out" of FSX,, I can knock you up a "one of" to suit what you are doing, no worries.
    I've done heaps for other guys over the years (mainly motion platform stuff) although none of them were using Arduino's.
    I want to get this bug out of my "keys" program first though.
    In the meantime,, have a think of what info you want "out" and info back "in" to FSX ,,,, and its format.
    Just think of a basic "get it going" interface at this stage as I have plans to do a full blown in/out program to suit what we do. (A user can choose what he wants out and what he wants in)

    Of course we want code snippetts and pictures and anything you can produce that shares knowledge and helps other guys,, silly question ,,

    Well done James ,,,,, Jim
    www.jimspage.co.nz
    All this and Liz still loves me ! !

  9. #8
    150+ Forum Groupie
    Join Date
    Apr 2011
    Location
    United States of America
    Posts
    228
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Arduino COM / NAV LED display - FSX

    The basic wiring on the 12pos rotary switch - (Black) loop the 1st, 4th, 7th, and 10th pin to "input 53"; (Yellow) Loop the 2nd, 5th, 8th, and 11th pin to "input 51"; (Red) loop the 3rd, 6th, 9th, and 12th pins to "input 49". Place the common poles to +Vcc (w/ resistor).

    The basic code is as follows ( a smarter man can clean it up ):

    int pin53 = 53;
    int pin51 = 51;
    int pin49 = 49;

    int Black;
    int Yellow;
    int Red;

    int BlackMEM;
    int YellowMEM;
    int RedMEM;
    int BlackLOW;
    int YellowLOW;
    int RedLOW;

    int LOOPcycle;
    int Completed;


    void setup()
    {
    pinMode(pin53, INPUT);
    pinMode(pin51, INPUT);
    pinMode(pin49, INPUT);

    Serial.begin(9600);
    LOOPcycle = 0;
    Completed = 0;
    BlackMEM;
    YellowMEM = 0;
    RedMEM = 0;
    BlackLOW = 0;
    YellowLOW = 0;
    RedLOW = 0;
    }

    void loop()
    {
    Black = digitalRead(pin53);
    Yellow = digitalRead(pin51);
    Red = digitalRead(pin49);

    /* ++++++++++++++++++++++++++ Memory Storage ++++++++++++++++++++++++++ */
    if (Black == HIGH && LOOPcycle == 20)
    {
    BlackMEM = 1;
    // Serial.println("Black is HIGH");

    }

    if (Black != HIGH && BlackMEM == 1 && LOOPcycle == 20)
    {
    BlackLOW = 1;
    Completed = 0;
    }

    if (Yellow == HIGH && LOOPcycle == 20)
    {
    YellowMEM = 1;
    // Serial.println("Yellow is HIGH");
    }
    if (Yellow == !HIGH && YellowMEM == 1 && LOOPcycle == 20)
    {
    YellowLOW = 1;
    Completed = 0;
    }

    if (Red == HIGH && LOOPcycle == 20)
    {
    RedMEM = 1;
    // Serial.println("Red is HIGH");
    }
    if (Red == !HIGH && RedMEM == 1 && LOOPcycle == 20)
    {
    RedLOW = 1;
    Completed = 0;
    }

    /* ++++++++++++++++++++++++++ Determine Change ++++++++++++++++++++++++++ */

    if (Black == HIGH && RedLOW == 1 && LOOPcycle == 30)
    {
    Serial.println ("+1");
    RedMEM = 0;
    RedLOW = 0;
    Completed = 1;
    }
    if (Black == HIGH && YellowLOW == 1 && LOOPcycle == 30)
    {
    Serial.println ("-1");
    YellowMEM = 0;
    YellowLOW = 0;
    Completed = 1;
    }

    if (Yellow == HIGH && BlackLOW == 1 && LOOPcycle == 30)
    {
    Serial.println ("+1");
    BlackMEM = 0;
    BlackLOW = 0;
    Completed = 1;
    }
    if (Yellow == HIGH && RedLOW == 1 && LOOPcycle == 30)
    {
    Serial.println ("-1");
    RedMEM = 0;
    RedLOW = 0;
    Completed = 1;
    }

    if (Red == HIGH && YellowLOW == 1 && LOOPcycle == 30)
    {
    Serial.println ("+1");
    YellowMEM = 0;
    YellowLOW = 0;
    Completed = 1;
    }
    if (Red == HIGH && BlackLOW == 1 && LOOPcycle == 30)
    {
    Serial.println ("-1");
    BlackMEM = 0;
    BlackLOW = 0;
    Completed = 1;
    }

    LOOPcycle = LOOPcycle + 1;

    if (LOOPcycle == 40)
    {
    LOOPcycle = 0;
    }

    // if (Completed == 1)
    // LOOPcycle = 0;
    // Serial.println (LOOPcycle);
    delay(0);

    }



    -James

  10. Thanks mndless, Jim NZ thanked for this post
  11. #9
    150+ Forum Groupie
    Join Date
    Apr 2011
    Location
    United States of America
    Posts
    228
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Arduino COM / NAV LED display - FSX

    Jim,
    The basic vision for the COM / NAV LED display is to rotate the freq switch, arduino recogizes the change and sends a "C1 +" or "CC1 +", etc, command to FSX to increase the comm freq. When FSX changes the freq, it sends a command back to the arduino indicating the actual freq. After the arduino receives the value, it displays it on the on the 7-seg LEDs. This will allow the display and FSX to always be in sync.

    I tweaked the code to run a little faster and found that if I turn the knob as fast I can, the code does not miss a beat. Therefore, I believe I will stick with a 12pos rotary switch as opposed to an encoder.

    As for you programming the custom interface code - I appreciate that immensely! However, I am sure you are a busy guy. I don't want to bog you down - because after I complete each phase, I will be asking for more That being stated, I would be grateful if you would point me in the direction of how you built LinkFS... or I can pester you for updates --heheh. The Arduino has opened a whole realm of easy possibilities w/ FSX and my mind is racing!!

  12. #10
    500+ This must be a daytime job Jim NZ's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    656
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Arduino COM / NAV LED display - FSX

    Hi James ,, Ive been away with work for a couple of days (can be a week sometimes) anyway ,,, thanks for posting your code ,, its things like that that help other people and for heavens sake ,,, dont worry if its "prettey" or not ,,,, It works and thats what counts. Any code can be improved on by some-one that is more "into it" than we are but thats the fun of it.

    Great stuff on where you are at now ,, How are you sending the CC1 + to FSX and how are you getting the frequency back out of FSX ???. I am presuming thats where Link2fs comes in ???

    On my site there is a program called "Link2fs_Testa" and I have supplied the source code as well, but its "visual basic 6" (not the ".net" one). Another way is to use VB or C# .net express edition (Free from Microsoft) and sort out via the FSX SDK what you want to do.(There are samples supplied)

    As you get nearer your finished radio setup you could start thinking of a PDE file to suit a more logical sequence.
    For instance ,,, you turn the knob ,,, you look at your LED's ,, you expect them to change as you turn the knob,, the actual indication showing in FSX is not really relevent in those split seconds. (There will be lag)

    You need a trigger for the coms sequence ... Lets call them A=com1,, B=com2 and so on.

    Turn the knob,, LED's change ,,, FSX changes.
    What actually happens is ,,
    Say your com1 radio is sitting on 123.45 ,, this figure is sitting in your Arduino as a string or some other form of data.
    Turn the knob up one click ,, the string now is 123.46 and because the string has changed,, 123.46 is sent to your LED display routene and also "A123.46" is sent to FSX via some extra program.

    As a back up to "on change" data ,, every 1 or 2 or 3 seconds the Arduino sends everything it knows ,, I.E. "A123.45 B122.33 C110.23 D112.67" etc etc. ,, all read from internal strings. (Or another form of storrage)
    Thats how my in/out program will work at anyrate and you can see hints of it in Link2fs_Arduino_uno1's PDE file. (The send immediately and the backup every so often)

    Simply speaking ,,, the radio/nav LEDs comes from the Arduino and NOT from FSX. !! although, I realize, at the moment you are stuck with inputing via keystrokes.... That will change though.

    Roger on the rotary switchs,, I agree ,,, thats what I use here as well, although mine are as a homemade pulse switchs and like you ,,, they havent missed a beat.

    geeze,, writing a book here again ,,,,, Cheers ,, Jim
    ps this bug in my "keys" program is still a problem but I'll get it sorted,, it just takes time.
    www.jimspage.co.nz
    All this and Liz still loves me ! !

Page 1 of 10 12345 ... LastLast