Gantry square procedure with PlanetCNC

Many machines use two lead/ball screws or rack and pinion rods per machine axis. In most cases, the Y axis.
Rods can be driven with one motor or two. One motor usually drives both rods using a timing belt, which also helps with

But you can also drive each rod with its separate motor. At PlanetCNC we use the terms Master and Slave motor.
PlanetCNC TNG software takes care of master and slave motor synchronization internally.

Nevertheless, between the two motors, there might be some discrepancy in a sense of gantry squareness. This can be due motor failure, lost steps, mechanical problems etc..

Since CNC machines are meant to ease the pain of accuracy and repeatability of machining process, we as users always strive
for squareness of our CNC machine.

In order to achieve this with dual motor setup, PlanetCNC TNG sw offers Gantry Square feature.

What gantry square feature does,  it “decouples” the master and slave axis motors from their common axis (e.g. Y), and assigns them new axis letters U and V, for the purpose of gantry square procedure. This needs to be done so that system is able to detect limit switches of each motor, as also to separately control each motor in order to  align gantry.


Before you proceed, we recommend that your machine steps per unit and limit switch configuration is set correctly:
Steps per unit tutorial
Limit switch tutorial

1. Setting the motors of Master and Slave axis

Under File/Settings/Motors we set additional (slave) motor of desired axis. In our case, axis output 4 will be used.


2. Settings Limit switches

Configuration of limit switch inputs for master and slave motor. We need to set limit switch inputs under motor U and V.

Motor U will have the same input number as motor Y, while motor V will have input number 4.



3. Gantry square parameters

Here we set the parameters of gantry square procedure.


Speed value at which gantry square procedure will be performed.



Machine axis that will be squared. In our case Y.



Direction of squaring axis motion. It should be the same direction as set for limit switches for U and V.


Move U:

Value of measured misalignment of master axis. This is the distance for which master motor will retract.


Move V:

Value of measured misalignment of master axis. This is the distance for which slave motor will retract.


4. Using the gantry square procedure

Gantry square procedure will consist of two takes.

For first take we will use Move UV values set to zero. So, if any misalignment of limit switches (gantry) exists (and it probably does), we will measure it trough a test. In second take we will use these measured values as Move UV values, and therefore square our gantry.


We start the procedure under : Machine/Measure/Gantry square

Machine will move in direction set under Direction. Once the first limit switch is activated, corresponding motor will stop, second motor will continue to move its side of the gantry until the second limit switch is activated. After activation, second motor also stops.

After first take, mill or engrave a square and measure the discrepancy of the angle. One user recommended the use the 3-4-5 Triangle approach. Trough measurement or calculation, we can obtain the Move UV correctional values and use it with second take.


Image below demonstrates (exaggerated) situation of limit switch misalignment.

-Normal line represents gantry misalignment due to limit switch

-The doted line represents squared gantry.



CNC machine semaphore application, using expressions (Expr.txt) – Part 3

At this step of the process we pretty much defined everything needed for semaphore application and we can begin writing the program.

Diagram of program

First we will illustrate simple program diagram(flowchart). Diagram is very helpful, because it visually  illustrates the program flow(in this case state machine) which we can use as a reference when designing program structure.

Diagram for state machine of our semaphore application:


Each state is able to transition to other state, which was defined earlier in the process. All transitions are conditioned, meaning in order for transition to happen, condition needs to be fulfilled.

So we will now describe each states possible transitions as also transition conditions.

It can transition to:

Run state
State transition condition: Start program

Estop state
State transition condition: Estop activated

Corresponding IDLE state parameter:

We can evaluate Idle state by combining three parameters.  Idle state is basically inverted run state, in a sense that no program or any other task is being executed. For this  we can use run state parameter !_hw_run. In order that we are 100% sure that system is not executing any remaining commands from the buffer, we also check _hw_buffempty parameter. We also need to be sure that Estop mode is not active with !_hw_estop.

(_hw_buffempty && !_hw_run) && !_hw_estop





Below is a flowchart for #OnInit. #OnInit is a built in expression function, which is executed when TNG software is launched/initialized. It only has one iteration.  It is perfect for initialisation code of our semaphore.

At the beginning we define state decimal values and conditions for Alarm, Estop and Idle states.  Only these three states because, when system is powered up, it can only take up states Estop(button pressed), Alarm(alarm before system shutdown was not reset) or Idle(all is OK). So, depending on the conditions met, OnInit will set the state which will be then recognized in the #Loop function.

Snippet of code for flowchart above is following:

state_estop = 0; 
state_idle  = 1; 
state_pause = 2; 
state_run   = 3;  
state_alarm = 4;
from_init = 0;

cleared_not = !_alarm_cleared;
if(cleared_not,exec(state=state_alarm,from_init=1,msg('INIT: Please Reset Error')));

estop = _hw_estop && _hw_idle; 
if(estop, state=state_estop);

idle  = (_hw_buffempty && !_hw_run) && !_hw_estop && _alarm_cleared; 
if(idle, state=state_idle);



#Loop function’s role is that is constantly checks and recognizes active state of the system.

If we, for the sake of this tutorial say, that this will be #Loop’s first execution and iteration, and since we just launched the TNG system, somebody pressed the Estop button before system shutdown (many CNC machines actually recommend to activate Estop button before system shutdown). So, #OnInit recognized and set as state Estop state.

#Loop then checks for active state and executes corresponding procedure. In our case, Estop state -> #StateEstop

Snippet of code for flowchart above is following:

;Every 83ms
if (state == state_estop, exec('#StateEStop'));
if (state == state_idle, exec('#StateIdle'));
if (state == state_run, exec('#StateRun'));
if (state == state_pause, exec('#StatePause'));
if (state == state_alarm, exec('#StateAlarm'));


#StateEstop flowchart is below:

At the beginning we have two safety instances. First one checks if state is indeed StateEstop, second one checks if last valid state was not StateEstop. This is important since we execute the #StateEstopInit procedure only at first and initial state change.

#StateEstopInit procedure is where we actually set the new last state and activate corresponding light on the semaphore.

With _state_last = state_estop command we set new last state. _extout1|5 = 1  will activate Red light on our ExtInOut board. All other lights are in this state at 0.


Further we check for any state transition conditions being met. This will be continuously evaluated until Estop button is not released. So if Estop button is released and error has been reset, Idle state conditions are met and we execute procedure #StateEstopEnd and set new state, state_idle. And then we return back to #Loop, where Idle state is recognized and #StateIdle is executed.

Which state transitions conditions need to be checked within each state, is defined in our state machine at the beginning of this tutorial. 


Snippet of code for flowchart above is following:

if (state != state_estop, return(0));
if (_state_last != state_estop, exec('#StateEStopInit'));

;Here we check for state transition conditions

idle = (_hw_buffempty && !_hw_run) && !_hw_estop; 
if(idle, exec('#StateEStopEnd', state = state_idle, return()));

if((!_alarm_cleared && !_hw_estop), exec('#StateEStopEnd', state = state_alarm, return()));

_state_last = state_estop;
print('EStop: ',estop);
_extout1|5 = 1;
_extout1|1 = 0;
_extout1|2 = 0;
_extout1|3 = 0;



#StateRun flowchart is below:

At the beginning we have two safety instances. First one checks if state is indeed StateRun, second one checks if last valid state was not StateRun. This is important since we execute the #StateRunInit procedure only at first and initial state change.

#StateRunInit procedure is where we actually set the new last state and activate corresponding light on the semaphore.

With _state_last = state_run command we set new last state. _extout1|5 = 2  will activate Green light on our ExtInOut board. All other lights are in this state at 0.


Further we check for any state transition conditions being met. These conditions will be continuously evaluated until either Estop, Pause, Stop buttons are pressed or CNC doors are open.

Let’s say CNC doors are suddenly opened during program run (this is checked using the ExtInOut board’s input 1, _extin1|1).  Alarm state condition is met and program will execute procedure #StateRunEnd and set new state, state_alarm. Program returns back to #Loop function, where Alarm state is recognized and #StateAlarm procedure is executed.

Which state transitions conditions need to be checked within each state, is defined in our state machine at the beginning of this tutorial. 




CNC machine semaphore application, using expressions (Expr.txt) – Part 2

What is a State Machine and how it is used?

If you google State machine, this would be the average result more or less:

“A state machine is a behaviour model. It consists of a finite number of states and is therefore also called finite-state machine (FSM). Based on the current state and a given input the machine performs state transitions and produces outputs.” 

Sounds exactly what we need for our application doesn’t it?  5 states, which can transition one from another based on the pre-defined conditions.

Each semaphore state has its outputs and inputs.  State outputs are semaphore light configurations where specific relay output will be activated. State inputs are conditions that will cause the state transitions.

Both will be described in detail in Part 3 of this tutorial.


What is an Expr.txt file and how it is used?

  • Expr.txt is a file which contains functions that are evaluated by PlanetCNC TNG expression evaluator.
  • it can be very practical for PLC type applications where periodical evaluation is necessary or for program events
  • Expr.txt file can contain and use vast array of expression functions, parameters and other commands supported by PlanetCNC TNG
  • Expr.txt file is located in the profile folder of TNG software
  • Profile folder can contain multiple Expr.txt files. Specific Expr file naming convention is available for better distinction. e.g.: Expr_Semaphore
  • If multiple expr files use same function, then function will be called first in first file and only then the with the next file
  • Local variables(e.g. name convention of local variables: red_light, global variables: _red_light ) have scope only within the parent Expr file.
  • Each Expr file contains functions that are marked with symbol #.
  • Each function begins with symbol # and ends with the next # symbol.
  • Each expr file can use built-in functions that are related with program events


Built-in Expr functions:

  • #OnInit -> When TNG software is started/initialized, code under this function will be executed.
  • #OnShutdown -> On PlanetCNC TNG software shutdown request, code under this function will be executed, then TNG will shutdown.
  • #OnStart -> On NC program Start event, code under this function will be executed. Če obstaja v katerokoli expr datoteki s tem imenom, bo opoklicana
  • #OnEnd -> On NC program End event, code under this function will be executed.
  • #OnStop -> On NC program Stop event, code under this function will be executed.
  • #OnEStop -> On Estop event, code under this function will be executed.
  • #OnJog -> On Jogging event, code under this function will be executed.
  • #OnWheel -> On handwheel event, code under this function will be executed.
  • #OnCmd -> On MDI command event, code under this function will be executed.
  • #Loop          -> this loop is executed every 83ms, or the value of refresh rate set in settings, under: File/Settings/User Interface/Refresh Rate
  • #Loop5       ->this loop is executed every 5s
  • #Loop15      ->this loop is executed every 15s
  • #Loop60     ->this loop is executed every 60s
  • #Loop300  ->this loop is executed every 300s




CNC machine semaphore application, using expressions (Expr.txt) – Part 1

For this multi-part tutorial we will create CNC machine semaphore(signal tower lamp).

We hope that this tutorial will serve as a good example on how to set application goals and requirements as also on how to define the tools and solutions  for achieving them, while using powerful tools and flexibility of PlanetCNC motion control system.


How to begin?

First we need to clarify and define application requirements.

Semaphore application requirements

We want:

  • to use a semaphore with 5 lights.
  • Each light with different colour will visually represent dedicated machine state.
  • Combination of two active lights is allowed. This applies when NC program is running and pause is initiated.
  • Additionally, alarm should be activated if, at the beginning or during the program execution, front door of machine enclosure is open(ed).
  • In case of alarm, system should prevent or stop program execution.
  • Play siren sound to notify CNC operator.
  • Alarm notification is displayed on the main screen
  • Alarm state needs to be reset. Hardware Reset button will be used.
  • If alarm is not reset and system is shut down, system will notify user to reset any pre-existing alarm at the system startup.


Machine states are:

  • Estop state
  • Idle state
  • Run state
  • Pause state
  • Alarm state


State description:


Estop state indicates that estop has been activated either using a PC keyboard key, controller estop pin (e-stop button) or Error pin indicating a motor driver fault.

This state will be indicated using active RED LIGHT on the semaphore.



Idle state indicates that machine is turned ON and connected with PC. Machine in Idle state does not perform any motion.

This state will be indicated using active YELLOW LIGHT on the semaphore.



Run state indicates that CNC machine is executing the NC program.

This state will be indicated using active GREEN LIGHT on the semaphore.



Pause state indicates that machine is executing NC program, however program pause has been initiated, meaning program execution is on hold.

This state will be indicated using active ORANGE LIGHT in combination with active GREEN LIGHT(Run state) on the semaphore.



Alarm state will indicate if CNC machine enclosure doors are open, at the start of program or during the program execution. So, if doors will be opened in any other state than Run, there is no need for an alarm.

This state will be indicated using a  BLUE LIGHT on the semaphore. In this state, we will also use siren sound alarm.


What hardware will we use?

So, we need to control 5 lights on the semaphore, and read one enclosure door switch. Meaning we need to occupy 5 digital outputs and 1 digital input of our MK3 controller.

But, digital input and output pins of controller are a precious commodity.  It would be better to use these pins for some other purpose.

More economic approach would be the use of ExtInOut board. This board expands the number of inputs and relay outputs used with controller by 8, respectively.


-ExtInOut board relays will control the semaphore lights, while one of the inputs will be used to evaluate CNC front door switch and Alarm reset button: ExtInOut board

-PlanetCNC Mk3 motion controller and EXT interface will be used for communication with external ExtInOut board: Mk3 controller

-Semaphore lights will be simulated with normal LED’s. If a real semaphore device would be used, integration would not be much different.

Programming the application

For a clearer and effective programming, we will use a concept called State Machine. Its functionality is suitable for the type of our application.

Drawing a flowchart will help us with visualization of such state machine and better overview of state definitions and state transition conditions.

Since we need constant and responsive background evaluation of various parameters and control of relay outputs, all our code will be included in the Expr.txt file.



In part 2 we will describe our state machine and Expr.txt file

Tool change settings in PlanetCNC TNG software

Prior following this tutorial we recommend that you perform tutorials below:

How to measure tool offset with fixed tool sensor in PlanetCNC TNG software
How to measure work position with movable sensor in PlanetCNC TNG software


Tool change settings are located under File/Settings/Program Options/Tool Change:


Tool Change settings are divided into three setting groups: Tool change – General, Tool offset and ATC*.
*Tool Change ATC group of settings will not be described and used in this tutorial. ATC configuration is described in depth in the PlanetCNC TNG user manual.


Tool Change – General settings group:

Here we set how we want our machine to “behave” during Tool change.

Tool Change – Enable:
This enables tool change procedure.

Skip Same Tool – Enable:
If tool with number “n” is already mounted then Tn M6 g-code will be ignored and tool change will not occur.

Spindle Check – Enable:
At the beginning of tool change procedure, spindle will be turned OFF (if it was ON prior)and when tool change procedure is completed, spindle will be turned ON.

Safe Height:
This value represents the machine Z axis value to which machine will ascend when tool change occurs. You enable it with a check on radio button. If Position is enabled, machine will travel to its XYZ position at Safe Height value.

This is XYZ machine position value to which machine will travel once the tool change is initiated. This position is final position where you will change your tool.

Action – Message:
When tool change occurs, tool change message will be displayed, informing user of current and a new tool number. Until user confirms the OK button, motion will be paused.

Action – Pause:
When tool change occurs, pause will be activated. Machine travels to tool change position and motion is paused. This way user can safely change the tool and resumes program execution.

Both enabled:
When tool change occurs, message will be displayed first, after message is confirmed, pause will be activated.


Tool Offset settings group:

Measure Offset -None:

Tool length will not be measured and stored. This is suitable when user already has created and populated its tool table. Each tool in the tool table has already been measured and its tool offset value has been stored in the tool table.


Measure Offset -Set Offset:

If your machine and tool change process uses fixed tool sensor to measure tool length offset you enable this option. After tool offset measurement is completed, tool offset value will be set and stored.


Measure Offset -Set Tooltable:

If your machine and tool change process uses fixed tool sensor to measure tool length offset you enable this option. After tool offset measurement is completed, tool offset value will be set and stored in the tool table.

This comes handy when your tool change gcode uses such format: Tn M6 G43 -> G43 command will activate tool offset from tool table previously set and stored during tool offset measurement.


Enable Offset:

With your tool offset measured and set, you need to activate it. To activate tool offset value you need to enable this option.

This comes handy when your tool change gcode does not use G43.


Auto Return:

This depends on your g-code. By g-code standard g-code return moves should be in g-code program but are often not.
Here is example:

This is correct g-code:

G01 X0 Y0(start position)
G01 X10 Y0(cut to X10 Y0 with first tool)
T2 M6 (change tool tool with auto return off)
G01 X10 Y0(return to last position)
G01 X20 Y0
G01 X30 Y0

This is wrong but often used:

G01 X0 Y0(start position)
G01 X10 Y0 (cut to X10 Y0 with first tool)
T2 M6 (change tool with with auto return on)
(no need for G01 X10 Y0 line because of auto return)
G01 X20 Y0
G01 X30 Y0



Here, we will describe what prior settings configuration need to be performed before we set our workpiece and work offsets.

We will also describe the tool change procedure itself. So based on our tool change settings configuration, what will be the machine motion sequence during tool change procedure.


Below is the tool change setting configuration that will be used for this example.

The requirements are :
– If Tn M6 code is present in the program, tool change procedure should be executed -> Tool Change > Enable

-If spindle is in ON state and tool change command is executed, spindle is turned OFF and once the tool change procedure is completed, spindle will restore its ON state  -> Spindle Check > Enable

-Once tool change command is executed, machine will travel to tool change position at Safe Height value -> Safe Height > 24.15mm

-Machine position where we will change the tool will be at X: 50mm Y:50mm and Z:20mm -> Position > Enable > X50; Y50; Z20

-When machine arrives to tool change position, motion should be paused and notification is displayed. Once we change our tool, we confirm the dialog and proceed with tool offset measurement. -> Action > Message

-Tool offset will be measured for each individual tool during the tool change procedure. For this, fixed tool sensor will be used. -> Tool Offset > Measure Offset > Set Offset

-After tool offset value is set and stored, we want to activate tool offset -> Enable Offset > Enable



Here are the steps, that should be performed in chronological order before we start our gcode program that uses multiple tools and therefore tool change procedure:

1. Homing procedure. Machine should be referenced so that we are sure that machine uses correct positions.

Click: Machine/Home

2. Mount and set the tool that you will use as first tool in your main gcode program. 

2.1 Type into the MDI: Tn M6.

2.2. Machine will now perform tool change procedure:

-Machine will move to position of tool change at X50, Y50 and Z 20 at Z = 24.15mm position

-Software will open a dialog which will inform us of the new tool number. Motion will be paused, and we can now mount our first tool into spindle.

-Once we confirm the dialog, machine moves to position of fixed tool sensor and measures tool offset. Machine will return to position where the tool change command was executed.

-In software, new tool number and its tool offset value will be set and activated.

3. Set Work Position XY = 0 of your workpiece.  

Click the left toolbar button Work Position/Axis To Zero/XY  or via Machine/Work Position/Axis To Zero/XY

4. Set Work Position Z = 0 of your workpiece. You can do this manually or you can use measure height Z procedure with movable sensor.

Click the left toolbar button Work Position/Axis To Zero/Z  or via Machine/Work Position/Axis To Zero/Z

To use movable sensor click the left toolbar: Work Position/Measure Height or via Machine/Work Position/Measure Height


So once we mount, measure and set our first tool, and after we set the XY and  Z axis work offsets, we can start our gcode program:

1. Start your gcode program

2. Tool change for second tool is executed. Steps are the same as at point 2. 

3. Machine will continue with program execution after the tool change gcode.












Program debugging in PlanetCNC TNG software

Debugging tools in PlanetCNC TNG

For purposes of program observation or debugging, user can use PRINT and LOG commands, output window and state tabs for parameter value display. G-code ref manual will also come very handy.

Output window

To show/hide output panel in PlanetCNC TNG main window, click the middle square symbol in the upper right corner:

Output window will appear at the bottom middle section of the main window:


PRINT and LOG commands can be inserted within main gcode or script gcode at appropriate program lines. With output window, printed values can be then observed, while LOG command creates its own file that can save desired parameter values.


We want to observe values of the following parameters:


These parameters can be displayed in Output window, Custom state tab or separate LOG file:


More on PRINT, LOG commands and how to create your own state tab can be found on links below:



State tabs:



Gcode in PlanetCNC TNG software

PlanetCNC TNG is a motion control software intended for control of CNC machines. As a standard, g-code is used as native programming language.

PlanetCNC TNG software processes gcode program and sends series of commands to motion controller. Controller interprets these commands and arranges coordinated machine motion.



G-code commands can be divided into multiple groups which differ from one another based on functionality and intended use.

Single G-code line, aka block, can include commands for modal state configuration, machine motion, program control and data manipulation, or peripheral control.
PlanetCNC TNG supports also gcode functions, expression functions, parameters, operators etc…


List of Gcode groups:
G-codes (G21,G17,G90, G00,G01…)
M-codes (M3,M5,M6…)
Other codes (F,S,T)
Operators (+,-,EQ,GT,AND…)
G-code functions (Exists, Sin, Cos, Inc, Dec…)
Expression functions (infoIsInitialized, infoMachinePosition…)


Complete list of gcode commands and system parameters is available in PlanetCNC TNG G-code reference manual. This document is located in Doc folder of PlanetCNC TNG main installation folder. 


Simple g-code programs (i.e. toolpaths) can be easily written manually. For this purpose we recommend that users gets at least familiar with g-code. Get to know groups of g-code commands, syntax, format and programming guidelines. Even if user does not have an intention of manually writing his g-code programs, it can be in great help when debugging and understanding program and machine behaviour.


We really encourage our users that they explore PlanetCNC TNG scripts, they are a really great source for discovering different types of gcode programming and programming approaches. Single script code can offer a lot of new knowledge for a curious CNC beginner as also for a well rounded programmer.

More about accessing and configuration of scripts can be read here:
Accessing script files in PlanetCNC TNG

Customization of PlanetCNC TNG user interface

How to create new profile in PlanetCNC TNG software

Adding user toolbar buttons in PlanetCNC TNG software

How to create custom tabs in PlanetCNC TNG software




Installing PlanetCNC TNG software on Raspberry Pi 3

You will need:
– Raspberry Pi 3 Model B (or B+)
– Monitor with HDMI cable
– Mouse and Keyboard
– Power supply
– 8GB SD card (16GB and 32GB should also work, 64GB or more will not work)

We used NOOBS version 2.8.2 in this tutorial but it should also work with newer versions.

1. Download NOOBS from here:

You will get almost 2GB large file named “”

2. You need to format SD card. We suggest that you use “SD Memory Card Formatter 5.0” which you can get here:

– Download “SD Memory Card Formatter 5.0”.
– Follow the instructions to install the software.
– Insert your SD card into the computer or laptop’s SD card reader and make a note of the drive letter allocated to it, e.g.
– In SD Memory Card Formatter, select the drive letter for your SD card and format it.

3. Extract files from NOOBS zip file to SD card.

Your SD card contents should look like this:

4. When this process has finished, safely remove the SD card and insert it into your Raspberry Pi. Connect monitor, mouse and keyborad and power up Raspberry Pi.
After few moments selection dialog will appear.

Select “Raspbian (full desktop version)” and click install. Confirm overwriting SD card and wait for Raspbian to be installed. It might take a while.

Another tutorial for Raspbian installation using NOOBS is here:

5. When installation is finished you will get nice welcome screen and Raspbian will ask you to set country, time zone and password.
You do not have to set password if you do not want it.

If connected to internet it will download and install updates. If not then skip this step.

When finished it will ask to reboot.

After reboot you are ready to install PlanetCNC TNG.

6. First we will modify “config.txt” file.
– Open terminal.

– Type “sudo nano /boot/config.txt”

– GNU nano will apear. Scroll to bottom of file and type:

– If you have black border on your monitor then locate line “disable_overscan=1” and uncomment it.

– When done exit GNU nano by clicking Ctrl+X and confirm saving modified buffer.

7. Reboot Raspberry Pi

7. After reboot we will install PlanetCNC TNG. Create subdirectory “PlanetCNC” in your HOME directory.

8. Download or copy ‘PlanetCNCPi-TNG_(version).tar.gz’ tarball to subdirectory.

9. Extract ‘PlanetCNCPi-TNG_(version).tar.gz’ tarball with “tar -xvf PlanetCNCPi-TNG_*.tar.gz”

10. Run installation script with “sh”

If you set password then you will be asked to enter it. After instalation completes PlanetNCC TNG will start automaticaly.

11. You can close all windows. There should be PlanetCNC icon on desktop. Double click will start PlanetCNC TNG.

Using ExtOut board with PlanetCNC TNG software

This tutorial will help you configure ExtOut board related settings in PlanetCNC TNG software.


ExtOut board settings are located under File/Settings/Input&Output/I2C,TX,Enc,RC.

Under Ext section insert value 10000 for Frequency and enable Invert option for SEL1 Pin:

Related g-codes:

M64 – Output ExtOut

Usage: M64 H Q <L>

– H = ExtOut SSEL value (1 or 2)
– Q = data send to ExtOut
– L (optional) = number of bytes send to ExtOut

M64 H Q E <L>

– H = ExtOut SSEL value (1 or 2)
– Q = parameter number of first data location
– E = data count
– L (optional) = number of bytes send to ExtOut

M64 H P Q <L>

– H = ExtOut SSEL value (1 or 2)
– P = bit position
– Q = zero for Off, otherwise On
– L (optional) = number of bytes send to ExtOut

M64 H L0

– H = ExtOut SSEL value (1 or 2)
– L = zero bytes send to ExtOut



In PlanetCNC TNG install folder locate and open Samples folder. Open Tutorials folder and locate files: M64ex1.txt, M64ex2.txt, M64ex3.txt, M64ex4.txt, M64ex5.txt, M64ex6.txt

These sample g-code programs describe various uses of M64 g-code and ExtOut board.


Using MPG pendant with PlanetCNC TNG software

This tutorial will help you configure MPG pendant related settings in PlanetCNC TNG software.

MPG settings are located under File/Settings/Control/Jogging -> Handwheel

Parameter description:

Enables use of encoder for purposes of jogging when using MPG pendant(used with Mk3 MPG adapter) or standalone encoder. For more info regarding controllers encoder inputs please read Mk3 and Mk3/4 controller user manual.
Note: These settings apply to encoder connected to controller header CTRL pins: EN1A and EN1B

Enter PPR value (parts per revolution) of your MPG encoder. Usually around 100PPR.

Reverses direction of jogging when MPG encoder is used for jogging.

Step Mode 0-6:

You can configure seven modes of jogging when using MPG pendant with PlanetCNC TNG. To select between modes you use MPG hardware switch(x1, x10, x100).

Each step mode can be configured either as Speed Factor or as Step Distance.
If radio button is left unchecked Speed Factor mode will be used, if you enable radio button , Step Distance mode will be used.

Speed Factor:
Encoder wheel will be translated into motion using Speed Factor value.
Inserted value is speed factor which can behave as prescaler or multiplication of MPG encoder wheel rotation.

For example, Speed Factor of value 0.1 is used when you need fine tuning of axis motion.


Step Distance:
Rotation of encoder will jog machine for distance that is set with Step Distance.

Please note:
With PlanetCNC MPG pendant hardware switch you can select only between Step Mode 1, Step Mode 2 and Step Mode 3.

So when you are using using PlanetCNC MPG pendant, configure only Step Modes 1,2 and 3.

Machine jogging with PlanetCNC TNG software

For purposes of machine jogging, user can use on screen jogging keys, PC keyboard keys or external jogging keyboard.


On-screen jogging keys:

Click the cross button next to jogging speed window:
Cloud with jogging keys will appear:
Jogging keys can appear permanently on main screen if you set:
File/Settings/User Interface/Jog Panel -> enable “Fixed”. You can choose among XY Cross, UV cross or default keys layout.:

Default keys layout:

XY Cross layout:

PC keyboard keys:

PC keyboard keys used for jogging  need to be configured in settings File/Settings/User Interface/Shortcuts -> under Jog chapter. Under Code, set keyboard keys you wish to use:


External jogging keyboard:

First under IO tab observe which jogging keyboard keys activate which JOG input.
Then in File/Settings/User Interface/Shortcuts -> under Jog and Pin set designated jog input pins:

Jog1 (X-),Jog2 (X+),Jog3 (Y-),Jog4 (Y+),Jog5 (Z-),Jog 6(Z-)
Since external jogging keyboard also supports Shift key, which in combination with any other jogging key initiates step Jog motion, you should set these shortcuts also: