With the support for Arduino, Air Manager can be the heart of your sim. Taking care of the instrument visuals and hardware I/O.
The Arduino Mega2560, Uno, Nano and various clones of these types are supported by Air Manager and Air Player. All it takes you to do is upload Sim Innovations firmware to the Arduino, with our free to use Arduino Installer tool. When this is done, the Arduino is automatically recognized by Air Manager and Air Player, even on the Raspberry Pi.
Up to 16 Arduino’s from each supported type can be connected, giving you a crazy (theoretical) amount of 1696 I/O ports per computer. Should be enough right?
The behavior of the Arduino I/O is scripted in the same easy to learn scripting language as our instruments: Lua
The script can be integrated in existing instruments, or run as a dedicated ‘hardware-only’ instrument. The hardware uses our easy to understand hardware API functions, which has a full range of skills from input to output. No need to learn C++, no compiling, it can’t possibly be easier!
These examples give a brief overview of what is possible with our API, in fact the possibilities are nearly endless. Click here to see the full hardware API. In these examples random Arduino pins and channels were chosen, click here to see the full hardware ID list.
An example on how to connect a button, this uses the API function hw_button_add. In this case we use the button to swap the NAV1 radio frequency.
-- Callback function which is called when the button is pressed function button_pressed() -- Swap the NAV1 radio frequency fsx_event("NAV1_RADIO_SWAP") print("NAV1 frequency just swapped") end -- Bind to Arduino Nano, Channel B, Pin A0 hw_button_add("ARDUINO_NANO_B_A0", button_pressed)
An example on how to connect a switch, this uses the API function hw_switch_add. In this case we use a switch to turn the strobe light on and off.
-- This function is called every time the switch has a new position function switch_callback(position) if position == 0 then xpl_command("sim/lights/strobe_lights_off") elseif position == 1 then xpl_command("sim/lights/strobe_lights_on") end print("The switch got changed to position " .. position) end -- Bind to Arduino Uno, Channel A, Pin D7 and D8 hw_switch_add("ARDUINO_UNO_A_D7", "ARDUINO_UNO_A_D8", switch_callback)
An example on how to connect a rotary encoder, this uses the API function hw_dial_add. In this case we use the rotary encoder to set the autopilot heading.
-- Callback function which is called when the rotary encoder is turned -- direction 1: The dial turned clockwise -- direciton -1: The dial turned counterclockwise function dial_change(direction) if direction == 1 then -- Move the autopilot heading up xpl_command("sim/autopilot/heading_up") fsx_event("HEADING_BUG_INC") print("The autopilot heading was increased") end if direction == -1 then -- Move the autopilot heading down xpl_command("sim/autopilot/heading_down") fsx_event("HEADING_BUG_DEC") print("The autopilot heading was decreased") end end -- Bind to Arduino Mega2560, Channel A, Pin D2 and D3 hw_dial_add("ARDUINO_MEGA2560_A_D2", "ARDUINO_MEGA2560_A_D3", dial_change)
An example on how to connect a potentiometer, this uses the API function hw_adc_input_add. In this case we use the potentiometer to set the volume of the COM radio.
-- Callback function which is called when the ADC input state changes -- 0.0 : GND (lowest voltage) -- 1.0 : VCC (highest voltage) function adc_input_change(value) print("COM volume: " .. tostring(value) ) -- Set the COM radio volume xpl_dataref_write("sim/operation/sound/radio_volume_ratio", "FLOAT", value) end -- Bind to Arduino Nano, Channel A, Pin D11 hw_adc_input_add("ARDUINO_NANO_A_D11", adc_input_change)
An example on how to connect an LED, this uses the API function hw_led_add. In this case the brightness of the LED will be controlled by the instrument lighting.
-- Bind to Arduino Uno, Channel A, Pin D10 led_id = hw_led_add("ARDUINO_UNO_A_D10", 0.0) -- Let the simulator value from X-Plane control the brightness function new_data_xpl(brightness) -- The value from X-Plane ranges from 0 to 1 hw_led_set(led_id, brightness) end xpl_dataref_subscribe("sim/cockpit/electrical/instrument_brightness", "FLOAT", new_data_xpl)
An example on how to connect a servo, this uses the API function hw_output_pwm_add. In this case the PWM output will be controlled by the flaps deployment ranging from 0 to 1.
-- Bind to Arduino Mega2560, Channel C, Pin D5 -- PWM frequency is set to 50 Hz, with a duty cycle of 5%. output_id = hw_output_pwm_add("ARDUINO_MEGA2560_C_D5", 50, 0.05) function new_data_xpl(flaps) -- We change the duty cycle runtime, between 5 and 15% -- These values are about right for a TowerPro SG90 servo hw_output_pwm_duty_cycle(output_id, 0.05 + (0.1 * flaps) ) end xpl_dataref_subscribe("sim/flightmodel2/controls/flap_handle_deploy_ratio", "FLOAT", new_data_xpl)
An example on how to use the MessagePort library, this uses the API function hw_message_port_add. The MessagePort library can be used to directly communicate between instruments and your own Arduino sketch.
-- This function will be called when a message is received from the Arduino. function new_message(id, payload) print("Received new message with id: " .. id) end id = hw_message_port_add("ARDUINO_MEGA2560_A", new_message) -- You can also send messages to the Arduino -- In this case a message with id 7000 with 4 bytes (0x01, 0x02, 0x03, 0x04) hw_message_port_send(id, 7000, [ 7, 6, 0, 0 ])