1

I am a NOOB. I admit to a huge lack of understanding of programming. I just need my machine to work.

I cannot wrap my head around getting independent speed control of 2 steppers since it seems that controlling the speed is dependent upon adjusting the length of delay between sending pulses to the motors, however sketches only contain one Loop and any delay in that loop has a global effect.

Here is my code so far

// My sketch to control 1.8 degree stepper motors operating the Gizmoto V3 Braiding Machine
// One 10k Pot speed-controls 2 braiding steppers, 
// Second Pot speed-controls 3rd stepper which operates the take-up capstan

// Rev 1.0  March 10 2021

// Defines pins numbers

const int braidStepPin = 3;
const int braidDirPin = 2;

const int capstanStepPin = 5;
const int capstanDirPin = 4;

//Define variables here

int braidDelay; // Controls the speed of the braiding drive according to braidSpeed function
int capstanDelay; // Controls the speed of the capstan drive according to capstanSpeed function
 
void setup() {
  // Sets the pins as Outputs
  pinMode(braidStepPin,OUTPUT);
  pinMode(braidDirPin,OUTPUT);
  pinMode(capstanStepPin,OUTPUT);
  pinMode(capstanDirPin,OUTPUT);

 
  digitalWrite(braidDirPin,HIGH); // Sets the braid motors' direction
  digitalWrite(capstanDirPin,HIGH); // Sets the capstan motor's direction
}
void loop() {
  
  digitalWrite(braidStepPin, HIGH); // Sends the braid motors one pulse
  digitalWrite(braidStepPin, LOW);
  delayMicroseconds(braidSpeed);

  digitalWrite(capstanStepPin, HIGH); //Sends the capstan motor one pulse
  digitalWrite(capstanStepPin, LOW);
  delayMicroseconds(capstanSpeed);
}
// Function for reading the Braiding Potentiometer
int braidSpeed() {
  int braidDelay = analogRead(A0); // Reads the potentiometer
  int newBraidDelay = map(braidDelay, 0, 1020, 200, 700); // Converts the read values of the potentiometer from 0 to 1023 into desired delay values
  return newBraidDelay; 
}
// Function for reading the Capstan Potentiometer
int capstanSpeed() {
  int capstanDelay = analogRead(A1); // Reads the potentiometer
  int newCapstanDelay = map(capstanDelay, 0, 1020, 200, 700); // Converts the read values of the potentiometer from 0 to 1023 into desired delay values
  return newCapstanDelay; 
}
4
  • your code is step braid ... pause ... step capstan ... pause ... do you see a problem with that? .... the code needs to be look at time ... if needed, step braid ... if needed, step capstan .... or this ... decrement braid counter ... if zero, reset braid counter and step braid ... decrement capstan counter ... if zero, reset capstan counter and step capstan – jsotola Mar 12 at 16:54
  • Thank you for taking the time to offer help. As I stated I am very inexperienced at coding. I am aware of the accumulative effects of multiple pauses in the loop.. Do you know of an example of the code which you described: using counters, decrements and resets.. once I see that, maybe I'll be able to work through it. Sorry to be a nuisance. – robertbaker Mar 13 at 17:32
  • there is a lot of example code included with the Arduino IDE ... lots more code on the internet ... here is an example of a counter mechatrofice.com/arduino/arduino-counter-code-circuit-working .... look at the lines that deal with count_value ... remove all the code that deals with the button ... keep the delay just for testing ... you'll have increment count_value ... print count_value ... delay 100 – jsotola Mar 13 at 17:47
  • next, change the increment to decrement ... next, add code that sets value of count_value if count_value == 0 .... it's all baby steps ... expand your code slowly – jsotola Mar 13 at 17:50

Your Answer

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

Browse other questions tagged or ask your own question.