I cannot unerstand the relationship between the argument in the move() command and the value returned by currentPosition(). For example move(3000)
moves only a tiny fraction of one revolution, and then currentPostion()
changes by only one unit. move(30000)
gives a similar result. Using any negative vaue for move()
makes the currentPosition()
value reduce by one unit.
#include <AccelStepper.h>
// Bluetooth connection to HC-05
#include <SoftwareSerial.h> // use the software uart
#include <Wire.h>
SoftwareSerial bluetooth(A5,A4); // RX, TX
#define MOTOR_LIFT_ENABLE_PIN 8
#define MOTOR_LIFT_STEP_PIN 2
#define MOTOR_LIFT_DIR_PIN 5
#define MOTOR_STEER_ENABLE_PIN 8
#define MOTOR_STEER_STEP_PIN 3
#define MOTOR_STEER_DIR_PIN 6
#define MOTOR_TILT_ENABLE_PIN 8
#define MOTOR_TILT_STEP_PIN 4
#define MOTOR_TILT_DIR_PIN 7
#define MOTOR_MOVE_ENABLE_PIN 8
#define MOTOR_MOVE_STEP_PIN 12
#define MOTOR_MOVE_DIR_PIN 13
AccelStepper motorLift(1, MOTOR_LIFT_STEP_PIN, MOTOR_LIFT_DIR_PIN);
AccelStepper motorSteer(1, MOTOR_STEER_STEP_PIN, MOTOR_STEER_DIR_PIN);
AccelStepper motorTilt(1, MOTOR_TILT_STEP_PIN, MOTOR_TILT_DIR_PIN);
AccelStepper motorMove(1, MOTOR_MOVE_STEP_PIN, MOTOR_MOVE_DIR_PIN);
void setup()
{
Serial.begin(9600);Serial.println("Arduino ready");
// first set up the BT connection
bluetooth.begin(9600); // start the bluetooth uart at 9600 which is its default
delay(200); // wait for voltage stabilize
bluetooth.print("AT+NAMEquilkin.com");
delay(3000); // wait for settings to take effect.
pinMode(MOTOR_LIFT_ENABLE_PIN, OUTPUT);
pinMode(MOTOR_STEER_ENABLE_PIN, OUTPUT);
pinMode(MOTOR_TILT_ENABLE_PIN, OUTPUT);
pinMode(MOTOR_MOVE_ENABLE_PIN, OUTPUT);
motorLift.setEnablePin(MOTOR_LIFT_ENABLE_PIN);
motorLift.setPinsInverted(false, false, true);
motorLift.setAcceleration(100);
//motorLift.setMaxSpeed(100);
//motorLift.setSpeed(100);
motorLift.enableOutputs();
motorSteer.setEnablePin(MOTOR_STEER_ENABLE_PIN);
motorSteer.setPinsInverted(false, false, true);
motorSteer.setAcceleration(100);
//motorSteer.setMaxSpeed(100);
//motorSteer.setSpeed(100);
motorSteer.enableOutputs();
motorTilt.setEnablePin(MOTOR_TILT_ENABLE_PIN);
motorTilt.setPinsInverted(false, false, true);
motorTilt.setAcceleration(100);
//motorTilt.setMaxSpeed(100);
//motorTilt.setSpeed(100);
motorTilt.enableOutputs();
motorMove.setEnablePin(MOTOR_TILT_ENABLE_PIN);
motorMove.setPinsInverted(false, false, true);
motorMove.setAcceleration(100);
//motorMove.setMaxSpeed(100);
//motorMove.setSpeed(100);
motorMove.enableOutputs();
}
void loop()
{
if (bluetooth.available()) { // check if anything in UART buffer
char action = bluetooth.read(); // action value is text character
digitalWrite(13,!digitalRead(13)); // toggle the onboard LED
switch (action) {
case '1':
motorMove.enableOutputs();
motorMove.move(32000);
motorMove.run();
break;
case '2':
motorMove.move(-32000);
motorMove.run();
break;
case '3':
motorSteer.move(3000);
motorSteer.run();
break;
case '4':
motorSteer.move(-3000);
motorSteer.run();
break;
case '5':
motorMove.disableOutputs();
break;
}
Serial.print("positions: ");
Serial.print(motorMove.currentPosition());
Serial.print(" and ");
Serial.println(motorSteer.currentPosition());
}
}
I'm using A4988 drivers on a CNC shield.