Compass Stepper Motor

Support for Arduino in combination with Air Manager and Air Player

Moderators: russ, Ralph

Post Reply
Message
Author
Dcf
Posts: 2
Joined: Thu Apr 30, 2020 7:25 am

Compass Stepper Motor

#1 Post by Dcf »

Hello!
I am trying to make a compass with stepper motor 28BYJ-48 and one endstop.
I don't understand too much about LUA, so I'm probably doing something wrong. I have looked for more information in this forum ( this topic has already been discussed) but any sript works for me.
I can move my stepper correctly when I send the data from the Air Manager 3.6 window, but when I used the X-Plane (with the Cessna 172) it seems that the stepper motor lose steps and ardly moves. However I print the values ​​and they are ok.

I have tried to fix it by adding the function math.floor (x).It improves but doesn´t solve the problem.

Thank you for your help!


This is my script:

Code: Select all

stepper_compass = hw_stepper_motor_add("4WIRE_4STEP", 2048, 60, true,"ARDUINO_MEGA2560_A_D22", "ARDUINO_MEGA2560_A_D23", "ARDUINO_MEGA2560_A_D24", "ARDUINO_MEGA2560_A_D25" )

hw_input_add("ARDUINO_MEGA2560_A_D26", function(state)
  if state then
    hw_stepper_motor_calibrate(stepper_compass,0.01) 
  end
end)

function dir_mag(rumbo)
    rumbo=math.floor (rumbo)
    print("rumbo: "..rumbo)
    hw_stepper_motor_position(stepper_compass, rumbo/360 )
end

xpl_dataref_subscribe("sim/cockpit2/gauges/indicators/compass_heading_deg_mag", "FLOAT", dir_mag)

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

Re: Compass Stepper Motor

#2 Post by Sling »

We had a recent discussion on this and the conclusion was that it can’t keep up with the sim updates because it has to translate every update into the required motor pulses on the fly. The suggested solution was to take the motor driving pulse generation task away from the Arduino by using a dedicated motor driver such that the Arduino just needs to output the much simpler step and direction signals. Motor drivers that accept a step and direction input should work.

I did get some kind of a result by just using the ULN board but I had to slow down the speed and number of updates by sampling the input from the sim. Best to get a driver such as a A4988 or VID66-06 based board.

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

Re: Compass Stepper Motor

#3 Post by Ralph »

A hacky solution might be to update the motor position with a timer each x amount of ms. I'm not sure how often would be possible, maybe every 50 milliseconds.

Dcf
Posts: 2
Joined: Thu Apr 30, 2020 7:25 am

Re: Compass Stepper Motor Solved !

#4 Post by Dcf »

Sling wrote: Thu Apr 30, 2020 12:54 pm We had a recent discussion on this and the conclusion was that it can’t keep up with the sim updates because it has to translate every update into the required motor pulses on the fly. The suggested solution was to take the motor driving pulse generation task away from the Arduino by using a dedicated motor driver such that the Arduino just needs to output the much simpler step and direction signals. Motor drivers that accept a step and direction input should work.

I did get some kind of a result by just using the ULN board but I had to slow down the speed and number of updates by sampling the input from the sim. Best to get a driver such as a A4988 or VID66-06 based board.
Great! Thank you!
I´ve modified my 28BYJ-48 and used an Easydriver and it works!!! :D :D
Here it´s the code that I have used, maybe it can help someone:

Code: Select all

stepper_compass = hw_stepper_motor_add(VID66-06, 2048, 30, true,ARDUINO_MEGA2560_A_D22, ARDUINO_MEGA2560_A_D23)

hw_input_add(ARDUINO_MEGA2560_A_D24, function(state)
  if state then
    hw_stepper_motor_calibrate(stepper_compass,0.01) 
  end
end)

function dir_mag(rumbo)
    print(rumbo ..rumbo)
    hw_stepper_motor_position(stepper_compass, rumbo/360 )
end

xpl_dataref_subscribe(simcockpit2gaugesindicatorscompass_heading_deg_mag, FLOAT, dir_mag)

pscarratt
Posts: 32
Joined: Mon May 11, 2020 4:06 pm

Re: Compass Stepper Motor

#5 Post by pscarratt »

Hello gents. Going through this compass issue right now myself - bought some A4988 based controllers but I can't find any info on what type to enter into the hw_stepper_motor_add command? Will VID66-06 work?

Thanks!

pscarratt
Posts: 32
Joined: Mon May 11, 2020 4:06 pm

Re: Compass Stepper Motor

#6 Post by pscarratt »

Got my own answer by some elaborate searches of this forum - seems that the VID66-06 type will work with any stepper using direction and step commands.

Thanks!

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

Re: Compass Stepper Motor

#7 Post by Sling »

You got it. I think someone requested the wiki be updated to say exactly this.

User avatar
warbirdguy1
Posts: 25
Joined: Sat May 01, 2021 12:57 am
Location: United States

Re: Compass Stepper Motor Solved !

#8 Post by warbirdguy1 »

Dcf wrote: Thu Apr 30, 2020 5:45 pm
Sling wrote: Thu Apr 30, 2020 12:54 pm We had a recent discussion on this and the conclusion was that it can’t keep up with the sim updates because it has to translate every update into the required motor pulses on the fly. The suggested solution was to take the motor driving pulse generation task away from the Arduino by using a dedicated motor driver such that the Arduino just needs to output the much simpler step and direction signals. Motor drivers that accept a step and direction input should work.

I did get some kind of a result by just using the ULN board but I had to slow down the speed and number of updates by sampling the input from the sim. Best to get a driver such as a A4988 or VID66-06 based board.
Great! Thank you!
I´ve modified my 28BYJ-48 and used an Easydriver and it works!!! :D :D
Here it´s the code that I have used, maybe it can help someone:

Code: Select all

stepper_compass = hw_stepper_motor_add(VID66-06, 2048, 30, true,ARDUINO_MEGA2560_A_D22, ARDUINO_MEGA2560_A_D23)

hw_input_add(ARDUINO_MEGA2560_A_D24, function(state)
  if state then
    hw_stepper_motor_calibrate(stepper_compass,0.01) 
  end
end)

function dir_mag(rumbo)
    print(rumbo ..rumbo)
    hw_stepper_motor_position(stepper_compass, rumbo/360 )
end

xpl_dataref_subscribe(simcockpit2gaugesindicatorscompass_heading_deg_mag, FLOAT, dir_mag)
Do you have a good diagram to how you wired your 28BYJ to the EasyDriver? I have a large collection of these boards and if they are better than the ULN driver I am thinking about converting over.
"I know just enough to break something"

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

Re: Compass Stepper Motor

#9 Post by jph »

Hi guys,
Just to clarify one thing.
As sling says, The VID66-06 selection in AM is absolutely the correct one to use for any industry standard stepper driver. - @Corjan @Ralph - Please (pretty please ? :D ) can we have a generic industry standard option to remove confusion with the vid66 ? - it is exactly the same I believe. It just needs to be called something else. - and it would be really useful to clarify the role of the VID66-06 (hardware) in that it is excellent, BUT, limited to the X.xx series automotive steppers. and, also the X.xx steppers are limited to certain drivers.
(yes, It was me who asked it to be clarified in wiki)
but it is absolutely worth repeating the above and noting that the VID66-06 DRIVER IC / BOARD cannot be used with just any stepper. This chip is specifically designed to work with the X27 X.XX type automotive instrument stepper motors. Certainly not the normal steppers an A4988 would drive !

For the BYJ, then the choice is absolutely not the VID66 IC / BOARD - or any board using the VID66-06 ... but, it IS the only current option to chose in AM for the signalling as that is the only thing in AM that produces the correct (and again, industry standard) step / direction outputs.
I hope that is clear as it seems a bit ass backwards at first glance.

The above is really important. if I am not explaining it well enough then please ask and then I or others will try to help to clarify.

In the same way that you should never try to run an actual X27 X.XX automotive stepper from a 4988 driver board, although you would still need to select (at the moment) the VID66-06 option within AM to even control the A4988 board in the first place .... :o ;) - yes, it can be a bit head banging.
Anyway, regarding the a4988 and the BYJ
First you need to Modify the BYJ from unipolar to bipolar - see this link to a thread I posted in - https://siminnovations.com/forums/viewt ... 459#p36459
Then,
after getting rid of the red wire and cutting the track as per the thread, use a simple multimeter to find the two coils. - if you are unsure how to do this please ask.
Mark these (I usually simply twist the end of the pairs together a turn or so and then tape them) - or you could use a bit of heat shrink.
then if you check this page you will see the connections for the easydriver board- https://learn.sparkfun.com/tutorials/ea ... -guide/all
Connect one coil pair from the modded byj to the A+ A- pins, and the other coil to the B+ B- pins thats it. - if it runs in the wrong direction reverse the pins in one set of coils only.

The above also applies to any other standard bipolar stepper as far as coil finding and connection is concerned (be it for an A4988 or Easydriver etc.)
If using something like a NEMA 17 or 23, then coil pair finding is even easier as the motor is non geared. You don't even need a multimeter. Just play with the 4 wires and find two wires that when connected make the motor more difficult to turn by hand than without any wires connected - you will easily feel the difference. When you find a pair that makes the motor more difficult to turn, mark those wires as one coil. then the other 2 are the other coil. That's it. after that - same as above.

Hope that helps ?
Joe
Joe. CISSP, MSc.

Post Reply