Results 1 to 2 of 2
  1. #1
    New Member
    Join Date
    Nov 2016
    Location
    Philippines
    Posts
    2
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Fuel Selector for A2A PA-28

    Hi,

    Can someone help me how can I make the fuel selector function in link2fs work with my A2A Piper Cherokee Aircraft?

    I've already tried the Fuel System functions under SimConnect Inputs but it won't work with my PA28.

    Are there other options to make it work?


    Thanks!

    Prepar3d V3
    Link2fs Multi FSX V6f for Experts
    A2A Piper Cherokee 180 / PA28

  2. #2
    150+ Forum Groupie
    Join Date
    Nov 2013
    Location
    Evansville, Indiana
    Posts
    248
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Fuel Selector for A2A PA-28

    Quote Originally Posted by christie101010 View Post
    Hi,

    Can someone help me how can I make the fuel selector function in link2fs work with my A2A Piper Cherokee Aircraft?

    I've already tried the Fuel System functions under SimConnect Inputs but it won't work with my PA28.

    Are there other options to make it work?


    Thanks!

    Prepar3d V3
    Link2fs Multi FSX V6f for Experts
    A2A Piper Cherokee 180 / PA28
    I have been wanting to make a Fuel switch for the A2A Comanche and saw your post.
    It took some digging but I found a couple of possible solutions and they are outside of Link2FS.
    A2A, like a lot of developers, utilize LVariables(LVar for short) in cockpit animations and controlling various systems.

    In the A2A Cherokee the variable that you want to manipulate is "FselCherokeeState".
    "FselCherokeeState" has three numerical positions "0" is off, "1" is left tank and "2" is right tank.

    Ways to do this... all require Registered FSUIPC:

    1) Use FSUIPC and make a macro (MCRO) file that changes the value of the LVar. I have done this once, long ago to assign the cruise trim on the CaptainSim 727 to a joystick button in FSX. I would have to research it to get up to speed. A toggle up/down or cycle thru could be assigned to a joystick button for the Fuel selector.

    2) Use a LUA script that connects to your Arduino.
    If you have a bunch of things already programmed for Link2FS on the Arduino that has the Fuel Selector, then you can add a second Arduino to hook the fuel selector up to, and and then run it thru the LUA script.

    Here is a LUA script you can try. (It does require FSUIPC Registered)
    Copy the code text below and save it as PA28_FSel.lua and then place it in the Modules folder with FSUIPC.
    Instructions for setting up a launch button are in the remarks at the top of the script.
    This script will create a .txt file in your Modules folder to remember your Arduino COM Port.
    You can review my first tutorial for LUA and Arduino here http://thegeekforge.com/2017/11/10/a...utorial-001_a/
    This Script is set to respond to Jim's codes for Fuel Selector in Link2FS.
    F040 = Off
    F042 = Left
    F043 = Right

    If your Arduino code is already set to use these codes you can test the script without much hassle.

    NOTE
    : You can NOT have Link2FS and the LUA script connected to the same Arduino at the same time.

    Just disconnect Link2FS and run the script, enter the COM port when prompted and test your fuel selector.
    The script will ignore the other inputs and only act on the Fuel Selector.

    Code:
    -- You Will Need:
    -- The appropriate registered version for your sim of Pete Dowson's FSUIPC
    -- http://www.schiratti.com/dowson.html
    --
    -- Instructions To Launch the script:
    -- * Place this file in the Modules folder of your sim with the other FSUIPC files
    -- * Have the COM port of the Arduino handy you will need to enter it on first launch
    -- * In P3D go to Add-ons
    -- * Select FSUIPC
    -- * Select Buttons and Switches Tab
    -- * Press a button on your joystick to assign a launch button
    -- * Tick the "Select for FS control" box
    -- * In the drop down "Control sent when button is pressed"
    -- * Scroll down and select "Lua PA28 FSel"
    -- * NOTE: NOT LuaClear, LuaSet, LuaDebug
    -- * You can set another button for "LuaKill PA28 FSel"
    -- * Hit OK. 
    -- * Back in the sim, press the Joystick button that you assigned to launch
    -- * Enter the COM port when requested. 
    -- * Afterwards it should remember the COM port on future launches
    -- * Press your buttons or switches for Fuel selector on the Arduino and it should change.
    -----------------------------------------------------------------
    port_file = "PA28_FSel_port.txt"
    speed = 115200
    handshake = 0
    
    
    ------This Top Part Is to Handle Arduino Connection------
    file = io.open(port_file, "r")
    if file == nil then
        port_number = "10"
        file = io.open(port_file, "w")
        io.output(file)
        io.write(port_number)
        io.close(file)
        Arduino_Com_Port = com.open("COM"..port_number, speed, handshake)
    else
        port_number = file:read (2)
        --ipc.display(port_number)
        io.close(file)
        Arduino_Com_Port = com.open("COM"..port_number, speed, handshake)
    end 
    if Arduino_Com_Port ~= 0 then
        ipc.display("Arduino Com Port "..port_number.." Open",5)
        
        
    else
        ipc.display("Could not open ARDUINO Com Port",5)
        
        port_number = ipc.ask('\n'..'\n'..'\n'..'\n'..'\n'..'\n'..'\n'..'\n'.." Enter the Arduino COM Port for Your Switch Panel")
        file = io.open(port_file, "w")
        io.output(file)
        io.write(port_number)
        io.close(file)
    
    
        Arduino_Com_Port = com.open("COM"..port_number, speed, handshake)
         
        if Arduino_Com_Port == 0 then
            ipc.display("Could not open ARDUINO Com Port",5)
            
            ipc.exit()
        else
            ipc.display("Arduino Com Port "..port_number.." Open",5)
            
        end
    end 
    ------END of the ARDUINO Connection Part
    -------------------------------------------------------------------
    -------------------------------------------------------------------
    ------When Serial Data comes thru it is sent to this function------
    function ArdData(Arduino_Com_Port, datastring, length)
    
    
    --- Fuel Selector -------------------------------------
        
        if (string.find(datastring, "F042")) then --Fuel Selector LEFT
            ipc.writeLvar("L:FselCherokeeState", 1)
        end
        if (string.find(datastring, "F043")) then --Fuel Selector RIGHT
            ipc.writeLvar("L:FselCherokeeState", 2)
        end
        if (string.find(datastring, "F040")) then --Fuel Selector OFF
            ipc.writeLvar("L:FselCherokeeState", 0)
        end
    ----------------------------------------------------------
    end
    ------End of the Serial Data Processing Function------
    ----------------------------------------------------------
    ----------------------------------------------------------
    ------This section is for EVENTS------
    --Events are kind of like continuous loops but dont bog down. 
    --They just sit and wait for a trigger and then send call a function.
    event.com(Arduino_Com_Port, 50,1, "ArdData") -----This event looks for data on the Arduino connection and then sends it up to the ArdData function.
    
    
    ----------------------------------------------------------
    ----------------------------------------------------------
    Now for the 300 level lesson proposal.
    You can hook 2 arduinos together, one talking to the Sim thru Link2FS and the other talking thru LUA/FSUIPC.
    This would allow you to keep the Fuel Selector on the original Arduino that you use for other planes. The second Arduino would be talking to the Sim only when you have the A2A PA28 loaded. It would get instructions from the Primary Arduino thru "Wire" protocol or "i2c" connection (a couple of pins on both Arduinos) and then relay those instruction to the LUA script. I did this once, before I made the full transition to LUA. It is complicated and not for the faint of heart.

    Anyway...
    Hopefully, I did not screw up the script and it can work straight away.
    I think I got you all of the info needed.

    ~Fess
    I will only ever be, half the Geek that I wished I was.
    TheGeekForge.Com