I am having issues with my code/set up. I have a TB6600 driver for my nema 23 stepper motor. My wiring is as shown in the reference image. I also have 2 switches, one at pin 4 and one at pin 5. The problem I am having is the stepper motor keeps rotating as if its fighting itself without any command. When I push either button, they work as is. Is there something wrong with my code that makes the motor run automatically when power is supplied?
Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project. See About the Installation & Troubleshooting category.
My suspicion here is there is no pull up on the switch and nothing to debounce, the capacitance no doubt is causing oscillation.
My money is on some parasitics causing your headache, in the pin declaration set the input pins to INPUT and PULLUP using the internal resistors.
Arduino will let you declare this so you won't need to go poking registers, they have made it easy(er).
I would use a timer for the pulse, create a PWM and see if you can get a baseline, if you need to move a specific amount of steps afterwards you can work on you code, get it spinning first as you want it to perform then dive deeper.
Happy to help if you get stuck bud, just holla, everyone on here started somewhere!