Beta 35 with Arduino hangs when connecting to FS2020

Discuss suspected bugs with other users and Sim Innovations Staff

Moderators: russ, Ralph

Message
Author
User avatar
bartroozendaal
Posts: 30
Joined: Wed Jan 06, 2021 8:01 pm
Contact:

Re: Beta 35 with Arduino hangs when connecting to FS2020

#11 Post by bartroozendaal »

For full transparency: I did the following...

1) Reflashed the Arduino

2) Updated the script to no longer handle the avionics, but only the essential functions in the Cessna 152 I want to fly mainly. I leave handling the avionics in the 182 to the panel itself. I *think* there was a situation where the avionics was disabled, but that wasn't reflected on the panel itself. With the avionics disabled, there were no updates from FS, and no events I sent were picked up. Hence, there were no updates. Now I'm no longer managing the avionics from my own panel; and it looks like my instrument is now working correctly.

I will clone the 182 panel and remove the instruments the 152 doesn't have. I hope AM4 sees light soon, and there is a better 152 panel that I can use. I can write software, but cannot create graphics. A man needs to know his weaknesses :-)

As said, for transparency, I'm posting my code again

Code: Select all

-- /*
-- +----------------------------------------------------------+
-- |                                                          |
-- |   +-------------------+             (53)     (52)        |
-- |   |                   |                                  |
-- |   |                   |             (38)     (40)        |
-- |   |                   |             [28/29]  [24/25]     |
-- |   +-------------------+                                  |
-- |                                                          |
-- |     (48)    (51)    (50)    (39)    (41)     (43)        |
-- |                             [30/31] [26/27]  [22/23]     |
-- |                                                          |
-- |     (32)    (46)    (47)    (44)    (37)     (42)        |
-- |                                                          |
-- +----------------------------------------------------------+
-- */
local CLOCKWISE = 1
local COUNTERCLOCKWISE = -1

local btntogglecom1highlow = 38
local btntogglecom1 = 53
local knobcom1a = 28
local knobcom1b = 29

local btntogglecom2 = 52
local btntogglecom2highlow = 40
local knobcom2a = 24
local knobcom2b = 25

local btnonoffalternator = 48
local btnonoffbattery = 51
local btnonoffpitotheat = 50

local knobvor1a = 26
local knobvor1b = 27
local knobvor2a = 22
local knobvor2b = 23

local btnheadingtoggle = 39
local knobheadinga = 30
local knobheadingb = 31

local btnonoffcabinlight = 32
local btnonoffbeaconlights = 46
local btnonofflandinglights = 47
local btnonofftaxilights = 44
local btnonoffnavigationlights = 37
local btnonoffstrobelights = 42

local display

local whatcom = "FRACT"
local whatcom2 = "FRACT"
local masteralternator = true
local masterbattery = true
local headingmode = "HEADING_BUG"
local cabinlight = false
local beaconlights = false
local taxilights = false
local navlights = false

function addHardware()
    display = hw_chr_display_add("HD44780", 2, 16, "ARDUINO_MEGA2560_A_D6", "ARDUINO_MEGA2560_A_D7",
                  "ARDUINO_MEGA2560_A_D5", "ARDUINO_MEGA2560_A_D4", "ARDUINO_MEGA2560_A_D3", "ARDUINO_MEGA2560_A_D2")
    if (not (hw_connected(display))) then
        return false
    end
    if (not (hw_connected(hw_button_add("ARDUINO_MEGA2560_A_D" .. btntogglecom1highlow, noop, btntogglecom1highlowoff)))) then
        return false
    end
    if (not (hw_connected(hw_button_add("ARDUINO_MEGA2560_A_D" .. btntogglecom1, noop, btntogglecom1off)))) then
        return false
    end
    if (not (hw_connected(hw_dial_add("ARDUINO_MEGA2560_A_D" .. knobcom1a, "ARDUINO_MEGA2560_A_D" .. knobcom1b,
                              "TYPE_1_DETENT_PER_PULSE", knobcom1callback)))) then
        return false
    end
    if (not (hw_connected(hw_button_add("ARDUINO_MEGA2560_A_D" .. btntogglecom2highlow, noop, btntogglecom2highlowoff)))) then
        return false
    end
    if (not (hw_connected(hw_button_add("ARDUINO_MEGA2560_A_D" .. btntogglecom2, noop, btntogglecom2off)))) then
        return false
    end
    if (not (hw_connected(hw_dial_add("ARDUINO_MEGA2560_A_D" .. knobcom2a, "ARDUINO_MEGA2560_A_D" .. knobcom2b,
                              "TYPE_1_DETENT_PER_PULSE", knobcom2callback)))) then
        return false
    end
    if (not (hw_connected(hw_switch_add("ARDUINO_MEGA2560_A_D" .. btnonoffalternator, btnonoffalternatorchanged)))) then
        return false
    end
    if (not (hw_connected(hw_switch_add("ARDUINO_MEGA2560_A_D" .. btnonoffbattery, btnonoffbatterychanged)))) then
        return false
    end
    if (not (hw_connected(hw_button_add("ARDUINO_MEGA2560_A_D" .. btnheadingtoggle, noop, btnheadingtoggleoff)))) then
        return false
    end
    if (not (hw_connected(hw_switch_add("ARDUINO_MEGA2560_A_D" .. btnonoffpitotheat, btnonoffpitotheatchanged)))) then
        return false
    end
    if (not (hw_connected(hw_switch_add("ARDUINO_MEGA2560_A_D" .. btnonoffcabinlight, btnonoffcabinlightchanged)))) then
        return false
    end
    if (not (hw_connected(hw_switch_add("ARDUINO_MEGA2560_A_D" .. btnonoffbeaconlights, btnonoffbeaconlightschanged)))) then
        return false
    end
    if (not (hw_connected(hw_switch_add("ARDUINO_MEGA2560_A_D" .. btnonofflandinglights, btnonofflandinglightschanged)))) then
        return false
    end
    if (not (hw_connected(hw_switch_add("ARDUINO_MEGA2560_A_D" .. btnonofftaxilights, btnonofftaxilightschanged)))) then
        return false
    end
    if (not (hw_connected(hw_switch_add("ARDUINO_MEGA2560_A_D" .. btnonoffnavigationlights,
                              btnonoffnavigationlightschanged)))) then
        return false
    end
    if (not (hw_connected(hw_switch_add("ARDUINO_MEGA2560_A_D" .. btnonoffstrobelights, btnonoffstrobelightschanged)))) then
        return false
    end
    if (not (hw_connected(hw_dial_add("ARDUINO_MEGA2560_A_D" .. knobheadinga, "ARDUINO_MEGA2560_A_D" .. knobheadingb,
                              "TYPE_1_DETENT_PER_PULSE", knobheadingcallback)))) then
        return false
    end
    if (not (hw_connected(hw_dial_add("ARDUINO_MEGA2560_A_D" .. knobvor1a, "ARDUINO_MEGA2560_A_D" .. knobvor1b,
                              "TYPE_1_DETENT_PER_PULSE", knobvor1callback)))) then
        return false
    end
    if (not (hw_connected(hw_dial_add("ARDUINO_MEGA2560_A_D" .. knobvor2a, "ARDUINO_MEGA2560_A_D" .. knobvor2b,
                              "TYPE_1_DETENT_PER_PULSE", knobvor2callback)))) then
        return false
    end
    return true
end

function triggerOptionally(event, oldvalue, newvalue)
    if (not (oldvalue == newvalue)) then
        fs2020_event(event)
    end
end

function noop()
end

-- ************* COM1 **********
-- Switch com1 mode (inc/dec high/low)
function btntogglecom1highlowoff()
    whatcom = fif(whatcom == "FRACT", "WHOLE", "FRACT")
end

-- Switch frequencies COM1
function btntogglecom1off()
    fs2020_event("COM_STBY_RADIO_SWAP")
end

-- Radio COM1 frequency
function knobcom1callback(direction)
    fs2020_event("COM_RADIO_" .. whatcom .. fif(direction == CLOCKWISE, "_INC", "_DEC"))
end

function newCom1Frequencies(com1, com1stby)
    hw_chr_display_set_text(display, 0, string.format("%03.03f", com1) .. "  " .. string.format("%03.03f", com1stby))
end
-- ************* ENDOF COM1 **********

-- ************* COM2 **********
-- Switch com1 mode (inc/dec high/low)
function btntogglecom2highlowoff()
    whatcom2 = fif(whatcom2 == "FRACT", "WHOLE", "FRACT")
end

-- Switch frequencies COM2
function btntogglecom2off()
    fs2020_event("COM2_RADIO_SWAP")
end

-- Radio COM2 frequency
function knobcom2callback(direction)
    fs2020_event("COM2_RADIO_" .. whatcom2 .. fif(direction == CLOCKWISE, "_INC", "_DEC"))
end

function newCom2Frequencies(com2, com2stby)
    hw_chr_display_set_text(display, 1, string.format("%03.03f", com2) .. "  " .. string.format("%03.03f", com2stby))
end

-- ************* ENDOF COM2 **********

-- Turn power on/off
function btnonoffalternatorchanged(position)
    triggerOptionally("TOGGLE_MASTER_ALTERNATOR", masteralternator, (position == 1))
end

-- Turn avionics on/off
function btnonoffbatterychanged(position)
    triggerOptionally("TOGGLE_MASTER_BATTERY", masterbattery, (position == 1))
end

-- Toggle heading / ADF
function btnheadingtoggleoff()
    headingmode = fif(headingmode == "HEADING_BUG", "ADF_CARD", "HEADING_BUG")
end

-- Turn pitot head on/off
function btnonoffpitotheatchanged(position)
    fs2020_event("PITOT_HEAT_SET", position)
end

-- Turn fuel pump on/off
function btnonoffcabinlightchanged(position)
    triggerOptionally("TOGGLE_CABIN_LIGHTS", cabinlight, (position == 1))
end

-- Turn beacon lights on/off
function btnonoffbeaconlightschanged(position)
    triggerOptionally("TOGGLE_BEACON_LIGHTS", beaconlights, (position == 1))
end

-- Turn landing lights on/off
function btnonofflandinglightschanged(position)
    fs2020_event("LANDING_LIGHTS_SET", position)
end

-- Turn taxi lights on/off
function btnonofftaxilightschanged(position)
    triggerOptionally("TOGGLE_TAXI_LIGHTS", taxilights, (position == 1))
end

-- Turn navigation lights on/off
function btnonoffnavigationlightschanged(position)
    triggerOptionally("TOGGLE_NAV_LIGHTS", navlights, (position == 1))
end

-- Turn strobes on/off
function btnonoffstrobelightschanged(position)
    fs2020_event("STROBES_SET", position)
end

-- Change heading
function knobheadingcallback(direction)
    fs2020_event(headingmode .. fif(direction == CLOCKWISE, "_INC", "_DEC"))
end

-- Change VOR1
function knobvor1callback(direction)
    fs2020_event("VOR1_OBI" .. fif(direction == CLOCKWISE, "_INC", "_DEC"))
end

-- Change VOR2
function knobvor2callback(direction)
    fs2020_event("VOR2_OBI" .. fif(direction == CLOCKWISE, "_INC", "_DEC"))
end

function clearscreen()
    hw_chr_display_set_text(display, 0, "                ")
    hw_chr_display_set_text(display, 1, "                ")
end

-- *** Read variables from FS -----
function updateVariables(newMasterAlternator, newBeaconLights, newTaxiLights, newNavLights, newcabinlight,
    newMasterBattery)
    masteralternator = newMasterAlternator
    beaconlights = newBeaconLights
    taxilights = newTaxiLights
    navlights = newNavLights
    cabinlight = newcabinlight
    masterbattery = newMasterBattery
    if (not (masterbattery)) then
        clearscreen()
    else
        request_callback(newCom1Frequencies)
        request_callback(newCom2Frequencies)
    end
end

function subscribeVariables()
    fs2020_variable_subscribe("COM ACTIVE FREQUENCY:1", "Mhz", "COM STANDBY FREQUENCY:1", "MHz", newCom1Frequencies)
    fs2020_variable_subscribe("COM ACTIVE FREQUENCY:2", "Mhz", "COM STANDBY FREQUENCY:2", "MHz", newCom2Frequencies)
    fs2020_variable_subscribe("GENERAL ENG MASTER ALTERNATOR", "Bool", "LIGHT BEACON", "Bool", "LIGHT TAXI", "Bool",
        "LIGHT NAV", "Bool", "LIGHT CABIN", "Bool", "ELECTRICAL MASTER BATTERY", "Bool", updateVariables)
end

if (not (addHardware())) then
    print "Hardware is not ready..."
end
subscribeVariables()
Bart Roozendaal
https://fsarduino.com

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

Re: Beta 35 with Arduino hangs when connecting to FS2020

#12 Post by Ralph »

I haven't followed this closely. Was the problem solved or is there still something we should look at?

User avatar
bartroozendaal
Posts: 30
Joined: Wed Jan 06, 2021 8:01 pm
Contact:

Re: Beta 35 with Arduino hangs when connecting to FS2020

#13 Post by bartroozendaal »

It happened a couple of times again. I am suspecting there is some error in am or in the fs2020 Bridge. But, I can reset the application when it happens and start over.

Let's close the issue for now, but I might be back with more info on it.

If you have beta 33 available still somewhere, I can double check if it is indeed a new issue introduced with 35, or an old issue.
Bart Roozendaal
https://fsarduino.com

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

Re: Beta 35 with Arduino hangs when connecting to FS2020

#14 Post by Ralph »

No, we never store old versions. If it is something you can easily reproduce, then we can have an online debug session.

User avatar
bartroozendaal
Posts: 30
Joined: Wed Jan 06, 2021 8:01 pm
Contact:

Re: Beta 35 with Arduino hangs when connecting to FS2020

#15 Post by bartroozendaal »

Yes, it happens quite regularly. Please let me know what time would best suit you. I do have a day job, but with the working from home situation, it should be possible to free up a bit of time during working hours....

No rush for me; I know what to do to get the instrument working. Sometimes I need a couple of tries, but eventually I can get it working again.
Bart Roozendaal
https://fsarduino.com

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

Re: Beta 35 with Arduino hangs when connecting to FS2020

#16 Post by Ralph »

Today is an option for us. Do you have time?

User avatar
bartroozendaal
Posts: 30
Joined: Wed Jan 06, 2021 8:01 pm
Contact:

Re: Beta 35 with Arduino hangs when connecting to FS2020

#17 Post by bartroozendaal »

Yes. After 10:30 if that's ok with you. Ping me at bart@fysiofriends.com please. I can use Microsoft Teams (or anything else if you like that better)
Bart Roozendaal
https://fsarduino.com


User avatar
bartroozendaal
Posts: 30
Joined: Wed Jan 06, 2021 8:01 pm
Contact:

Re: Beta 35 with Arduino hangs when connecting to FS2020

#19 Post by bartroozendaal »

FYI and maybe future reference: the software (both mine as AirManager itself) worked fine. The problem I found was in a faulty soldering of the battery master switch. That gave intermittent errors in reading the status of that switch. Simply resoldering the ground solved this particular problem.

As you were .... ;-)
Bart Roozendaal
https://fsarduino.com

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

Re: Beta 35 with Arduino hangs when connecting to FS2020

#20 Post by jph »

bartroozendaal wrote: Fri Apr 16, 2021 11:25 am FYI and maybe future reference: the software (both mine as AirManager itself) worked fine. The problem I found was in a faulty soldering of the battery master switch. That gave intermittent errors in reading the status of that switch. Simply resoldering the ground solved this particular problem.

As you were .... ;-)
Credit where credit is due. ! :mrgreen:

Thanks ever so much for actually responding with the solution. It is, unfortunately rare that people do.
It is of no consequence that the issue is AM, Hardware, User, connections, setups whatever./ the main thing is that after a series of questions and answers to aid fault finding that you come back with an actual result that may well help many many others.
Thank you for you contribution and long may it continue, Your input is valued and indeed necessary to these forums.
Oh, how I hope some people learn from this. Again, a credit to you. THIS is how people learn.
Joe.
Joe. CISSP, MSc.

Post Reply