0

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?

4
  • You're saying it's working fine. So what is your problem?
    – PMF
    Jun 28 at 19:22
  • The servo motor is working fine but the stepper motor is not working at all. A Servo motor and a Stepper motor are two different animals. I need both to work from the same Win10 controller. Jun 29 at 5:34
  • I don't have any of these, so I can only guess. I think you need the AccelStepper firmata module. What client library are you using on the PC?
    – PMF
    Jun 29 at 6:13
  • Thanks for help and understood but that is a library for a sketch not running Firmata protocol that will allow me to run from C# Win32 app with the other items. Jun 29 at 7:40
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.