1

I have a stepper motor and at present it is controlled by a sketch all working fine. I need now to add it to a Win32 app to control it in circuit with existing Servo Motor. The servo Motor is working well via Firmata from Win32 app as follows

in setup part

arduino.pinMode(9, Arduino.SERVO);

In loop

 private void btn_set_servo_Click(object sender, EventArgs e)
        {
            int angle = Convert.ToInt32(Math.Round(numupdwn_degrees.Value, 0));
            arduino.servoWrite(9, angle);//tell the servo motor go to the position
        }

How do you drive the stepper motor using Firmata has anyone got an example I can see please?

user3884423
  • 111
  • 3

1 Answers1

0

Update: I have created a C# .Net App to connect and control the stepper Motor. The code and a Readme file is available at

https://github.com/zizwiz/Arduino_Projects/tree/main/FirmataStepperMotorTest


Initial Answer:

After a bit of thinking time I have managed to start the stepper motor running with Firmata protocol from my C# Win32 app. This post is just a basic outline I use to get it running I need lots more thinking and tinkering till I get what I need but in case this is helpful here it is.

Create a button to press to start. Create a thread when the button is clicked

   private void btn_stepper_start_Click(object sender, EventArgs e)
        {
           var thread = new Thread(() =>
           {
               while (true)
               {
                   RunStepper();
               }
       });

        thread.IsBackground = true;
        thread.Start();

    }

In the function RunStepper() create the following

 private void RunStepper()
        {
            while (true)
            {
                arduino.digitalWrite(7, Convert.ToByte(255));
                arduino.digitalWrite(8, 0);
                arduino.digitalWrite(9, 0);
                arduino.digitalWrite(10, 0);
                Task.Delay(10);
                arduino.digitalWrite(7, 0);
                arduino.digitalWrite(8, Convert.ToByte(255));
                arduino.digitalWrite(9, 0);
                arduino.digitalWrite(10, 0);
                Task.Delay(10);
                arduino.digitalWrite(7, 0);
                arduino.digitalWrite(8, 0);
                arduino.digitalWrite(9, Convert.ToByte(255));
                arduino.digitalWrite(10, 0);
                Task.Delay(10);
                arduino.digitalWrite(7, 0);
                arduino.digitalWrite(8, 0);
                arduino.digitalWrite(9, 0);
                arduino.digitalWrite(10, Convert.ToByte(255));
                Task.Delay(10);
            }
        }

As mentioned this small basic example is just a start to prove I may be able to do what I need.

user3884423
  • 111
  • 3