M3 G-code

M3 starts the spindle at a specific speed.

What is a Spindle?

A spindle is a controlled motor that turns a tool (such as an endmill) at a given speed to allow it to remove material from the workpiece.

This is commonly used in CNC milling operations.

Speed Parameter

The M3 command must be accompanied by an S parameter which sets the speed of rotation.

M3’s counterpart is the M5 command which turns the spindle off (equivalent to M3 S0).

In V1, there are additional spindle-related commands:

  • M4 - Start spindle in reverse direction
  • M957 - Report current spindle speed and PWM value
  • M958 - Report or set PID control parameters

In V2, the primary spindle commands are M3 and M5. Additional commands may vary based on firmware version and configuration.

Format

The command is used as such:

M3 S1000

Which means: start the spindle and make it turn at 1000 rotations per minute.

Parameters

Parameter Usage Example
S The spindle must turn at this speed in rotations per minute M3 S1000

Configuration

The spindle functionality of Smoothie V1 is configured via the Spindle module.

The spindle module supports three control types:

  • PWM: Direct PWM control with optional PID closed-loop feedback
  • Analog: 0-10V analog signal for VFDs (Variable Frequency Drives)
  • Modbus: RS485 communication for advanced VFD control

V1 Basic Setup

Before using M3, ensure you have:

  • Enabled the spindle module: spindle.enable true
  • Selected a control type: spindle.type pwm (or analog/modbus)
  • Configured the appropriate output pin: spindle.pwm_pin 2.4 (must be PWM-capable)
  • Set the spindle speed range (min/max RPM based on your hardware)

V1 PWM Spindle Example

spindle.enable                    true
spindle.type                      pwm
spindle.pwm_pin                   2.4
spindle.pwm_period                1000
spindle.max_pwm                   1.0
spindle.default_rpm               5000
spindle.feedback_pin              0.22    # Optional: for closed-loop PID control
spindle.pulses_per_rev            1.0
spindle.control_P                 0.0001
spindle.control_I                 0.0001
spindle.control_D                 0.0001
spindle.control_smoothing         0.1

See Spindle module documentation for detailed configuration of all three control types.

The spindle functionality of Smoothie V2 is configured via the spindle control module.

V2 has a simplified spindle implementation compared to V1, with fewer configuration options but the same core M3/M5 command support.

V2 Basic Setup

Before using M3, ensure you have:

  • Enabled spindle control in your configuration
  • Configured the appropriate output pin (STM32 format: PXn)
  • Set the spindle speed parameters

Note: V2 configuration uses STM32H7xx pin notation (e.g., PA5, PB12) instead of LPC1769 format (e.g., 2.4).

Further Reading

These resources are used as references for Gcode:

This is a wiki! If you'd like to improve this page, you can edit it on GitHub.