Modify code that controls DCmoto so that Nema17 control with MC338870

Hello everyone

since a little while ago I'm in the arduino world, but you do not know me because I make my topics in the Spanish section.

but for some time I have not found a solution to my problem in the Spanish forum so I try in English hoping someone can help me

I have this code that works me very well controlling a DC motor

/*


 The code is written by Farshid Jafari Harandi,
 (C) Spekel, Spekel.se y modificado por cuchara con ayuda del foro arduino

 */
int Revers =5;       // boton de cambi de direccion 
int ledPin =  13;    // LED connected to digital pin 13
int pwmPin = 11;     // PWM Motor driver (/D2 pin pin on MC338870 motor board)
int motorPin1 = 7;   // Motor pin 1 (IN1 on MC338870 motor board)
int motorPin2 = 8;   // Motor pin 2 (IN2 on MC338870 motor board)
int pot = 0;        // Potentiometer pin on analog input 0
                    //Leave D1 and /FS and /FB unconnceted
                    //Connect the EN to +5V on Arduino board


int state = HIGH;      // the current state of the output pin
int reading;           // the current reading from the input pin
int previous = LOW;    // the previous reading from the input pin

// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0;         // the last time the output pin was toggled
long debounce = 200;   // the debounce time, increase if the output flickers







int val;
// The setup() method runs once, when the sketch starts

 void setup()   {         
  pinMode(Revers, INPUT);       
  pinMode(ledPin, OUTPUT); // initialize the digital pin as an output:
  pinMode(pwmPin, OUTPUT); // initialize the digital pin as an output:
  pinMode(motorPin1, OUTPUT); // initialize the digital pin as an output:
  pinMode(motorPin2, OUTPUT); // initialize the digital pin as an output:
  digitalWrite(Revers,HIGH);
   
   Serial.begin(9600);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()                     
{


   reading = digitalRead(Revers);

  // if the input just went from LOW and HIGH and we've waited long enough
  // to ignore any noise on the circuit, toggle the output pin and remember
  // the time
  if (reading == HIGH && previous == LOW && millis() - time > debounce) {
    if (state == HIGH)
      state = LOW;
    else
      state = HIGH;

    time = millis();    
  }

  digitalWrite(ledPin, state);

  previous = reading;


val = analogRead(pot);
 val = map(val,0,1023,-255,255);
 Serial.println(val);


  if (state){
 if (val >= 0) 
  
     {
    digitalWrite(ledPin,HIGH);
    digitalWrite(motorPin1,LOW);
    digitalWrite(motorPin2,HIGH);
    analogWrite(pwmPin,val);
     }
   else
   {
    val *= -1;
    digitalWrite(ledPin,LOW);
    digitalWrite(motorPin1,HIGH);
    digitalWrite(motorPin2,LOW);
    analogWrite(pwmPin,val);
   }
  }
  if (!state)  {
    if (val >= 0) {
    digitalWrite(ledPin,HIGH);
    digitalWrite(motorPin1,HIGH);
    digitalWrite(motorPin2,LOW);
    analogWrite(pwmPin,val);
   }
   else {
    val *= -1;
    digitalWrite(ledPin,LOW);
    digitalWrite(motorPin1,LOW);
    digitalWrite(motorPin2,HIGH);
    analogWrite(pwmPin,val);
   }
  
  }
   
   delay(100);

  
   
}

here is a demonstration video:

I connect it like that

What I am looking for and I do not get is to get the same result by controlling a stepper motor nema17

I tried many modifications to the code but I do not think it will be useful because nothing happens

I hope you can help me

Thanks

I tried many modifications to the code but I do not think it will be useful because nothing happens

Get a stepper motor driver. Dump that piece of crap. You do NOT control a stepper that way.

Hi, What are the specs of your stepper, a link to data would help.

Tom.. :)

Hi guys

Thank you for your replays

The reason why I try to do this using this driver is because I tried it before with a (easy drive board) and it does not work, I proves all multiple codes and examples I change motors espc etc.

the specs of my stepper

Like PaulS said, proper stepper driver like these from Pololu will make your life much easier. The A4988 or DRV8825 are good choices and are available on Ebay for pretty cheap. You will also need a proper 12V power supply.

Ok already buy the ones that recommend me

-Newest A3967 EasyDriver Shield Stepper -Stepstick Drv8825 Stepper Motor Driver Reprap

but I go back to my initial problem... which is the transformation of the code from a DCmotor to a Stepermotor

then how do I have to modify it ?

Thank you very much in advance

then how do I have to modify it ?

Use a text editor.

You have given NO details on exactly what the motor is supposed to do. Frankly, I have my doubts that a stepper motor is even the right choice.

This post has good basic stepper information including how to use the DRV8825 driver.

PaulS: Use a text editor.

You have given NO details on exactly what the motor is supposed to do. Frankly, I have my doubts that a stepper motor is even the right choice.

ok, I modified the original post and I added a video. (I already received the DRV8825 Stepper Motor Driver)

cuchara: ok, I modified the original post

You wrote the original post nearly 2 months ago. I'm not going back to read it now and try to remember what it was used to have so as to know what is new.

Put that Original Post back the way it was and post your new information in your next Reply after this one.

...R

the only thing I add is the video link :https://www.youtube.com/watch?v=wkZ23_Z1l3w&feature=youtu.be

These links may help Stepper Motor Basics Simple Stepper Code

also look up the AccelStepper library

...R

Thank you very much for all the information you bring

But like I said before, My english is very poor ... although it seems so simple for you, for me it is difficult to identify and save only what I need for my project.

actually if someone can give me an example "code" that has some similarities, I can probably modify it

or I need someone to talk to me and explain things to me as a baby

or even ... does someone accept to adapt my existing code to the new components? I can reward it by sending components such as Arduinos

I would really love to learn to create my own codes from 0. but I do not have time to learn

I spend a month trying to create a simple code.

till now I have found examples and I have been modifying them until I get what I want but for this I can not find an example that looks enough.