Stepper motor with more revolution for altimeter.

Support for Arduino in combination with Air Manager and Air Player

Moderators: russ, Ralph

Message
Author
Orzelek
Posts: 4
Joined: Fri Sep 24, 2021 5:06 pm

Stepper motor with more revolution for altimeter.

#1 Post by Orzelek »

Hi everyone.
This is my first topic :)
I almost have done my first Cessna 172 cockpit just before I noticed quite a big problem.
I have a single stepper motor powered altimeter and to work properly it has to move around with the 100ft needle, so e.q. to achieve 10'000ft stepper has to execute 10 full rotations.
The problem is that AM allows to move from 0.0 to 1.0, so only 360°.
I read something about message port but I don't know If I fully understand the topic.
Maybe with message port I can use another arduino board to run just stepper motors (I need also 2 of them to run heading indicator and autopilot hdg bug) and code them with arduino ino, but I have no idea how it should look like :/
I also tried to make it with "if, elseif" to specify every 1000ft but only first 1000ft (360°) worked and then stepper died.
Any advice will be nice :D
IMG_2884.jpg
If You open in full window mode, altimeter is in the top (without stepper) and at the left-bottom site are located 2 steppers for heading indicator.
IMG_2883.jpg
Photo from front.

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

Re: Stepper motor with more revolution for altimeter.

#2 Post by Ralph »

You can go from 0.99 for example to 0, without going back. You'll just have to some smart scripting with fastest and slowest, and probably using % so you always stay at 1 and below.

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

Re: Stepper motor with more revolution for altimeter.

#3 Post by Sling »

Perhaps if you posted your existing code we could take a look.

Orzelek
Posts: 4
Joined: Fri Sep 24, 2021 5:06 pm

Re: Stepper motor with more revolution for altimeter.

#4 Post by Orzelek »

This how my code looks like for now. It has to has more "elseif" for each 1000ft, but as I mentioned before, for now only first 1000ft works and then stepper die...
I'm also worry about that if simulator starts at e.g. 3400ft, my stepper would run only 400ft forward because of my non smart code.

Code: Select all

--Made by Wendy, FlightSimparts.eu
--use as you like

local CollectData = false

function input_change(state)
if state == false then
hw_stepper_motor_calibrate(id, 0.0)
hw_stepper_motor_position(id, 0.0)
CollectData = true
end
print("state = " .. tostring(state))
end

-- Initialization starting, rotate clockwise for 3 seconds
id = hw_stepper_motor_add("Altimeter", "4WIRE_4STEP", 2048, 60)

-- Initialization starting, rotate clockwise for 3 seconds
hw_stepper_motor_position(id, nil, "ENDLESS_COUNTERCLOCKWISE")

input = hw_input_add("ZeroStop", input_change)

local function new_altitude(altitude)

altimeter_altitude = var_cap(altitude, 0, 40000)

if CollectData == true then

hw_stepper_motor_position(id, 1/1000 * altitude) -- , "FASTEST")

elseif (CollectData == true and altitude >= 1000) then

hw_stepper_motor_position(id, 1/1000 * (altitude - 1000))

else

end
end

xpl_dataref_subscribe("sim/cockpit2/gauges/indicators/altitude_ft_pilot", "FLOAT", new_altitude)

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

Re: Stepper motor with more revolution for altimeter.

#5 Post by Sling »

Your code will always do the first if because that condition is always met after calibration. But rather than fix that, It just seems excessive to use all those if..else. Why not just something like this. You will need to handle the minus altitudes slightly differently but i'll let you do that.

Code: Select all

    if CollectData == true then
 
        hw_stepper_motor_position(id, altitude % 1000)
 
    end    

Orzelek
Posts: 4
Joined: Fri Sep 24, 2021 5:06 pm

Re: Stepper motor with more revolution for altimeter.

#6 Post by Orzelek »

Sling wrote: Sat Sep 25, 2021 1:41 pm Your code will always do the first if because that condition is always met after calibration. But rather than fix that, It just seems excessive to use all those if..else. Why not just something like this. You will need to handle the minus altitudes slightly differently but i'll let you do that.

Code: Select all

    if CollectData == true then
 
        hw_stepper_motor_position(id, altitude % 1000)
 
    end    
Yeah!
If I could I would buy u a beer :P
Now my code looks like that and works just fine! I even deleted the "var_cap" values and works both positive and negative altitudes.
Thanks a lot :D

Code: Select all

if CollectData == true then
        
       hw_stepper_motor_position(id, ((altitude % 1000) / 1000), "FASTEST")
       
       end
Ok, edit... After assembly I still need to calibrate it :P After all it works!

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

Re: Stepper motor with more revolution for altimeter.

#7 Post by Sling »

Happy to assist. Glad you got it working.

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

Re: Stepper motor with more revolution for altimeter.

#8 Post by Ralph »

The only problem I can think of is that if you reset your flight, it can get out of sync. So it might be smart to set the position/altitude through a timer.

I think that there are a few Cessna 172 instruments that use this for the animation. You could use this as an example.

Orzelek
Posts: 4
Joined: Fri Sep 24, 2021 5:06 pm

Re: Stepper motor with more revolution for altimeter.

#9 Post by Orzelek »

Ralph wrote: Sun Sep 26, 2021 9:36 am The only problem I can think of is that if you reset your flight, it can get out of sync. So it might be smart to set the position/altitude through a timer.

I think that there are a few Cessna 172 instruments that use this for the animation. You could use this as an example.
You might be right, I have to look for it, thanks.

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

Re: Stepper motor with more revolution for altimeter.

#10 Post by Ralph »

Let us know if you need help with that part.

Post Reply