I know this is really late, but in case you did not solve this. I have a similar altimeter that is built like a clock. 10,000 ft is 10 full rotations and so on. Air manager expects steppers to have a position of 0-1. What I did was to tell it that I had 15 times the steps per revolution than I actually had. I then calculated the steps per foot and used that in my stepper position code. This gives position 1 at 15,000 ft.
stepper_alt = hw_stepper_motor_add("Altimeter", "4WIRE_4STEP", 61440, 900) -- Multiplied step and rpm by 15 to allow up to 15K ft without running into the 0-1 limit
In the callback from the altitude subscription, I have
altitude = var_cap(altitude,0,15000)
Homing is accomplished as follows. I set a variable AltimeterCalibrated = 0. This variable is used to ensure this only runs when needed and only as long as needed. First I run the altimeter forward for 2 seconds, just in case my last flight landed in Death Vally and is negative. Since it can be 15 turns from home and a timer would not work for the primary homing, I am using an optical light sensor on either side of the gear train. There are holes drilled in all three gears so that only when all three hands are at zero will the holes be lined up and let light through. The optical sensor is setup in Air Manager as a switch that is triggered when the altimeter reaches 0. The module is powered on using a hardware output to the VCC pin on the module, which when it goes high the module is powered. When the module detects light, the output pin on the module goes low. This triggers the hw_switch function which sets the altimeter value to 0.0, sets AltimeterCalibrated = 1 so that it does not run again, and then turns the module off to save power. The hardware is one of these modules.
https://www.amazon.com/dp/B099K5188Q?ps ... ct_details
I use a pin to apply power to the module and another pin to detect that it saw light through a hole drilled through all three gears.
The code looks like this:
local AltimeterCalibrated = 0
hw_switch_add("Altimeter Home", 1,function(position) --optical light sensor
if position == 1 and AltimeterCalibrated == 0 then
print("Altimeter is at zero")
AltimeterCalibrated = 1
led_alt_sensor = hw_output_add("Altimeter Sensor", false)
local function zero_altimeter()
--run the altimeter backward until the zero sensor is tripped
if AltimeterCalibrated == 0 then --only run this on power up
--Run altimeter back to zero
hw_stepper_motor_position(stepper_alt, nil, "ENDLESS_COUNTERCLOCKWISE") -- run continuously until the hardware sees it at zero.
--Preload altimeter in case it was at a negative altitude
AltimeterCalibrated = 0
hw_output_set(led_alt_sensor, true) -- Turn on the sensor module
hw_stepper_motor_position(stepper_alt, nil, "ENDLESS_CLOCKWISE") -- Run altimeter forward in case it is negative
timer_start(2000,zero_altimeter()) -- After 2 seconds running forward, call the function to find home.
If you want to know more, let me know.
Support for Arduino in combination with Air Manager and Air Player