// stepper motor with crossed wires
// for https://forum.arduino.cc/t/accelstepper-run-question/1121994/16
// and https://forum.arduino.cc/t/order-of-stepper-pins-in-stepper-library/906873
// and https://forum.arduino.cc/t/stepper-motor-not-turning-counterclockwise/1343378/11
// and https://forum.arduino.cc/t/step-motor-direction-does-not-change/1232152/2
// https://wokwi.com/projects/363629517927347201
// Copied from Acrostasi's https://wokwi.com/projects/360399388158511105
// The center two coil wires are swapped, so the stepper only steps in
// one direction
#include <AccelStepper.h>
// Define a stepper and the pins it will use
AccelStepper stepper(AccelStepper::FULL4WIRE,2,3,4,5); // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
// This defines the analog input pin for reading the control voltage
// Tested with a 10k linear pot between 5v and GND
#define ANALOG_IN A0
void setup()
{
stepper.setMaxSpeed(10);
stepper.setAcceleration(10);
}
void loop()
{
// Read new position
int analog_in = analogRead(ANALOG_IN);
stepper.moveTo(analog_in/10);
stepper.run();
}
Note the crossed wires at the Arduino pins 3&4. This causes one-directional, (CCW) motion.
Note that sometimes, some coils are "off"
with both terminals having the same voltage.
Contrary to normal full-step operation
with all coils fully powered.
Swap the switches to see normal polarities
Slide to absolute target position (102 <> 0)