---
title: M54, M55, M56, M57 (General purpose IO)
slug: m54-m55-m56-m57-general-purpose-io
docTags: 
createdAt: 2023-04-17T15:17:50.000Z
---

:::hint{type="warning"}
Please note that mentioned commands may fail during loading and/or simulation.

To make your macro code avoid these errors please take a look at the manual section [Run behavior during loading of job file and simulation](docId\:p2Jh9fFRvp0WCb5jCD9px)
:::

## Digital outputs

### Set output - M54 &#x50;*...&#x20;*

The P word must be between `1` and `10` where `1` is *AUX1* and `10` is *AUX10*.&#x20;

:::BlockQuote
M54 P1  (set AUX1 out to 1)
:::

If the connected controller only has one AUX output, `2` is mapped to *FLOOD&#x20;*&#x61;nd `3` to *MIST*.

:::BlockQuote
M54 P2  (set AUX2 out to 1 or FLOOD to 1 if the controller has 1 AUX)
:::

***

### Clear output - M55 &#x50;*...*

Clear output. The P word must be between `1` and `10` where `1` is *AUX1* and `10` is *AUX10*.&#x20;

:::BlockQuote
M55 P1 (set AUX1 out to 0)
:::

If the connected controller only has one AUX output, `2` is mapped to *FLOOD* and `3` to *MIST*.

:::BlockQuote
M55 P2  (set AUX2 out to 0 or FLOAD to 0 if the controller has 1 AUX)
:::

***

### Read outputs - M57 P

Read output *x*, store the result in variable `#5399`

:::BlockQuote
M57 P...
:::

| Output           | P value  |
| ---------------- | -------- |
| AUX1-AUX*n*      | 1 to *n* |
| Machine On       | 51       |
| Drive Enable     | 52       |
| Coolant1 (Flood) | 61       |
| Coolant2 (Mist)  | 62       |
| Tool             | 63       |
| Tool direction   | 64       |

***

## Digital inputs

### Read input - M56 &#x50;*...*&#x20;

| P value  | Input           |
| -------- | --------------- |
| 51 - 56  | Home Inputs X-C |
| 61       | Probe Input     |
| 62       | Sync Input      |
| 63       | HWA Input       |
| 64       | HWB Input       |
| 65       | ESTOP1          |
| 66       | ESTOP2          |
| 67       | EXTERR          |
| 68       | PAUSE           |

The result is stored in [variable](docId\:oqHjs3LLCfQkSac_cemc2)  `#5399`

Example: erad AUX input 3:

:::BlockQuote
M56 P3 (Read AUX in 3)
If \[#5399 == 1]
&#x20;  Msg "AUX3=ON"
Else
&#x20;  Msg "AUX3=OFF"
endif
:::

Example: read home-input of X axis:

:::BlockQuote
M56 P51
If \[#5399 == 1]
&#x20;  Msg "HOME X=ON"
Else
&#x20;  Msg "HOME X=OFF"
endif
:::

***

### Read input + wait - M56 &#x50;*&#x20;...&#x20;*&#x4C;...  Q...

Read digital input *P* and specify wait mode, the result is stored in variable `#5399`

- **P**...: the input number
- **L*0*:** do not wait
- **L*1*:** Wait for High
- **L*2***: Wait for Low
- **Q**...: timeout (seconds)

:::BlockQuote
M56 P3 L2 Q30 (Read AUX in 3)
If \[#5399 == -1]
&#x20;  Errmsg "Timeout while waiting for AUX3 becoming low"
Else
&#x20;  Msg "AUX3 is off"
Endif
:::

Note that we use wait (L2) here, in the event of a timeout, the value of `#5399` is -1.

In order to make this **code simulation and rendering proof&#x20;**&#x77;e need to extend it like this:

:::BlockQuote
If \[\[#5380 == 0] and \[#5397 == 0]] ;;Check only if running job
&#x20;  M56 P3 L2 Q30 (Read AUX in 3)
&#x20;  If \[#5399 == -1]
&#x20;   Errmsg “Timeout while waiting for AUX3 becoming low”
&#x20; Else
&#x20;   Msg “AUX3 is off”
&#x20; Endif
Endif&#x20;
:::

***

## Analog inputs

### Read analog input - M56 &#x45;*…*

Read analog input E, result stored in `#5399`

:::BlockQuote
M56 E3
Msg "analog value is " #5399
:::

***

## PWM

### Set PWM - M54 E... &#x51;*...*

Set PWM output E to permille value Q (0 \<= *y* \<= 1000)

:::BlockQuote
M54 E2 Q500 (Set PWM2 to 50% PWM)
:::

***

### Read PWM output - M57 E...

Read PWM output, result stored in `#5399`

:::BlockQuote
M57 E3
If \[#5399 == 0]
&#x20;  Msg "PWM IS OFF"
Else
&#x20;  Msg "PWM IS ON, VALUE="#5399
endif
:::

***

## Optional IOCARD

If a relay board is used such as [RLY8](https://edingcnc.com/product/rly8-io/), the IO number *P* or *E* is specified like in the following examples:

- value of `103` means card 1 port 3
- value of `208` means card 2 port 8

