{"id":"mcode-m66","model_id":"M66","name":"LinuxCNC M66 Wait on Input","summary":"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.","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."],"safety_notes":["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."],"sources":[{"url":"https://linuxcnc.org/docs/html/gcode/m-code.html#mcode:m66","title":"M-Codes","accessed":"2026-10-26"}],"verification":{"status":"source_checked","checked_at":"2026-10-26","values":11,"method":"llm_source_check"},"updated_at":"2026-10-26","type":"instruction","spec":{"language":"gcode","code":"M66","group":"M-Codes","syntax":"M66 P- | E- <L->","parameters":[{"name":"P-","description":"Digital input number from 0 to 3 (adjustable with the motmod num_dio argument)."},{"name":"E-","description":"Analog input number from 0 to 3 (adjustable with the motmod num_aio argument)."},{"name":"L-","description":"Wait mode type: 0 IMMEDIATE, 1 RISE, 2 FALL, 3 HIGH, 4 LOW."},{"name":"Q-","description":"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."}],"dialect":"LinuxCNC","related":[],"standards":[]},"url":"https://machineschema.com/instruction/mcode-m66","license":"https://creativecommons.org/licenses/by/4.0/"}