Site Tools


projects:cnc:4th_axis

This is an old revision of the document!


A manual controller for a spindle motor

This page describes hardware and software for controlling a stepper motor based lathe spindle manually, Such lathes are produced in China and can be commonly found on ebay.

Movement control is done using a potentiometer and button. With the potentiometer the speed and direction can be set, while the button allows to rotate at a specific angle, after which the motor stops.

After powering up, it is required to either rotate the potentiometer to the center position (speed: 0) or press the button to rotate exactly 90 degrees. This is done to make sure that the spindle initially only rotates, when the user explicitly acknowledges. Afterwards the button can be pressed at any moment to rotate another 90 degrees angle further. While the stepper motor is in pause state, to commence moving at a certain speed, it is necessary to first move the potentiometer to the center position from which the direction and speed can than be set accordingly.

Project summary:

  • Code runs on an arduino (nano).
  • With a 4k7 potentiometer on A0, direction and speed can be set.
  • When using a button on D8 (to GND), the axis rotates certain degrees (currently hard-coded as 90 degrees) in the direction it was rotating previously and stops afterwards, regardless of the potentiometer setting.
  • To start motor movement, either press the switch, or move the potentiometer to the center position, after which the motor will rotate continuously when moving the potentiometer any further.
  • If the indicator led is blinking fast, it will indicate that the potentiometer need to be positioned at the center first. This is to prevent any unwanted motor rotation.

The documentation of the stepper controller can be found here: hpsteppro_doku_2016_04.pdf

The wiring between the HP_Step.pro board and the Arduino nano controller is the following:

PIN FUNCTION DESCRIPTION ARDUINO PIN
CN4,1 RXD Unspecified 12
CN4,2 /Clock Clocksignal, rising edge causes step 9
CN4,3 /Error During low state 11
CN4,4 /CCW Rotation direction 4
CN4,5 /Off Power off stepper drivers 5
CN4,6 /Sleep Reduces motor current to 25% from nominal during low state 6
CN4,7 + CN4,8 +5v This pin is not connected but rewired to the internal 5v supply of the stepper controller and used to power the Arduino nano standalone +5v
CN4,9 + CN4,10 GND Ground GND
CN7.5 /Reset Reset 13

Arduino software using the FastAccelStepper library

const uint8_t bcd10 = PIN_A1;
const uint8_t bcd20 = PIN_A2;
const uint8_t bcd40 = PIN_A4;
const uint8_t bcd80 = PIN_A3;
const uint8_t bcd01 = PIN_A5;
const uint8_t bcd02 = 2;
const uint8_t bcd04 = 10;
const uint8_t bcd08 = 3;
 
 
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(bcd10,INPUT_PULLUP);
  pinMode(bcd20,INPUT_PULLUP);
  pinMode(bcd40,INPUT_PULLUP);
  pinMode(bcd80,INPUT_PULLUP);
  pinMode(bcd01,INPUT_PULLUP);
  pinMode(bcd02,INPUT_PULLUP);
  pinMode(bcd04,INPUT_PULLUP);
  pinMode(bcd08,INPUT_PULLUP);
}
 
uint8_t read_bcd_wheel(void) {
  return 10 * (!digitalRead(bcd10) | 
               !digitalRead(bcd20) << 1 |
               !digitalRead(bcd40) << 2 | 
               !digitalRead(bcd80) << 3) +
              (!digitalRead(bcd01) |
               !digitalRead(bcd02) << 1 |
               !digitalRead(bcd04) << 2 |
               !digitalRead(bcd08) << 3);
}
 
void loop() {
  // put your main code here, to run repeatedly:
  Serial.print("switch_state:>");
  Serial.print(read_bcd_wheel());
  Serial.print("-");
  Serial.print(!digitalRead(bcd80));
  Serial.print(!digitalRead(bcd40));
  Serial.print(!digitalRead(bcd20));
  Serial.print(!digitalRead(bcd10));
  Serial.print(!digitalRead(bcd08));
  Serial.print(!digitalRead(bcd04));
  Serial.print(!digitalRead(bcd02));
  Serial.print(!digitalRead(bcd01));
  Serial.println("<");
  delay(1000);  // delay in between reads for stability
}
projects/cnc/4th_axis.1744667541.txt.gz · Last modified: 2025/04/14 23:52 by admin