Page 1 of 3 123 LastLast
Results 1 to 10 of 25

Thread: Help needed

  1. #1
    75+ Posting Member
    Join Date
    Nov 2011
    Location
    UK
    Posts
    77
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Help needed

    Hello. I am completely new to the world of arduino. I have managed to get a toggle switch working and have incorporated it into a prototype gear lever which works the undercarriage. I though 'I got a switch to work how hard can a push button be'. Hours later and still confused.

    I have bee struggling all day with floating pins. I have researched and have done everything I could think of. I started by testing the code with the onboard LED and that worked fine but as soon as I changed it into a serial.println fo Link2FS to swap NAV 1 active & stby radios over, they went nuts and kept flicking between the two.

    A general question I have is from my reading it seems that there are 2 ways to use the internal pull up resistor. firstly by using a digitalWrite(input, HIGH) or by pinMode(?, INPUT_PULLUP). Is this right or have I completely missed it? What is the difference between these two lines?

    Anyway the code I have now ended up with is this which seems to have stopped the floating but when I push the button, unless I am quick it will keep repeating. The only thing I could think of to prevent this was to include a delay. It works but is there a more efficient way of doing this.

    Code:
    void setup() {
    
    
    Serial.begin(115200);
    pinMode(9, INPUT_PULLUP);
    digitalWrite(9, HIGH);
    }
    
    
    void loop() {
    bool buttonState = digitalRead(9);
    if (9, buttonState == LOW){
    Serial.println("A06");
    delay(1000);
    }
    }
    Many thanks
    Marc

  2. #2
    150+ Forum Groupie


    BushPilotWannabe's Avatar
    Join Date
    Jan 2014
    Location
    Alberta, Canada
    Posts
    176
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Help needed

    Download Jim's http://www.jimspage.co.nz/multi_starter_pack.htm on the page http://www.jimspage.co.nz/intro.htm Run the starter pack 2 ino. Connect only what you need for now, two pushbuttons for the gear and the LEDs.

    Your code. Both commands to create an internal pullup are not needed. I usually use the INPUT_PULLUP method for quick testing. The Arduino IDE likes you. I don't know how it compiled. I usually have to use pinMode(int(9), INPUT_PULLUP) or fix something else in the line before; and in the "if (9, buttonState == LOW){" statement - the 9 may interpreted as "true proceed with the following statement" and the state of buttonState is irrelevant. The real problem is that as long as the switch is closed the sketch will upload "A06" every 10 milliseconds or so. You need something to upload the command once and wait for the switch to be released and then closed again before re-uploading. Jim's void INPUTS() does this very well.

    There is a lot going on in the code but in essence he has created a register "Kstringoldstate" in character array form which records whether each switch was open or closed. A new string "Kstringnewstate" is created, it builds character by character every time a pin is scanned. If the characters representing the old state and the new state are the same (ascii 0 for closed, ascii 1 for open) do nothing but add the new character to the end of Kscringnewstate, BUT if the two characters differ the switch has changed AND if the switch has gone from open to closed, the command is again uploaded and the new character is added. At the end of the function the old register is updated.

    Starting with "// now the "Keys" bit ,,," introduces a procedure to duplicate keyboard commands with one pushbutton. This may be very useful if payware aircraft use keyboard commands not programmed into the basic FSX aircraft. Have a look at Link2fs_keys


    Hugh
    ---CYXD ----- TWR --- GND ------ Closed
    ILS-- NDB -- 119.1 -- 121.9 ---- 11/2013

  3. #3
    75+ Posting Member
    Join Date
    Nov 2011
    Location
    UK
    Posts
    77
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Help needed

    Thanks Hugh for taking the time to reply. I used a variety of examples that others have used. They are a bit tempramental when I use the button and toggle switch script together. So I will look at the starter pack and try and find another way. I will check out the void inputs as delay is not a great way to do it.

    One question I did have is what will keys do that simconnect inputs wont? Can keys be used instead of simconnect and is there any advantage of doing this?

    Thanks again.
    Marc

  4. #4
    75+ Posting Member
    Join Date
    Nov 2011
    Location
    UK
    Posts
    77
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Help needed

    Thanks Hugh for taking the time to reply. I used a variety of examples that others have used. They are a bit tempramental when I use the button and toggle switch script together. So I will look at the starter pack and try and find another way. I will check out the void inputs as delay is not a great way to do it.

    One question I did have is what will keys do that simconnect inputs wont? Can keys be used instead of simconnect and is there any advantage of doing this?

    Thanks again.
    Marc

  5. #5
    150+ Forum Groupie


    BushPilotWannabe's Avatar
    Join Date
    Jan 2014
    Location
    Alberta, Canada
    Posts
    176
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Help needed

    Are you having a problem with the contacts bouncing on closing and arcing when opened? I have two tactile switches from the same order. One bounces and the other arcs. Figure delay(4) likely for tactiles and up to delay(20) for rotary switches to clear this up.

    Program the toggles and pushbuttons separately, it may help to locate them into two groups on the board then save code by repeating the same procedure for each switch in succession for group #1 and another procedure for group #2.

    Toggle switches are easy, do something when they close, ignore them until they open, and then stop the event or do something else.

    Pushbuttons may have three functions. Momentary (creates a very short pulse ONLY when the switch is closing or opening), programming determines the length of the resulting action, the switch has to be released before the action can be repeated, and holding the switch down does not prolong the event. Maintained (similar to a toggle switch but you kinda get tired holding the switch down) eg. trim switches. Or PushOn/PushOff (two momentary actions, one starts something and the next stops it. eg. light controlled by one pushbutton. There has to be better examples.

    Use Simconnects before Keys. I was thinking about designers building features into the aircraft not thought of by FSX. If the designer provided a keyboard shortcut as well as mouse and drop down. The Keys section can pass almost any combination of keystrokes. Watch the code in Jim's example 2. You either have to add a linefeed to the second Serial.print statement or find a way to add line feeds inside Links2FS. Haven't spent enough time using it to confirm the latter.
    ---CYXD ----- TWR --- GND ------ Closed
    ILS-- NDB -- 119.1 -- 121.9 ---- 11/2013

  6. #6
    75+ Posting Member
    Join Date
    Nov 2011
    Location
    UK
    Posts
    77
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Help needed

    I had a play with the keys. As I am probably going to stay with GA aircraft for the time being, the only use I could think of would be to set transponder to standby/mode C/Ident. I use fsinn and these can be selected using keyboard commands but when I set it up through keys, it does not work, I'm not sure why. I'm sure I am setting it up right as I am able to get other functions to work such as gear (G) or pause (P) etc. I assumed that as I can select fsinn functions from keyboard within FSX that it would work with keys?

    One other question I had is do people use the whole memory on the card when writing code. If I could fill my whole cockpit on one card, would I? The though of doing it all one script seems a bit daunting.

  7. #7
    150+ Forum Groupie


    BushPilotWannabe's Avatar
    Join Date
    Jan 2014
    Location
    Alberta, Canada
    Posts
    176
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Help needed

    Where to start? I had a quick look at FSinn and have to admit that I have no experience with payware. Better leave it at that. Nice looking manual. Easier to understand than some others. The KEYS program did not work for the first two tries then I discovered that all keyboard commands were removed when setting up the yoke for FSUIPC and did not replace the keyboard commands before leaving. I will have to run KEYS and experiment with setting up FSUIPC keyboard codes for the transponder and maybe have time to get the C172 taxi lights to work. Whatever code you enter must have a place to go.

    What Arduino card are you using? My current minimum budget project is running two UNOs and memory will be tight. I have not come close to filling the memory on a MEGA. Partly 127 kB of program storage space (Jim's Multi Radio Head for the UNO uses 10% of program storage space and 10% of dynamic memory). 127KB in compiled code is a lot of typing and I am easily distracted and too often go off on some tangent chasing different methods. All too often I have to look through the sketchbook and wonder where did all these saved-work sketches come from.

    But in the sketch itself, limit the size of any one routine. If the routine has an individual purpose or can be used by three or more other sections of the program package it into a function using nice long descriptive names and seriously worded comments. Some things like decoding the serial feed does need multi line functions but I have created 5 line functions to position the LCD display cursor and write the text to the screen in one command, or run 80 bit registers to archive current input pin status. Two functions in two years and and stole everything that I could.

    Hugh
    Last edited by BushPilotWannabe; 08-28-2015 at 11:42 PM. Reason: missed two edits
    ---CYXD ----- TWR --- GND ------ Closed
    ILS-- NDB -- 119.1 -- 121.9 ---- 11/2013

  8. #8
    150+ Forum Groupie


    BushPilotWannabe's Avatar
    Join Date
    Jan 2014
    Location
    Alberta, Canada
    Posts
    176
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Help needed

    Hi Marc

    Are you using a payware aircraft?
    ---CYXD ----- TWR --- GND ------ Closed
    ILS-- NDB -- 119.1 -- 121.9 ---- 11/2013

  9. #9
    75+ Posting Member
    Join Date
    Nov 2011
    Location
    UK
    Posts
    77
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Help needed

    With the FSinn thing I can select the transponder modes from my joystick by programming the Saitek profile editor and linking a joystick button to a keyboard command, I just cant get it working with keys.

    To give you an idea as to what I am looking at I am sticking with a GA cockpit based on the A36 bonanza. I am currently flying the Carenado A36 Bonanza which is payware. Although my panel will be set out like a bonanza I will also fly the 172 from time to time but can fit the instruments in with the bonanza layout. I plan on using 2 PC'c one for FSX and the other for the gauges which will probably be done with FSXpand on 2 monitors. I was originally going to go down the route of using Leo Bodnar cards but when I realised I could do it cheaper via arduino I thought I would have a go at learning arduino and now I think I can pick it up sufficiently to do the whole thing via arduino. I am only using a nano card at the moment simply to test the various components and practice writing scripts. When I come to do the build properly I will invest in an Uno or Mega card (guessing I will need more than 1). I have counted roughly what I will require.

    42 LED's
    20 Switches
    25 buttons
    6 rotary encoders
    3 dual rotary encoders
    5 servo's
    3 rotary switches

    When you see it all listed, it seems a bit daunting. As I am going along even if I have something working I will post the code on here to see if there is a more efficient way to do it.

    I was just fiddling with some buttons trying to get the autopilot buttons working, although most of them did, not all are recognised as an FSX control or link2fs for example altitude arm (this is a function on the bonanza). I did notice that on the expert version of link2fs there is an option for FSUIPC. FSUIPC does recognise Altitude arm. Would it therefore be possible to do this using FSUIPC and link2fs?

  10. #10
    150+ Forum Groupie


    BushPilotWannabe's Avatar
    Join Date
    Jan 2014
    Location
    Alberta, Canada
    Posts
    176
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Help needed

    Using FSUIPC and Link2FS, I certainly hope so. But if not, you have a large part of the MEGA's 127KB memory to build in an ARM function yourself. This and cost are two good reasons for playing with the Arduino. So much to find out what works and when.

    I like the UNO for development. Replaced the socket headers with header pins and removed the blink LED. And one of these days I will blow the replaceable dip chip. On the other hand if you can find a piece of strip board with 7 pads each side and the trace is notched between pads, you can build this into a nice development board using low profile sockets to accept the Nano sporting headers on the underside. Add a budget for soldering station, magnifying lamp with LED illumination & cable fabrication.

    Step backwards last night. Built a circuit to check out FSUIPC using keys and nothing worked. Things have been going too well lately.

    Hugh
    ---CYXD ----- TWR --- GND ------ Closed
    ILS-- NDB -- 119.1 -- 121.9 ---- 11/2013

Page 1 of 3 123 LastLast