# LinuxCNC M66 Wait on Input

Instructions · `M66` · verification: source checked

M66 pauses program execution until a selected digital or analog input reaches a specified state, or until a programmed timeout expires. The input is chosen with a P- word (digital) or an E- word (analog), the wait condition with an L- word, and the timeout in seconds with a Q- word. The input value read is stored in parameter #5399, which holds -1 if the timeout is exceeded.

## Specification

| Property | Value |
|---|---|
| Language | gcode |
| Code | M66 |
| Group | M-Codes |
| Syntax | M66 P- \| E- <L-> |
| Dialect | LinuxCNC |

### Parameters

| Name | Description |
|---|---|
| P- | Digital input number from 0 to 3 (adjustable with the motmod num_dio argument). |
| E- | Analog input number from 0 to 3 (adjustable with the motmod num_aio argument). |
| L- | Wait mode type: 0 IMMEDIATE, 1 RISE, 2 FALL, 3 HIGH, 4 LOW. |
| Q- | Timeout in seconds for waiting; if exceeded, #5399 holds -1. Ignored when L is 0; a Q value of zero is an error when L is non-zero. |

## Safety

- In LinuxCNC these inputs are not monitored in real time and thus should not be used for timing-critical applications.
- M66 will not function unless the appropriate motion.digital-in-nn pins or motion.analog-in-nn pins are connected in the HAL file to an input.

## Study notes

- Wait modes: 0 IMMEDIATE (no waiting, returns immediately), 1 RISE, 2 FALL, 3 HIGH, 4 LOW.
- The current value of the input is stored in parameter #5399 in mode 0; on timeout #5399 holds -1.
- Mode 0 is the only wait mode permitted for an analog input.
- Programming M66 with both a P- word and an E- word (selecting both a digital and an analog input) is an error.
- The number of I/O can be increased with the num_dio or num_aio parameter when loading the motion controller.
- Example given: M66 P0 L3 Q5 waits up to 5 seconds for digital input 0 to turn on.
- M66 stops further execution of the program until the selected event or the programmed timeout occurs.

## Sources

1. [M-Codes](https://linuxcnc.org/docs/html/gcode/m-code.html#mcode:m66) (accessed 2026-10-26)

---

Source page: https://machineschema.com/instruction/mcode-m66  
JSON: https://machineschema.com/instruction/mcode-m66.json  
License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Cite Machine Schema and the original sources.
