The axis following function with electronic gear ratio can be set. After this function is enabled, the target machine will follow the movement of the coordinate axis according to the electronic gear ratio.


machine.config_EGearSlave(target, xRatio, yRatio, zRatio);


  • machine: is the Machine object.
  • target: For the Machine object, this target machine will follow the motion of the coordinate axis according to the electronic gear ratio.
  • xRatio: The electronic gear ratio corresponding to the X-axis.
  • yRatio: The gear ratio of Y-axis.
  • zRatio: The electronic gear ratio corresponding to the Z-axis.



  • true: Both machines exist and were created successfully.
  • false: Any machine does not exist or failed to be created.


The slave_machine will follow the G-code movement of the machine according to the electronic gear ratio (1.5, 0.5, 1.0).

#include "Motion86.h"
#include "SD.h"
// Generate machine objects, up to three machines from machine 0 to 2, each machine has three axes. 
// In this example, machine 0 and machine 1 are used.
Machine machine(0);
Machine slave_machine(1);
// Stepper motor enable pin.
int EnablePin = 4;
// This gcode file is stored in the SD card.
char *filename = "auto.gcode";
File gfile;
char buf[256];
int ptr;
bool working;
void setup() {
  while (!Serial);
  pinMode(EnablePin, OUTPUT);
  // If necessary, the direction of motion of the motion axis can be reversed.
  // In this example, the direction of x-axis and y-axis should be reversed.
  // PPU (pulse per unit) is a virtual length unit, depending on different requirements.
  // In this example, the unit length of x-axis is set to 80 pulses, which corresponds to 1 mm in real application.
  machine.config_PPU(AXIS_X, 80.0);
  machine.config_PPU(AXIS_Y, 80.0);
  machine.config_PPU(AXIS_Z, 1600.0);
  // Set the software limit for the machine motion.
  machine.config_PosLimit(AXIS_X, 0, 300);
  machine.config_PosLimit(AXIS_Y, 0, 200);
  machine.config_PosLimit(AXIS_Z, 0, 300);
  // Set the pin used to set the limit switch for the home point.
  machine.config_HomePins(2, 7, 8);
  // In this example, slave_machine needs to reverse the direction of y-axis.
  // Set the PPU (pulse per unit) of the slave_machine.
  slave_machine.config_PPU(AXIS_X, 80.0);
  slave_machine.config_PPU(AXIS_Y, 80.0);
  slave_machine.config_PPU(AXIS_Z, 3200.0);
  // Set the software limit of slave_machine movement.
  slave_machine.config_PosLimit(AXIS_X, 0, 200);
  slave_machine.config_PosLimit(AXIS_Y, 0, 200);
  slave_machine.config_PosLimit(AXIS_Z, 0, 300);
  // Set slave_machine to set the pin used for limit switch of home point.
  slave_machine.config_HomePins(21, 22, 23);
  // Set the slave_machine to the machine's EGearSlave, which means that the slave_machine will calculate and follow the machine's motion.
  machine.config_EGearSlave(slave_machine, 1.5, 0.5, 1.0);
  // Before controlling, the machine must be started.
  // Enable the software limit.
  // Set the feed rate back to the home point.
  machine.setHomeSpeed(1000, 1000, 200);
  slave_machine.setHomeSpeed(1000, 1000, 100);
  // Open the gcode file in SD card
  if (SD.exists(filename)) {
    gfile =;
    working = true;
  } else {
    Serial.print("File does not exist: ");
    while (1);
  // Start the stepper motor.
  digitalWrite(EnablePin, LOW);
  // Return to the home point defined by the limit switch.
home(); }
void loop() {
  // Read and parse the gcode file.
  // slave_machine is a scaled gcode path, width x 1.5, height x 0.5.
  if (working && !machine.isCmdBufferFull()) {
    ptr = 0;
    while (gfile.available()) {
      buf[ptr] =;
      if (buf[ptr] == '\n') {
        buf[ptr + 1] = '\0';
      } else {
        ptr ++;
    if (!gfile.available())
      Serial.println("GCODE FINISH");
      working = false;

Libraries Reference Home

The text of the 86Duino reference is a modification of the Arduino reference and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.

Leave a Comment

Scroll to Top