RPI Communication Problem

Support for Air Player desktop on ARM devices, like the Raspberry Pi.

Moderators: russ, Ralph

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

Re: RPI Communication Problem

#21 Post by Huberflight »

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 to finde out why you don't.

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

Re: RPI Communication Problem

#22 Post by Ralph »

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

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

Re: RPI Communication Problem

#23 Post by Huberflight »

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 202 times
Here is the code for the TQ.

Code: Select all

----------------------------------------------------------------------
-- This is the script for the Throttle Quadrant with the Throttle ----
-- Prop, Mixture, Rudder Trim, Flap Handle, Flap Pos. Indicator LED --
-- It works on Channel D only ----------------------------------------
----------------------------------------------------------------------

--------------------------------------------------------------------
-- Rudder Trim
--------------------------------------------------------------------

function adc_rudder_trim(value)
print("The Ruddel Trim is now by " ..value)


-- X-Plane expects a value between -1 and 1,
xpl_dataref_write("sim/cockpit2/controls/rudder_trim", "FLOAT", (2 * value)-1)
end

-- Create a ADC input
hw_adc_input_add("ARDUINO_MEGA2560_D_A0", adc_rudder_trim)


--------------------------------------------------------------------
-- Throttle 1 LH
--------------------------------------------------------------------

function adc_input_throttle_left(value)
print("The Throttle Nr.1 LH is now by " ..value)


-- X-Plane expects a value between 0 and 1, no conversion necessary
xpl_dataref_write("sim/flightmodel/engine/ENGN_thro", "FLOAT[8]", {value}, 0)
end

-- Create a ADC input
hw_adc_input_add("ARDUINO_MEGA2560_D_A1", adc_input_throttle_left)


--------------------------------------------------------------------
-- Throttle 2 RH
--------------------------------------------------------------------

function adc_input_throttle_right(value)
print("The Throttle Nr.2 RH is now by " ..value)


-- X-Plane expects a value between 0 and 1, no conversion necessary
xpl_dataref_write("sim/flightmodel/engine/ENGN_thro", "FLOAT[8]", {value}, 1)
end

-- Create a ADC input
hw_adc_input_add("ARDUINO_MEGA2560_D_A2", adc_input_throttle_right)


--------------------------------------------------------------------
-- Propeller Pitch LH
--------------------------------------------------------------------

function adc_input_prop(value)
print("The Prop Pitch LH is in the Position" ..value)

xpl_dataref_write("sim/flightmodel/engine/ENGN_prop", "FLOAT[8]", {73.2 + (282 - 73.2) * value}, 0)

end

-- Create a ADC input
hw_adc_input_add("ARDUINO_MEGA2560_D_A3", adc_input_prop)


--------------------------------------------------------------------
-- Propeller Pitch RH
--------------------------------------------------------------------

function adc_input_prop(value)
print("The Prop Pitch RH is in the Position" ..value)


xpl_dataref_write("sim/flightmodel/engine/ENGN_prop", "FLOAT[8]", {73.2 + (282 - 73.2) * value}, 1)

end

-- Create a ADC input
hw_adc_input_add("ARDUINO_MEGA2560_D_A4", adc_input_prop)

--------------------------------------------------------------------
-- Mixture LH
--------------------------------------------------------------------

-- For X-Plane we need to override the joystick input first
xpl_dataref_write("sim/operation/override/override_mixture", "INT", 1)


-- Callback function which is called when the ADC input state changes
-- 0.0 : GND (lowest voltage)
-- 1.0 : VCC (highest voltage)
function adc_input_mixt(value)
print("The Mixture LH is now by " ..value)
-- X-Plane expects a value between 0 and 1, no conversion necessary
xpl_dataref_write("sim/flightmodel/engine/ENGN_mixt", "FLOAT[8]", {value}, 0)

end

-- Create a ADC input
hw_adc_input_add("ARDUINO_MEGA2560_D_A5", adc_input_mixt)


--------------------------------------------------------------------
-- Mixture RH
--------------------------------------------------------------------

-- For X-Plane we need to override the joystick input first
-- xpl_dataref_write("sim/operation/override/override_mixture", "INT", 2)


-- Callback function which is called when the ADC input state changes
-- 0.0 : GND (lowest voltage)
-- 1.0 : VCC (highest voltage)
function adc_input_mixt(value)
print("The Mixture RH is now by " ..value)
-- X-Plane expects a value between 0 and 1, no conversion necessary
xpl_dataref_write("sim/flightmodel/engine/ENGN_mixt", "FLOAT[8]", {value}, 1)

end

-- Create a ADC input
hw_adc_input_add("ARDUINO_MEGA2560_D_A6", adc_input_mixt)


--------------------------------------------------------------------
-- Flap Handle Up a Notch
--------------------------------------------------------------------

-- Callback function which is called when the button is pressed
function Flap_Pos_switch_callback()
print("The Flap Pos. switch got changed to position ")
xpl_command("sim/flight_controls/flaps_up")
end

-- Bind to
hw_button_add("ARDUINO_MEGA2560_D_D3", Flap_Pos_switch_callback)


--------------------------------------------------------------------
-- Flap Handle down a Notch
--------------------------------------------------------------------

-- Callback function which is called when the button is pressed
function Flap_Pos_switch_callback()
print("The Flap Pos. switch got changed to position ")
xpl_command("sim/flight_controls/flaps_down")
end

-- Bind to
hw_button_add("ARDUINO_MEGA2560_D_D2", Flap_Pos_switch_callback)


--------------------------------------------------------------------
-- Flap Pos. Light Transit (Red)
--------------------------------------------------------------------

led_transit = hw_led_add("ARDUINO_MEGA2560_D_D4", 0.0)

function new_data_xpl(flapsdeployment)

flapsdeployment = var_round(flapsdeployment, 1)

if(flapsdeployment > 0 and flapsdeployment < 0.4) or (flapsdeployment > 0.4 and flapsdeployment < 1) then
hw_led_set(led_transit, 0.3)
else
hw_led_set(led_transit, 0)
end
end

xpl_dataref_subscribe("sim/flightmodel/controls/flaprat", "FLOAT", new_data_xpl)


--------------------------------------------------------------------
-- Flap Pos. Light Approach (Blue)
--------------------------------------------------------------------

led_approach = hw_led_add("ARDUINO_MEGA2560_D_D5", 0.0)

function new_data_xpl(flapsdeployment)

flapsdeployment = var_round(flapsdeployment, 1)

if(flapsdeployment == 0.4) then
hw_led_set(led_approach, 0.3)
else
hw_led_set(led_approach, 0)
end
end

xpl_dataref_subscribe("sim/flightmodel/controls/flaprat", "FLOAT", new_data_xpl)


--------------------------------------------------------------------
-- Flap Pos. Light DN (Yellow)
--------------------------------------------------------------------

led_DN = hw_led_add("ARDUINO_MEGA2560_D_D6", 0.0)

function new_data_xpl(flapsdeployment)

flapsdeployment = var_round(flapsdeployment, 1)

if(flapsdeployment == 1) then
hw_led_set(led_DN, 1)
else
hw_led_set(led_DN, 0)
end
end


xpl_dataref_subscribe("sim/flightmodel/controls/flaprat", "FLOAT", new_data_xpl)


--------------------------------------------------------------------
-- Raspberry PI 3 b+ shut down
--------------------------------------------------------------------

function shutdown()

-- Shut down Windows (Application) or the Raspberry Pi (SYSTEM)
shut_down("SYSTEM")
end

hw_button_add("RPI_V2_P1_38", shutdown)


--------------------------------------------------------------------
-- Raspberry PI 3 b+ Status LED
--------------------------------------------------------------------

my_led = hw_led_add("RPI_V2_P1_40", 1.0)




--[[
--------------------------------------------------------------------
-- Landing Gear Emer down
--------------------------------------------------------------------

function switch_emer_gear_callback(position)
print("The Emer Gear switch got changed to position " .. position)

if position == 0 then
xpl_command("sim/flight_controls/pump_gear", 0)
elseif position == 1 then
xpl_command("sim/flight_controls/pump_gear", 1)
end
end

-- Here we create the hardware switch and to witch board (pin) it is connected
hw_switch_add("ARDUINO_MEGA2560_D_D8", switch_emer_gear_callback)
]]--

------------------------------------------------------------------------------
-- Here we creae the ALTN LEDs in the TQ just to be sure they will not -------
-- light up in normal operation ----------------------------------------------
------------------------------------------------------------------------------
--[[
ALTN_LED_RH_MLG = hw_led_add("RPI_V2_P1_31", 0.0)

ALTN_LED_LH_MLG = hw_led_add("RPI_V2_P1_33", 0.0)

ALTN_LED_NLG = hw_led_add("RPI_V2_P1_35", 0.0)

ALTN_LED_Transit = hw_led_add("RPI_V2_P1_37", 0.0)
]]--

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

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

Re: RPI Communication Problem

#24 Post by Huberflight »

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?

Code: Select all


--------------------------------------------------------------------------
-- Here i create the script for the Trim wheel with Trim Pos. Indicator --
-- wich is driven by a Servo Motor. !!ACHTUNG!! Der Servo funktioniert ---
-- nur auf Pin D9 & D10 at the Arduino Uno -------------------------------
--------------------------------------------------------------------------

--------------------------------------------------------------------------
-- Here we create the functions of the Rotary Switch
--------------------------------------------------------------------------

function dial_change(direction)

if direction == 1 then
print("The dial turned clockwise")
xpl_command("sim/flight_controls/pitch_trim_up_mech")

elseif direction == -1 then
print("The dial turned counterclockwise")
xpl_command("sim/flight_controls/pitch_trim_down_mech")
end
end

-- Create a new Hardware rotary encoder for Arduino Uno on Pin D2 & D3
hw_dial_add("ARDUINO_UNO_C_D2", "ARDUINO_UNO_C_D3", dial_change)


-- Here we install the servo SG90 for the Trim Indicator Elevator
-- wich is connected at Arduino Uno on Pin D9
pwm_trim_indicator_elv = hw_output_pwm_add("ARDUINO_UNO_C_D9", 50, 0.07)


-- In this case the duty cycle ranges from 0.025 to 0.122
-- Take of position is at 0.7
function new_trim(trim)

hw_output_pwm_duty_cycle(pwm_trim_indicator_elv, 0.025 + ((0.122 - 0.025) / 2)*( 1 + trim))

end

xpl_dataref_subscribe("sim/cockpit2/controls/elevator_trim", "FLOAT", new_trim)


-------------------------------------------------------------------------------
-- Fuel Selector Switch (3 Positions) -----------------------------------------
-------------------------------------------------------------------------------

function Fuel_Selector_Switch_callback(position)
print("The Fuel Selector Switch changed to position " .. position)

if position == 0 then
xpl_command("sim/fuel/fuel_selector_lft")
elseif position == 1 then
xpl_command("sim/fuel/fuel_selector_all")
elseif position == 2 then
xpl_command("sim/fuel/fuel_selector_rgt")

end
end

hw_switch_add("ARDUINO_UNO_C_D4", "ARDUINO_UNO_C_D5", "ARDUINO_UNO_C_D6", Fuel_Selector_Switch_callback)

-------------------------------------------------------------------------------
-- Fuel shut Off Switch -------------------------------------------------------
-------------------------------------------------------------------------------


-- This function is called every time the switch has a new position
function Fuel_Shut_off_switch_callback(position)
print("The Fuel Shut off switch got changed to position " .. position)
xpl_command("sim/starters/shut_down")
end

-- Bind to Arduino Uno, Channel C, Pin 7
hw_switch_add("ARDUINO_UNO_C_D7", Fuel_Shut_off_switch_callback)

--------------------------------------------------------------------
-- Raspberry PI 3 b+ shut down
--------------------------------------------------------------------

function shutdown()

-- Shut down Windows (Application) or the Raspberry Pi (SYSTEM)
shut_down("SYSTEM")
end

hw_button_add("RPI_V2_P1_40", shutdown)

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

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

Re: RPI Communication Problem

#25 Post by Huberflight »

Here is my Code for the LSP.

Code: Select all

--------------------------------------------------------------------
-- This is a script for my Lower Switch Panel of the Baron B58. ----
-- There are only Switch-comands and LED Status --------------------
-- The hole Panel works on Arduino Mega 2560 on Chanel B only. -----
-- For the Pin Out look at the Pin Out Plan (Excel-table) ----------
--------------------------------------------------------------------

--------------------------------------------------------------------
-- Battery
--------------------------------------------------------------------

function switch_battery_callback(position)
print("The battery switch got changed to position " .. position)

if position == 0 then
xpl_command("sim/electrical/battery_1_off")
elseif position == 1 then
xpl_command("sim/electrical/battery_1_on")
end
end

-- Here we create the hardware switch and to witch board (pin) it is connected
hw_switch_add("ARDUINO_MEGA2560_B_D2", switch_battery_callback)


--------------------------------------------------------------------
-- Generator L ALT
--------------------------------------------------------------------

function switch_L_ALT_callback(position)
print("The L ALT switch got changed to position " .. position)

if position == 0 then
xpl_command("sim/electrical/generator_1_off")
elseif position == 1 then
xpl_command("sim/electrical/generator_1_on")
end

end

-- Here we create the hardware switch and to witch board (pin) it is connected
hw_switch_add("ARDUINO_MEGA2560_B_D3", switch_L_ALT_callback)


--------------------------------------------------------------------
-- Generator R ALT
--------------------------------------------------------------------

function switch_R_ALT_callback(position)
print("The R ALT switch got changed to position " .. position)

if position == 0 then
xpl_command("sim/electrical/generator_2_off")
elseif position == 1 then
xpl_command("sim/electrical/generator_2_on")
end

end

-- Here we create the hardware switch and to witch board (pin) it is connected
hw_switch_add("ARDUINO_MEGA2560_B_D4", switch_R_ALT_callback)


--------------------------------------------------------------------
-- Avionics
--------------------------------------------------------------------

function switch_Avionics_callback(position)
print("The Avionics switch got changed to position " .. position)

if position == 0 then
xpl_command("sim/systems/avionics_off")
elseif position == 1 then
xpl_command("sim/systems/avionics_on")
end
end

-- Here we create the hardware switch and to witch board (pin) it is connected
hw_switch_add("ARDUINO_MEGA2560_B_D5", switch_Avionics_callback)


--------------------------------------------------------------------
-- Prop Sync
--------------------------------------------------------------------

function switch_Prop_Sync_callback(position)
print("The Prop Sync switch got changed to position " .. position)

if position == 0 then
xpl_command("sim/systems/prop_sync_off")
elseif position == 1 then
xpl_command("sim/systems/prop_sync_on")
end
end

-- Here we create the hardware switch and to witch board (pin) it is connected
hw_switch_add("ARDUINO_MEGA2560_B_D6", switch_Prop_Sync_callback)


--------------------------------------------------------------------
-- Fuel Pump 1
--------------------------------------------------------------------

function Switch_Fuel_pump_1_callback(position)
print("The fuel pump 1 switch got changed to position " .. position)

if position == 0 then
xpl_command("sim/fuel/fuel_pump_1_off")
elseif position == 1 then
xpl_command("sim/fuel/fuel_pump_1_on")
end
end

-- Here we create the hardware switch and to witch board (pin) it is connected
hw_switch_add("ARDUINO_MEGA2560_B_D7", Switch_Fuel_pump_1_callback)


--------------------------------------------------------------------
-- Fuel Pump 2
--------------------------------------------------------------------

function Switch_Fuel_pump_2_callback(position)
print("The fuel pump 2 switch got changed to position " .. position)

if position == 0 then
xpl_command("sim/fuel/fuel_pump_2_off")
elseif position == 1 then
xpl_command("sim/fuel/fuel_pump_2_on")
end
end

-- Here we create the hardware switch and to witch board (pin) it is connected
hw_switch_add("ARDUINO_MEGA2560_B_D8", Switch_Fuel_pump_2_callback)


--------------------------------------------------------------------
-- Pitot Heat L
--------------------------------------------------------------------

function Switch_Pitot_Heat_L_callback(position)
print("The Pitot Heat L switch got changed to position " .. position)

if position == 0 then
xpl_command("sim/ice/pitot_heat0_off")
elseif position == 1 then
xpl_command("sim/ice/pitot_heat0_on")
end
end

-- Here we create the hardware switch and to witch board (pin) it is connected
hw_switch_add("ARDUINO_MEGA2560_B_D9", Switch_Pitot_Heat_L_callback)


--------------------------------------------------------------------
-- Pitot Heat R
--------------------------------------------------------------------

function Switch_Pitot_Heat_R_callback(position)
print("The Pitot Heat R switch got changed to position " .. position)

if position == 0 then
xpl_command("sim/ice/pitot_heat1_off")
elseif position == 1 then
xpl_command("sim/ice/pitot_heat1_on")
end
end

-- Here we create the hardware switch and to witch board (pin) it is connected
hw_switch_add("ARDUINO_MEGA2560_B_D10", Switch_Pitot_Heat_R_callback)


--------------------------------------------------------------------
-- Stall Warn Heat
--------------------------------------------------------------------

function Switch_Stall_Warn_Heat_callback(position)
print("The Stall Warn Heat switch got changed to position " .. position)

if position == 0 then
xpl_command("sim/ice/AOA_heat0_off")
elseif position == 1 then
xpl_command("sim/ice/AOA_heat0_on")
end
end

-- Here we create the hardware switch and to witch board (pin) it is connected
hw_switch_add("ARDUINO_MEGA2560_B_D11", Switch_Stall_Warn_Heat_callback)


--------------------------------------------------------------------
-- Prop Heat
--------------------------------------------------------------------

function Switch_Prop_Heat_callback(position)
print("The Prop Heat switch got changed to position " .. position)

if position == 0 then
xpl_command("sim/ice/prop_heat_off")
elseif position == 1 then
xpl_command("sim/ice/prop_heat_on")
end
end

-- Here we create the hardware switch and to witch board (pin) it is connected
hw_switch_add("ARDUINO_MEGA2560_B_D12", Switch_Prop_Heat_callback)


--------------------------------------------------------------------
-- WSHLD (Windshield) Heat
--------------------------------------------------------------------

function Switch_WSHLD_Heat_callback(position)
print("The Windshield Heat switch got changed to position " .. position)

if position == 0 then
xpl_command("sim/ice/window_heat_off")
elseif position == 1 then
xpl_command("sim/ice/window_heat_on")
end
end

-- Here we create the hardware switch and to witch board (pin) it is connected
hw_switch_add("ARDUINO_MEGA2560_B_D13", Switch_WSHLD_Heat_callback)


--------------------------------------------------------------------
-- Wing Heat
--------------------------------------------------------------------

function Switch_Wing_Heat_callback(position)
print("The Wing Heat switch got changed to position " .. position)

if position == 0 then
xpl_command("sim/ice/wing_heat_off")
elseif position == 1 then
xpl_command("sim/ice/wing_heat_on")
end
end

-- Here we create the hardware switch and to witch board (pin) it is connected
hw_switch_add("ARDUINO_MEGA2560_B_D14", Switch_Wing_Heat_callback)


-------------------------------------------------------------------------------
-- Annunciator Test Button
-------------------------------------------------------------------------------

-- Callback function which is called when the button is pressed
function button_pressed()
print("button pressed")
xpl_command("sim/annunciator/test_all_annunciators", 1)
end

-- Callback function which is called when the button is released
function button_released()
print("button released")
xpl_command("sim/annunciator/test_all_annunciators", 0)
end

-- Create a button with the name 'Annunciators Test'
hw_button_add("ARDUINO_MEGA2560_B_D15", button_pressed, button_released)


-------------------------------------------------------------------------------
-- Magnetos Left (Engine 1)
-------------------------------------------------------------------------------

--Ignition Switch
function switch_ignition_Left_callback(position)
print("The ignition switch Left got changed to position " .. position)

if position == 0 then
xpl_command("sim/magnetos/magnetos_off_1")
elseif position == 1 then
xpl_command("sim/magnetos/magnetos_right_1")
elseif position == 2 then
xpl_command("sim/magnetos/magnetos_left_1")
elseif position == 3 then
xpl_command("sim/magnetos/magnetos_both_1")
-- 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
xpl_command("sim/starters/engage_starter_1", 0)
elseif position == 4 then
-- The starter engine will run as long as you keep it in the last position.
xpl_command("sim/starters/engage_starter_1", 1)
end
end

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)
-- End Ignition Switch Left


-------------------------------------------------------------------------------
-- Magnetos Right (Engine 2)
-------------------------------------------------------------------------------

--Ignition Switch
function switch_ignition_Right_callback(position)
print("The ignition switch Right got changed to position " .. position)

if position == 0 then
xpl_command("sim/magnetos/magnetos_off_2")
elseif position == 1 then
xpl_command("sim/magnetos/magnetos_right_2")
elseif position == 2 then
xpl_command("sim/magnetos/magnetos_left_2")
elseif position == 3 then
xpl_command("sim/magnetos/magnetos_both_2")
-- 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
xpl_command("sim/starters/engage_starter_2", 0)
elseif position == 4 then
-- The starter engine will run as long as you keep it in the last position.
xpl_command("sim/starters/engage_starter_2", 1)
end
end

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)
-- End Ignition Switch Right


--------------------------------------------------------------------
-- ICE Light
--------------------------------------------------------------------

function Switch_ICE_Light_callback(position)
print("The ICE Light switch got changed to position " .. position)

if position == 0 then
xpl_command("sim/lights/generic_01_light_tog", 1)
elseif position == 1 then
xpl_command("sim/lights/generic_01_light_tog", 0)
end
end

-- Here we create the hardware switch and to witch board (pin) it is connected
hw_switch_add("ARDUINO_MEGA2560_B_D26", Switch_ICE_Light_callback)


--------------------------------------------------------------------
-- Strope Light
--------------------------------------------------------------------

function Switch_Strope_Light_callback(position)
print("The Strope Light switch got changed to position " .. position)

if position == 0 then
xpl_command("sim/lights/strobe_lights_off")
elseif position == 1 then
xpl_command("sim/lights/strobe_lights_on")
end
end

-- Here we create the hardware switch and to witch board (pin) it is connected
hw_switch_add("ARDUINO_MEGA2560_B_D27", Switch_Strope_Light_callback)


--------------------------------------------------------------------
-- BCN Light
--------------------------------------------------------------------

function Switch_Beacon_Light_callback(position)
print("The Beacon Light switch got changed to position " .. position)

if position == 0 then
xpl_command("sim/lights/beacon_lights_off")
elseif position == 1 then
xpl_command("sim/lights/beacon_lights_on")
end
end

-- Here we create the hardware switch and to witch board (pin) it is connected
hw_switch_add("ARDUINO_MEGA2560_B_D28", Switch_Beacon_Light_callback)


--------------------------------------------------------------------
-- NAV Light
--------------------------------------------------------------------

function Switch_NAV_Light_callback(position)
print("The NAV Light switch got changed to position " .. position)

if position == 0 then
xpl_command("sim/lights/nav_lights_off")
elseif position == 1 then
xpl_command("sim/lights/nav_lights_on")
end
end

-- Here we create the hardware switch and to witch board (pin) it is connected
hw_switch_add("ARDUINO_MEGA2560_B_D29", Switch_NAV_Light_callback)


--------------------------------------------------------------------
-- Flood Light
--------------------------------------------------------------------

function Switch_Flood_Light_callback(position)
print("The Flood Light switch got changed to position " .. position)

if position == 0 then
xpl_command("laminar/b58/lighting/flood_light_switch", 1)
elseif position == 1 then
xpl_command("laminar/b58/lighting/flood_light_switch", 0)
end
end

-- Here we create the hardware switch and to witch board (pin) it is connected
hw_switch_add("ARDUINO_MEGA2560_B_D30", Switch_Flood_Light_callback)


--------------------------------------------------------------------
-- Panel Light
--------------------------------------------------------------------

function Switch_Panel_Light_callback(position)
print("The Panel Light switch got changed to position " .. position)

if position == 0 then
xpl_command("laminar/b58/lighting/panel_light_switch", 1)
elseif position == 1 then
xpl_command("laminar/b58/lighting/panel_light_switch", 0)
end
end

-- Here we create the hardware switch and to witch board (pin) it is connected
hw_switch_add("ARDUINO_MEGA2560_B_D31", Switch_Panel_Light_callback)


--------------------------------------------------------------------
-- Taxi Light
--------------------------------------------------------------------

function Switch_Taxi_Light_callback(position)
print("The Taxi Light switch got changed to position " .. position)

if position == 0 then
xpl_command("sim/lights/taxi_lights_off")
elseif position == 1 then
xpl_command("sim/lights/taxi_lights_on")
end
end

-- Here we create the hardware switch and to witch board (pin) it is connected
hw_switch_add("ARDUINO_MEGA2560_B_D32", Switch_Taxi_Light_callback)


--------------------------------------------------------------------
-- Landing Light Left
--------------------------------------------------------------------

function Switch_Landing_Light_Left_callback(position)
print("The Landing Light Left switch got changed to position " .. position)

if position == 0 then
xpl_command("sim/lights/landing_01_light_off")
elseif position == 1 then
xpl_command("sim/lights/landing_01_light_on")
end
end

-- Here we create the hardware switch and to witch board (pin) it is connected
hw_switch_add("ARDUINO_MEGA2560_B_D33", Switch_Landing_Light_Left_callback)


--------------------------------------------------------------------
-- Landing Light Right
--------------------------------------------------------------------

function Switch_Landing_Light_Right_callback(position)
print("The Landing Light Right switch got changed to position " .. position)

if position == 0 then
xpl_command("sim/lights/landing_02_light_off")
elseif position == 1 then
xpl_command("sim/lights/landing_02_light_on")
end
end

-- Here we create the hardware switch and to witch board (pin) it is connected
hw_switch_add("ARDUINO_MEGA2560_B_D34", Switch_Landing_Light_Right_callback)


--------------------------------------------------------------------
-- Landing Gear Leveler
--------------------------------------------------------------------

function Switch_Landing_Gear_callback(position)
print("The Landing Gear switch got changed to position " .. position)

if position == 0 then
xpl_command("sim/flight_controls/landing_gear_up")
elseif position == 1 then
xpl_command("sim/flight_controls/landing_gear_down")
end
end

-- Here we create the hardware switch and to witch board (pin) it is connected
hw_switch_add("ARDUINO_MEGA2560_B_D35", Switch_Landing_Gear_callback)


--------------------------------------------------------------------
-- Landing Gear Status Lights NLG --
--------------------------------------------------------------------

led_nlg = hw_led_add("ARDUINO_MEGA2560_B_D36", 0.0)

function new_data_xpl(acf_gear_deploy)

gear_deploy = acf_gear_deploy[1] >= 0.99

if acf_gear_deploy[1] < 0.99 then
hw_led_set(led_nlg, 0)
else
hw_led_set(led_nlg, 0.2)
end
end

xpl_dataref_subscribe("sim/aircraft/parts/acf_gear_deploy", "FLOAT[10]", new_data_xpl)


--------------------------------------------------------------------
-- Landing Gear Status Lights MLG LH --
--------------------------------------------------------------------

-- Create one LED, and have them off by default
led_mlg_lh = hw_led_add("ARDUINO_MEGA2560_B_D37", 0.0)

function new_data_xpl(acf_gear_deploy)

gear_deploy = acf_gear_deploy[2] >= 0.99

if acf_gear_deploy[2] < 0.99 then
hw_led_set(led_mlg_lh, 0)
else
hw_led_set(led_mlg_lh, 0.2)
end
end

xpl_dataref_subscribe("sim/aircraft/parts/acf_gear_deploy", "FLOAT[10]", new_data_xpl)


--------------------------------------------------------------------
-- Landing Gear Status Lights MLG RH --
--------------------------------------------------------------------

led_mlg_rh = hw_led_add("ARDUINO_MEGA2560_B_D38", 0.0)

function new_data_xpl(acf_gear_deploy)

gear_deploy = acf_gear_deploy[3] >= 0.99

if acf_gear_deploy[3] < 0.99 then
hw_led_set(led_mlg_rh, 0)
else
hw_led_set(led_mlg_rh, 0.2)
end
end

xpl_dataref_subscribe("sim/aircraft/parts/acf_gear_deploy", "FLOAT[10]", new_data_xpl)


--------------------------------------------------------------------
-- Landing Gear Status Light Transit --
--------------------------------------------------------------------

led_transit = hw_led_add("ARDUINO_MEGA2560_B_D39", 0.0)

function new_data_xpl(gear_in_transit)
print("The Landing Gear Transition Light is on when 1.0 and off when 0.0 is displayed: " .. gear_in_transit)

if gear_in_transit == 0 then
hw_led_set(led_transit, 0)
elseif gear_in_transit == 1 then
hw_led_set(led_transit, 1)
end
end

xpl_dataref_subscribe("laminar/b58/annun/gear_in_transit", "FLOAT", new_data_xpl)


--------------------------------------------------------------------
-- Parking Brake --
--------------------------------------------------------------------
xpl_switch_function="sim/flightmodel/controls/parkbrake"
xpl_switch_type="FLOAT"


function Parkbrake_callback(position)
print("The Parkbrake got changed to position " .. position)
if position == 0 then
xpl_dataref_write(xpl_switch_function,xpl_switch_type, 0)

elseif position == 1 then
xpl_dataref_write(xpl_switch_function,xpl_switch_type, 1)
end

end

hw_switch_add("ARDUINO_MEGA2560_B_D40", Parkbrake_callback)
When it looks not right, go around. It's easier to explain why you done it, than for others to finde out why you don't.

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

Re: RPI Communication Problem

#26 Post by Huberflight »

And last but not least. My code for the Annunciator Lights (ANN).

Code: Select all


----------------------------------------------------------------------------------
-- This is the script for the MIP with G1000 for the Baron B58. ------------------
-- It will connect the Annunciator Light LEDs with the Arduino on channel(H) -----
----------------------------------------------------------------------------------

------------------------------------------------------------------------------
-- Annunciator Test Light Gear
------------------------------------------------------------------------------

led_gear_test = hw_led_add("ARDUINO_UNO_H_D2", 0.0)

function new_data_annunciator(gear_test, gear_up)

if gear_test == 1 then
hw_led_set(led_gear_test, 1)
else
hw_led_set(led_gear_test, 0)
end
end

xpl_dataref_subscribe("sim/cockpit2/annunciators/gear_unsafe", "INT", new_data_annunciator)

------------------------------------------------------------------------------
-- Annunciator Light Gear
------------------------------------------------------------------------------

led_gear_up = hw_led_add("ARDUINO_UNO_H_D2", 0.0)

function new_data_xpl(gear_up)

if gear_up == 1 then
hw_led_set(led_gear_up, 1)
else
hw_led_set(led_gear_up, 0)
end
end

xpl_dataref_subscribe("sim/cockpit2/annunciators/gear_warning", "INT", new_data_xpl)


--------------------------------------------------------------------
-- Annunciator Light LH Generator Off
--------------------------------------------------------------------

led_lh_generator = hw_led_add("ARDUINO_UNO_H_D3", 0.0)

function new_data_xpl(gen_lh_off)

if (gen_lh_off == 1) or (gen_lh_off > 3) then
print("Generator LH is off")
hw_led_set(led_lh_generator, 1)
else
print("Generator LH is on")
hw_led_set(led_lh_generator, 0)
end
end

xpl_dataref_subscribe("sim/cockpit2/annunciators/generator", "INT", new_data_xpl)


--------------------------------------------------------------------
-- Annunciator Light RH Generator Off
--------------------------------------------------------------------

led_rh_generator = hw_led_add("ARDUINO_UNO_H_D4", 0.0)

function new_data_xpl(gen_rh_off)

if gen_rh_off >= 2 then
print("Generator RH is off")
hw_led_set(led_rh_generator, 1)
else
print("Generator RH is on")
hw_led_set(led_rh_generator, 0)
end
end

xpl_dataref_subscribe("sim/cockpit2/annunciators/generator", "INT", new_data_xpl)


-------------------------------------------------------------------------------
-- Annunciator Light Starter LH Test
-------------------------------------------------------------------------------

led_Starter_lh_rh_test = hw_led_add("ARDUINO_UNO_H_D5", 0.0)

function new_data_Annunciator_Starter_test(starter_lh_rh_test_on)


if(starter_lh_rh_test_on[1]) == 1 then
print("Starter is on")
hw_led_set(led_Starter_lh_rh_test, 1)
else
print("Starter is off")
hw_led_set(led_Starter_lh_rh_test, 0)
end
end

xpl_dataref_subscribe("sim/cockpit2/annunciators/igniter_on", "INT[8]", new_data_Annunciator_Starter_test)

-------------------------------------------------------------------------------
-- Annunciator Light Starter LH
-------------------------------------------------------------------------------

led_Starter_lh_generator = hw_led_add("ARDUINO_UNO_H_D5", 0.0)

function new_data_Annunciator_Starter(starter_lh_on)


if(starter_lh_on[1]) == 4 then
print("Starter is on")
hw_led_set(led_Starter_lh_generator, 1)
else
print("Starter is off")
hw_led_set(led_Starter_lh_generator, 0)
end
end

xpl_dataref_subscribe("sim/cockpit2/engine/actuators/ignition_key", "INT[8]", new_data_Annunciator_Starter)


-------------------------------------------------------------------------------
-- Annunciator Light Starter RH
-------------------------------------------------------------------------------

led_Starter_rh_generator = hw_led_add("ARDUINO_UNO_H_D5", 0.0)

function new_data_Annunciator_Starter(starter_rh_on)


if(starter_rh_on[2]) == 4 then
print("Starter is on")
hw_led_set(led_Starter_rh_generator, 1)
else
print("Starter is off")
hw_led_set(led_Starter_rh_generator, 0)
end
end

xpl_dataref_subscribe("sim/cockpit2/engine/actuators/ignition_key", "INT[8]", new_data_Annunciator_Starter)


--------------------------------------------------------------------
-- Annunciator Light Cabin Door Open and Test
--------------------------------------------------------------------

led_cabin_door_open = hw_led_add("ARDUINO_UNO_H_D6", 0.0)

function cabin_door(cabin_door_open)

if cabin_door_open == 1 then
print("Cabin Door is open")
hw_led_set(led_cabin_door_open, 1)
else
print("Cabin Door is shut")
hw_led_set(led_cabin_door_open, 0)
end
end

xpl_dataref_subscribe("sim/cockpit2/annunciators/cabin_door_open", "INT", cabin_door)


--------------------------------------------------------------------
-- Annunciator Light Pitot Tube is on
--------------------------------------------------------------------

led_Pitot_Heat = hw_led_add("ARDUINO_UNO_H_D7", 0.0)

function pitot_tube(pitot_tube_on)

if pitot_tube_on == 0 then
print("Pitot Tube is ON")
hw_led_set(led_Pitot_Heat, 1)
else
print("Pitot Tube is OFF")
hw_led_set(led_Pitot_Heat, 0)
end
end

xpl_dataref_subscribe("sim/cockpit2/annunciators/pitot_heat", "INT", pitot_tube)


--------------------------------------------------------------------
-- Annunciator Light Pitot Tube TEST is on
--------------------------------------------------------------------

led_Pitot_Heat_test = hw_led_add("ARDUINO_UNO_H_D7", 0.0)

function pitot_tube(pitot_tube_test_on)

if pitot_tube_test_on == 1 then
print("Pitot Tube TEST is ON")
hw_led_set(led_Pitot_Heat_test, 1)
else
print("Pitot Tube TEST is OFF")
hw_led_set(led_Pitot_Heat_test, 0)
end
end

xpl_dataref_subscribe("sim/cockpit2/annunciators/ice", "INT", pitot_tube)

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

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

Re: RPI Communication Problem

#27 Post by Huberflight »

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 to finde out why you don't.

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

Re: RPI Communication Problem

#28 Post by Huberflight »

*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 to finde out why you don't.

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

Re: RPI Communication Problem

#29 Post by Ralph »

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

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

Re: RPI Communication Problem

#30 Post by Huberflight »

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 to finde out why you don't.

Post Reply