arduino diy needle seder with steep motors

Im sory for not answering on reply 17. I will post tomorow full program whitch is created in stepper.h library whitch workes fine , and what i succeeded to make in accelstepper library for now .
And yes i study and learnt some funkcion , how to start motor , move to anf somthing elshe but i eont know how to connect all together and put condition thet all of that works together .

Gm

This is stepeer.h code whitch work fine for me but i can use it , like you say

#include <Stepper.h>

const int stepsPerRevolution = 45;  // 70% left

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup() {
  // set the speed at 40 rpm:
  myStepper.setSpeed(40);
  // initialize the serial port:
  Serial.begin(9600);
}

void loop() {
  // step one revolution  in one direction:(left)
  Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  delay(2000);//2 second pause

  // step one revolution in the other direction:(right)
  Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
  delay(2000);//2 second pause
}

soo i try transfer this code in AccelStepeer.h library

#include <AccelStepper.h>

AccelStepper myStepper(AccelStepper::FULL4WIRE, 8, 9, 10, 11);

const int stepsPerRevolution = 45;  // 70% left

void setup()
{
  myStepper.setMaxSpeed(40.0);
  myStepper.setSpeed(40);
}

void loop()
{
    Serial.println("clockwise");
    myStepper.move(stepsPerRevolution);
    delay(2000);//2 second pause

    Serial.println("counterclockwise");
    myStepper.move(-stepsPerRevolution);
    delay(2000);

    // step one revolution in the other direction:(right)
    // --or absolute positioning
    Serial.println("counterclockwise");
    myStepper.moveTo(-stepsPerRevolution);
    myStepper.runSpeedToPosition();
    delay(2000);//2 second pause*/
}

code upload succes but nothing hepend with motor, motor freeze, can i do this on this way or i nitu use aproximtely miles to define position left and right, and how i can connect this code with (for loop) so i can count numper of repeated steps (19 time ) ? i hope i put all what you need to see where im stuck

tnx for reply

Please spend a few hours studying the AccelStepper library and trying some of its examples before trying to use it.

Then you will find that

myStepper.move();

has a very different meaning from its use in the simple Stepper library.

You need calls to .run() or .runSpeed() to make the motor move.

It is not reasonable to ask questions here that you could learn by studying the documentation for the library. I there is something in the documentation that you don't understand then I don't mind helping.

...R

Tnx for rply ,

None of them exmples dosen't work , motor only worm up and doing rly litle steps. Mybe is problem because i try to control this with l298 driver ?

marinac94:
None of them exmples dosen't work , motor only worm up and doing rly litle steps. Mybe is problem because i try to control this with l298 driver ?

Then post the exact code that you uploaded for one of the examples that doesn't work and post a photo of a simple drawing showing how you have everything connected.

I don't think you have told us exactly what stepper motors you are using so post a link to the motor datasheet.

And tell us what motor power supply you are using (volts and amps).

...R

Hello , this is sketch of conection. Imgur: The magic of the Internet , i have computer power whitch is revised to kolektoe for 12 V (16A) ,5V (20A) 3.3V (14A) , step motor - Mitsumi M42SP-6TG and i obly found this motor have 10 ohm , nothing else... I found it in computer printer .. connection - 5V and GND to arduino , 12 Vand GND to l298 shild , step motor wires to A+A-B+B- , in1,in2,in3,in4- 8,9,10,11 pins on arduino , program whitch i wana rune is this ...

  #include <AccelStepper.h>     AccelStepper stepper( AccelStepper::FULL4WIRE, 8, 9, 10, 11);
void setup()
{  
  stepper.setMaxSpeed(150);
  stepper.setAcceleration(100);
}
void loop()
{    
  stepper.moveTo(500);
  while (stepper.currentPosition() != 300) // Full speed up to 300
    stepper.run();
  stepper.stop(); // Stop as fast as possible: sets new target
  stepper.runToPosition(); 
  // Now stopped after quickstop
  // Now go backwards
  stepper.moveTo(-500);
  while (stepper.currentPosition() != 0) // Full speed basck to 0
    stepper.run();
  stepper.stop(); // Stop as fast as possible: sets new target
  stepper.runToPosition(); 
  // Now stopped after quickstop
}

. Tnx for rply

The program you posted is wrong. What you have on the first line should be on two lines.

Does it work when you correct that?

And why not start with the much simpler ConstantSpeed example?

If your program still does not work please post a diagram showing all the connections (as I requested in Reply #24). It is too easy to misunderstand verbal wiring descriptions.

...R

I know this need to be in 2 row , bad coping with mobile phone sry for that , const spped examp rune fine . Problem with program whitch i post before is same direction full time , after quick stop motor will need go back to 0 , be he rune in same direction

marinac94:
I know this need to be in 2 row , bad coping with mobile phone sry for that

Then please take the trouble to use your PC so that I am not commenting on irrelevant problems. It should also mean that you avoid silly spelling mistakes.

const spped examp rune fine .

Can you make the motor move in both directions by modifying that simple example?

...R

yes i can this code will work fine , rune to position, and back or ? my motor only vibrating in same place

#include <AccelStepper.h>
int motor = 150;
AccelStepper stepper(AccelStepper::FULL4WIRE, 8, 9, 10, 11);


void setup()
{  
  stepper.setMaxSpeed(200);
  stepper.setSpeed(100);
  stepper.moveTo(motor);
  stepper.runSpeedToPosition();
}

void loop()
{
  if (stepper.distanceToGo() == 0 )
   stepper.moveTo(-stepper.currentPosition());
   stepper.setSpeed(100);
    stepper.runSpeedToPosition();
   }

marinac94:
yes i can this code will work fine , rune to position, and back or ? my motor only vibrating in same place

It's a very strange way to do the two directions but I can see how it would work.

What I can't understand is why you say "this code will work fine , rune to position, and back" and then in the same sentence say "or ? my motor only vibrating in same place"

Does it work fine? or does it not work fine?

Try this

#include <AccelStepper.h>
int motor = 150;
AccelStepper stepper(AccelStepper::FULL4WIRE, 8, 9, 10, 11);


void setup()
{ 
  stepper.setMaxSpeed(200);
  stepper.setSpeed(100);
  stepper.moveTo(motor);
  stepper.runSpeedToPosition();
  delay(1000);
  stepper.moveTo(-stepper.currentPosition());
  stepper.setSpeed(100);
  stepper.runSpeedToPosition();
}

void loop()
{

}

and if that is better think hard about what is different about it and why the change has helped.

...R

What i said in last post i ment that code witch i send should work fine as much as I could see in Accelstepper library, but it doesn't work . I'm sorry for misunderstanding. I'll check your code later. Thanks

marinac94:
What i said in last post i ment that code witch i send should work fine as much as I could see in Accelstepper library, but it doesn't work .

Then make things even simpler. Just stay with the simple AccelStepper ConstantSpeed example until that works properly.

Try it, and tell me exactly what happens.

...R

hello, I'm testing your code and it does not work, motor only frezzes, it dose not move

finally i succeeded :DD

this code do what i rly need, move to position pause 2 second, and return to 0, how can i set limit of repetition, i need 19 repetition. Can i just write 19 time same code ori can use somthing like this (i=1; i<=19; i++)

tnx you for all help, Everything is in learning and researching :slight_smile:

#include <AccelStepper.h>

AccelStepper stepper(AccelStepper::FULL4WIRE, 8, 9, 10, 11);


 void setup()
{  
  // Change these to suit your stepper if you want
  stepper.setMaxSpeed(100);
  stepper.setAcceleration(50);
  stepper.setSpeed(50);
  stepper.moveTo(40); 
  delay(2000);
  while (stepper.distanceToGo() != 0) 
  {  stepper.run();
  
  }

  stepper.moveTo(0);
  delay(2000);// set target back at start position
  while (stepper.distanceToGo() != 0) 
  {  stepper.run(); 
  }

  stepper.moveTo(40);
  delay(2000);
  while (stepper.distanceToGo() != 0) 
  {  stepper.run(); 
  }
}

void loop()
{

}

marinac94:
finally i succeeded :DD

this code do what i rly need, move to position pause 2 second, and return to 0, how can i set limit of repetition,

Glad to hear you are making progress.

Before you go any further you now need to learn how to use the AccelStepper library properly - with the code in loop() rather than in setup().

Get the ConstantSpeed example to work and report back.

...R