<?xml version="1.0" encoding="UTF-8"?>        <rss version="2.0"
             xmlns:atom="http://www.w3.org/2005/Atom"
             xmlns:dc="http://purl.org/dc/elements/1.1/"
             xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
             xmlns:admin="http://webns.net/mvcb/"
             xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
             xmlns:content="http://purl.org/rss/1.0/modules/content/">
        <channel>
            <title>
									A4988 with Stepper motors switches direction every step - Arduino				            </title>
            <link>https://www.tweaking4all.com/forum/arduino/a4988-with-stepper-motors-switches-direction-every-step/</link>
            <description>Tweaking4All.com Discussion Board</description>
            <language>en-US</language>
            <lastBuildDate>Sun, 15 Nov 2026 00:57:29 +0000</lastBuildDate>
            <generator>wpForo</generator>
            <ttl>60</ttl>
							                    <item>
                        <title>RE: A4988 with Stepper motors switches direction every step</title>
                        <link>https://www.tweaking4all.com/forum/arduino/a4988-with-stepper-motors-switches-direction-every-step/#post-2562</link>
                        <pubDate>Mon, 07 Sep 2020 13:53:16 +0000</pubDate>
                        <description><![CDATA[I don&#039;t have any experience with stepper motors but I am wondering if the issue is related to the pins you are using.Great idea to include a video. 
You are using pins 11, 12 and 13.  On th...]]></description>
                        <content:encoded><![CDATA[<p>I don't have any experience with stepper motors but I am wondering if the issue is related to the pins you are using.<br />Great idea to include a video. </p>
<p><br />You are using pins 11, 12 and 13.  On the Arduino Uno these are for SPI commucation.  Pin 11 is MOSI, 12 is MISO and 13 is SCK.<br />I don't think you can override this function.<br /><br />Here is a basic pinout<br />https://components101.com/microcontrollers/arduino-uno</p>
<p>I found this post with a similar question.  Skip through the inappropriate comments some people made.<br />https://forum.arduino.cc/index.php?topic=530977.0</p>
<p>I can understand keeping the pins together to make wiring easier plus your project requires a lot pf pins.<br /><br />All you would need to do is change a few lines in your code to reflect the change in wiring<br /><br />What do you think?<br /><br /></p>
<p> </p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>tvr4</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/a4988-with-stepper-motors-switches-direction-every-step/#post-2562</guid>
                    </item>
				                    <item>
                        <title>RE: A4988 with Stepper motors switches direction every step</title>
                        <link>https://www.tweaking4all.com/forum/arduino/a4988-with-stepper-motors-switches-direction-every-step/#post-2560</link>
                        <pubDate>Mon, 07 Sep 2020 09:25:24 +0000</pubDate>
                        <description><![CDATA[Hi itisyeetimetoday!
This looks like a very cool project (I hope you don&#039;t mind I embedded your video)!
Unfortunately my experiences with stepper motors is pretty much zero - I know how th...]]></description>
                        <content:encoded><![CDATA[<p>Hi itisyeetimetoday!</p>
<p>This looks like a very cool project (I hope you don't mind I embedded your video)!</p>
<p>Unfortunately my experiences with stepper motors is pretty much zero - I know how they work, just never got around playing with them.<br />Since this is a little over my head, I'd recommend (which you probably already did) reading this section <a href="https://www.arduino.cc/en/Reference/Stepper" target="true">Arduino Stepper Library</a> on the Arduino website and start with some barebones experiments.<br />I'd also start dumping the variables like stepH and such to the serial monitor to see if there is a mistake in the logic (happens to me at times as well haha).</p>
<p>Like I said: I'm pretty sure you've already done all that. But unfortunately, I do not know enough about stepper motors and such to be of any useful help 😞 .</p>
<p>Maybe one of the other users here can chime in ...</p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>Hans</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/a4988-with-stepper-motors-switches-direction-every-step/#post-2560</guid>
                    </item>
				                    <item>
                        <title>A4988 with Stepper motors switches direction every step</title>
                        <link>https://www.tweaking4all.com/forum/arduino/a4988-with-stepper-motors-switches-direction-every-step/#post-2559</link>
                        <pubDate>Mon, 07 Sep 2020 01:27:46 +0000</pubDate>
                        <description><![CDATA[I&#039;m currently trying to build a 3d scanner with a garmin v3, sparkfun motors, a4988, and an Arduino Uno. However, currently, my sparkfun stepper motors, which are driven by A4988, switch dir...]]></description>
                        <content:encoded><![CDATA[<p class="_1qeIAgB0cPwnLhDF9XSiJM">I'm currently trying to build a 3d scanner with a garmin v3, sparkfun motors, a4988, and an Arduino Uno. However, currently, my sparkfun stepper motors, which are driven by A4988, switch directions every step. I'm not sure why this issue occurs, and sometimes the stepper motors steps properly, but 95% of the time, the stepper switches direction every step. I'm currently micro stepping by 1/16, but when the oscillation occurs, it appears to be taken over 1 step every oscillation cycle. Here is a link to a video of this issue:</p>
84
<p class="_1qeIAgB0cPwnLhDF9XSiJM"><br />Here is my code</p>
<p class="_1qeIAgB0cPwnLhDF9XSiJM">#include <br />#include</p>
<p class="_1qeIAgB0cPwnLhDF9XSiJM">LIDARLite myLidarLite;<br />const int dirPinV = 2;  // Direction<br />const int stepPinV = 3; // Step<br />const int dirPinH = 4;  // Direction<br />const int stepPinH = 5; // Step</p>
<p class="_1qeIAgB0cPwnLhDF9XSiJM">// Motor steps per rotation</p>
<p class="_1qeIAgB0cPwnLhDF9XSiJM">void setup() {<br />  Serial.begin(115200);<br />  myLidarLite.begin(0, true); // Set configuration to default and I2C to 400 kHz<br />  myLidarLite.configure(0); // Change this number to try out alternate configurations</p>
<p class="_1qeIAgB0cPwnLhDF9XSiJM">  // Setup the pins as Outputs<br />  pinMode(stepPinV,OUTPUT);<br />  pinMode(dirPinV,OUTPUT);<br />  pinMode(stepPinH,OUTPUT);<br />  pinMode(dirPinH,OUTPUT);</p>
<p class="_1qeIAgB0cPwnLhDF9XSiJM">  pinMode(8,OUTPUT);<br />  pinMode(9,OUTPUT);<br />  pinMode(10,OUTPUT);</p>
<p class="_1qeIAgB0cPwnLhDF9XSiJM">  pinMode(11,OUTPUT);<br />  pinMode(12,OUTPUT);<br />  pinMode(13,OUTPUT);</p>
<p class="_1qeIAgB0cPwnLhDF9XSiJM">  digitalWrite(8,HIGH);<br />  digitalWrite(9,HIGH);<br />  digitalWrite(10,HIGH);</p>
<p class="_1qeIAgB0cPwnLhDF9XSiJM">  digitalWrite(11,HIGH);<br />  digitalWrite(12,HIGH);<br />  digitalWrite(13,HIGH);</p>
<p class="_1qeIAgB0cPwnLhDF9XSiJM">}<br />void loop() {<br />  int maxStepV = 45*16;<br />  int stepV = 1;</p>
<p class="_1qeIAgB0cPwnLhDF9XSiJM">  int maxStepH = 60*16;<br />  int stepH = 1;<br />  for (int x = 0; x &lt; maxStepH; x = x + stepH*2)<br />  {<br />    // Set motor direction clockwise<br />    digitalWrite(dirPinV,HIGH);<br />    // Spin vertical<br />    for(int v = 0; v &lt;= maxStepV; v= v + stepV) {<br />      digitalWrite(stepPinV,HIGH);<br />      delayMicroseconds(500);<br />      digitalWrite(stepPinV,LOW);<br />      delayMicroseconds(500);<br />      Serial.println(myLidarLite.distance(false));<br />    }<br />    // Pause for one second<br />    delay(1000);</p>
<p class="_1qeIAgB0cPwnLhDF9XSiJM">    // Spin horizontal<br />    digitalWrite(dirPinH,HIGH);<br />    for(int hstep = 0; hstep &lt;= stepH; hstep= hstep + stepH) {<br />      digitalWrite(stepPinH,HIGH);<br />      delayMicroseconds(10000);<br />      digitalWrite(stepPinH,LOW);<br />      delayMicroseconds(10000);<br />    }<br />    myLidarLite.distance(true);</p>
<p class="_1qeIAgB0cPwnLhDF9XSiJM">    // Pause for one second<br />    delay(1000);</p>
<p class="_1qeIAgB0cPwnLhDF9XSiJM">    // spin vertical<br />    digitalWrite(dirPinV,LOW);<br />    // Spin motor two rotations quickly<br />    for(int v = 0; v &lt;= maxStepV; v= v + stepV) {<br />      digitalWrite(stepPinV,HIGH);<br />      delayMicroseconds(500);<br />      digitalWrite(stepPinV,LOW);<br />      delayMicroseconds(500);<br />      Serial.println(myLidarLite.distance(false));<br />    }<br />    // Pause for one second<br />    delay(1000);</p>
<p class="_1qeIAgB0cPwnLhDF9XSiJM">    // Spin horizontal<br />    digitalWrite(dirPinH,HIGH);<br />    for(int hstep = 0; hstep &lt;= stepH; hstep= hstep + stepH) {<br />      digitalWrite(stepPinH,HIGH);<br />      delayMicroseconds(10000);<br />      digitalWrite(stepPinH,LOW);<br />      delayMicroseconds(10000);<br />    }<br />    myLidarLite.distance(true);<br />    // Pause for one second<br />    delay(1000);<br />  }<br />}</p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>itisyeetimetoday</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/a4988-with-stepper-motors-switches-direction-every-step/#post-2559</guid>
                    </item>
							        </channel>
        </rss>
		