Go Down

### Topic: stepper motor connection with driver. (Read 1 time)previous topic - next topic

#### Robin2

#15
##### Mar 12, 2018, 07:03 pm
the total wight of the arm is 600 grams and length is 58 cm. so the torque is T = 27.53kgcm
How did you figure that out? On my calculator 0.6 * 58 = 34.8

If the arm is 58 cm long and the weight is uniformly distributed it will act at the half-way point = 29cm and with 0.6kg that gives a torque of 0.6 * 29 = 17.4 kg.cm.

Which is still marginal for a 19kg.cm motor

Whichever calculation is correct a 45 kg.cm motor should be strong enough. How are you powering the motor? How have you set the current limit on your stepper driver?

Post a photo of your machine.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

#### shramik

#16
##### Mar 12, 2018, 07:24 pm
the motor driver is connected to a 12v 7.5ah lead acid battery. the motor coil currernt is set to 2.8a .

#### Robin2

#17
##### Mar 12, 2018, 11:25 pm

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

#### Robin2

#18
##### Mar 12, 2018, 11:27 pm
Quote
Ideal Motor for CNC machines and other machinery. Standard NEMA 34 frame size. 45Kgcm bipolar configuration motor with RMCS-1101 Stepper Drive. Ideal performance at 4.2Amp configuration.
so it is hardly surprising if it is not producing full torque when you limit the current to 2.8 amps.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

#### shramik

#19
##### Mar 13, 2018, 07:45 am
thank you sir, changing to 4.2a seems to be getting the arm on top position but when a object is placed in the gripper it falls back to bottom position. looks like i have to buy a bigger motor or reduce the weight of the arm. back to designing again.

#### Robin2

#20
##### Mar 13, 2018, 09:30 am
looks like i have to buy a bigger motor or reduce the weight of the arm. back to designing again.
I suspect a much better solution would be to gear down the movement between the motor and the arm. For example with a 3:1 gearing you would have 3 times the torque and I doubt very much if the movement would be too slow.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

#### shramik

#21
##### Mar 14, 2018, 02:44 pm
sir, i have made some changes and have some trouble with controlling speed of the stepper motor. i changed millisBetweenSteps but not working.

Code: [Select]
`// testing a stepper motor with a Pololu A4988 driver board or equivalent// this version uses millis() to manage timing rather than delay()// and the movement is determined by a pair of momentary push switches// press one and it turns CW, press the other and it turns CCWbyte directionPin = 3;byte stepPin = 2;byte buttonCWpin = 32;byte buttonCCWpin = 33;boolean buttonCWpressed = false;boolean buttonCCWpressed = false;byte ledPin = 13;unsigned long curMillis;unsigned long prevStepMillis = 0;unsigned long millisBetweenSteps = 20; // milliseconds#define RC_1 24#define RC_2 25#define RC_3 26#define RC_4 27#define RC_5 28#define RC_6 29int ptr = 0;int RC_1_Value;int RC_2_Value;int RC_3_Value;int RC_4_Value;int RC_5_Value;int RC_6_Value;void setup() {  Serial.begin(9600);  Serial.println("Starting Stepper Demo with millis()");  pinMode(directionPin, OUTPUT);  pinMode(stepPin, OUTPUT);  pinMode(ledPin, OUTPUT);  pinMode(buttonCWpin, INPUT_PULLUP);  pinMode(buttonCCWpin, INPUT_PULLUP);  pinMode(RC_1, INPUT);  pinMode(RC_2, INPUT);  pinMode(RC_3, INPUT);  pinMode(RC_4, INPUT);  pinMode(RC_5, INPUT);  pinMode(RC_6, INPUT);}void loop() {  curMillis = millis();  ptr += 1;  if (ptr > 5) {    ptr = 0;  }  buttonCCWpressed = false;  buttonCWpressed = false;  switch (ptr) {    case 0:      RC_1_Value = pulseIn(RC_1, HIGH, 60000);      break;    case 1:      RC_2_Value = pulseIn(RC_2, HIGH, 60000);      break;    case 3:      RC_3_Value = pulseIn(RC_3, HIGH, 60000);      break;    case 4:      RC_4_Value = pulseIn(RC_4, HIGH, 60000);      break;  }  if (RC_3_Value > 1650 && (RC_4_Value < 1749 && RC_4_Value > 1251))  {    buttonCWpressed = true;    actOnButtons();  }}void actOnButtons() {  if (buttonCWpressed == true) {    digitalWrite(directionPin, LOW);    singleStep();  }  if (buttonCCWpressed == true) {    digitalWrite(directionPin, HIGH);    singleStep();  }}void singleStep() {  if (curMillis - prevStepMillis >= millisBetweenSteps) {    prevStepMillis += millisBetweenSteps;    digitalWrite(stepPin, HIGH);    digitalWrite(stepPin, LOW);  }}`

#### shramik

#22
##### Mar 14, 2018, 05:08 pm
sir, also i have tried accelstepper library and got something working. but now i am stuck at something.
i am able to move it clockwise and anticlockwise for certain number of revolution. now i want it work to rotate clockwise or anticlockwise until it touches limit switch on either end.

Code: [Select]
`#include <AccelStepper.h>int dir_pin = 7;int pwm_pin = 6;int brake_pin = 5;int dir_pin1 = 10;int pwm_pin1 = 11;#define RC_1 24#define RC_2 25#define RC_3 26#define RC_4 27#define RC_5 28#define RC_6 29int ptr = 0;int RC_1_Value;int RC_2_Value;int RC_3_Value;int RC_4_Value;int RC_5_Value;int RC_6_Value;int pinStep = 2;int pinDir = 3;AccelStepper mystepper(1, pinStep, pinDir);void setup(){  Serial.begin(9600);  mystepper.setMaxSpeed(3000.0);  mystepper.setSpeed(3000.0);  mystepper.setAcceleration(2000.0);  pinMode(dir_pin, OUTPUT);  pinMode(pwm_pin, OUTPUT);  pinMode(dir_pin1, OUTPUT);  pinMode(pwm_pin1, OUTPUT);  pinMode(brake_pin, OUTPUT);  pinMode(RC_1, INPUT);  pinMode(RC_2, INPUT);  pinMode(RC_3, INPUT);  pinMode(RC_4, INPUT);  pinMode(RC_5, INPUT);  pinMode(RC_6, INPUT);}//*****************************************************void loop()//*****************************************************{  ptr += 1;  if (ptr > 5) {    ptr = 0;  }  switch (ptr) {    case 0:      RC_1_Value = pulseIn(RC_1, HIGH, 60000);      break;    case 1:      RC_2_Value = pulseIn(RC_2, HIGH, 60000);      break;    case 3:      RC_3_Value = pulseIn(RC_3, HIGH, 60000);      break;    case 4:      RC_4_Value = pulseIn(RC_4, HIGH, 60000);      break;  }  //robot movement motor  if (RC_2_Value > 1351 && RC_2_Value < 1649 && RC_1_Value > 1251 && RC_1_Value < 1749)  {    //Serial.println("stop");    analogWrite(pwm_pin, 0);    analogWrite(pwm_pin1, 0);  }  if (RC_2_Value > 1650 && (RC_1_Value < 1749 && RC_1_Value > 1251))  {    Serial.println("forward");    analogWrite(pwm_pin, 50);    digitalWrite(dir_pin, LOW);    analogWrite(pwm_pin1, 50);    digitalWrite(dir_pin1, LOW);  }  if (RC_1_Value > 1750 && (RC_2_Value < 1649 && RC_2_Value > 1351))  {    Serial.println("Right");    analogWrite(pwm_pin, 50);    digitalWrite(dir_pin, HIGH);    analogWrite(pwm_pin1, 50);    digitalWrite(dir_pin1, LOW);  }  if (RC_2_Value < 1350 && (RC_1_Value < 1749 && RC_1_Value > 1251))  {    Serial.println("backward");    analogWrite(pwm_pin, 50);    digitalWrite(dir_pin, HIGH);    analogWrite(pwm_pin1, 50);    digitalWrite(dir_pin1, HIGH);  }  if (RC_1_Value < 1250 && (RC_2_Value < 1649 && RC_2_Value > 1351))  {    Serial.println("left");    analogWrite(pwm_pin, 50);    digitalWrite(dir_pin, LOW);    analogWrite(pwm_pin1, 50);    digitalWrite(dir_pin1, HIGH);  }  if (RC_2_Value > 1650 && RC_1_Value < 1250 )  {    Serial.println("forward left");    analogWrite(pwm_pin, 50);    digitalWrite(dir_pin, LOW);    analogWrite(pwm_pin1, 25);    digitalWrite(dir_pin1, LOW);  }  if (RC_2_Value > 1650 && RC_1_Value > 1750 )  {    Serial.println("forward right");    analogWrite(pwm_pin, 25);    digitalWrite(dir_pin, LOW);    analogWrite(pwm_pin1, 50);    digitalWrite(dir_pin1, LOW);  }  if (RC_2_Value < 1350 && RC_1_Value < 1250 )  {    Serial.println("backward left");    analogWrite(pwm_pin, 50);    digitalWrite(dir_pin, HIGH);    analogWrite(pwm_pin1, 25);    digitalWrite(dir_pin1, HIGH);  }  if (RC_2_Value < 1350 && RC_1_Value > 1750 )  {    Serial.println("backward right");    analogWrite(pwm_pin, 25);    digitalWrite(dir_pin, HIGH);    analogWrite(pwm_pin1, 50);    digitalWrite(dir_pin1, HIGH);  }  //robot arm motor  if (RC_3_Value > 1650 && (RC_4_Value < 1749 && RC_4_Value > 1251))  {    Serial.println(" both arm forward");    /*int x = map(RC_3_Value, 1650, 2000, 600, 800);      Serial.println(x);      mystepper.moveTo(x);      mystepper.setSpeed(100);      mystepper.runSpeedToPosition();*/          analogWrite(pwm_pin, 0);    analogWrite(pwm_pin1, 0);    mystepper.runToNewPosition(0);  }  if (RC_3_Value < 1350 && (RC_4_Value < 1749 && RC_4_Value > 1251))  {    Serial.println(" both arm backward");        analogWrite(pwm_pin, 0);    analogWrite(pwm_pin1, 0);    mystepper.runToNewPosition(12000);  }}`

#### Robin2

#23
##### Mar 14, 2018, 07:19 pm
sir, i have made some changes and have some trouble with controlling speed of the stepper motor. i changed millisBetweenSteps but not working.
"Not working" gives me no useful information from which to help you. You need to describe exactly what happens in as much detail as possible.

If you don't need acceleration then the AccelStepper library is not ideal for moving to a limit switch - that's not what it is designed for.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

#### shramik

#24
##### Mar 14, 2018, 07:48 pm
sir, i have two limit switch at two end which act as end points A and B. an rc remote controls this stepper motor to move an robot arm up and down till the end points. now i have moved to stepper library but not tested this code. will this work?

Code: [Select]
`  if (RC_3_Value > 1650 && (RC_4_Value < 1749 && RC_4_Value > 1251))  {    Serial.println(" both arm forward");    analogWrite(pwm_pin, 0);    analogWrite(pwm_pin1, 0);    int sensorVal = digitalRead(LimitSwitchPinA);    if (sensorVal == HIGH)    {      Serial.println(" right");      stepper.step(1);    }  }  if (RC_3_Value < 1350 && (RC_4_Value < 1749 && RC_4_Value > 1251))  {    Serial.println(" both arm backward");    analogWrite(pwm_pin, 0);    analogWrite(pwm_pin1, 0);    int sensorVal1 = digitalRead(LimitSwitchPinB);    if (sensorVal1 == HIGH)    {      Serial.println(" right");      stepper.step(-1);    }  }`

#### Robin2

#25
##### Mar 14, 2018, 08:11 pm
but not tested this code. will this work?
Test it first. There is no point asking or answering a question if the code works as you require.

And you have not responded to my Reply #23. It is very difficult to help when there is no response to things I say.

...r

Two or three hours spent thinking and reading documentation solves most programming problems.

#### shramik

#26
##### Mar 15, 2018, 03:22 amLast Edit: Mar 15, 2018, 04:55 am by shramik
Test it first. There is no point asking or answering a question if the code works as you require.

i will test it out and let you know.

And you have not responded to my Reply #23. It is very difficult to help when there is no response to things I say.

...r

sorry sir.

"Not working" gives me no useful information from which to help you. You need to describe exactly what happens in as much detail as possible.

as the stepper motor was not able to lift the arm, i changed the mechanism to nut and bolt and now it requires the steppe motor to move very fast in clockwise and anticlockwise to bring it down or up.
so the code in post #21 i tried increasing the speed by changing millisBetweenSteps (lowered and increased the value), but the sleep did not increased.

If you don't need acceleration then the AccelStepper library is not ideal for moving to a limit switch - that's not what it is designed for.

...R
so i shifted to accelstepper library as i would achieve higher speed. but could not get it working with limit switch.

now i have shifted to stepper library.

#### shramik

#27
##### Mar 21, 2018, 05:03 pm
hi robin2,
we made changes in design and have used a rack and pinion to move the arm up and bottom. only that sometime the gears slip and the position is not achieved. so i placed a limit switch at the bottom and it homes every time it reaches the switch and then moves up again.
Code: [Select]
`if (RC_3_Value > 1650 && RC_4_Value < 1250 && x1 == 1 )  {    stepperX1.runToNewPosition(8000);    x1 = 0;  }  if (RC_3_Value < 1350 && RC_4_Value < 1250 && x1 == 0)  {    initial_homing1 = -1;    while (digitalRead(home_switch1)) {  // Make the Stepper move CCW until the switch is activated      stepperX1.moveTo(initial_homing1);  // Set the position to move to      initial_homing1 -= 60;  // Decrease by 1 for next move if needed      stepperX1.run();  // Start moving the stepper    }    stepperX1.setCurrentPosition(0);  // Set the current position as zero for now    stepperX1.setMaxSpeed(4000.0);      // Set Max Speed of Stepper (Slower to get better accuracy)    stepperX1.setAcceleration(4000.0);  // Set Acceleration of Stepper    initial_homing1 = 1;    while (!digitalRead(home_switch1)) { // Make the Stepper move CW until the switch is deactivated      stepperX1.moveTo(initial_homing1);      stepperX1.run();      initial_homing1 += 60;    }    stepperX1.setCurrentPosition(0);    x1 = 1;  }`

this works perfect for each arm. but when i want both arm to go up together and using the below code, one  arm reaches top position and then second arm starts.

Code: [Select]
` if (RC_3_Value > 1650 && (RC_4_Value < 1749 && RC_4_Value > 1251))  {    stepperX.runToNewPosition(8000);    stepperX1.runToNewPosition(8000);      }`

is there a  way to change this code, so that both arms move together.

#### Robin2

#28
##### Mar 21, 2018, 06:52 pm
this works perfect for each arm. but when i want both arm to go up together and using the below code, one  arm reaches top position and then second arm starts.

Code: [Select]
` if (RC_3_Value > 1650 && (RC_4_Value < 1749 && RC_4_Value > 1251))  {    stepperX.runToNewPosition(8000);    stepperX1.runToNewPosition(8000);      }`

is there a  way to change this code, so that both arms move together.
Use stepper.run() rather than runToNewPosition().

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

#### anamikagupta

#29
##### Dec 01, 2018, 12:19 pm
stepper motor drivers are capable of continuous rotation with precise position control even without a feedback system.

Go Up