C# MotorHat Both Stepper Motors Run Same Time?

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
cschron
 
Posts: 11
Joined: Fri Dec 11, 2015 9:44 am

C# MotorHat Both Stepper Motors Run Same Time?

Post by cschron »

I'm using Adafruit Class Library for Windows IoT Core with the MotorHat.

I can get the stepper motors 1 & 2 to work individually. How do I get BOTH to work at the same time?

Looking for examples in C#.

Thanks!!

User avatar
Franklin97355
 
Posts: 23910
Joined: Mon Apr 21, 2008 2:33 pm

Re: C# MotorHat Both Stepper Motors Run Same Time?

Post by Franklin97355 »

Please post you code so we can see what you've tried.

User avatar
cschron
 
Posts: 11
Joined: Fri Dec 11, 2015 9:44 am

Re: C# MotorHat Both Stepper Motors Run Same Time?

Post by cschron »

Below is the code. When the button is pressed Stepper 1 works then Stepper 2 works. But what I want is both Steppers to go at same time. THANKS!!


Code: Select all


using Windows.UI.Xaml;
using AdafruitClassLibrary;
 
namespace Blinky
{
    public sealed partial class MainPage
    {

       static MotorHat motorHat;
       static MotorHat.Stepper stepper1;
       static MotorHat.Stepper stepper2;
         

    public MainPage()
        {
            InitializeComponent();

          
           motorHat = new MotorHat();
           motorHat.InitAsync(1600).ConfigureAwait(true);

            stepper1 = motorHat.GetStepper(100, 1);   
            stepper2 = motorHat.GetStepper(100, 2);   

        } 

   private void buttonON_Click(object sender, RoutedEventArgs e)  
        { 

            while (true)
            {

                motor1();
                motor2();

            } 

        } 

        public void motor1() { 
                
                   stepper1.SetSpeed(500); //10 rpm
                   stepper1.step(2000, MotorHat.Stepper.Command.FORWARD, MotorHat.Stepper.Style.DOUBLE); 

        }

        public void motor2()
        { 
                stepper2.SetSpeed(500); //10 rpm
                stepper2.step(2000, MotorHat.Stepper.Command.FORWARD, MotorHat.Stepper.Style.DOUBLE); 
        } 

    }

}

User avatar
adafruit2
 
Posts: 22144
Joined: Fri Mar 11, 2005 7:36 pm

Re: C# MotorHat Both Stepper Motors Run Same Time?

Post by adafruit2 »

you should perform one step at a time, interleaved

User avatar
cschron
 
Posts: 11
Joined: Fri Dec 11, 2015 9:44 am

Re: C# MotorHat Both Stepper Motors Run Same Time?

Post by cschron »

Thank you that worked!

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”