And everything is working fine but there is one major problem - it makes random length rotation when providing power, after that it works normally. Any problems how to solve that ? I also didn't have any condensator between VCC and GND for motors.
According to your code, naturally it will jump sometimes when you apply power.
That's because you have a loop..... and when you turn off the motor, you won't know which logic states you ended up with. So when you power-up again, the starting combination:
digitalWrite(4,HIGH);
digitalWrite(8,LOW);
might be different from the state at which the motor was holding when you turned off the motor.
I notice that you don't have delay added at the end of your code. Maybe you didn't need it. But just indicating it. Might just want to check the ordering of your sequences. Yours starts with 8,3,8,4 --- then it goes 4, 8, 3, 8, 4.... then it goes 4, 8.... then goes back to the beginning of the loop. In order to make the motor do exactly what you want.... just need to really think about what these control commands are doing when we're running the code; and think about where the states finally end up at power-off, and what starting states you have during power-up.
I dont know. At the begining it starts spinning in one way, immediately after one rotation it makes another rotation in other direction , and after 3 seconds it makes not full rotation in other direction.
After changing numer of steps it makes full rotations - one in one direction, another in other direction, and after 3 seconds another in other direction
JashorPL:
After changing numer of steps it makes full rotations - one in one direction, another in other direction, and after 3 seconds another in other direction
That sounds like it is doing what it is supposed to do.
From your description I presume it is NOT making "random length rotation when providing power".
Does this all mean that you now have a suitable solution to your problem?
JashorPL:
I solved a problem in a other, very simple way i just switch on motors 10 seconds after providing power Problem solved
That removed the symptoms. The main thing is explaining why.... ie. what was the cause of your issue to begin with. And why activating the motors after 10 seconds makes it all behave.
I think it was difficult to understand your code because there was no explanation about what the pins 4, 3, and 8 were associated with. Your code has comments like 'step 1', 'dir 1' etc. Others probably won't know what these are for.
For example..... it appears that pin 8 is an enable/disable pin.
So why in the code below you appear to enable something, and then set a 'direction' and then disable something? And then you send a 'step' command. Doesn't appear to make sense.
digitalWrite(8,HIGH) ;
digitalWrite(3,LOW) ;// O
digitalWrite(8,LOW) ;
digitalWrite(4,HIGH);