0

C# MotorHat Both Stepper Motors Run Same Time?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

C# MotorHat Both Stepper Motors Run Same Time?

by cschron on Sat Sep 25, 2021 9:46 am

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!!

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

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

by franklin97355 on Sat Sep 25, 2021 7:54 pm

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

franklin97355
 
Posts: 22270
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

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

by cschron on Sun Sep 26, 2021 7:51 am

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 | TOGGLE FULL SIZE

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);
        }

    }

}

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

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

by adafruit2 on Sun Sep 26, 2021 4:49 pm

you should perform one step at a time, interleaved

adafruit2
Site Admin
 
Posts: 20291
Joined: Fri Mar 11, 2005 7:36 pm

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

by cschron on Mon Sep 27, 2021 2:47 pm

Thank you that worked!

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

Please be positive and constructive with your questions and comments.