Skip to main content
Fixed syntax highlighting.
Source Link
VE7JRO
  • 2.5k
  • 19
  • 28
  • 31
#include <Arduino.h>
#include <Vnh2sp30.h>

//              ENA A   B   PWM   CS    inv
Vnh2sp30  mtrL( A0, 7,  8,  5,    A2,   0);             

void setup() {                          
  Serial.begin(9600);
}

void loop() {
  if (Serial.available() > 0)   {
    String first  = Serial.readStringUntil(',');
    Serial.read(); 
    String second = Serial.readStringUntil(','); 
    Serial.read();
    String third = Serial.readStringUntil(','); 
    Serial.read();
    String echo = Serial.readString();
    Serial.println(echo);
       if(first == "start"){
                Serial.println("Starting DC motor");
                int duration = atoi(second.c_str());
                int power = atoi(third.c_str());
                int starttime = millis();
                int endtime = starttime;
                while ((endtime - starttime) <= duration) // mS
                {
                  endtime = millis();
                  mtrL.run(1023);
                }
                mtrL.stop();
                Serial.println("DONE");
       }
   }
}
#include <Arduino.h>
#include <Vnh2sp30.h>

//              ENA A   B   PWM   CS    inv
Vnh2sp30  mtrL( A0, 7,  8,  5,    A2,   0);             

void setup() {                          
  Serial.begin(9600);
}

void loop() {
  if (Serial.available() > 0)   {
    String first  = Serial.readStringUntil(',');
    Serial.read(); 
    String second = Serial.readStringUntil(','); 
    Serial.read();
    String third = Serial.readStringUntil(','); 
    Serial.read();
    String echo = Serial.readString();
    Serial.println(echo);
       if(first == "start"){
                Serial.println("Starting DC motor");
                int duration = atoi(second.c_str());
                int power = atoi(third.c_str());
                int starttime = millis();
                int endtime = starttime;
                while ((endtime - starttime) <= duration) // mS
                {
                  endtime = millis();
                  mtrL.run(1023);
                }
                mtrL.stop();
                Serial.println("DONE");
       }
   }
}
#include "BasicStepperDriver.h"

int incomingByte = 0;   // for incoming serial data
String readString = "";

void setup() {
    Serial.begin(9600);
    motors.begin();
}

void loop() {
    if (Serial.available() > 0) {
    String first  = Serial.readStringUntil(','); // start
    Serial.read(); 
    String second = Serial.readStringUntil(','); // motor number
    Serial.read();
    String third = Serial.readStringUntil(','); // motor steps
    Serial.read();
    String fourth = Serial.readStringUntil(','); // duration (millisec)
    Serial.read();
    String fifth = Serial.readStringUntil(','); // deg
                if(first == "start") {
                  if(second == "ALL") {
                    Serial.println("Starting stepper motor ALL");
                    int steps = atoi(third.c_str());
                    int duration = atoi(fourth.c_str());
                    int deg = atoi(fifth.c_str());
                    
                    BasicStepperDriver stepper1(steps, DIR, STEP, ENBL);
                    stepper1.enable();
                    stepper1.setMicrostep(MICROSTEPS);
                    stepper1.setRPM(MAX_RPM);
                    
                    BasicStepperDriver stepper2(steps, DIR_2, STEP_2, ENBL_2);
                    stepper2.enable();
                    stepper2.setMicrostep(MICROSTEPS);
                    stepper2.setRPM(MAX_RPM);

                    BasicStepperDriver stepper3(steps, DIR_3, STEP_3, ENBL_3);
                    stepper3.enable();
                    stepper3.setMicrostep(MICROSTEPS);
                    stepper3.setRPM(MAX_RPM);

                    BasicStepperDriver stepper4(steps, DIR_4, STEP_4, ENBL_4);
                    stepper4.enable();
                    stepper4.setMicrostep(MICROSTEPS);
                    stepper4.setRPM(MAX_RPM);
                    
                    int starttime = millis();
                    int endtime = starttime;
                    while ((endtime - starttime) <= duration) // mS
                    {
                      stepper1.rotate(deg);  
                      stepper2.rotate(deg);  
                      stepper3.rotate(deg);
                      stepper4.rotate(deg);
                      endtime = millis();
                    }
                    stepper1.disable();
                    stepper2.disable();
                    stepper3.disable();
                    stepper4.disable();
                    Serial.println("DONE");
                  }
                }
        }
}
#include "BasicStepperDriver.h"

int incomingByte = 0;   // for incoming serial data
String readString = "";

void setup() {
    Serial.begin(9600);
    motors.begin();
}

void loop() {
    if (Serial.available() > 0) {
    String first  = Serial.readStringUntil(','); // start
    Serial.read(); 
    String second = Serial.readStringUntil(','); // motor number
    Serial.read();
    String third = Serial.readStringUntil(','); // motor steps
    Serial.read();
    String fourth = Serial.readStringUntil(','); // duration (millisec)
    Serial.read();
    String fifth = Serial.readStringUntil(','); // deg
                if(first == "start") {
                  if(second == "ALL") {
                    Serial.println("Starting stepper motor ALL");
                    int steps = atoi(third.c_str());
                    int duration = atoi(fourth.c_str());
                    int deg = atoi(fifth.c_str());
                    
                    BasicStepperDriver stepper1(steps, DIR, STEP, ENBL);
                    stepper1.enable();
                    stepper1.setMicrostep(MICROSTEPS);
                    stepper1.setRPM(MAX_RPM);
                    
                    BasicStepperDriver stepper2(steps, DIR_2, STEP_2, ENBL_2);
                    stepper2.enable();
                    stepper2.setMicrostep(MICROSTEPS);
                    stepper2.setRPM(MAX_RPM);

                    BasicStepperDriver stepper3(steps, DIR_3, STEP_3, ENBL_3);
                    stepper3.enable();
                    stepper3.setMicrostep(MICROSTEPS);
                    stepper3.setRPM(MAX_RPM);

                    BasicStepperDriver stepper4(steps, DIR_4, STEP_4, ENBL_4);
                    stepper4.enable();
                    stepper4.setMicrostep(MICROSTEPS);
                    stepper4.setRPM(MAX_RPM);
                    
                    int starttime = millis();
                    int endtime = starttime;
                    while ((endtime - starttime) <= duration) // mS
                    {
                      stepper1.rotate(deg);  
                      stepper2.rotate(deg);  
                      stepper3.rotate(deg);
                      stepper4.rotate(deg);
                      endtime = millis();
                    }
                    stepper1.disable();
                    stepper2.disable();
                    stepper3.disable();
                    stepper4.disable();
                    Serial.println("DONE");
                  }
                }
        }
}
#include <Arduino.h>
#include <Vnh2sp30.h>

//              ENA A   B   PWM   CS    inv
Vnh2sp30  mtrL( A0, 7,  8,  5,    A2,   0);             

void setup() {                          
  Serial.begin(9600);
}

void loop() {
  if (Serial.available() > 0)   {
    String first  = Serial.readStringUntil(',');
    Serial.read(); 
    String second = Serial.readStringUntil(','); 
    Serial.read();
    String third = Serial.readStringUntil(','); 
    Serial.read();
    String echo = Serial.readString();
    Serial.println(echo);
       if(first == "start"){
                Serial.println("Starting DC motor");
                int duration = atoi(second.c_str());
                int power = atoi(third.c_str());
                int starttime = millis();
                int endtime = starttime;
                while ((endtime - starttime) <= duration) // mS
                {
                  endtime = millis();
                  mtrL.run(1023);
                }
                mtrL.stop();
                Serial.println("DONE");
       }
   }
}
#include "BasicStepperDriver.h"

int incomingByte = 0;   // for incoming serial data
String readString = "";

void setup() {
    Serial.begin(9600);
    motors.begin();
}

void loop() {
    if (Serial.available() > 0) {
    String first  = Serial.readStringUntil(','); // start
    Serial.read(); 
    String second = Serial.readStringUntil(','); // motor number
    Serial.read();
    String third = Serial.readStringUntil(','); // motor steps
    Serial.read();
    String fourth = Serial.readStringUntil(','); // duration (millisec)
    Serial.read();
    String fifth = Serial.readStringUntil(','); // deg
                if(first == "start") {
                  if(second == "ALL") {
                    Serial.println("Starting stepper motor ALL");
                    int steps = atoi(third.c_str());
                    int duration = atoi(fourth.c_str());
                    int deg = atoi(fifth.c_str());
                    
                    BasicStepperDriver stepper1(steps, DIR, STEP, ENBL);
                    stepper1.enable();
                    stepper1.setMicrostep(MICROSTEPS);
                    stepper1.setRPM(MAX_RPM);
                    
                    BasicStepperDriver stepper2(steps, DIR_2, STEP_2, ENBL_2);
                    stepper2.enable();
                    stepper2.setMicrostep(MICROSTEPS);
                    stepper2.setRPM(MAX_RPM);

                    BasicStepperDriver stepper3(steps, DIR_3, STEP_3, ENBL_3);
                    stepper3.enable();
                    stepper3.setMicrostep(MICROSTEPS);
                    stepper3.setRPM(MAX_RPM);

                    BasicStepperDriver stepper4(steps, DIR_4, STEP_4, ENBL_4);
                    stepper4.enable();
                    stepper4.setMicrostep(MICROSTEPS);
                    stepper4.setRPM(MAX_RPM);
                    
                    int starttime = millis();
                    int endtime = starttime;
                    while ((endtime - starttime) <= duration) // mS
                    {
                      stepper1.rotate(deg);  
                      stepper2.rotate(deg);  
                      stepper3.rotate(deg);
                      stepper4.rotate(deg);
                      endtime = millis();
                    }
                    stepper1.disable();
                    stepper2.disable();
                    stepper3.disable();
                    stepper4.disable();
                    Serial.println("DONE");
                  }
                }
        }
}
#include <Arduino.h>
#include <Vnh2sp30.h>

//              ENA A   B   PWM   CS    inv
Vnh2sp30  mtrL( A0, 7,  8,  5,    A2,   0);             

void setup() {                          
  Serial.begin(9600);
}

void loop() {
  if (Serial.available() > 0)   {
    String first  = Serial.readStringUntil(',');
    Serial.read(); 
    String second = Serial.readStringUntil(','); 
    Serial.read();
    String third = Serial.readStringUntil(','); 
    Serial.read();
    String echo = Serial.readString();
    Serial.println(echo);
       if(first == "start"){
                Serial.println("Starting DC motor");
                int duration = atoi(second.c_str());
                int power = atoi(third.c_str());
                int starttime = millis();
                int endtime = starttime;
                while ((endtime - starttime) <= duration) // mS
                {
                  endtime = millis();
                  mtrL.run(1023);
                }
                mtrL.stop();
                Serial.println("DONE");
       }
   }
}
#include "BasicStepperDriver.h"

int incomingByte = 0;   // for incoming serial data
String readString = "";

void setup() {
    Serial.begin(9600);
    motors.begin();
}

void loop() {
    if (Serial.available() > 0) {
    String first  = Serial.readStringUntil(','); // start
    Serial.read(); 
    String second = Serial.readStringUntil(','); // motor number
    Serial.read();
    String third = Serial.readStringUntil(','); // motor steps
    Serial.read();
    String fourth = Serial.readStringUntil(','); // duration (millisec)
    Serial.read();
    String fifth = Serial.readStringUntil(','); // deg
                if(first == "start") {
                  if(second == "ALL") {
                    Serial.println("Starting stepper motor ALL");
                    int steps = atoi(third.c_str());
                    int duration = atoi(fourth.c_str());
                    int deg = atoi(fifth.c_str());
                    
                    BasicStepperDriver stepper1(steps, DIR, STEP, ENBL);
                    stepper1.enable();
                    stepper1.setMicrostep(MICROSTEPS);
                    stepper1.setRPM(MAX_RPM);
                    
                    BasicStepperDriver stepper2(steps, DIR_2, STEP_2, ENBL_2);
                    stepper2.enable();
                    stepper2.setMicrostep(MICROSTEPS);
                    stepper2.setRPM(MAX_RPM);

                    BasicStepperDriver stepper3(steps, DIR_3, STEP_3, ENBL_3);
                    stepper3.enable();
                    stepper3.setMicrostep(MICROSTEPS);
                    stepper3.setRPM(MAX_RPM);

                    BasicStepperDriver stepper4(steps, DIR_4, STEP_4, ENBL_4);
                    stepper4.enable();
                    stepper4.setMicrostep(MICROSTEPS);
                    stepper4.setRPM(MAX_RPM);
                    
                    int starttime = millis();
                    int endtime = starttime;
                    while ((endtime - starttime) <= duration) // mS
                    {
                      stepper1.rotate(deg);  
                      stepper2.rotate(deg);  
                      stepper3.rotate(deg);
                      stepper4.rotate(deg);
                      endtime = millis();
                    }
                    stepper1.disable();
                    stepper2.disable();
                    stepper3.disable();
                    stepper4.disable();
                    Serial.println("DONE");
                  }
                }
        }
}
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user