filament spooler speed control help requested.

im not the greatest at writing code or that fluent with arduino (yet, im trying to learn), ive written a quick code to control the speed of two stepper motors, one as a filament puller and one to drive a spool to collect filament as it is pulled, the hopes are to have this eventually controlled by a digital caliper to measure the diameter of the filament.

until i become more competent with writing working sketches id basically planned to control these steppers with 10k pots, using this code.

int steppin = 5;
int dirpin = 8;
int stepdelay;

int steppin1 = 6;
int dirpin1 = 9;
int stepdelay1;

void setup() {
pinMode (steppin, OUTPUT);
pinMode (dirpin, OUTPUT);
digitalWrite (dirpin, HIGH); //change this to change direction.

pinMode (steppin1, OUTPUT);
pinMode (dirpin1, OUTPUT);
digitalWrite (dirpin1, HIGH); //change this to change direction.

}

void loop() {
int val = analogRead(A7);
stepdelay = map(val, 0, 1023, 1, 1000);
digitalWrite(steppin, HIGH);
delayMicroseconds (stepdelay);
digitalWrite(steppin, LOW);
delayMicroseconds(stepdelay);

int val1 = analogRead(A6);
stepdelay1 = map(val1, 0, 1023, 1, 1000);
digitalWrite(steppin1, HIGH);
delayMicroseconds (stepdelay1);
digitalWrite(steppin1, LOW);
delayMicroseconds(stepdelay1);

}

unfortunately it doesnt work.

im using one of these CNC Shield V4 Expansion Board Nano 3.0 Stepper A4988 Driver for Arduino 3d PR LP for sale online | eBay

ive mapped the pins so the connections are correct, the only time ive had a motor turning is when i picked it up to check it and touched something on the board.

any help would be much appreciated and if i need to supply any more information please let me know

How is all this powered?

The code looks plausible. Maybe you're stepping too fast. Try setting stepdelay to a fixed (large) number of microseconds and ignore the pots.

I'd also just try with a single stepper until you get that working.

kaighn80:
unfortunately it doesnt work.

That does not give us much to go on. What actually happens?

Please post a link to the datasheet for the CNC board so we can see how the Arduino I/O pins are used

You may need to set a value for the ENable pins on the drivers.

Post a link to the datasheet for your stepper motors.

Tell us what stepper motor power supply you are using (volts and amps).

Always start testing stepper motors at very slow speeds.

...R

all i have is a high pitch whine from the motors, the pots do nothing to change the pitch or affect the motors.
im using a 12v 2a power brick,

stepper motor data

High pitch whine often means (in stepper language) "Stop it, I can't step that fast!".

thanks ill try a standard stepper code from one of the examples and see what happens

thanks guys the steppers are now working but the pots control both motors so if i try to increase the speed of one they both increase in speed, any ideas what i've done wrong this time?

Try reading the pots twice each. There is only one ADC so previous readings may impact the one you're currently making.

kaighn80:
thanks guys the steppers are now working but the pots control both motors so if i try to increase the speed of one they both increase in speed, any ideas what i've done wrong this time?

You must post the program that gives rise to your symptoms if we are to help.

...R

havent changed the program, so ive already posted the code!?!?

It seems likely that you made some code changes, even if it was just regarding the length of your delays or did you fix it by changes to wiring and if so, what were they?

kaighn80:
havent changed the program, so ive already posted the code!?!?

Are you saying that you have not tried any changes following the various Replies you have received?

...R

I tried just running a sketch to sweep a single stepper back and forth, that worked, so I uploaded my original code, and that worked, then I added a second read for each pot, that has stopped the motors doing anything, I’m not at my pc right now so I can’t post the code right now.

kaighn80:
I’m not at my pc right now so I can’t post the code right now.

When you do I will look at it

...R

Thanks robin but I don’t think you’ll be much help anyway, as of yet all youve done is bashed the new guy, for a community that’s is supposed to be about sharing and furthering this ‘hobby’ you seem to be doing the opposite! To be honest I find you obtuse and actively unhelpful, I came here to learn if there’s a better place then please point me to it so I don’t waste anymore of your or my time.

kaighn80:
as of yet all youve done is bashed the new guy,

Where did I do that?

I made some suggestions in Reply #2 that you have not responded to and I also asked some questions that you did not reply to. I think the ball is in your court.

...R