MSFS2020 - Manage switch with AirManager & Arduino

Support for Arduino in combination with Air Manager and Air Player

Moderators: russ, Ralph

Message
Author
User avatar
PilotOlivier
Posts: 12
Joined: Sun Aug 07, 2022 7:17 pm

MSFS2020 - Manage switch with AirManager & Arduino

#1 Post by PilotOlivier »

Hi Team

I have the project to build a KingAir 350i home cockpit with MSFS 2020, Arduino and Air Manager.

After spending a lot of time, I can't find the answer to my problem. On the same computer, I have :

- MSFS2020
- FSUIPC (latest registered version)
- Air Manager (latest registered version)
- SPAD.neXt (latest registered version)
- Arduino MEGA2560 (original board)

I wrote a lua logic to change the position of the light beacons. It works fine between the switch and Air Manager but nothing happens in the MSFS.

I use the LVAR LIGHTING_BEACON_1 which is assigned to the aircraft button according to SPAD.neXt tool

Here attached 3 examples of code.
Capture d’écran 2022-10-31 172210.png
Capture d’écran 2022-10-31 172804.png
Capture d’écran 2022-10-31 172844.png
Do you know why it doesn't work?

Thank you by advance for your support.
Pilot Olivier

MSFS 2020 - KIng Air 350i - Steam Gauge Overhaul - Analog King Air
Air Manager - SPAD.neXt
Arduino MEGA2560

User avatar
PilotOlivier
Posts: 12
Joined: Sun Aug 07, 2022 7:17 pm

Re: MSFS2020 - Manage switch with AirManager & Arduino

#2 Post by PilotOlivier »

Following my previous email.... I have made some progress that I would like to share with you.

First of all, I create a hardware instrument that is certainly better and I put my LUA script here.
Capture d’écran 2022-10-31 185641.png
Capture d’écran 2022-10-31 185641.png (11.22 KiB) Viewed 865 times
Then I wrote a new script according to an example provided in the Air Manager software and now my switch is able to change the value to LVAR.
Capture d’écran 2022-10-31 185859.png
But this script has no action on the aircraft ..... I discovered that I had to use "TOGGLE_BEACON" and this variable is accessible via FSUIPC.
Capture d’écran 2022-10-31 190622.png
My question: what is the script to call this variable?

Thank you !
Pilot Olivier

MSFS 2020 - KIng Air 350i - Steam Gauge Overhaul - Analog King Air
Air Manager - SPAD.neXt
Arduino MEGA2560

SimPassion
Posts: 5336
Joined: Thu Jul 27, 2017 12:22 am

Re: MSFS2020 - Manage switch with AirManager & Arduino

#3 Post by SimPassion »

PilotOlivier wrote: Mon Oct 31, 2022 6:10 pm Following my previous email.... I have made some progress that I would like to share with you.

First of all, I create a hardware instrument that is certainly better and I put my LUA script here.
Then I wrote a new script according to an example provided in the Air Manager software and now my switch is able to change the value to LVAR.
But this script has no action on the aircraft ..... I discovered that I had to use "TOGGLE_BEACON" and this variable is accessible via FSUIPC.
My question: what is the script to call this variable?

Thank you !
This is not variable, for MSFS2020, this is called "events", what is called "commands" in X-Plane sim

We're using "fs2020_event" in Air Manager to trigger such event to the sim, see "TOGGLE_BEACON_LIGHTS" in the Lights section here :https://docs.flightsimulator.com/html/P ... aft-lights
 

User avatar
PilotOlivier
Posts: 12
Joined: Sun Aug 07, 2022 7:17 pm

Re: MSFS2020 - Manage switch with AirManager & Arduino

#4 Post by PilotOlivier »

Hi SimPassion

Thank you for your answer.... it is working now !!

Hereafter the script which can help someone who is facing to the same issue.
Capture d’écran 2022-11-01 084643.png
Pilot Olivier

MSFS 2020 - KIng Air 350i - Steam Gauge Overhaul - Analog King Air
Air Manager - SPAD.neXt
Arduino MEGA2560

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: MSFS2020 - Manage switch with AirManager & Arduino

#5 Post by jph »

SimPassion wrote: Mon Oct 31, 2022 7:13 pm
PilotOlivier wrote: Mon Oct 31, 2022 6:10 pm Following my previous email.... I have made some progress that I would like to share with you.

First of all, I create a hardware instrument that is certainly better and I put my LUA script here.
Then I wrote a new script according to an example provided in the Air Manager software and now my switch is able to change the value to LVAR.
But this script has no action on the aircraft ..... I discovered that I had to use "TOGGLE_BEACON" and this variable is accessible via FSUIPC.
My question: what is the script to call this variable?

Thank you !
This is not variable, for MSFS2020, this is called "events", what is called "commands" in X-Plane sim

We're using "fs2020_event" in Air Manager to trigger such event to the sim, see "TOGGLE_BEACON_LIGHTS" in the Lights section here :https://docs.flightsimulator.com/html/P ... aft-lights
 
Hello Gilles,
I don't use MSFS, but am thinking that the use of 'BEACON_LIGHTS_ON' and 'BEACON_LIGHTS_OFF' would be a better solution as otherwise the switch can be out of sync ?
Joe
Joe. CISSP, MSc.

SimPassion
Posts: 5336
Joined: Thu Jul 27, 2017 12:22 am

Re: MSFS2020 - Manage switch with AirManager & Arduino

#6 Post by SimPassion »

jph wrote: Tue Nov 01, 2022 9:26 am Hello Gilles,
I don't use MSFS, but am thinking that the use of 'BEACON_LIGHTS_ON' and 'BEACON_LIGHTS_OFF' would be a better solution as otherwise the switch can be out of sync ?
Joe
Hi Joe, fully right, I've just not gone in deep into this, so it would be fine to suggest an appropriate snippet for this goal, using your mentioned events
If I have time, I will also check what's occurring using the OP original variables

For info, two other parts to check before, at the moment, around plugins. Next I will see if I still have time before going out around 12am

User avatar
PilotOlivier
Posts: 12
Joined: Sun Aug 07, 2022 7:17 pm

Re: MSFS2020 - Manage switch with AirManager & Arduino

#7 Post by PilotOlivier »

Hello JPH

I tested your solution and it works! I'm not a programmer but this script seems better!

Air Manager is really an amazing tool .... happy to have it !
Pilot Olivier

MSFS 2020 - KIng Air 350i - Steam Gauge Overhaul - Analog King Air
Air Manager - SPAD.neXt
Arduino MEGA2560

SimPassion
Posts: 5336
Joined: Thu Jul 27, 2017 12:22 am

Re: MSFS2020 - Manage switch with AirManager & Arduino

#8 Post by SimPassion »

PilotOlivier wrote: Tue Nov 01, 2022 7:47 am Hi SimPassion

Thank you for your answer.... it is working now !!

Hereafter the script which can help someone who is facing to the same issue.
Here's the snippet using Joe's suggested events :

Code: Select all

local pos_save = 0

function switch_A1(position)
	print("Switch A1 initial position " .. pos_save)
	
	if position == 0 then
		fs2020_event("BEACON_LIGHTS_OFF")
	elseif position == 1 then
		fs2020_event("BEACON_LIGHTS_ON")
	end
	pos_save = position
	print("Switch A1 new position " .. position)
end

hw_switch_add("ARDUINO_MEGA2560_A_D2", switch_A1)
Just in any case, could also be that the original LIGHTING_BEACON_1 should be replaced with the proper internal related variable from the specific addon
[EDIT] Corrected in place as it works with the default KA 350i using "LIGHT BEACON:1" as a Boolean in place

So the working snippet using variable write :

Code: Select all

local pos_save = 0

function switch_A1(position)
	print("Switch A1 initial position " .. pos_save)
	fs2020_variable_write("LIGHT BEACON:1","Bool",position == 1)
	pos_save = position
	print("Switch A1 new position " .. position)
end

As we see here :


[attachment=0]image.png[/attachment]
 

hw_switch_add("ARDUINO_MEGA2560_A_D2", switch_A1)
Attachments
image.png

SimPassion
Posts: 5336
Joined: Thu Jul 27, 2017 12:22 am

Re: MSFS2020 - Manage switch with AirManager & Arduino

#9 Post by SimPassion »

Previous post edited to add the proper working snippet using variable write

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: MSFS2020 - Manage switch with AirManager & Arduino

#10 Post by jph »

Hey Gilles, nice one. :)
I am considering using msfs2020 for experimentation and I must confess that I have a steep hill to climb to get my head around the way MSFS is addressed with AM.
I am happy with X-Plane datarefs and commands but the MSFS communication is a new area. At least the simvar api is reasonably well documented. It seems to be improving all the time as well (the documentation) as well as the sim.
I will be trying to pick your brains on several areas in the future if you don't mind ?. At the moment I am still confused when I read about Lvars and Hvars as there is so much legacy stuff written that is sometimes referring to the older fsuipc days. It will be 'fun' though. :lol:
Joe. CISSP, MSc.

Post Reply