RPI Communication Problem

Support for Air Player on the Raspberry Pi.

Moderators: Ralph, russ

Message
Author
User avatar
Huberflight
Posts: 25
Joined: Sat Mar 31, 2018 2:27 pm

Re: RPI Communication Problem

#21 Post by Huberflight » Mon Feb 01, 2021 7:43 am

I‘m using Self created Instruments.
When it looks not right, go around. It's easier to explain why you done it, than for others why you don't.

User avatar
Ralph
Posts: 5088
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: RPI Communication Problem

#22 Post by Ralph » Mon Feb 01, 2021 5:22 pm

Then I expect a scripting issue. Can you post the instrument(s) here? If you are okay with sharing them.

User avatar
Huberflight
Posts: 25
Joined: Sat Mar 31, 2018 2:27 pm

Re: RPI Communication Problem

#23 Post by Huberflight » Tue Feb 02, 2021 8:21 am

Yes, of curse i want to share 8-) .

But please keep in mind that I´m an absolute Code-beginner.
Every help and tips are welcome.

My system is build like you can see in the schematic drawing.

TQ = Thrust Quadrant
LCP = Lower Center Pedestal
LSP = Lower Switch Panel
ANN = Annunciator Lights
1. PC X-Plane & Baron B58 Standard.pdf
(65.31 KiB) Downloaded 42 times
Here is the code for the TQ.
  1. ----------------------------------------------------------------------
  2.  
  3. -- This is the script for the Throttle Quadrant with the Throttle ----
  4.  
  5. -- Prop, Mixture, Rudder Trim, Flap Handle, Flap Pos. Indicator LED --
  6.  
  7. -- It works on Channel D only ----------------------------------------
  8.  
  9. ----------------------------------------------------------------------
  10.  
  11.  
  12.  
  13. --------------------------------------------------------------------
  14.  
  15. -- Rudder Trim
  16.  
  17. --------------------------------------------------------------------
  18.  
  19.  
  20.  
  21. function adc_rudder_trim(value)
  22.  
  23.     print("The Ruddel Trim is now by " ..value)
  24.  
  25.  
  26.  
  27.  
  28.  
  29.   -- X-Plane expects a value between -1 and 1,
  30.  
  31.   xpl_dataref_write("sim/cockpit2/controls/rudder_trim", "FLOAT", (2 * value)-1)
  32.  
  33. end
  34.  
  35.  
  36.  
  37. -- Create a ADC input
  38.  
  39. hw_adc_input_add("ARDUINO_MEGA2560_D_A0", adc_rudder_trim)
  40.  
  41.  
  42.  
  43.  
  44.  
  45. --------------------------------------------------------------------
  46.  
  47. -- Throttle 1 LH
  48.  
  49. --------------------------------------------------------------------
  50.  
  51.  
  52.  
  53. function adc_input_throttle_left(value)
  54.  
  55.     print("The Throttle Nr.1 LH is now by " ..value)
  56.  
  57.  
  58.  
  59.  
  60.  
  61.   -- X-Plane expects a value between 0 and 1, no conversion necessary
  62.  
  63.   xpl_dataref_write("sim/flightmodel/engine/ENGN_thro", "FLOAT[8]", {value}, 0)
  64.  
  65. end
  66.  
  67.  
  68.  
  69. -- Create a ADC input
  70.  
  71. hw_adc_input_add("ARDUINO_MEGA2560_D_A1", adc_input_throttle_left)
  72.  
  73.  
  74.  
  75.  
  76.  
  77. --------------------------------------------------------------------
  78.  
  79. -- Throttle 2 RH
  80.  
  81. --------------------------------------------------------------------
  82.  
  83.  
  84.  
  85. function adc_input_throttle_right(value)
  86.  
  87.     print("The Throttle Nr.2 RH is now by " ..value)
  88.  
  89.  
  90.  
  91.  
  92.  
  93.   -- X-Plane expects a value between 0 and 1, no conversion necessary
  94.  
  95.   xpl_dataref_write("sim/flightmodel/engine/ENGN_thro", "FLOAT[8]", {value}, 1)
  96.  
  97. end
  98.  
  99.  
  100.  
  101. -- Create a ADC input
  102.  
  103. hw_adc_input_add("ARDUINO_MEGA2560_D_A2", adc_input_throttle_right)
  104.  
  105.  
  106.  
  107.  
  108.  
  109. --------------------------------------------------------------------
  110.  
  111. -- Propeller Pitch LH
  112.  
  113. --------------------------------------------------------------------
  114.  
  115.  
  116.  
  117. function adc_input_prop(value)
  118.  
  119.     print("The Prop Pitch LH is in the Position" ..value)
  120.  
  121.  
  122.  
  123.    xpl_dataref_write("sim/flightmodel/engine/ENGN_prop", "FLOAT[8]", {73.2 + (282 - 73.2) *  value}, 0)
  124.  
  125.  
  126.  
  127. end
  128.  
  129.  
  130.  
  131. -- Create a ADC input
  132.  
  133. hw_adc_input_add("ARDUINO_MEGA2560_D_A3", adc_input_prop)
  134.  
  135.  
  136.  
  137.  
  138.  
  139. --------------------------------------------------------------------
  140.  
  141. -- Propeller Pitch RH
  142.  
  143. --------------------------------------------------------------------
  144.  
  145.  
  146.  
  147. function adc_input_prop(value)
  148.  
  149.     print("The Prop Pitch RH is in the Position" ..value)
  150.  
  151.  
  152.  
  153.  
  154.  
  155.     xpl_dataref_write("sim/flightmodel/engine/ENGN_prop", "FLOAT[8]", {73.2 + (282 - 73.2) *  value}, 1)
  156.  
  157.  
  158.  
  159. end
  160.  
  161.  
  162.  
  163. -- Create a ADC input
  164.  
  165. hw_adc_input_add("ARDUINO_MEGA2560_D_A4", adc_input_prop)
  166.  
  167.  
  168.  
  169. --------------------------------------------------------------------
  170.  
  171. -- Mixture LH
  172.  
  173. --------------------------------------------------------------------
  174.  
  175.  
  176.  
  177. -- For X-Plane we need to override the joystick input first
  178.  
  179.     xpl_dataref_write("sim/operation/override/override_mixture", "INT", 1)
  180.  
  181.  
  182.  
  183.  
  184.  
  185. -- Callback function which is called when the ADC input state changes
  186.  
  187. -- 0.0 : GND (lowest voltage)
  188.  
  189. -- 1.0 : VCC (highest voltage)
  190.  
  191. function adc_input_mixt(value)
  192.  
  193.     print("The Mixture LH is now by " ..value)
  194.  
  195.   -- X-Plane expects a value between 0 and 1, no conversion necessary
  196.  
  197.     xpl_dataref_write("sim/flightmodel/engine/ENGN_mixt", "FLOAT[8]", {value}, 0)
  198.  
  199.  
  200.  
  201. end
  202.  
  203.  
  204.  
  205. -- Create a ADC input
  206.  
  207. hw_adc_input_add("ARDUINO_MEGA2560_D_A5", adc_input_mixt)
  208.  
  209.  
  210.  
  211.  
  212.  
  213. --------------------------------------------------------------------
  214.  
  215. -- Mixture RH
  216.  
  217. --------------------------------------------------------------------
  218.  
  219.  
  220.  
  221. -- For X-Plane we need to override the joystick input first
  222.  
  223.  --   xpl_dataref_write("sim/operation/override/override_mixture", "INT", 2)
  224.  
  225.  
  226.  
  227.  
  228.  
  229. -- Callback function which is called when the ADC input state changes
  230.  
  231. -- 0.0 : GND (lowest voltage)
  232.  
  233. -- 1.0 : VCC (highest voltage)
  234.  
  235. function adc_input_mixt(value)
  236.  
  237.     print("The Mixture RH is now by " ..value)
  238.  
  239.   -- X-Plane expects a value between 0 and 1, no conversion necessary
  240.  
  241.     xpl_dataref_write("sim/flightmodel/engine/ENGN_mixt", "FLOAT[8]", {value}, 1)
  242.  
  243.  
  244.  
  245. end
  246.  
  247.  
  248.  
  249. -- Create a ADC input
  250.  
  251. hw_adc_input_add("ARDUINO_MEGA2560_D_A6", adc_input_mixt)
  252.  
  253.  
  254.  
  255.  
  256.  
  257. --------------------------------------------------------------------
  258.  
  259. -- Flap Handle Up a Notch
  260.  
  261. --------------------------------------------------------------------
  262.  
  263.  
  264.  
  265. -- Callback function which is called when the button is pressed
  266.  
  267. function Flap_Pos_switch_callback()
  268.  
  269.   print("The Flap Pos. switch got changed to position ")
  270.  
  271.     xpl_command("sim/flight_controls/flaps_up")
  272.  
  273. end
  274.  
  275.  
  276.  
  277. -- Bind to
  278.  
  279. hw_button_add("ARDUINO_MEGA2560_D_D3", Flap_Pos_switch_callback)
  280.  
  281.  
  282.  
  283.  
  284.  
  285. --------------------------------------------------------------------
  286.  
  287. -- Flap Handle down a Notch
  288.  
  289. --------------------------------------------------------------------
  290.  
  291.  
  292.  
  293. -- Callback function which is called when the button is pressed
  294.  
  295. function Flap_Pos_switch_callback()
  296.  
  297.   print("The Flap Pos. switch got changed to position ")
  298.  
  299.     xpl_command("sim/flight_controls/flaps_down")
  300.  
  301. end
  302.  
  303.  
  304.  
  305. -- Bind to
  306.  
  307. hw_button_add("ARDUINO_MEGA2560_D_D2", Flap_Pos_switch_callback)
  308.  
  309.  
  310.  
  311.  
  312.  
  313. --------------------------------------------------------------------
  314.  
  315. -- Flap Pos. Light Transit (Red)
  316.  
  317. --------------------------------------------------------------------
  318.  
  319.  
  320.  
  321. led_transit = hw_led_add("ARDUINO_MEGA2560_D_D4", 0.0)
  322.  
  323.  
  324.  
  325. function new_data_xpl(flapsdeployment)
  326.  
  327.  
  328.  
  329.     flapsdeployment = var_round(flapsdeployment, 1)
  330.  
  331.  
  332.  
  333.      if(flapsdeployment > 0 and flapsdeployment < 0.4) or (flapsdeployment > 0.4 and flapsdeployment < 1) then
  334.  
  335.         hw_led_set(led_transit, 0.3)
  336.  
  337.     else
  338.  
  339.         hw_led_set(led_transit, 0)
  340.  
  341.     end
  342.  
  343. end
  344.  
  345.  
  346.  
  347. xpl_dataref_subscribe("sim/flightmodel/controls/flaprat", "FLOAT", new_data_xpl)
  348.  
  349.  
  350.  
  351.  
  352.  
  353. --------------------------------------------------------------------
  354.  
  355. -- Flap Pos. Light Approach (Blue)
  356.  
  357. --------------------------------------------------------------------
  358.  
  359.  
  360.  
  361. led_approach = hw_led_add("ARDUINO_MEGA2560_D_D5", 0.0)
  362.  
  363.  
  364.  
  365. function new_data_xpl(flapsdeployment)
  366.  
  367.  
  368.  
  369.     flapsdeployment = var_round(flapsdeployment, 1)
  370.  
  371.  
  372.  
  373.      if(flapsdeployment == 0.4) then
  374.  
  375.         hw_led_set(led_approach, 0.3)
  376.  
  377.     else
  378.  
  379.         hw_led_set(led_approach, 0)
  380.  
  381.     end
  382.  
  383. end
  384.  
  385.  
  386.  
  387. xpl_dataref_subscribe("sim/flightmodel/controls/flaprat", "FLOAT", new_data_xpl)
  388.  
  389.  
  390.  
  391.  
  392.  
  393. --------------------------------------------------------------------
  394.  
  395. -- Flap Pos. Light DN (Yellow)
  396.  
  397. --------------------------------------------------------------------
  398.  
  399.  
  400.  
  401. led_DN = hw_led_add("ARDUINO_MEGA2560_D_D6", 0.0)
  402.  
  403.  
  404.  
  405. function new_data_xpl(flapsdeployment)
  406.  
  407.  
  408.  
  409.     flapsdeployment = var_round(flapsdeployment, 1)
  410.  
  411.  
  412.  
  413.      if(flapsdeployment == 1) then
  414.  
  415.         hw_led_set(led_DN, 1)
  416.  
  417.     else
  418.  
  419.         hw_led_set(led_DN, 0)
  420.  
  421.     end
  422.  
  423. end
  424.  
  425.  
  426.  
  427.  
  428.  
  429. xpl_dataref_subscribe("sim/flightmodel/controls/flaprat", "FLOAT", new_data_xpl)
  430.  
  431.  
  432.  
  433.  
  434.  
  435. --------------------------------------------------------------------
  436.  
  437. -- Raspberry PI 3 b+ shut down
  438.  
  439. --------------------------------------------------------------------
  440.  
  441.  
  442.  
  443. function shutdown()
  444.  
  445.  
  446.  
  447.   -- Shut down Windows (Application) or the Raspberry Pi (SYSTEM)
  448.  
  449. shut_down("SYSTEM")
  450.  
  451. end
  452.  
  453.  
  454.  
  455. hw_button_add("RPI_V2_P1_38", shutdown)
  456.  
  457.  
  458.  
  459.  
  460.  
  461. --------------------------------------------------------------------
  462.  
  463. -- Raspberry PI 3 b+ Status LED
  464.  
  465. --------------------------------------------------------------------
  466.  
  467.  
  468.  
  469. my_led = hw_led_add("RPI_V2_P1_40", 1.0)
  470.  
  471.  
  472.  
  473.  
  474.  
  475.  
  476.  
  477.  
  478.  
  479. --[[
  480.  
  481. --------------------------------------------------------------------
  482.  
  483. -- Landing Gear Emer down
  484.  
  485. --------------------------------------------------------------------
  486.  
  487.  
  488.  
  489. function switch_emer_gear_callback(position)
  490.  
  491.   print("The Emer Gear switch got changed to position " .. position)
  492.  
  493.  
  494.  
  495.   if position == 0 then
  496.  
  497.     xpl_command("sim/flight_controls/pump_gear", 0)
  498.  
  499.   elseif position == 1 then
  500.  
  501.     xpl_command("sim/flight_controls/pump_gear", 1)
  502.  
  503.   end
  504.  
  505. end
  506.  
  507.  
  508.  
  509. -- Here we create the hardware switch and to witch board (pin) it is connected
  510.  
  511. hw_switch_add("ARDUINO_MEGA2560_D_D8", switch_emer_gear_callback)
  512.  
  513. ]]--
  514.  
  515.  
  516.  
  517. ------------------------------------------------------------------------------
  518.  
  519. -- Here we creae the ALTN LEDs in the TQ just to be sure they will not -------
  520.  
  521. -- light up in normal operation ----------------------------------------------
  522.  
  523. ------------------------------------------------------------------------------
  524.  
  525. --[[
  526.  
  527. ALTN_LED_RH_MLG = hw_led_add("RPI_V2_P1_31", 0.0)
  528.  
  529.  
  530.  
  531. ALTN_LED_LH_MLG = hw_led_add("RPI_V2_P1_33", 0.0)
  532.  
  533.  
  534.  
  535. ALTN_LED_NLG = hw_led_add("RPI_V2_P1_35", 0.0)
  536.  
  537.  
  538.  
  539. ALTN_LED_Transit = hw_led_add("RPI_V2_P1_37", 0.0)
  540.  
  541. ]]--
  542.  
  543.  
  544.  
  545.  
When it looks not right, go around. It's easier to explain why you done it, than for others why you don't.

User avatar
Huberflight
Posts: 25
Joined: Sat Mar 31, 2018 2:27 pm

Re: RPI Communication Problem

#24 Post by Huberflight » Tue Feb 02, 2021 8:26 am

Here is my code for the LCP. I saw in this moment that I have the shutdown command two times programmed.
May be it is a part or the problem?
  1.  
  2.  
  3. --------------------------------------------------------------------------
  4.  
  5. -- Here i create the script for the Trim wheel with Trim Pos. Indicator --
  6.  
  7. -- wich is driven by a Servo Motor. !!ACHTUNG!! Der Servo funktioniert ---
  8.  
  9. -- nur auf Pin D9 & D10 at the Arduino Uno -------------------------------
  10.  
  11. --------------------------------------------------------------------------
  12.  
  13.  
  14.  
  15. --------------------------------------------------------------------------
  16.  
  17. -- Here we create the functions of the Rotary Switch
  18.  
  19. --------------------------------------------------------------------------
  20.  
  21.  
  22.  
  23. function dial_change(direction)
  24.  
  25.  
  26.  
  27.   if direction == 1 then
  28.  
  29.     print("The dial turned clockwise")
  30.  
  31.     xpl_command("sim/flight_controls/pitch_trim_up_mech")
  32.  
  33.  
  34.  
  35.   elseif direction == -1 then
  36.  
  37.     print("The dial turned counterclockwise")
  38.  
  39.     xpl_command("sim/flight_controls/pitch_trim_down_mech")
  40.  
  41.   end
  42.  
  43. end
  44.  
  45.  
  46.  
  47. -- Create a new Hardware rotary encoder for Arduino Uno on Pin D2 & D3
  48.  
  49. hw_dial_add("ARDUINO_UNO_C_D2", "ARDUINO_UNO_C_D3", dial_change)
  50.  
  51.  
  52.  
  53.  
  54.  
  55. -- Here we install the servo SG90 for the Trim Indicator Elevator
  56.  
  57. -- wich is connected at Arduino Uno on Pin D9
  58.  
  59. pwm_trim_indicator_elv = hw_output_pwm_add("ARDUINO_UNO_C_D9", 50, 0.07)
  60.  
  61.  
  62.  
  63.  
  64.  
  65. -- In this case the duty cycle ranges from 0.025 to 0.122
  66.  
  67. -- Take of position is at 0.7
  68.  
  69. function new_trim(trim)
  70.  
  71.  
  72.  
  73.   hw_output_pwm_duty_cycle(pwm_trim_indicator_elv, 0.025 + ((0.122 - 0.025) / 2)*( 1 + trim))
  74.  
  75.  
  76.  
  77. end
  78.  
  79.  
  80.  
  81. xpl_dataref_subscribe("sim/cockpit2/controls/elevator_trim", "FLOAT", new_trim)
  82.  
  83.  
  84.  
  85.  
  86.  
  87. -------------------------------------------------------------------------------
  88.  
  89. -- Fuel Selector Switch (3 Positions) -----------------------------------------
  90.  
  91. -------------------------------------------------------------------------------
  92.  
  93.  
  94.  
  95. function Fuel_Selector_Switch_callback(position)
  96.  
  97. print("The Fuel Selector Switch changed to position " .. position)
  98.  
  99.  
  100.  
  101. if position == 0 then
  102.  
  103. xpl_command("sim/fuel/fuel_selector_lft")
  104.  
  105. elseif position == 1 then
  106.  
  107. xpl_command("sim/fuel/fuel_selector_all")
  108.  
  109. elseif position == 2 then
  110.  
  111. xpl_command("sim/fuel/fuel_selector_rgt")
  112.  
  113.  
  114.  
  115.     end
  116.  
  117. end
  118.  
  119.  
  120.  
  121. hw_switch_add("ARDUINO_UNO_C_D4", "ARDUINO_UNO_C_D5", "ARDUINO_UNO_C_D6", Fuel_Selector_Switch_callback)
  122.  
  123.  
  124.  
  125. -------------------------------------------------------------------------------
  126.  
  127. -- Fuel shut Off Switch -------------------------------------------------------
  128.  
  129. -------------------------------------------------------------------------------
  130.  
  131.  
  132.  
  133.  
  134.  
  135. -- This function is called every time the switch has a new position
  136.  
  137. function Fuel_Shut_off_switch_callback(position)
  138.  
  139.   print("The Fuel Shut off switch got changed to position " .. position)
  140.  
  141.     xpl_command("sim/starters/shut_down")
  142.  
  143. end
  144.  
  145.  
  146.  
  147. -- Bind to Arduino Uno, Channel C, Pin 7
  148.  
  149. hw_switch_add("ARDUINO_UNO_C_D7", Fuel_Shut_off_switch_callback)
  150.  
  151.  
  152.  
  153. --------------------------------------------------------------------
  154.  
  155. -- Raspberry PI 3 b+ shut down
  156.  
  157. --------------------------------------------------------------------
  158.  
  159.  
  160.  
  161. function shutdown()
  162.  
  163.  
  164.  
  165.   -- Shut down Windows (Application) or the Raspberry Pi (SYSTEM)
  166.  
  167. shut_down("SYSTEM")
  168.  
  169. end
  170.  
  171.  
  172.  
  173. hw_button_add("RPI_V2_P1_40", shutdown)
  174.  
  175.  
  176.  
  177.  
When it looks not right, go around. It's easier to explain why you done it, than for others why you don't.

User avatar
Huberflight
Posts: 25
Joined: Sat Mar 31, 2018 2:27 pm

Re: RPI Communication Problem

#25 Post by Huberflight » Tue Feb 02, 2021 8:27 am

Here is my Code for the LSP.
  1. --------------------------------------------------------------------
  2.  
  3. -- This is a script for my Lower Switch Panel of the Baron B58. ----
  4.  
  5. -- There are only Switch-comands and LED Status --------------------
  6.  
  7. -- The hole Panel works on Arduino Mega 2560 on Chanel B only. -----
  8.  
  9. -- For the Pin Out look at the Pin Out Plan (Excel-table) ----------
  10.  
  11. --------------------------------------------------------------------
  12.  
  13.  
  14.  
  15. --------------------------------------------------------------------
  16.  
  17. -- Battery
  18.  
  19. --------------------------------------------------------------------
  20.  
  21.  
  22.  
  23. function switch_battery_callback(position)
  24.  
  25.   print("The battery switch got changed to position " .. position)
  26.  
  27.  
  28.  
  29.   if position == 0 then
  30.  
  31.     xpl_command("sim/electrical/battery_1_off")
  32.  
  33.   elseif position == 1 then
  34.  
  35.     xpl_command("sim/electrical/battery_1_on")
  36.  
  37.   end
  38.  
  39. end
  40.  
  41.  
  42.  
  43. -- Here we create the hardware switch and to witch board (pin) it is connected
  44.  
  45. hw_switch_add("ARDUINO_MEGA2560_B_D2", switch_battery_callback)
  46.  
  47.  
  48.  
  49.  
  50.  
  51. --------------------------------------------------------------------
  52.  
  53. -- Generator L ALT
  54.  
  55. --------------------------------------------------------------------
  56.  
  57.  
  58.  
  59. function switch_L_ALT_callback(position)
  60.  
  61.   print("The L ALT switch got changed to position " .. position)
  62.  
  63.  
  64.  
  65.   if position == 0 then
  66.  
  67.     xpl_command("sim/electrical/generator_1_off")
  68.  
  69.   elseif position == 1 then
  70.  
  71.     xpl_command("sim/electrical/generator_1_on")
  72.  
  73.   end
  74.  
  75.  
  76.  
  77. end
  78.  
  79.  
  80.  
  81. -- Here we create the hardware switch and to witch board (pin) it is connected
  82.  
  83. hw_switch_add("ARDUINO_MEGA2560_B_D3", switch_L_ALT_callback)
  84.  
  85.  
  86.  
  87.  
  88.  
  89. --------------------------------------------------------------------
  90.  
  91. -- Generator R ALT
  92.  
  93. --------------------------------------------------------------------
  94.  
  95.  
  96.  
  97. function switch_R_ALT_callback(position)
  98.  
  99.   print("The R ALT switch got changed to position " .. position)
  100.  
  101.  
  102.  
  103.   if position == 0 then
  104.  
  105.     xpl_command("sim/electrical/generator_2_off")
  106.  
  107.   elseif position == 1 then
  108.  
  109.     xpl_command("sim/electrical/generator_2_on")
  110.  
  111.   end
  112.  
  113.  
  114.  
  115. end
  116.  
  117.  
  118.  
  119. -- Here we create the hardware switch and to witch board (pin) it is connected
  120.  
  121. hw_switch_add("ARDUINO_MEGA2560_B_D4", switch_R_ALT_callback)
  122.  
  123.  
  124.  
  125.  
  126.  
  127. --------------------------------------------------------------------
  128.  
  129. -- Avionics
  130.  
  131. --------------------------------------------------------------------
  132.  
  133.  
  134.  
  135. function switch_Avionics_callback(position)
  136.  
  137.   print("The Avionics switch got changed to position " .. position)
  138.  
  139.  
  140.  
  141.   if position == 0 then
  142.  
  143.     xpl_command("sim/systems/avionics_off")
  144.  
  145.   elseif position == 1 then
  146.  
  147.     xpl_command("sim/systems/avionics_on")
  148.  
  149.   end
  150.  
  151. end
  152.  
  153.  
  154.  
  155. -- Here we create the hardware switch and to witch board (pin) it is connected
  156.  
  157. hw_switch_add("ARDUINO_MEGA2560_B_D5", switch_Avionics_callback)
  158.  
  159.  
  160.  
  161.  
  162.  
  163. --------------------------------------------------------------------
  164.  
  165. -- Prop Sync
  166.  
  167. --------------------------------------------------------------------
  168.  
  169.  
  170.  
  171. function switch_Prop_Sync_callback(position)
  172.  
  173.   print("The Prop Sync switch got changed to position " .. position)
  174.  
  175.  
  176.  
  177.   if position == 0 then
  178.  
  179.     xpl_command("sim/systems/prop_sync_off")
  180.  
  181.   elseif position == 1 then
  182.  
  183.     xpl_command("sim/systems/prop_sync_on")
  184.  
  185.   end
  186.  
  187. end
  188.  
  189.  
  190.  
  191. -- Here we create the hardware switch and to witch board (pin) it is connected
  192.  
  193. hw_switch_add("ARDUINO_MEGA2560_B_D6", switch_Prop_Sync_callback)
  194.  
  195.  
  196.  
  197.  
  198.  
  199. --------------------------------------------------------------------
  200.  
  201. -- Fuel Pump 1
  202.  
  203. --------------------------------------------------------------------
  204.  
  205.  
  206.  
  207. function Switch_Fuel_pump_1_callback(position)
  208.  
  209.   print("The fuel pump 1 switch got changed to position " .. position)
  210.  
  211.  
  212.  
  213.   if position == 0 then
  214.  
  215.     xpl_command("sim/fuel/fuel_pump_1_off")
  216.  
  217.   elseif position == 1 then
  218.  
  219.     xpl_command("sim/fuel/fuel_pump_1_on")
  220.  
  221.   end
  222.  
  223. end
  224.  
  225.  
  226.  
  227. -- Here we create the hardware switch and to witch board (pin) it is connected
  228.  
  229. hw_switch_add("ARDUINO_MEGA2560_B_D7", Switch_Fuel_pump_1_callback)
  230.  
  231.  
  232.  
  233.  
  234.  
  235. --------------------------------------------------------------------
  236.  
  237. -- Fuel Pump 2
  238.  
  239. --------------------------------------------------------------------
  240.  
  241.  
  242.  
  243. function Switch_Fuel_pump_2_callback(position)
  244.  
  245.   print("The fuel pump 2 switch got changed to position " .. position)
  246.  
  247.  
  248.  
  249.   if position == 0 then
  250.  
  251.     xpl_command("sim/fuel/fuel_pump_2_off")
  252.  
  253.   elseif position == 1 then
  254.  
  255.     xpl_command("sim/fuel/fuel_pump_2_on")
  256.  
  257.   end
  258.  
  259. end
  260.  
  261.  
  262.  
  263. -- Here we create the hardware switch and to witch board (pin) it is connected
  264.  
  265. hw_switch_add("ARDUINO_MEGA2560_B_D8", Switch_Fuel_pump_2_callback)
  266.  
  267.  
  268.  
  269.  
  270.  
  271. --------------------------------------------------------------------
  272.  
  273. -- Pitot Heat L
  274.  
  275. --------------------------------------------------------------------
  276.  
  277.  
  278.  
  279. function Switch_Pitot_Heat_L_callback(position)
  280.  
  281.   print("The Pitot Heat L switch got changed to position " .. position)
  282.  
  283.  
  284.  
  285.   if position == 0 then
  286.  
  287.     xpl_command("sim/ice/pitot_heat0_off")
  288.  
  289.   elseif position == 1 then
  290.  
  291.     xpl_command("sim/ice/pitot_heat0_on")
  292.  
  293.   end
  294.  
  295. end
  296.  
  297.  
  298.  
  299. -- Here we create the hardware switch and to witch board (pin) it is connected
  300.  
  301. hw_switch_add("ARDUINO_MEGA2560_B_D9", Switch_Pitot_Heat_L_callback)
  302.  
  303.  
  304.  
  305.  
  306.  
  307. --------------------------------------------------------------------
  308.  
  309. -- Pitot Heat R
  310.  
  311. --------------------------------------------------------------------
  312.  
  313.  
  314.  
  315. function Switch_Pitot_Heat_R_callback(position)
  316.  
  317.   print("The Pitot Heat R switch got changed to position " .. position)
  318.  
  319.  
  320.  
  321.   if position == 0 then
  322.  
  323.     xpl_command("sim/ice/pitot_heat1_off")
  324.  
  325.   elseif position == 1 then
  326.  
  327.     xpl_command("sim/ice/pitot_heat1_on")
  328.  
  329.   end
  330.  
  331. end
  332.  
  333.  
  334.  
  335. -- Here we create the hardware switch and to witch board (pin) it is connected
  336.  
  337. hw_switch_add("ARDUINO_MEGA2560_B_D10", Switch_Pitot_Heat_R_callback)
  338.  
  339.  
  340.  
  341.  
  342.  
  343. --------------------------------------------------------------------
  344.  
  345. -- Stall Warn Heat
  346.  
  347. --------------------------------------------------------------------
  348.  
  349.  
  350.  
  351. function Switch_Stall_Warn_Heat_callback(position)
  352.  
  353.   print("The Stall Warn Heat switch got changed to position " .. position)
  354.  
  355.  
  356.  
  357.   if position == 0 then
  358.  
  359.     xpl_command("sim/ice/AOA_heat0_off")
  360.  
  361.   elseif position == 1 then
  362.  
  363.     xpl_command("sim/ice/AOA_heat0_on")
  364.  
  365.   end
  366.  
  367. end
  368.  
  369.  
  370.  
  371. -- Here we create the hardware switch and to witch board (pin) it is connected
  372.  
  373. hw_switch_add("ARDUINO_MEGA2560_B_D11", Switch_Stall_Warn_Heat_callback)
  374.  
  375.  
  376.  
  377.  
  378.  
  379. --------------------------------------------------------------------
  380.  
  381. -- Prop Heat
  382.  
  383. --------------------------------------------------------------------
  384.  
  385.  
  386.  
  387. function Switch_Prop_Heat_callback(position)
  388.  
  389.   print("The Prop Heat switch got changed to position " .. position)
  390.  
  391.  
  392.  
  393.   if position == 0 then
  394.  
  395.     xpl_command("sim/ice/prop_heat_off")
  396.  
  397.   elseif position == 1 then
  398.  
  399.     xpl_command("sim/ice/prop_heat_on")
  400.  
  401.   end
  402.  
  403. end
  404.  
  405.  
  406.  
  407. -- Here we create the hardware switch and to witch board (pin) it is connected
  408.  
  409. hw_switch_add("ARDUINO_MEGA2560_B_D12", Switch_Prop_Heat_callback)
  410.  
  411.  
  412.  
  413.  
  414.  
  415. --------------------------------------------------------------------
  416.  
  417. -- WSHLD (Windshield) Heat
  418.  
  419. --------------------------------------------------------------------
  420.  
  421.  
  422.  
  423. function Switch_WSHLD_Heat_callback(position)
  424.  
  425.   print("The Windshield Heat switch got changed to position " .. position)
  426.  
  427.  
  428.  
  429.   if position == 0 then
  430.  
  431.     xpl_command("sim/ice/window_heat_off")
  432.  
  433.   elseif position == 1 then
  434.  
  435.     xpl_command("sim/ice/window_heat_on")
  436.  
  437.   end
  438.  
  439. end
  440.  
  441.  
  442.  
  443. -- Here we create the hardware switch and to witch board (pin) it is connected
  444.  
  445. hw_switch_add("ARDUINO_MEGA2560_B_D13", Switch_WSHLD_Heat_callback)
  446.  
  447.  
  448.  
  449.  
  450.  
  451. --------------------------------------------------------------------
  452.  
  453. -- Wing Heat
  454.  
  455. --------------------------------------------------------------------
  456.  
  457.  
  458.  
  459. function Switch_Wing_Heat_callback(position)
  460.  
  461.   print("The Wing Heat switch got changed to position " .. position)
  462.  
  463.  
  464.  
  465.   if position == 0 then
  466.  
  467.     xpl_command("sim/ice/wing_heat_off")
  468.  
  469.   elseif position == 1 then
  470.  
  471.     xpl_command("sim/ice/wing_heat_on")
  472.  
  473.   end
  474.  
  475. end
  476.  
  477.  
  478.  
  479. -- Here we create the hardware switch and to witch board (pin) it is connected
  480.  
  481. hw_switch_add("ARDUINO_MEGA2560_B_D14", Switch_Wing_Heat_callback)
  482.  
  483.  
  484.  
  485.  
  486.  
  487. -------------------------------------------------------------------------------
  488.  
  489. -- Annunciator Test Button
  490.  
  491. -------------------------------------------------------------------------------
  492.  
  493.  
  494.  
  495. -- Callback function which is called when the button is pressed
  496.  
  497. function button_pressed()
  498.  
  499.     print("button pressed")
  500.  
  501.     xpl_command("sim/annunciator/test_all_annunciators", 1)
  502.  
  503. end
  504.  
  505.  
  506.  
  507. -- Callback function which is called when the button is released
  508.  
  509.  function button_released()
  510.  
  511.     print("button released")
  512.  
  513.     xpl_command("sim/annunciator/test_all_annunciators", 0)
  514.  
  515. end
  516.  
  517.  
  518.  
  519. -- Create a button with the name 'Annunciators Test'
  520.  
  521. hw_button_add("ARDUINO_MEGA2560_B_D15", button_pressed, button_released)
  522.  
  523.  
  524.  
  525.  
  526.  
  527. -------------------------------------------------------------------------------
  528.  
  529. -- Magnetos Left (Engine 1)
  530.  
  531. -------------------------------------------------------------------------------
  532.  
  533.  
  534.  
  535. --Ignition Switch
  536.  
  537. function switch_ignition_Left_callback(position)
  538.  
  539. print("The ignition switch Left got changed to position " .. position)
  540.  
  541.  
  542.  
  543. if position == 0 then
  544.  
  545. xpl_command("sim/magnetos/magnetos_off_1")
  546.  
  547. elseif position == 1 then
  548.  
  549. xpl_command("sim/magnetos/magnetos_right_1")
  550.  
  551. elseif position == 2 then
  552.  
  553. xpl_command("sim/magnetos/magnetos_left_1")
  554.  
  555. elseif position == 3 then
  556.  
  557. xpl_command("sim/magnetos/magnetos_both_1")
  558.  
  559. -- X-Plane requires you to send a begin command (1) to keep the starter engine activated, after that we need to turn it off (0) when going back to BOTH
  560.  
  561. xpl_command("sim/starters/engage_starter_1", 0)
  562.  
  563. elseif position == 4 then
  564.  
  565. -- The starter engine will run as long as you keep it in the last position.
  566.  
  567. xpl_command("sim/starters/engage_starter_1", 1)
  568.  
  569.     end
  570.  
  571. end
  572.  
  573.  
  574.  
  575. hw_switch_add("ARDUINO_MEGA2560_B_D16", "ARDUINO_MEGA2560_B_D17", "ARDUINO_MEGA2560_B_D18", "ARDUINO_MEGA2560_B_D19", "ARDUINO_MEGA2560_B_D20", switch_ignition_Left_callback)
  576.  
  577. -- End Ignition Switch Left
  578.  
  579.  
  580.  
  581.  
  582.  
  583. -------------------------------------------------------------------------------
  584.  
  585. -- Magnetos Right (Engine 2)
  586.  
  587. -------------------------------------------------------------------------------
  588.  
  589.  
  590.  
  591. --Ignition Switch
  592.  
  593. function switch_ignition_Right_callback(position)
  594.  
  595. print("The ignition switch Right got changed to position " .. position)
  596.  
  597.  
  598.  
  599. if position == 0 then
  600.  
  601. xpl_command("sim/magnetos/magnetos_off_2")
  602.  
  603. elseif position == 1 then
  604.  
  605. xpl_command("sim/magnetos/magnetos_right_2")
  606.  
  607. elseif position == 2 then
  608.  
  609. xpl_command("sim/magnetos/magnetos_left_2")
  610.  
  611. elseif position == 3 then
  612.  
  613. xpl_command("sim/magnetos/magnetos_both_2")
  614.  
  615. -- X-Plane requires you to send a begin command (1) to keep the starter engine activated, after that we need to turn it off (0) when going back to BOTH
  616.  
  617. xpl_command("sim/starters/engage_starter_2", 0)
  618.  
  619. elseif position == 4 then
  620.  
  621. -- The starter engine will run as long as you keep it in the last position.
  622.  
  623. xpl_command("sim/starters/engage_starter_2", 1)
  624.  
  625.     end
  626.  
  627. end
  628.  
  629.  
  630.  
  631. hw_switch_add("ARDUINO_MEGA2560_B_D21", "ARDUINO_MEGA2560_B_D22", "ARDUINO_MEGA2560_B_D23", "ARDUINO_MEGA2560_B_D24", "ARDUINO_MEGA2560_B_D25", switch_ignition_Right_callback)
  632.  
  633. -- End Ignition Switch Right
  634.  
  635.  
  636.  
  637.  
  638.  
  639. --------------------------------------------------------------------
  640.  
  641. -- ICE Light
  642.  
  643. --------------------------------------------------------------------
  644.  
  645.  
  646.  
  647. function Switch_ICE_Light_callback(position)
  648.  
  649.   print("The ICE Light switch got changed to position " .. position)
  650.  
  651.  
  652.  
  653.   if position == 0 then
  654.  
  655.     xpl_command("sim/lights/generic_01_light_tog", 1)
  656.  
  657.   elseif position == 1 then
  658.  
  659.     xpl_command("sim/lights/generic_01_light_tog", 0)
  660.  
  661.   end
  662.  
  663. end
  664.  
  665.  
  666.  
  667. -- Here we create the hardware switch and to witch board (pin) it is connected
  668.  
  669. hw_switch_add("ARDUINO_MEGA2560_B_D26", Switch_ICE_Light_callback)
  670.  
  671.  
  672.  
  673.  
  674.  
  675. --------------------------------------------------------------------
  676.  
  677. -- Strope Light
  678.  
  679. --------------------------------------------------------------------
  680.  
  681.  
  682.  
  683. function Switch_Strope_Light_callback(position)
  684.  
  685.   print("The Strope Light switch got changed to position " .. position)
  686.  
  687.  
  688.  
  689.   if position == 0 then
  690.  
  691.     xpl_command("sim/lights/strobe_lights_off")
  692.  
  693.   elseif position == 1 then
  694.  
  695.     xpl_command("sim/lights/strobe_lights_on")
  696.  
  697.   end
  698.  
  699. end
  700.  
  701.  
  702.  
  703. -- Here we create the hardware switch and to witch board (pin) it is connected
  704.  
  705. hw_switch_add("ARDUINO_MEGA2560_B_D27", Switch_Strope_Light_callback)
  706.  
  707.  
  708.  
  709.  
  710.  
  711. --------------------------------------------------------------------
  712.  
  713. -- BCN Light
  714.  
  715. --------------------------------------------------------------------
  716.  
  717.  
  718.  
  719. function Switch_Beacon_Light_callback(position)
  720.  
  721.   print("The Beacon Light switch got changed to position " .. position)
  722.  
  723.  
  724.  
  725.   if position == 0 then
  726.  
  727.     xpl_command("sim/lights/beacon_lights_off")
  728.  
  729.   elseif position == 1 then
  730.  
  731.     xpl_command("sim/lights/beacon_lights_on")
  732.  
  733.   end
  734.  
  735. end
  736.  
  737.  
  738.  
  739. -- Here we create the hardware switch and to witch board (pin) it is connected
  740.  
  741. hw_switch_add("ARDUINO_MEGA2560_B_D28", Switch_Beacon_Light_callback)
  742.  
  743.  
  744.  
  745.  
  746.  
  747. --------------------------------------------------------------------
  748.  
  749. -- NAV Light
  750.  
  751. --------------------------------------------------------------------
  752.  
  753.  
  754.  
  755. function Switch_NAV_Light_callback(position)
  756.  
  757.   print("The NAV Light switch got changed to position " .. position)
  758.  
  759.  
  760.  
  761.   if position == 0 then
  762.  
  763.     xpl_command("sim/lights/nav_lights_off")
  764.  
  765.   elseif position == 1 then
  766.  
  767.     xpl_command("sim/lights/nav_lights_on")
  768.  
  769.   end
  770.  
  771. end
  772.  
  773.  
  774.  
  775. -- Here we create the hardware switch and to witch board (pin) it is connected
  776.  
  777. hw_switch_add("ARDUINO_MEGA2560_B_D29", Switch_NAV_Light_callback)
  778.  
  779.  
  780.  
  781.  
  782.  
  783. --------------------------------------------------------------------
  784.  
  785. -- Flood Light
  786.  
  787. --------------------------------------------------------------------
  788.  
  789.  
  790.  
  791. function Switch_Flood_Light_callback(position)
  792.  
  793.   print("The Flood Light switch got changed to position " .. position)
  794.  
  795.  
  796.  
  797.   if position == 0 then
  798.  
  799.     xpl_command("laminar/b58/lighting/flood_light_switch", 1)
  800.  
  801.   elseif position == 1 then
  802.  
  803.     xpl_command("laminar/b58/lighting/flood_light_switch", 0)
  804.  
  805.   end
  806.  
  807. end
  808.  
  809.  
  810.  
  811. -- Here we create the hardware switch and to witch board (pin) it is connected
  812.  
  813. hw_switch_add("ARDUINO_MEGA2560_B_D30", Switch_Flood_Light_callback)
  814.  
  815.  
  816.  
  817.  
  818.  
  819. --------------------------------------------------------------------
  820.  
  821. -- Panel Light
  822.  
  823. --------------------------------------------------------------------
  824.  
  825.  
  826.  
  827. function Switch_Panel_Light_callback(position)
  828.  
  829.   print("The Panel Light switch got changed to position " .. position)
  830.  
  831.  
  832.  
  833.   if position == 0 then
  834.  
  835.     xpl_command("laminar/b58/lighting/panel_light_switch", 1)
  836.  
  837.   elseif position == 1 then
  838.  
  839.     xpl_command("laminar/b58/lighting/panel_light_switch", 0)
  840.  
  841.   end
  842.  
  843. end
  844.  
  845.  
  846.  
  847. -- Here we create the hardware switch and to witch board (pin) it is connected
  848.  
  849. hw_switch_add("ARDUINO_MEGA2560_B_D31", Switch_Panel_Light_callback)
  850.  
  851.  
  852.  
  853.  
  854.  
  855. --------------------------------------------------------------------
  856.  
  857. -- Taxi Light
  858.  
  859. --------------------------------------------------------------------
  860.  
  861.  
  862.  
  863. function Switch_Taxi_Light_callback(position)
  864.  
  865.   print("The Taxi Light switch got changed to position " .. position)
  866.  
  867.  
  868.  
  869.   if position == 0 then
  870.  
  871.     xpl_command("sim/lights/taxi_lights_off")
  872.  
  873.   elseif position == 1 then
  874.  
  875.     xpl_command("sim/lights/taxi_lights_on")
  876.  
  877.   end
  878.  
  879. end
  880.  
  881.  
  882.  
  883. -- Here we create the hardware switch and to witch board (pin) it is connected
  884.  
  885. hw_switch_add("ARDUINO_MEGA2560_B_D32", Switch_Taxi_Light_callback)
  886.  
  887.  
  888.  
  889.  
  890.  
  891. --------------------------------------------------------------------
  892.  
  893. -- Landing Light Left
  894.  
  895. --------------------------------------------------------------------
  896.  
  897.  
  898.  
  899. function Switch_Landing_Light_Left_callback(position)
  900.  
  901.   print("The Landing Light Left switch got changed to position " .. position)
  902.  
  903.  
  904.  
  905.   if position == 0 then
  906.  
  907.     xpl_command("sim/lights/landing_01_light_off")
  908.  
  909.   elseif position == 1 then
  910.  
  911.     xpl_command("sim/lights/landing_01_light_on")
  912.  
  913.   end
  914.  
  915. end
  916.  
  917.  
  918.  
  919. -- Here we create the hardware switch and to witch board (pin) it is connected
  920.  
  921. hw_switch_add("ARDUINO_MEGA2560_B_D33", Switch_Landing_Light_Left_callback)
  922.  
  923.  
  924.  
  925.  
  926.  
  927. --------------------------------------------------------------------
  928.  
  929. -- Landing Light Right
  930.  
  931. --------------------------------------------------------------------
  932.  
  933.  
  934.  
  935. function Switch_Landing_Light_Right_callback(position)
  936.  
  937.   print("The Landing Light Right switch got changed to position " .. position)
  938.  
  939.  
  940.  
  941.   if position == 0 then
  942.  
  943.     xpl_command("sim/lights/landing_02_light_off")
  944.  
  945.   elseif position == 1 then
  946.  
  947.     xpl_command("sim/lights/landing_02_light_on")
  948.  
  949.   end
  950.  
  951. end
  952.  
  953.  
  954.  
  955. -- Here we create the hardware switch and to witch board (pin) it is connected
  956.  
  957. hw_switch_add("ARDUINO_MEGA2560_B_D34", Switch_Landing_Light_Right_callback)
  958.  
  959.  
  960.  
  961.  
  962.  
  963. --------------------------------------------------------------------
  964.  
  965. -- Landing Gear Leveler
  966.  
  967. --------------------------------------------------------------------
  968.  
  969.  
  970.  
  971. function Switch_Landing_Gear_callback(position)
  972.  
  973.   print("The Landing Gear switch got changed to position " .. position)
  974.  
  975.  
  976.  
  977.   if position == 0 then
  978.  
  979.     xpl_command("sim/flight_controls/landing_gear_up")
  980.  
  981.   elseif position == 1 then
  982.  
  983.     xpl_command("sim/flight_controls/landing_gear_down")
  984.  
  985.   end
  986.  
  987. end
  988.  
  989.  
  990.  
  991. -- Here we create the hardware switch and to witch board (pin) it is connected
  992.  
  993. hw_switch_add("ARDUINO_MEGA2560_B_D35", Switch_Landing_Gear_callback)
  994.  
  995.  
  996.  
  997.  
  998.  
  999. --------------------------------------------------------------------
  1000.  
  1001. -- Landing Gear Status Lights NLG --
  1002.  
  1003. --------------------------------------------------------------------
  1004.  
  1005.  
  1006.  
  1007. led_nlg = hw_led_add("ARDUINO_MEGA2560_B_D36", 0.0)
  1008.  
  1009.  
  1010.  
  1011. function new_data_xpl(acf_gear_deploy)
  1012.  
  1013.  
  1014.  
  1015.   gear_deploy = acf_gear_deploy[1] >= 0.99
  1016.  
  1017.  
  1018.  
  1019.   if acf_gear_deploy[1] < 0.99 then
  1020.  
  1021.     hw_led_set(led_nlg, 0)
  1022.  
  1023.   else
  1024.  
  1025.     hw_led_set(led_nlg, 0.2)
  1026.  
  1027.   end
  1028.  
  1029. end
  1030.  
  1031.  
  1032.  
  1033. xpl_dataref_subscribe("sim/aircraft/parts/acf_gear_deploy", "FLOAT[10]", new_data_xpl)
  1034.  
  1035.  
  1036.  
  1037.  
  1038.  
  1039. --------------------------------------------------------------------
  1040.  
  1041. -- Landing Gear Status Lights MLG LH --
  1042.  
  1043. --------------------------------------------------------------------
  1044.  
  1045.  
  1046.  
  1047. -- Create one LED, and have them off by default
  1048.  
  1049. led_mlg_lh = hw_led_add("ARDUINO_MEGA2560_B_D37", 0.0)
  1050.  
  1051.  
  1052.  
  1053. function new_data_xpl(acf_gear_deploy)
  1054.  
  1055.  
  1056.  
  1057.   gear_deploy = acf_gear_deploy[2] >= 0.99
  1058.  
  1059.  
  1060.  
  1061.   if acf_gear_deploy[2] < 0.99 then
  1062.  
  1063.     hw_led_set(led_mlg_lh, 0)
  1064.  
  1065.   else
  1066.  
  1067.     hw_led_set(led_mlg_lh, 0.2)
  1068.  
  1069.   end
  1070.  
  1071. end
  1072.  
  1073.  
  1074.  
  1075. xpl_dataref_subscribe("sim/aircraft/parts/acf_gear_deploy", "FLOAT[10]", new_data_xpl)
  1076.  
  1077.  
  1078.  
  1079.  
  1080.  
  1081. --------------------------------------------------------------------
  1082.  
  1083. -- Landing Gear Status Lights MLG RH --
  1084.  
  1085. --------------------------------------------------------------------
  1086.  
  1087.  
  1088.  
  1089. led_mlg_rh = hw_led_add("ARDUINO_MEGA2560_B_D38", 0.0)
  1090.  
  1091.  
  1092.  
  1093. function new_data_xpl(acf_gear_deploy)
  1094.  
  1095.  
  1096.  
  1097.   gear_deploy = acf_gear_deploy[3] >= 0.99
  1098.  
  1099.  
  1100.  
  1101.   if acf_gear_deploy[3] < 0.99 then
  1102.  
  1103.     hw_led_set(led_mlg_rh, 0)
  1104.  
  1105.   else
  1106.  
  1107.    hw_led_set(led_mlg_rh, 0.2)
  1108.  
  1109.   end
  1110.  
  1111. end
  1112.  
  1113.  
  1114.  
  1115. xpl_dataref_subscribe("sim/aircraft/parts/acf_gear_deploy", "FLOAT[10]", new_data_xpl)
  1116.  
  1117.  
  1118.  
  1119.  
  1120.  
  1121. --------------------------------------------------------------------
  1122.  
  1123. -- Landing Gear Status Light Transit --
  1124.  
  1125. --------------------------------------------------------------------
  1126.  
  1127.  
  1128.  
  1129. led_transit = hw_led_add("ARDUINO_MEGA2560_B_D39", 0.0)
  1130.  
  1131.  
  1132.  
  1133. function new_data_xpl(gear_in_transit)
  1134.  
  1135.   print("The Landing Gear Transition Light is on when 1.0 and off when 0.0 is displayed: " .. gear_in_transit)
  1136.  
  1137.  
  1138.  
  1139.   if gear_in_transit == 0 then
  1140.  
  1141.     hw_led_set(led_transit, 0)
  1142.  
  1143.   elseif gear_in_transit == 1 then
  1144.  
  1145.      hw_led_set(led_transit, 1)
  1146.  
  1147.   end
  1148.  
  1149. end
  1150.  
  1151.  
  1152.  
  1153. xpl_dataref_subscribe("laminar/b58/annun/gear_in_transit", "FLOAT", new_data_xpl)
  1154.  
  1155.  
  1156.  
  1157.  
  1158.  
  1159. --------------------------------------------------------------------
  1160.  
  1161. -- Parking Brake --
  1162.  
  1163. --------------------------------------------------------------------
  1164.  
  1165.  xpl_switch_function="sim/flightmodel/controls/parkbrake"
  1166.  
  1167.  xpl_switch_type="FLOAT"
  1168.  
  1169.  
  1170.  
  1171.  
  1172.  
  1173. function Parkbrake_callback(position)
  1174.  
  1175.     print("The Parkbrake got changed to position " .. position)
  1176.  
  1177.     if position == 0 then
  1178.  
  1179.         xpl_dataref_write(xpl_switch_function,xpl_switch_type, 0)
  1180.  
  1181.    
  1182.  
  1183.     elseif position == 1 then
  1184.  
  1185.     xpl_dataref_write(xpl_switch_function,xpl_switch_type, 1)
  1186.  
  1187.     end
  1188.  
  1189.  
  1190.  
  1191. end
  1192.  
  1193.  
  1194.  
  1195. hw_switch_add("ARDUINO_MEGA2560_B_D40", Parkbrake_callback)
  1196.  
  1197.  
When it looks not right, go around. It's easier to explain why you done it, than for others why you don't.

User avatar
Huberflight
Posts: 25
Joined: Sat Mar 31, 2018 2:27 pm

Re: RPI Communication Problem

#26 Post by Huberflight » Tue Feb 02, 2021 8:29 am

And last but not least. My code for the Annunciator Lights (ANN).
  1.  
  2.  
  3. ----------------------------------------------------------------------------------
  4.  
  5. -- This is the script for the MIP with G1000 for the Baron B58. ------------------
  6.  
  7. -- It will connect the Annunciator Light LEDs with the Arduino on channel(H) -----
  8.  
  9. ----------------------------------------------------------------------------------
  10.  
  11.  
  12.  
  13. ------------------------------------------------------------------------------
  14.  
  15. -- Annunciator Test Light Gear
  16.  
  17. ------------------------------------------------------------------------------  
  18.  
  19.  
  20.  
  21. led_gear_test = hw_led_add("ARDUINO_UNO_H_D2", 0.0)
  22.  
  23.  
  24.  
  25. function new_data_annunciator(gear_test, gear_up)
  26.  
  27.  
  28.  
  29.     if gear_test == 1 then
  30.  
  31.    hw_led_set(led_gear_test, 1)
  32.  
  33.   else
  34.  
  35.    hw_led_set(led_gear_test, 0)
  36.  
  37.   end
  38.  
  39. end
  40.  
  41.  
  42.  
  43. xpl_dataref_subscribe("sim/cockpit2/annunciators/gear_unsafe", "INT", new_data_annunciator)
  44.  
  45.  
  46.  
  47. ------------------------------------------------------------------------------
  48.  
  49. -- Annunciator Light Gear
  50.  
  51. ------------------------------------------------------------------------------  
  52.  
  53.  
  54.  
  55. led_gear_up = hw_led_add("ARDUINO_UNO_H_D2", 0.0)
  56.  
  57.  
  58.  
  59. function new_data_xpl(gear_up)
  60.  
  61.  
  62.  
  63.     if gear_up == 1 then
  64.  
  65.    hw_led_set(led_gear_up, 1)
  66.  
  67.   else
  68.  
  69.    hw_led_set(led_gear_up, 0)
  70.  
  71.   end
  72.  
  73. end
  74.  
  75.  
  76.  
  77. xpl_dataref_subscribe("sim/cockpit2/annunciators/gear_warning", "INT", new_data_xpl)
  78.  
  79.  
  80.  
  81.  
  82.  
  83. --------------------------------------------------------------------
  84.  
  85. -- Annunciator Light LH Generator Off
  86.  
  87. --------------------------------------------------------------------
  88.  
  89.  
  90.  
  91. led_lh_generator = hw_led_add("ARDUINO_UNO_H_D3", 0.0)
  92.  
  93.  
  94.  
  95. function new_data_xpl(gen_lh_off)
  96.  
  97.  
  98.  
  99.   if (gen_lh_off == 1) or  (gen_lh_off > 3) then
  100.  
  101.     print("Generator LH is off")
  102.  
  103.     hw_led_set(led_lh_generator, 1)
  104.  
  105.   else
  106.  
  107.     print("Generator LH is on")
  108.  
  109.     hw_led_set(led_lh_generator, 0)
  110.  
  111.   end
  112.  
  113. end
  114.  
  115.  
  116.  
  117. xpl_dataref_subscribe("sim/cockpit2/annunciators/generator", "INT", new_data_xpl)
  118.  
  119.  
  120.  
  121.  
  122.  
  123. --------------------------------------------------------------------
  124.  
  125. -- Annunciator Light RH Generator Off
  126.  
  127. --------------------------------------------------------------------
  128.  
  129.  
  130.  
  131. led_rh_generator = hw_led_add("ARDUINO_UNO_H_D4", 0.0)
  132.  
  133.  
  134.  
  135. function new_data_xpl(gen_rh_off)
  136.  
  137.  
  138.  
  139.   if gen_rh_off >= 2 then
  140.  
  141.     print("Generator RH is off")
  142.  
  143.         hw_led_set(led_rh_generator, 1)
  144.  
  145.   else
  146.  
  147.     print("Generator RH is on")
  148.  
  149.         hw_led_set(led_rh_generator, 0)
  150.  
  151.   end
  152.  
  153. end
  154.  
  155.  
  156.  
  157. xpl_dataref_subscribe("sim/cockpit2/annunciators/generator", "INT", new_data_xpl)
  158.  
  159.  
  160.  
  161.  
  162.  
  163. -------------------------------------------------------------------------------
  164.  
  165. -- Annunciator Light Starter LH Test
  166.  
  167. -------------------------------------------------------------------------------
  168.  
  169.  
  170.  
  171. led_Starter_lh_rh_test = hw_led_add("ARDUINO_UNO_H_D5", 0.0)
  172.  
  173.  
  174.  
  175. function new_data_Annunciator_Starter_test(starter_lh_rh_test_on)
  176.  
  177.      
  178.  
  179.  
  180.  
  181.     if(starter_lh_rh_test_on[1]) == 1 then
  182.  
  183.         print("Starter is on")
  184.  
  185.             hw_led_set(led_Starter_lh_rh_test, 1)
  186.  
  187.     else    
  188.  
  189.         print("Starter is off")
  190.  
  191.             hw_led_set(led_Starter_lh_rh_test, 0)
  192.  
  193.   end
  194.  
  195. end
  196.  
  197.  
  198.  
  199. xpl_dataref_subscribe("sim/cockpit2/annunciators/igniter_on", "INT[8]", new_data_Annunciator_Starter_test)
  200.  
  201.  
  202.  
  203. -------------------------------------------------------------------------------
  204.  
  205. -- Annunciator Light Starter LH
  206.  
  207. -------------------------------------------------------------------------------
  208.  
  209.  
  210.  
  211. led_Starter_lh_generator = hw_led_add("ARDUINO_UNO_H_D5", 0.0)
  212.  
  213.  
  214.  
  215. function new_data_Annunciator_Starter(starter_lh_on)
  216.  
  217.      
  218.  
  219.  
  220.  
  221.     if(starter_lh_on[1]) == 4 then
  222.  
  223.         print("Starter is on")
  224.  
  225.             hw_led_set(led_Starter_lh_generator, 1)
  226.  
  227.     else    
  228.  
  229.         print("Starter is off")
  230.  
  231.             hw_led_set(led_Starter_lh_generator, 0)
  232.  
  233.   end
  234.  
  235. end
  236.  
  237.  
  238.  
  239. xpl_dataref_subscribe("sim/cockpit2/engine/actuators/ignition_key", "INT[8]", new_data_Annunciator_Starter)
  240.  
  241.  
  242.  
  243.  
  244.  
  245. -------------------------------------------------------------------------------
  246.  
  247. -- Annunciator Light Starter RH
  248.  
  249. -------------------------------------------------------------------------------
  250.  
  251.  
  252.  
  253. led_Starter_rh_generator = hw_led_add("ARDUINO_UNO_H_D5", 0.0)
  254.  
  255.  
  256.  
  257. function new_data_Annunciator_Starter(starter_rh_on)
  258.  
  259.      
  260.  
  261.  
  262.  
  263.     if(starter_rh_on[2]) == 4 then
  264.  
  265.         print("Starter is on")
  266.  
  267.             hw_led_set(led_Starter_rh_generator, 1)
  268.  
  269.     else    
  270.  
  271.         print("Starter is off")
  272.  
  273.             hw_led_set(led_Starter_rh_generator, 0)
  274.  
  275.   end
  276.  
  277. end
  278.  
  279.  
  280.  
  281. xpl_dataref_subscribe("sim/cockpit2/engine/actuators/ignition_key", "INT[8]", new_data_Annunciator_Starter)
  282.  
  283.  
  284.  
  285.  
  286.  
  287. --------------------------------------------------------------------
  288.  
  289. -- Annunciator Light Cabin Door Open and  Test
  290.  
  291. --------------------------------------------------------------------
  292.  
  293.  
  294.  
  295. led_cabin_door_open = hw_led_add("ARDUINO_UNO_H_D6", 0.0)
  296.  
  297.  
  298.  
  299. function cabin_door(cabin_door_open)
  300.  
  301.  
  302.  
  303.   if cabin_door_open == 1 then
  304.  
  305.     print("Cabin Door is open")
  306.  
  307.         hw_led_set(led_cabin_door_open, 1)
  308.  
  309.   else
  310.  
  311.     print("Cabin Door is shut")
  312.  
  313.         hw_led_set(led_cabin_door_open, 0)
  314.  
  315.   end
  316.  
  317. end
  318.  
  319.  
  320.  
  321. xpl_dataref_subscribe("sim/cockpit2/annunciators/cabin_door_open", "INT", cabin_door)
  322.  
  323.  
  324.  
  325.  
  326.  
  327. --------------------------------------------------------------------
  328.  
  329. -- Annunciator Light Pitot Tube is on
  330.  
  331. --------------------------------------------------------------------
  332.  
  333.  
  334.  
  335. led_Pitot_Heat = hw_led_add("ARDUINO_UNO_H_D7", 0.0)
  336.  
  337.  
  338.  
  339. function pitot_tube(pitot_tube_on)
  340.  
  341.  
  342.  
  343.   if pitot_tube_on == 0 then
  344.  
  345.     print("Pitot Tube is ON")
  346.  
  347.         hw_led_set(led_Pitot_Heat, 1)
  348.  
  349.   else
  350.  
  351.     print("Pitot Tube is OFF")
  352.  
  353.         hw_led_set(led_Pitot_Heat, 0)
  354.  
  355.   end
  356.  
  357. end
  358.  
  359.  
  360.  
  361. xpl_dataref_subscribe("sim/cockpit2/annunciators/pitot_heat", "INT", pitot_tube)
  362.  
  363.  
  364.  
  365.  
  366.  
  367. --------------------------------------------------------------------
  368.  
  369. -- Annunciator Light Pitot Tube TEST is on
  370.  
  371. --------------------------------------------------------------------
  372.  
  373.  
  374.  
  375. led_Pitot_Heat_test = hw_led_add("ARDUINO_UNO_H_D7", 0.0)
  376.  
  377.  
  378.  
  379. function pitot_tube(pitot_tube_test_on)
  380.  
  381.  
  382.  
  383.   if pitot_tube_test_on == 1 then
  384.  
  385.     print("Pitot Tube TEST is ON")
  386.  
  387.         hw_led_set(led_Pitot_Heat_test, 1)
  388.  
  389.   else
  390.  
  391.     print("Pitot Tube TEST is OFF")
  392.  
  393.         hw_led_set(led_Pitot_Heat_test, 0)
  394.  
  395.   end
  396.  
  397. end
  398.  
  399.  
  400.  
  401. xpl_dataref_subscribe("sim/cockpit2/annunciators/ice", "INT", pitot_tube)
  402.  
  403.  
  404.  
  405.  
When it looks not right, go around. It's easier to explain why you done it, than for others why you don't.

User avatar
Huberflight
Posts: 25
Joined: Sat Mar 31, 2018 2:27 pm

Re: RPI Communication Problem

#27 Post by Huberflight » Tue Feb 02, 2021 8:35 am

In this moment it works.
But not really stable. When I boot the RPI it works only sometimes. But when it works, it works nice ;)
It's also possible, that there is a hardware issue.Today I will try some other Network parts and will see.

Thanks for your help :)
When it looks not right, go around. It's easier to explain why you done it, than for others why you don't.

User avatar
Huberflight
Posts: 25
Joined: Sat Mar 31, 2018 2:27 pm

Re: RPI Communication Problem

#28 Post by Huberflight » Wed Feb 03, 2021 5:35 pm

*Update*
It looks like a combinated Problem in my case.

First: I looked over my codes and clean them up. There where in two of them a shut down Comand with an opposite hardware (Pin) connection.

Second: it‘s possible That my network cable Adapter has a damage. I changed it and the connection is more stable.

:D :D :D
When it looks not right, go around. It's easier to explain why you done it, than for others why you don't.

User avatar
Ralph
Posts: 5088
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: RPI Communication Problem

#29 Post by Ralph » Wed Feb 03, 2021 8:42 pm

I haven't looked at the code yet. But if we still should then please let us know.

User avatar
Huberflight
Posts: 25
Joined: Sat Mar 31, 2018 2:27 pm

Re: RPI Communication Problem

#30 Post by Huberflight » Thu Feb 04, 2021 9:49 pm

Yes, please.
When you can have a look it would be nice to learn from a Pro :D.

Thx
When it looks not right, go around. It's easier to explain why you done it, than for others why you don't.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests