You haven't provided us with your code, or a circuit diagram, so we have no way of knowing whether there are any obvious mistakes in there. Usually, if you try to drive a stepper too fast (relative to the load it has to apply, and the supply power) it will simply slip. What is happening in your case if you try to drive it faster?
I know steppers are not realy fast, but i have another circuit (the old classic, without arduino, direct with parallel port) and the motor works more than 100% faster than the arduino circuit.
Any help would be greatly appreciated.
I share a couple of pictures of the stepper circuit:
That's a very poor way to pass parameters to a function, especially given that you need to call this function once per step. The String class is moderately dangerous to use due to the memory management bug, and in any case the string comparisons at every call are wasting CPU cycles.
Replace the 'stop' command with a function that just stops the stepper. You might want to choose a better name since this doesn't really stop the motor (the motor already stops when you stop stepping it) - it's actually powering the stepper down so that it no longer controls its position. It'd be pretty rare for that to be a sensible thing to do.
You might just as well get rid of paso() entirely and replace it with stepForward and stepBackward functions that increment/decrement the current_step_motor1 and then call a common function to write the output states corresponding to the new position.
You code to advance the motor one step at a time does not control the speed at all well. If you're going to control the stepper motor yourself then controlling the speed is important since the motor has to physically follow each step you give it, and it has significant inertia. You need to do this based on the current time, and not just put in fixed delays and hope that you get a consistent speed out. If this wasn't just a quick and dirty piece of test code then you would probably want to control the acceleration as well as the speed.
You should consider using a library to drive the stepper - there are libraries which will handle the timing for you, far more effectively and consistently than the crude timing you're using here.
You still haven't said how fast you're aiming to drive the stepper, or what goes wrong when you try to drive the stepper at that speed.
Hi PeterH, thank you very much for your response. I think there is another problem with this, anyway i will test what you suggest and I'll let you know the results.
I've tried it with arduino stepper library, but it does not work with this circuit. The arduino library works by activating two coils for each step sequence. If i try to do this with my circuit, it does not make the correct step sequence (if i energize one coil at a time, it works OK). This is the reason why i don't use the stepper library. If you have any "tips" on why is this happening, please let me know.
cmrv:
The arduino library works by activating two coils for each step sequence. If i try to do this with my circuit, it does not make the correct step sequence (if i energize one coil at a time, it works OK). This is the reason why i don't use the stepper library. If you have any "tips" on why is this happening, please let me know.
If you fix your code it should be able to drive the stepper faster than it can turn and the ability of the stepper itself to respond to the step changes should be the limiting factor. However, even if you were to sort the timing out you'd have to do a lot of work to get this working as well as the standard library. To be honest I suggest you concentrate on figuring out what's stopping the standard library from working and aim to use that, because it's quite a lot better than the crude implementation you've got here. Could it be that you've got one of the coils connected back to front?
what do you mean with "one of the coils connected back to front"?
my stepper have 6 wires, i know i got the correct stepping sequence because its working OK (it goes forward and back).
Please explain me what you mean about coils connected back to front... can i have the correct stepping sequence and still a bad wiring? I think maybe you're right and i have something wrong in the coils wiring.
As you know, you step the motor by turning coils on with the correct polarity in the correct sequence.
The stepper driver libraries will take care of that for you, but they need to know what the correct sequence is in terms of the output pins they're using. As well as getting the correct set of pins, and having them paired up correctly, each pair needs to be the correct way round. I guess since you have six wires that this is a unipolar motor so you will be supplying power to the two center taps and controlling the coils by grounding the other four connectors in the correct sequence. With the usual Stepper and AccelStepper libraries, that sequence is defined by the order that you pass the pin numbers to the stepper motor library constructor.
I've found the problem with my circuit and the Stepper arduino library, and now it's working
Looking into the code i found that the stepping sequence the library uses is not in the same order than the arduino pinout.
I have the stepper attached to pins 4, 5, 6, 7.
But if i do this:
Stepper myStepper = Stepper(200, 4, 5, 6, 7);
It does not work.
The correct one is:
Stepper myStepper = Stepper(200, 4, 6, 5, 7);
This one works OK and by using the stepper library (as suggested by PeterH) I got the correct stepper speed!!!
Thank you A LOT for your help.
I'm new in the forum, do i have to do something to mark this as resolved?