[solved] Strange potentiometer behaviour after AM 4.0 upgrade

Support for Arduino in combination with Air Manager and Air Player

Moderators: russ, Ralph

Message
Author
altack
Posts: 34
Joined: Mon Nov 21, 2016 1:13 pm

[solved] Strange potentiometer behaviour after AM 4.0 upgrade

#1 Post by altack »

Hi Guys,
I switched recently from AM 3.7.1 to the new AM 4.0
Before the change my Cessna 172 homecockpit was running fine and I made no hardware change whatsoever.
After upgrading to AM4.0 I used the leftmost "Device" button to find my 4 arduinos cards. I didn't flashed this cards under AM 4.0 (as it was alrerady done under the AM 3.7) and all of them have been recognized rapidly.
All of the cockpit is running fine except that all pot readings are very different from before the upgrade.
When the usual hw_adc_input was ranging from 0 to 1 (from GND to VCC) all I got now is running from 0.002 to 0.015 values !
Since I didn't changed anything on the hardware side I wonder why I got so strange readings ?
Of course I can patch that by editing the instruments logic and use a multiplier to obtain a 0-1 range value but I would rather understand this peculiarity and get it solved without code tinkering...
Do I need to flash my arduino cards with AM 4.0 ?
Is it a AM 4.0 related bug?
Any help would be appreciated !
Francois
Last edited by altack on Sat Jun 12, 2021 1:37 pm, edited 1 time in total.

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

Re: Strange potentiometer behaviour after AM 4.0 upgrade

#2 Post by Ralph »

You certainly have to. Especially if you use the ADC.

altack
Posts: 34
Joined: Mon Nov 21, 2016 1:13 pm

Re: Strange potentiometer behaviour after AM 4.0 upgrade

#3 Post by altack »

Thanks for your quick answer.
I will re-flash my Arduino cards, under AM 4.O this time, and let you know the outcome shortly...

altack
Posts: 34
Joined: Mon Nov 21, 2016 1:13 pm

Re: Strange potentiometer behaviour after AM 4.0 upgrade

#4 Post by altack »

Ok Ralph,

I flashed my 4 arduino cards: 3 Mega and 1 Uno
A Mega2560 (COM 3)
B Mega2560 (COM 4)
C Uno (COM 5)
D Mega2560 (COM 8)

All Mega 2560 are now running OK and, fortunately, pots are running normally now ! :D

You may consider the case closed except that, now, the Uno card is no longer running properly :shock:

I solely use the Uno for my wet compass (one stepper motor, one LED for internal lighting as output and one optical endstop LED as input).
The Uno flashing is proceeding ok and the card is recognized by AM 4.0 but there is no more communication with it or with any of the items connected to it.

I rebooted the PC and disconnected the Uno card so as to be sure everything was reseted properly.
I even flashed and added the card again (and removed the previous install) but to no avail...

Did I miss somerhing or shall I suspect a bug with Uno flashing code ?

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

Re: Strange potentiometer behaviour after AM 4.0 upgrade

#5 Post by Ralph »

Not that I know of, and haven't got any similar reports either.
Can you try just something simple like a button. Try to isolate things as much as possible.

altack
Posts: 34
Joined: Mon Nov 21, 2016 1:13 pm

Re: Strange potentiometer behaviour after AM 4.0 upgrade

#6 Post by altack »

I just did what you said, created a test instrument with only one physical push button on position D13: it works !

Afterward I added the output lighting LED wich is already connected on position D8 so that it is set to on (1.0) when the button is pushed and extinguished (0.0) when released : No Joy !

The lua logic is purely standard: hw_led_add with « ARDUINO_UNO_C_D8 » as argument and hw_led_set.

I remind that the whole Wet Compass was running OK before flashing the Uno card with AM 4.0.

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

Re: Strange potentiometer behaviour after AM 4.0 upgrade

#7 Post by Ralph »

Can you post the complete script of your compass?

altack
Posts: 34
Joined: Mon Nov 21, 2016 1:13 pm

Re: Strange potentiometer behaviour after AM 4.0 upgrade

#8 Post by altack »

Code: Select all


local Calibration_ok = false

local my_stepper = hw_stepper_motor_add("VID66-06", 2048, 30, true, "ARDUINO_UNO_C_D4", "ARDUINO_UNO_C_D3")
-- 2048: full step, 4096 half step recommended, 16384 1/8 step)

function Calibration(state)
    -- If we are not calibrated, we have to calibrate
    if not Calibration_ok then
            print ("Calibration_ok = "..tostring(Calibration_ok).." - We run Calibration")

        -- We turn to find North
        hw_stepper_motor_position(my_stepper, nil, "ENDLESS_CLOCKWISE")
    
        -- We waiting North
        if not state then
            hw_stepper_motor_calibrate(my_stepper, 0.01)    
                
            -- We stay on the North
            hw_stepper_motor_position(my_stepper, 0.0, "COUNTERCLOCKWISE")
            Calibration_ok = true
           print ("Calibration ok on North")
        end
    end
end

my_sensor = hw_input_add("ARDUINO_UNO_C_D2", Calibration)

function new_heading (heading)
    -- if not yet calibrate we leave
    heading = math.floor(heading)
    print(heading)

    if Calibration_ok then
 
        hw_stepper_motor_position(my_stepper, heading/360)
      
    end
end  

--xpl_dataref_subscribe("sim/cockpit2/gauges/indicators/compass_heading_deg_mag", "FLOAT", new_heading)
fsx_variable_subscribe("WISKEY COMPASS INDICATION DEGREES", "Degrees", new_heading)


just to let you know that the lighting LED is run from another instrument panel with this partial code:

Code: Select all

...
--Rhéostat PANEL LT
-- Callback function which is called when the ADC input state changes
-- 0.0 : GND (lowest voltage)
-- 1.0 : VCC (highest voltage)

-- Wet Compass LED internal ligthing
wc_led = hw_led_add("ARDUINO_UNO_C_D8", 0.0)

function panel_lt_adc_input_change(value)
  print("new value= " .. tostring(value) )
  fsx_variable_write("L:PanelLightKnob", "number", value*32)
--connexion avec l'éclairage du wet compass
    hw_led_set(wc_led, value)
end
...

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Strange potentiometer behaviour after AM 4.0 upgrade

#9 Post by Sling »

If that’s all the code and there’s no more then it won’t run because you don’t ever start the stepper moving. For the Calibration function to get called the sensor has to activate and before that can happen the motor has to be driving towards the sensor.

The LED code is also not complete as it doesn’t have something to call the function.

It helps if you post all the relevant code so we can see everything.

altack
Posts: 34
Joined: Mon Nov 21, 2016 1:13 pm

Re: Strange potentiometer behaviour after AM 4.0 upgrade

#10 Post by altack »

Thank you sling for your input.
You are right about the partial code so here is the total "*Extra switch panel" code:

Code: Select all

--*************************************************************************--
--BUTTON Function SECTION--
--*************************************************************************--

--ALT STATIC_AIR
function button_STATIC_AIR_pressed()
  -- The following print function is not necessary but can help you to verify that the button has been pressed
  print("Button STATIC_AIR pressed")

  -- Set the Alternate Static button ON FSX and Prepar3D
  fsx_variable_write("L:StaticAir", "number", 1)
end

function button_STATIC_AIR_released()
  -- The following print function is not necessary but can help you to verify that the button has been pressed
  print("Button STATIC_AIR released")

  -- Set the Alternate Static button OFF FSX and Prepar3D
  fsx_variable_write("L:StaticAir", "number", 0)
end

-- CABIN HEAT
function button_CABIN_HEAT_pressed()
  -- The following print function is not necessary but can help you to verify that the button has been pressed
  print("Button CABIN_HEAT pressed")

  -- Set the Cabin Heat to Full Heat FSX and Prepar3D
  fsx_variable_write("L:CabinTempControl", "percent", 100)
end

function button_CABIN_HEAT_released()
  -- The following print function is not necessary but can help you to verify that the button has been pressed
  print("Button CABIN_HEAT released")

  -- Set the Cabin Heat to Full Cold FSX and Prepar3D
  fsx_variable_write("L:CabinTempControl", "percent", 0)
end

--PARK_BRAKE
function button_PARK_BRAKE_pressed()
  -- The following print function is not necessary but can help you to verify that the button has been pressed
  print("Button PARK_BRAKE pressed")

  -- Set the Alternate Static button ON FSX and Prepar3D
  fsx_event("PARKING_BRAKES")
end

function button_PARK_BRAKE_released()
  -- The following print function is not necessary but can help you to verify that the button has been pressed
  print("Button PARK_BRAKE released")

  -- Set the Alternate Static button OFF FSX and Prepar3D
  fsx_event("PARKING_BRAKES")
end


--CABIN AIR
function button_CABIN_AIR_pressed()
  -- The following print function is not necessary but can help you to verify that the button has been pressed
  print("Button CABIN_AIR pressed")

  -- Set the Vent Air to Fully Open FSX and Prepar3D
  fsx_variable_write("L:CabinVent", "percent", 100)
end

function button_CABIN_AIR_released()
  -- The following print function is not necessary but can help you to verify that the button has been pressed
  print("Button CABIN_AIR released")

  -- Set the Vent Air to Fully Closed FSX and Prepar3D
  fsx_variable_write("L:CabinVent", "percent", 0)
end

--Rhéostat RADIO LT
-- Callback function which is called when the ADC input state changes
-- 0.0 : GND (lowest voltage)
-- 1.0 : VCC (highest voltage)
function radio_lt_adc_input_change(value)
  print("new value= " .. tostring(value) )
  fsx_variable_write("L:RadioLightKnob", "number", value*32)
--connexion avec l'éclairage des GNS Garmin de RXP
  fsx_variable_write("L:rxp.panel.rheostat_screen", "number", value)
end


--Rhéostat PANEL LT
-- Callback function which is called when the ADC input state changes
-- 0.0 : GND (lowest voltage)
-- 1.0 : VCC (highest voltage)

-- Wet Compass LED internal ligthing
wc_led = hw_led_add("ARDUINO_UNO_C_D8", 0.0)

function panel_lt_adc_input_change(value)
  print("new value= " .. tostring(value) )
  fsx_variable_write("L:PanelLightKnob", "number", value*32)
--connexion avec l'éclairage du wet compass
    hw_led_set(wc_led, value)
end


--Rhéostat GLARESHIELD LT
-- Callback function which is called when the ADC input state changes
-- 0.0 : GND (lowest voltage)
-- 1.0 : VCC (highest voltage)
function glareshield_lt_adc_input_change(value)
  print("new value= " .. tostring(value) )
  fsx_variable_write("L:GlareshieldLightKnob", "number", value*32)
end

--Rhéostat PEDESTAL LT
-- Callback function which is called when the ADC input state changes
-- 0.0 : GND (lowest voltage)
-- 1.0 : VCC (highest voltage)

-- Pededestal LED Lighting
pl_led = hw_led_add("ARDUINO_MEGA2560_A_D8", 0.0)

function pedestal_lt_adc_input_change(value)
  print("new value= " .. tostring(value) )
  fsx_variable_write("L:PedestalLightKnob", "number", value*32)
--connexion avec l'éclairage du pedestal
  hw_led_set(pl_led, value)
end

--Button Hardware section
--++++++++++++++++++++++++++++--
--A5
hw_button_add("Button_STATIC_AIR", button_STATIC_AIR_pressed, button_STATIC_AIR_released)

--"B" D13
hw_button_add("Button_PARK_BRAKE_B_D13", button_PARK_BRAKE_pressed, button_PARK_BRAKE_released)

--D12
hw_button_add("Button_CABIN_HEAT", button_CABIN_HEAT_pressed, button_CABIN_HEAT_released)

--D13                                                                                                12
hw_button_add("Button_CABIN_AIR", button_CABIN_AIR_pressed, button_CABIN_AIR_released)

--A1
hw_adc_input_add("RADIO_LT_ARDUINO_MEGA2560_A_A1", radio_lt_adc_input_change)

--A2
hw_adc_input_add("PANEL_LT_ARDUINO_MEGA2560_A_A2", panel_lt_adc_input_change)

--A3
hw_adc_input_add("GLARESHIELD_LT_ARDUINO_MEGA2560_A_A3", glareshield_lt_adc_input_change)

--A4
hw_adc_input_add("PEDESTAL_LT_ARDUINO_MEGA2560_A_A4", pedestal_lt_adc_input_change)


Regarding the actual Wet Compass code I'm far from being an expert so I'm eager to improve it.
I guess I've been lucky so far because from May 2020 until this morning, the Compass worked OK.
Here are two short videos I made last year for you to see that:
https://youtu.be/SmL-xYP_6ck

https://youtu.be/wzz9d5T0_yk

Again, thanks for your help

Post Reply