Newbie needing help with potentiometer

Peer support for Air Manager desktop users

Moderators: russ, Ralph

Post Reply
Message
Author
Steve1129
Posts: 3
Joined: Mon Apr 25, 2022 7:44 pm

Newbie needing help with potentiometer

#1 Post by Steve1129 »

I have been reading through tutorials and just can't figure out how to get started with my hardware (potentiometer). Would very much appreciate if someone can show me how to input this hardware. I have MSFS2020, Air Manager 4.1.3, and a Arduino Mega on channel A.

My yoke aileron input is connected to pin A2. The sim variable is "AILERON POSITION" and is looking for an input of: -16K=full left, 0=full right. Voltage at pin A2 is 1.6 volt full right and 3.8 volt full left. There is no mechanical stop on the yoke so it can be turned beyond the full right/left, but the code should not accept any out of range position.

User avatar
Keith Baxter
Posts: 4684
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Newbie needing help with potentiometer

#2 Post by Keith Baxter »

Hi,

Suggest you start here. Best to go through all so that you get the gist of what Air Manager can do, but what is around E26 i think.

https://www.forums.siminnovations.com/v ... 942#p22942

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

Steve1129
Posts: 3
Joined: Mon Apr 25, 2022 7:44 pm

Re: Newbie needing help with potentiometer

#3 Post by Steve1129 »

Thanks Keith, I've listened to all of the tutorials, some twice, and have read the air manager instructions but I have not been able to get anything to work and really need some help. Mostly, I lack an understanding of what information has to be included in the code. Here is what I have cobbled together so far with no success. If someone could please show me what I am doing wrong I would be very appreciative.
--------------------------------------------------------------------------
-- potentiometer is input for aileron position (yoke), Mega pin A0
-- potentiometer voltage output is: full left = 3.725v full right= 1.155v
--this should equate to 0.745 (left) and 0.231 (right)
-- MSFS2020 sdk says the variable range is: -16k for full left, 0 for full right

function aileron_callback(value)
aileron=((-31128*value)+7190)
if aileron>0 then aileron=0
if aileron<-16000 then aileron=-16000
print("aileron position is ..." aileron)
end

fs2020_variable_subscribe("AILERON_POSITION", "int", function(aileron)
fs2020_variable_write("AILERON_POSITION", "INT")
hw_adc_input_id = hw_adc_input_add("MEGA_A_A0", 0.02, aileron_callback)

JackZ
Posts: 2264
Joined: Mon Feb 22, 2016 1:02 pm

Re: Newbie needing help with potentiometer

#4 Post by JackZ »

Hi
No need to subscribe to the variable, you should set it instead, directly in the callback, so the value sent to MSFS is updated every time the potentiometer is moved.

As per the unit used in the variable write() it seems that “Position” is what is given by the SDK instead of “INT”. Untested though.

Try this:

Code: Select all

--------------------------------------------------------------------------
-- potentiometer is input for aileron position (yoke), Mega pin A0
-- potentiometer voltage output is: full left = 3.725v full right= 1.155v
--this should equate to 0.745 (left) and 0.231 (right)
-- MSFS2020 sdk says the variable range is: -16k for full left, 0 for full right

function aileron_callback(value)
   aileron=((-31128*value)+7190)
   if aileron>0 then aileron=0 end
   if aileron<-16000 then aileron=-16000 end
    print("aileron position is ..." aileron)

    fs2020_variable_write("AILERON_POSITION", "Position",aileron)

end

— fs2020_variable_subscribe("AILERON_POSITION", "int", function(aileron) — NOT NEEDED

hw_adc_input_id = hw_adc_input_add("MEGA_A_A0", 0.02, aileron_callback)
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

Geosim
Posts: 7
Joined: Wed May 19, 2021 2:21 am

Re: Newbie needing help with potentiometer

#5 Post by Geosim »

Hi Steve, what is your experience with Arduino? What is your experience with electronics? (Just to help me match my advice to your needs)


Steve1129 wrote: Mon Apr 25, 2022 9:08 pm I have been reading through tutorials and just can't figure out how to get started with my hardware (potentiometer). Would very much appreciate if someone can show me how to input this hardware. I have MSFS2020, Air Manager 4.1.3, and a Arduino Mega on channel A.

My yoke aileron input is connected to pin A2. The sim variable is "AILERON POSITION" and is looking for an input of: -16K=full left, 0=full right. Voltage at pin A2 is 1.6 volt full right and 3.8 volt full left. There is no mechanical stop on the yoke so it can be turned beyond the full right/left, but the code should not accept any out of range position.

Steve1129
Posts: 3
Joined: Mon Apr 25, 2022 7:44 pm

Re: Newbie needing help with potentiometer

#6 Post by Steve1129 »

Hi Geosim,
Ralph gave me a hand getting workable code in AM (thank you Ralph). I very much appreciate your offer of assistance and I will undoubtedly call on you as I move into the next phase of my build.

I'm embarrassed to report that I found a more efficient method to get axis and switch inputs into fs2020, although I still intend to use AM to read sim data into my instrument panel.
There's a GITHUB library called "Joystick.lib" which is used to turn an Arduino Micro into a game controller. All axis calibrations are handled in Windows' "Devices and Printers" section. Since fs2020 is designed as an Xbox application, the sim startup screen "options" GUI makes all the axis and button assignments very simple. The data transmission is handled by Windows in the background so it shouldn't affect frame rate.

Post Reply