I finally gave my MR-1 a real jog wheel: wired USB, works with stock CutControl, and it's all free

Alright MR-1 crew, I’ve wanted a real industrial-style handwheel on this machine forever, and I finally built one. It turned out awesome. :tada:

Video of it in action:

Quick backstory: I run an auto repair shop. I’m a wrench guy, not a programmer. I never liked the little keyboard pendant, because I wanted a wheel I could actually spin. So I grabbed a cheap MPG handwheel pendant off eBay and wired a $10 Arduino in between, and now I turn a real wheel and the mill moves with it. I didn’t change anything in CutControl. It just thinks a keyboard is plugged in.

The whole thing came in around $90. Everything you need is below: parts, pinout, how to check your own pendant, and the code (at the bottom of this post). It’s all free. Take it, use it, change it, run wild with it. If you adapt it to something else, post it up, because I want to see it.


:joystick: What it does

Control What it does
Green side button The enable. Hold it while you turn the wheel. Let go and nothing moves
Axis knob X / Y / Z picks the axis. OFF = idle
x1 0.001" per click (step mode)
x10 0.010" per click (step mode)
x100 Continuous: moves while you turn and stops when you stop. Speed = CutControl’s Jog Speed
E-stop Sends Stop Program (Alt+S) and locks the wheel until you twist it out

How it works: an Arduino Pro Micro reads the wheel and knobs and types CutControl’s own keyboard shortcuts (arrow keys, Page Up/Down, Tab, Alt+S). CutControl’s jog step cycles with Tab (CONT → 0.001 → 0.010), so the pendant counts its own Tab presses and puts CutControl back to CONT about a second after you let go of green. If the screen ever shows something other than CONT while you’re not jogging, just tap CONT and you’re back in sync.


:shopping_cart: Parts (about $90 total)

Part Notes
4-axis MPG handwheel pendant, 5V, 100PPR, E-stop, DB15 plug Mine is RATTM Motor on eBay (item 254462912819), about $57
Arduino Pro Micro, ATmega32U4, 5V/16MHz About $10. Get the USB-C version if you can. Buy a 2-pack so you have a spare
DB15 female, 2-row breakout with screw terminals About $14. Not the 3-row VGA type
USB-A to USB-C data cable Charge-only cables won’t work
22 AWG hookup wire

:electric_plug: Wiring (DB15 breakout terminal → Pro Micro pin)

Terminal Wire Job Pro Micro
1 Red + clear +5V VCC (not RAW)
2 White Wheel B 3
3 Yellow Wheel A 2
4 Brown Axis X 4
5 Light blue Axis Z 6
6 Clear/black x100 10
7 Green/black x1 8
8 Purple COM (through green button) GND
9 Black + light purple Ground GND
12 Orange Axis Y 5
13 Blue Axis 4 7
14 Blue/black x10 9
15 Red/black E-stop 14

Terminals 10, 11 (A/, B/) and the shell aren’t used. The Pro Micro has three GND pins, so 8 and 9 each get their own.

:warning: Don’t just copy my pinout. Meter your own pendant first. The seller told me the pin layout can change between batches, even on pendants that look identical. The sheet that came with mine listed 18 wires, but only 15 fit the plug, and the “axis 5” wire turned out to be the E-stop. So grab your meter, set it to continuity, and keep everything unpowered:

  1. Colors: open the pendant’s plug, put one probe on a solder cup and find which breakout terminal beeps.
  2. Knobs: on mine, the green button is an enable that sits between COM and the knobs, so nothing beeps unless you hold green. Hold it, keep one probe on COM, and click through each knob position. (This one had me scratching my head for a while.)
  3. E-stop: look for two terminals that are connected with the E-stop out and open when it’s pushed in (normally closed).

:laptop: Loading the code

  1. Install the free Arduino IDE.
  2. Copy the code from the bottom of this post into a new sketch named MR1_Pendant.
  3. Tools → Board → Arduino Leonardo (the Pro Micro uses the same chip), pick the port, and click Upload.
  4. It starts in test mode, so it doesn’t type anything. It just reports what it sees. Open Tools → Serial Monitor at 115200 and check every knob, button and wheel direction. One click should count as exactly 1, and clockwise should be +.
  5. When everything checks out, change WIRING_TEST to false at the top of the code, upload again, and plug it into the mill computer. Then go have fun.

If the upload can’t find the board, short RST to GND twice quickly and hit Upload within 8 seconds.

Settings at the top of the code: REVERSE_WHEEL if it goes backwards, ESTOP_NORMALLY_CLOSED if your E-stop is the other type, TAP_INTERVAL_MS if step mode lags, HOLD_RELEASE_MS if continuous mode stutters or coasts.


:warning: Safety (the boring but important part)

  • The pendant’s E-stop is a software stop, not a real E-stop. It sends a keystroke. Keep using the machine’s real E-stop.
  • Keys go to whatever window is active. Tap an empty spot in the 3D view before jogging, so the arrows don’t change a number in a text box.
  • Start Program and Home are left off the pendant on purpose, so it can’t start a job or move the machine on its own.
  • First run: spindle off, Z raised, Jog Speed low, start on x1.

:page_facing_up: The code: MR1_Pendant.ino

Make a new Arduino sketch named MR1_Pendant, delete what’s in it, and paste in everything from the box. It ships in test mode (WIRING_TEST = true), so it won’t type anything until you’ve checked your wiring and flipped that to false.

Click to show the code
/*
  ===========================================================================
  MR-1 JOG WHEEL PENDANT   (version 3: continuous on x100, self-syncing)
  ===========================================================================
  Turns a wired 5V / 100PPR MPG handwheel pendant into a USB keyboard
  that drives Langmuir CutControl's built-in keyboard shortcuts.
  CutControl itself needs no changes; it just sees key presses.

  Board:  Arduino Pro Micro (ATmega32U4, 5V / 16MHz)
          In the Arduino IDE pick:  Tools > Board > Arduino AVR Boards >
          Arduino Leonardo

  ---------------------------------------------------------------------------
  WHAT EACH CONTROL DOES
  ---------------------------------------------------------------------------
  Green button  ENABLE. Hold it while you turn the wheel. Let go and the
                wheel does nothing. (On this pendant the green button
                connects the knobs, so the knobs only read while it's held.)

  Axis knob     OFF        pendant idle; puts CutControl back to Continuous
                X / Y / Z  the wheel jogs that axis
                4          the wheel does nothing

  Ratio knob    x1   = 0.001" per wheel click (step mode)
                x10  = 0.010" per wheel click (step mode)
                x100 = CONTINUOUS: the axis moves while the wheel turns
                       and stops when you stop. Speed = CutControl's
                       Jog Speed setting on the screen.

  Wheel         clockwise = + direction (flip REVERSE_WHEEL if backwards)

  E-stop        press = Stop Program (Alt+S), and the wheel is locked until
                you twist the E-stop to release it.
                *** THIS IS A SOFTWARE STOP ONLY. IT IS NOT A SAFETY-RATED
                *** EMERGENCY STOP. KEEP USING THE MACHINE'S REAL E-STOP.

  ---------------------------------------------------------------------------
  HOW IT KEEPS IN STEP WITH CUTCONTROL
  ---------------------------------------------------------------------------
  CutControl's jog step changes with the Tab key:
      Continuous -> 0.001 -> 0.010 -> back to Continuous
  The pendant can't see the screen, so it counts its own Tab presses.
  To stay in step, it puts CutControl back to Continuous about a second
  after you let go of green (and when you turn the axis knob to OFF).
  So whenever you're NOT jogging, the screen should show CONT, and the
  pendant assumes it does.

  If the screen ever shows something other than CONT while you're not
  jogging (for example you tapped a jog step on the screen), just tap
  CONT on the screen. That's the whole re-sync.

  IMPORTANT: key presses go to whatever window is active. Tap an empty
  spot in CutControl's 3D view before jogging so no text box or button
  has focus.

  ---------------------------------------------------------------------------
  WIRING (DB15 breakout terminal -> Pro Micro pin)
  ---------------------------------------------------------------------------
   1  Red + clear     +5V            -> VCC  (not RAW)
   2  White           Wheel B        -> 3
   3  Yellow          Wheel A        -> 2
   4  Brown           Axis X         -> 4
   5  Light blue      Axis Z         -> 6
   6  Clear/black     x100           -> 10
   7  Green/black     x1             -> 8
   8  Purple          COM            -> GND
   9  Black + lt purple  Ground      -> GND
  10  Green           B/             -> not used
  11  Pink            A/             -> not used
  12  Orange          Axis Y         -> 5
  13  Blue            Axis 4         -> 7
  14  Blue/black      x10            -> 9
  15  Red/black       E-stop         -> 14
  ===========================================================================
*/

#include <Keyboard.h>

// ===========================================================================
// SETTINGS YOU MAY NEED TO CHANGE
// ===========================================================================

// WIRING_TEST = true: the pendant types NOTHING. It prints what it sees
// (knobs, wheel, green button, E-stop) to the Arduino Serial Monitor so you
// can check your wiring safely. Change to false once everything checks
// out, then upload again.
const bool WIRING_TEST = true;

// Wheel moves the wrong direction? Change to true.
const bool REVERSE_WHEEL = false;

// Signal edges per wheel click. Most 100PPR wheels are 4.
// In test mode, one click should count as exactly 1.
const int EDGES_PER_CLICK = 4;

// E-stop contact type. This pendant's E-stop is normally closed (NC):
// connected when released, open when pushed in.
const bool ESTOP_NORMALLY_CLOSED = true;

// Time between key taps (milliseconds). Raise it if CutControl can't keep
// up (the mill lags or misses steps). Lower it for faster jogging.
const unsigned long TAP_INTERVAL_MS = 50;

// How many clicks' worth of taps may pile up. Keeps the mill from coasting
// after you stop turning the wheel. Lower = stops sooner.
const int MAX_PENDING_CLICKS = 1;

// Continuous mode (x100): how long after the last wheel click the pendant
// lets go of the arrow key. Longer = smoother when turning slowly, but the
// mill coasts a little longer after you stop.
const unsigned long HOLD_RELEASE_MS = 150;

// How long after you let go of green before the pendant puts CutControl
// back to Continuous.
const unsigned long HANDBACK_MS = 1000;

// How long each key is held down for one tap (milliseconds).
const unsigned long KEY_HOLD_MS = 15;

// Pause after changing CutControl's jog step, before jogging.
const unsigned long TAB_SETTLE_MS = 150;

// ===========================================================================
// PIN ASSIGNMENTS (numbers printed on the Pro Micro)
// ===========================================================================
const uint8_t PIN_WHEEL_A = 2;   // terminal 3  Yellow
const uint8_t PIN_WHEEL_B = 3;   // terminal 2  White
const uint8_t PIN_AXIS_X  = 4;   // terminal 4  Brown
const uint8_t PIN_AXIS_Y  = 5;   // terminal 12 Orange
const uint8_t PIN_AXIS_Z  = 6;   // terminal 5  Light blue
const uint8_t PIN_AXIS_4  = 7;   // terminal 13 Blue
const uint8_t PIN_X1      = 8;   // terminal 7  Green/black
const uint8_t PIN_X10     = 9;   // terminal 14 Blue/black
const uint8_t PIN_X100    = 10;  // terminal 6  Clear/black
const uint8_t PIN_ESTOP   = 14;  // terminal 15 Red/black

// ===========================================================================
// Nothing below here should need changing.
// ===========================================================================

enum Axis  { AXIS_OFF, AXIS_X, AXIS_Y, AXIS_Z, AXIS_4 };
enum Ratio { RATIO_NONE, RATIO_X1, RATIO_X10, RATIO_X100 };

// CutControl jog step, in the order Tab cycles through them.
enum CutStep { STEP_CONTINUOUS = 0, STEP_001 = 1, STEP_010 = 2 };

const unsigned long DEBOUNCE_MS = 25;
const unsigned long AXIS_OFF_CONFIRM_MS = 300;

// ---------------------------------------------------------------------------
// Debounced switch input. "active" means the contact is closed to GND.
// ---------------------------------------------------------------------------
struct Input {
  uint8_t pin;
  bool raw;
  bool active;
  unsigned long changedAt;
};

Input inAxisX = { PIN_AXIS_X, false, false, 0 };
Input inAxisY = { PIN_AXIS_Y, false, false, 0 };
Input inAxisZ = { PIN_AXIS_Z, false, false, 0 };
Input inAxis4 = { PIN_AXIS_4, false, false, 0 };
Input inX1    = { PIN_X1,     false, false, 0 };
Input inX10   = { PIN_X10,    false, false, 0 };
Input inX100  = { PIN_X100,   false, false, 0 };
Input inEstop = { PIN_ESTOP,  false, false, 0 };

Input* allInputs[] = { &inAxisX, &inAxisY, &inAxisZ, &inAxis4,
                       &inX1, &inX10, &inX100, &inEstop };
const int NUM_INPUTS = sizeof(allInputs) / sizeof(allInputs[0]);

void setupInput(Input &in) {
  pinMode(in.pin, INPUT_PULLUP);
  in.raw = (digitalRead(in.pin) == LOW);
  in.active = in.raw;
  in.changedAt = millis();
}

void updateInput(Input &in) {
  bool r = (digitalRead(in.pin) == LOW);
  if (r != in.raw) {
    in.raw = r;
    in.changedAt = millis();
  }
  if (in.active != in.raw && millis() - in.changedAt >= DEBOUNCE_MS) {
    in.active = in.raw;
  }
}

// ---------------------------------------------------------------------------
// Handwheel (quadrature encoder), read with interrupts so no clicks are lost
// ---------------------------------------------------------------------------
volatile long encoderEdges = 0;
volatile uint8_t encoderPrev = 0;

// Lookup table: (previous state << 2 | new state) -> -1, 0 or +1
const int8_t QUAD_TABLE[16] = {
   0, -1,  1,  0,
   1,  0,  0, -1,
  -1,  0,  0,  1,
   0,  1, -1,  0
};

void encoderISR() {
  uint8_t a = digitalRead(PIN_WHEEL_A);
  uint8_t b = digitalRead(PIN_WHEEL_B);
  uint8_t now = (a << 1) | b;
  encoderEdges += QUAD_TABLE[(encoderPrev << 2) | now];
  encoderPrev = now;
}

long edgeRemainder = 0;

// Returns whole wheel clicks turned since the last call (+ or -).
long takeWheelClicks() {
  noInterrupts();
  long edges = encoderEdges;
  encoderEdges = 0;
  interrupts();

  edgeRemainder += edges;
  long clicks = edgeRemainder / EDGES_PER_CLICK;
  edgeRemainder -= clicks * EDGES_PER_CLICK;
  return REVERSE_WHEEL ? -clicks : clicks;
}

void discardWheelClicks() {
  noInterrupts();
  encoderEdges = 0;
  interrupts();
  edgeRemainder = 0;
}

// ---------------------------------------------------------------------------
// Keyboard output (prints instead of typing in WIRING_TEST)
// ---------------------------------------------------------------------------
const char* keyName(uint8_t key) {
  switch (key) {
    case KEY_RIGHT_ARROW: return "Right Arrow (X+)";
    case KEY_LEFT_ARROW:  return "Left Arrow (X-)";
    case KEY_UP_ARROW:    return "Up Arrow (Y+)";
    case KEY_DOWN_ARROW:  return "Down Arrow (Y-)";
    case KEY_PAGE_UP:     return "Page Up (Z+)";
    case KEY_PAGE_DOWN:   return "Page Down (Z-)";
    case KEY_TAB:         return "Tab";
    default:              return "?";
  }
}

void tapKey(uint8_t key) {
  if (WIRING_TEST) {
    Serial.print(F("  [would type] "));
    Serial.println(keyName(key));
    return;
  }
  Keyboard.press(key);
  delay(KEY_HOLD_MS);
  Keyboard.release(key);
}

void altCombo(char letter) {
  if (WIRING_TEST) {
    Serial.print(F("  [would type] Alt+"));
    Serial.println((char)(letter - 32));  // show as capital letter
    return;
  }
  Keyboard.press(KEY_LEFT_ALT);
  Keyboard.press(letter);
  delay(KEY_HOLD_MS * 2);
  Keyboard.releaseAll();
}

uint8_t heldKey = 0;             // arrow key held down in continuous mode
unsigned long lastClickAt = 0;

void pressHold(uint8_t key) {
  heldKey = key;
  if (WIRING_TEST) {
    Serial.print(F("  [would HOLD] "));
    Serial.println(keyName(key));
    return;
  }
  Keyboard.press(key);
}

void releaseHold() {
  if (heldKey == 0) return;
  if (WIRING_TEST) {
    Serial.print(F("  [would let go] "));
    Serial.println(keyName(heldKey));
  } else {
    Keyboard.release(heldKey);
  }
  heldKey = 0;
}

uint8_t arrowFor(int axis, bool plus);

// ---------------------------------------------------------------------------
// CutControl jog-step tracking
// ---------------------------------------------------------------------------
int cutStep = STEP_CONTINUOUS;  // CutControl starts in Continuous

void setCutStep(int target) {
  int presses = (target - cutStep + 3) % 3;
  if (presses == 0) return;
  for (int i = 0; i < presses; i++) {
    tapKey(KEY_TAB);
    delay(60);
  }
  cutStep = target;
  delay(TAB_SETTLE_MS);
}

// ---------------------------------------------------------------------------
// Knob readings
// ---------------------------------------------------------------------------
int readAxis() {
  int count = inAxisX.active + inAxisY.active + inAxisZ.active + inAxis4.active;
  if (count != 1) return AXIS_OFF;  // OFF, between positions, or green up
  if (inAxisX.active) return AXIS_X;
  if (inAxisY.active) return AXIS_Y;
  if (inAxisZ.active) return AXIS_Z;
  return AXIS_4;
}

int readRatio() {
  int count = inX1.active + inX10.active + inX100.active;
  if (count != 1) return RATIO_NONE;
  if (inX1.active) return RATIO_X1;
  if (inX10.active) return RATIO_X10;
  return RATIO_X100;
}

bool readEstopPressed() {
  // NC contact: closed (active) when NOT pressed. A broken wire also reads
  // as pressed, which safely locks the wheel.
  return ESTOP_NORMALLY_CLOSED ? !inEstop.active : inEstop.active;
}

const char* axisName(int a) {
  switch (a) {
    case AXIS_X: return "X";
    case AXIS_Y: return "Y";
    case AXIS_Z: return "Z";
    case AXIS_4: return "4";
    default:     return "OFF";
  }
}

const char* ratioName(int r) {
  switch (r) {
    case RATIO_X1:   return "x1";
    case RATIO_X10:  return "x10";
    case RATIO_X100: return "x100";
    default:         return "none";
  }
}

// ---------------------------------------------------------------------------
// State
// ---------------------------------------------------------------------------
int lastAxis = AXIS_OFF;
int lastRatio = RATIO_NONE;
bool lastEnable = false;
bool estopLatched = false;
long pendingTaps = 0;            // + or - taps still to send (step mode)
unsigned long lastTapAt = 0;
unsigned long axisNoneSince = 0;
unsigned long releasedAt = 0;    // when green was let go
long testWheelTotal = 0;

uint8_t arrowFor(int axis, bool plus) {
  if (axis == AXIS_X) return plus ? KEY_RIGHT_ARROW : KEY_LEFT_ARROW;
  if (axis == AXIS_Y) return plus ? KEY_UP_ARROW    : KEY_DOWN_ARROW;
  return plus ? KEY_PAGE_UP : KEY_PAGE_DOWN;
}

void printStatus(const char* reason) {
  if (!WIRING_TEST) return;
  Serial.print(reason);
  Serial.print(F("  | Green: "));
  Serial.print(lastEnable ? F("HELD") : F("up"));
  Serial.print(F("  Axis: "));
  Serial.print(axisName(readAxis()));
  Serial.print(F("  Ratio: "));
  Serial.print(ratioName(readRatio()));
  Serial.print(F("  E-stop: "));
  Serial.print(readEstopPressed() ? F("PRESSED") : F("released"));
  Serial.print(F("  Wheel total: "));
  Serial.println(testWheelTotal);
}

// ---------------------------------------------------------------------------
// Setup
// ---------------------------------------------------------------------------
void setup() {
  for (int i = 0; i < NUM_INPUTS; i++) setupInput(*allInputs[i]);

  pinMode(PIN_WHEEL_A, INPUT_PULLUP);
  pinMode(PIN_WHEEL_B, INPUT_PULLUP);
  encoderPrev = (digitalRead(PIN_WHEEL_A) << 1) | digitalRead(PIN_WHEEL_B);
  attachInterrupt(digitalPinToInterrupt(PIN_WHEEL_A), encoderISR, CHANGE);
  attachInterrupt(digitalPinToInterrupt(PIN_WHEEL_B), encoderISR, CHANGE);

  if (WIRING_TEST) {
    Serial.begin(115200);
    unsigned long start = millis();
    while (!Serial && millis() - start < 4000) { }  // wait for Serial Monitor
    Serial.println();
    Serial.println(F("=== MR-1 PENDANT - WIRING TEST (types nothing) ==="));
    Serial.println(F("Hold green, turn each knob, spin the wheel, press the E-stop."));
    Serial.println(F("Each change prints a line below."));
  } else {
    Keyboard.begin();
  }

  // Start up quietly: note the current positions without sending anything.
  lastEnable = (readAxis() != AXIS_OFF) || (readRatio() != RATIO_NONE);
  lastAxis = readAxis();
  lastRatio = readRatio();
  estopLatched = readEstopPressed();
  discardWheelClicks();
  printStatus("Start");
}

// ---------------------------------------------------------------------------
// Main loop
// ---------------------------------------------------------------------------
void loop() {
  for (int i = 0; i < NUM_INPUTS; i++) updateInput(*allInputs[i]);

  int rawAxis = readAxis();
  int rawRatio = readRatio();
  bool estop = readEstopPressed();

  // ----- E-stop -----
  if (estop && !estopLatched) {
    estopLatched = true;
    pendingTaps = 0;
    releaseHold();
    altCombo('s');                      // Stop Program
    printStatus("E-stop PRESSED");
  } else if (!estop && estopLatched) {
    estopLatched = false;
    discardWheelClicks();               // ignore any spins while locked
    printStatus("E-stop released");
  }

  // ----- Green (enable) button -----
  // The knobs only connect while green is held, so "any knob reads a
  // position" means green is held. The ratio knob always sits on one of
  // its three positions, so it reads whenever green is down.
  bool enable = (rawAxis != AXIS_OFF) || (rawRatio != RATIO_NONE);
  if (enable != lastEnable) {
    lastEnable = enable;
    pendingTaps = 0;
    releaseHold();
    axisNoneSince = 0;
    if (!enable) releasedAt = millis();
    printStatus(enable ? "Green held" : "Green released");
  }

  // Hand CutControl back to Continuous a moment after green is let go,
  // so the screen rests on CONT and the pendant always knows where it is.
  if (!enable && !estop && cutStep != STEP_CONTINUOUS &&
      millis() - releasedAt >= HANDBACK_MS) {
    setCutStep(STEP_CONTINUOUS);
    if (WIRING_TEST) Serial.println(F("  (green let go: CutControl back to Continuous)"));
  }

  int axis = lastAxis;
  int ratio = lastRatio;
  bool knobMoving = false;

  if (enable) {
    // The axis knob touches nothing for a moment between positions. Only
    // treat "nothing" as OFF once it has lasted a while.
    if (rawAxis != AXIS_OFF) {
      axisNoneSince = 0;
    } else if (axisNoneSince == 0) {
      axisNoneSince = millis();
    }
    axis = rawAxis;
    if (rawAxis == AXIS_OFF && lastAxis != AXIS_OFF &&
        millis() - axisNoneSince < AXIS_OFF_CONFIRM_MS) {
      axis = lastAxis;
      knobMoving = true;
    }
    ratio = rawRatio;

    if (axis != lastAxis) {
      pendingTaps = 0;
      releaseHold();
      lastAxis = axis;
      if (axis == AXIS_OFF) {
        setCutStep(STEP_CONTINUOUS);    // hand control back to the screen
      }
      printStatus("Axis knob");
    }
    if (ratio != lastRatio) {
      pendingTaps = 0;
      releaseHold();
      lastRatio = ratio;
      printStatus("Ratio knob");
    }
  }

  // ----- Wheel -----
  bool canJog = enable && !estop && !knobMoving && ratio != RATIO_NONE &&
                (axis == AXIS_X || axis == AXIS_Y || axis == AXIS_Z);
  bool continuousMode = (ratio == RATIO_X100);

  long clicks = takeWheelClicks();
  if (clicks != 0) {
    testWheelTotal += clicks;
    if (WIRING_TEST) {
      Serial.print(F("Wheel "));
      Serial.print(clicks > 0 ? F("+") : F(""));
      Serial.print(clicks);
      Serial.print(F(" click(s)"));
      if (!canJog) Serial.print(F("  (ignored: green up, knob on OFF/4, or E-stop)"));
      Serial.println();
    }
    if (canJog && continuousMode) {
      // Continuous: hold the arrow key while the wheel keeps turning.
      uint8_t key = arrowFor(axis, clicks > 0);
      if (heldKey != key) {
        releaseHold();                  // also handles a direction change
        setCutStep(STEP_CONTINUOUS);
        pressHold(key);
      }
      lastClickAt = millis();
    } else if (canJog) {
      // Step mode: one tap per click.
      long add = clicks;
      // Reversing the wheel cancels anything still queued the other way.
      if ((add > 0 && pendingTaps < 0) || (add < 0 && pendingTaps > 0)) {
        pendingTaps = 0;
      }
      pendingTaps += add;
      long cap = MAX_PENDING_CLICKS;
      if (pendingTaps > cap) pendingTaps = cap;
      if (pendingTaps < -cap) pendingTaps = -cap;
    }
  }

  if (!canJog) {
    pendingTaps = 0;
    releaseHold();
  }

  // Continuous: let go once the wheel stops turning.
  if (heldKey != 0 && millis() - lastClickAt >= HOLD_RELEASE_MS) {
    releaseHold();
  }

  // Step mode: send queued taps at a steady pace.
  if (canJog && !continuousMode && pendingTaps != 0 &&
      millis() - lastTapAt >= TAP_INTERVAL_MS) {
    setCutStep(ratio == RATIO_X1 ? STEP_001 : STEP_010);
    bool plus = pendingTaps > 0;
    tapKey(arrowFor(axis, plus));
    pendingTaps += plus ? -1 : 1;
    lastTapAt = millis();
  }
}

That’s it! Questions, ideas, or you built one yourself? Drop it below and I’ll help where I can.

Full disclosure: Claude (AI) wrote the code. I did the wiring, the meter work, the testing, and the swearing. :grinning_face_with_smiling_eyes:

4 Likes

Very nice and generous of you to share…cool too. Well thought out.

I did miss a step or two somewhere though. I understand that you are sending keystrokes to the PC, but what and how does the arduino send the key to the pc and how does the pc receive it?

For example, I use a game controller on my wood based CNC router and the connection for that is bluetooth and there is a piece of software on the PC that interprets the game controller “button push” and converts it to the coorisponding key strike. For example button push “A” means up arrow.

I apologize but I am not seeing the coorisponding button push to network between the arduino and PC (bluetooth for example) to recieving software on the pc that says “up arrow”. I get the arduino is saying this button means this, but how is that getting to and interpreted on the PC to manipulate CC?

I apologize I think I see it now…the arduino is connected to the pc via usb-c and the pc thinks the arduino is just an ordinary usb keyboard…right?

Yep, you nailed it! And no need to apologize, that’s a great question.

The Pro Micro has a chip (ATmega32U4) with USB built right in, so when you plug it in it tells Windows “hey, I’m a keyboard.” Windows uses its own standard keyboard driver, same as any keyboard you’d buy at the store. No Bluetooth, and nothing extra to install on the PC.

So the translating happens on the Arduino itself. With your game controller, the converter software runs on the PC (button A = up arrow). Mine does that conversion inside the Arduino before anything leaves the pendant (wheel click on X = right arrow). By the time it reaches the PC it’s just a key press, and CutControl reacts exactly like you hit the arrow key on a keyboard.

That’s also why it has to be a Pro Micro or a Leonardo. A regular Arduino Uno can’t act as a keyboard out of the box.

Bonus: since it just types keys, the same idea should work on your wood router too, as long as its software can jog with keyboard shortcuts. You’d just change which keys the code sends.

Beautiful execution. Really clever how have Tab key presses to change jog speed!