Spindle Control

The Spindle is the main effector on your CNC Mill/Router. It holds the end mill or drill bit, makes it turn and remove material.

While manual control is sometimes fine ( turn it on before starting your G-code, off when you are done ), it is so much neater to have G-codes to control it automatically : simply put an ON G-code at the beginning of your G-code file, and a off G-code at the end of your G-code file, and you don't have to think about it any-more.

First thing you need to do is choose which component on the Smoothieboard is going to choose to control your Spindle.

Mosfets are present on-board, but have limited current capacity ( up to 12A ) and need to be protected by a diode when controlling a motor.

Solid state relays are controlled via a GPIO pin, and can control higher loads, but are on/off only ( no control of the exact amount of power sent via PWM ). For more information about SSRs, see this appendix.

Here is a brief on the MOSFETs on the Smoothieboard : 



Smoothie has up to 6 MOSFET controls ( 6 on 5X, 4 on 4X and 2 on 3X ). You have to connect your PSU to the power input connector for those FETs, and connect your power consuming element ( be it heating element, spindle, etc… ) to the power outputs of those same FETs. Essentially Smoothie connects/disconnects the element ( connected to the mosfet connector ) from the PSU ( connected to the power input connector ) as needed to maintain temperature or as requested by G-codes.

There are three main pairs of Mosfets on the board :

  • Big MOSFETS pair : Their outputs are labelled P2_7 and P2_5 on the schematic, the input connector for them is found between them. They are found on the 4X and 5X boards. To power those mosfets, you need to provide them with power by wiring their power input to the power supply.
  • Small MOSFETS pair : Their outputs are labelled P2_6 and P2_4 on the schematic, the input connector for them is found by their side, between P2_6 and P1_23. They are found on all of the boards. To power those mosfets, you need to provide them with power by wiring their power input to the power supply.
  • Mixed MOSFETS pair : Their outputs are labelled P1_22 and P1_23 on the schematic. The pair is called "mixed" because it consists of one big MOSFET and one small MOSFET. They do not have a specific input, they take power directly from VBB ( the Stepper motors power input described in the Stepper Motors chapter ). To power those mosfets, you need to provide them with power by wiring their power input ( which is the same as the one for the stepper motors ) to the power supply.

MOSFET power inputs have a polarity, make sure you connect + on that connector to + on your PSU, and - to - on the PSU. Heater elements however do not have a polarity, so you do not have to worry about polarity on the outputs. If you are using another output element like a Peltier or a Spindle, you need to be careful to respect the polarity for the outputs too.

Big MOSFETS can handle up to 20A without cooling, but the 5mm green connectors are rated up to only 12A, and the Small MOSFETS can handle up to 3A, and their connectors are rated up to 7.5A. Therefore, never use the big MOSFETS for more than 12A ( and monitor connector and MOSFET temperatures at that current use ), and the small MOSFETS' use should be limited to small fans. Trying to power a 40W hotend cartridge heater at 12V with the small FETs will destroy them, locking them to the "ON" state.

If you need to control more than 12Amps, you can not do it with one of the MOSFETS on board, however you can use a Solid State Relay. For information see the Solid State Relay Appendix on this page.

In the case of both the Big MOSFETS pair, and the Small MOSFETS pair, you take power from the PSU to them via their respective power input connectors.

There is an alternative however. For each pair, you can use jumpers ( one jumper for the small MOSFETS pair ( JP28 ), two parralel jumpers for the two big MOSFETS pair ( JP11 and JP27 ) ). If you solder the pins for those, and connect a jumper to those pins, closing the circuit to VBB ( the stepper motors power input ), allowing you to take the power from those MOSFETS from the same place as the stepper motors do.

In the case of the big MOSFETS, you have to solder and put in place two jumpers, in parallel, in order to handle more current.

Current rating

However, WARNING, each jumper is rated for only 2A of current. This means you can not use this way of powering your MOSFETS if you are going to use more than 2A ( for the small MOSFETS ) or 4A ( for the big MOSFETS, with both jumpers used, for 2 x 2A ).

Do not use the jumpers to power a heated bed for example, as it uses much more than 4A.

In order to configure your Smoothieboard to use a specific MOSFET, you need to know which pin corresponds to which MOSFET. Here is a recapitulating table to help you find that out :

Label on diagram P2_7 P2_5 P2_4 P2_6 P1_23 P1_22
Digital output pin 2.7 2.5 2.4 2.6 1.23 1.22
Power Input Between P2_7 and P2_5 Between P2_6 and P1_23 Taken from VBB
Size Big Big Small Small Big Small
Maximum current 12A 12A 0.5A* 0.5A* 12A 0.5A*
Used by default for Heated bed First hotend heater Fan Second hotend heater

*While the datasheet says it can handle ~5A, it should not be used for anything but low-current fans, at least at 12V. Trying to run a hotend off of the small MOSFETs will destroy them (experimentally proven at 12V).


TODO : diagram


Now that you have located which MOSFET you are going to use for Spindle control, and what GPIO pin it corresponds to, you need to add a spindle control section to your configuration file.

We will be doing this using the Switch module

Add this to your configuration file : 

#Spindle control Switch module
switch.spindle.enable                            true             #
switch.spindle.input_on_command                  M3               #
switch.spindle.input_off_command                 M5               #
switch.spindle.output_pin                        2.7              # Here we are using the first big MOSFET
switch.spindle.output_type                       pwm              # pwm output settable with S parameter in the input_on_comand
switch.spindle.max_pwm                           255              # set max pwm for the pin default is 255

Controlling the Spindle

Now that everything is configured, you can use G-codes to control the Spindle.

You can do this either manually by sending G-codes directly to the board via serial or your host software, or add those G-codes to the beginning/end.

You can choose the exact G-codes in the configuration, here we used the standard M3 to turn the Spindle ON, and M5 to turn the Spindle OFF.

If you need to choose the power ( speed ) of your Spindle, you can do so because the output is configured as PWM.

Simply do :

M3 S128

To set the spindle to half power/speed. PWM values go from 0 to 255.


Because the spindle can feed power back into the MOSFET and damage the MOSFET, you also need to wire a diode of sufficient size across the output.

PID loopback spindle control

To get more accurate RPM control, you can use a feedback sensor. This can be optical or a hall effect sensor, which senses the rotation of the spindle. Smoothie then measures the real RPM of the spindle and adjusts the PWM value accordingly.

To use this module, you need to connect your spindle to pins with proper hardware support:

  • PWM output pin: any of P1.18, P1.20, P1.21, P1.23, P1.24, P1.26, P2.0 - P2.5, P2.26, P3.25
  • Feedback sensor pin: must be in port 0 or port 2; P2.6 and P2.7 are available on smoothieboard


Option Example value Explanation
spindle_enable true If set to true, enables the Spindle module, which uses an encoder to PID-control a PWM-modulated spindle motor
spindle_pwm_pin 2.4 Output PWM pin (uses hardware PWM). Note : hardware PWM is available only on pins 2.0 to 2.5, 1.18, 1.20, 1.21, 1.23, 1.24, 1.26, 3.25 and 3.26
spindle_pwm_period 100 PWM period to use in microseconds
spindle_feedback_pin 2.6 Feedback input pin (must be Port 0 or 2, meaning the pin number must be 2.x or 0.x )
spindle_pulses_per_rev 3 Number of feedback pulses per revolution on the feedback input pin
spindle_default_rpm 5000 RPM to use if none given in M3 command, in rotations/minute
spindle_control_P 0.0002 PID P factor (unit is 1 / RPM)
spindle_control_I 0.0001 PID I factor (unit is 1 / ( RPM x seconds ))
spindle_control_D 0.000001 PID D factor (unit is 1 / (R PM / seconds ))


Available G-code commands:

  • M3 will start the spindle. M3 S5000 will start the spindle and set speed to 5000 RPM.
  • M5 will stop the spindle. Last set RPM is remembered and used for next M3 command if S argument is not given.
  • M957 will report the current spindle speed and PWM value.
  • M958 will report the current PID parameters. M958 Px.xxx Ix.xxx Dx.xxx will set them (to save the new values, you need to edit config file manually).

Tuning the PID parameters

There is no PID autotuning for spindle parameters currently. You can use the following process to manually tune the PID:

  1. Set dummy values with M958 P0.0001 I0 D0
  2. Stop the spindle with M5 and make sure spindle is ready to run on next M3 command (i.e. power supply is on).
  3. Run M3 S100000, which should start the spindle at maximum speed.
  4. Measure the time T it takes for the spindle to reach full speed (using your ears and a stopwatch).
  5. Check the maximum RPM R the spindle reaches by running M957

Now set the parameters to:

  • P = 1/R (e.g. for 10 000 RPM, set P = 0.0001)
  • I = 2/(R*T) (e.g. if it took 1 second to speed up to 10 000 RPM, set I = 0.0002)
  • D = T / R / 10 (e.g. D = 0.00001)

Some manual tuning may be needed after this. Test speed changes using the M3 command and try loading the spindle to see if it reacts fast enough to load changes.