<p>Fixed it.</p>
<p>As expected and completely reasonable, the MCU needed some time to wake up, clocked it at 6-7 seconds so gave it a total 10 seconds in code. Found the most graceful way of doing it was in the same macro, also included a nice little beep to let me know the game is afoot. I also added an ATX power supply to the rig in the mean time so that is switched first, and I only turn on the 24V PSU after the MCU woke up because <strong>control before power</strong>.</p>
<pre><code># Switches 24V PSU through physical relay gate 1
[output_pin 24V_power]
pin: rpi:gpio17

# Switches 12V PSU through physical relay gate 2
[output_pin 12V_power]
pin: rpi:gpio27

# Switches power ON
[gcode_macro POWER_ON]
gcode:
    SET_PIN PIN=12V_power VALUE=1
    G4 P9000 # Give MCU time to wake up
    SET_PIN PIN=24V_power VALUE=1
    G4 P1000 # Give 24V PSU time to wake up
    BEEP_STARTUP

# Switches power OFF
[gcode_macro POWER_OFF]
gcode:
    BEEP_POWEROFF
    SET_PIN PIN=24V_power VALUE=0
    SET_PIN PIN=12V_power VALUE=0
    
</code></pre>
<p>Included the extra bit because it might help a stranger, as the original question is simply answered by adding:</p>
<pre><code>G4 P10000 # Give MCU time to wake up
</code></pre>
<p>directly after the power supply turns on, either after the macro in the slicer or in the macro as I did, and before any action from the MCU is requested. Note that this time can vary based on your MCU, and I refrained from tuning this further to prevent errors down the line.</p>

CC BY-SA 4.0
2023-07-26T22:09:42.217Z
2023-07-26T22:10:38.857Z
2023-07-26T22:10:38.857Z
Sasquatch-cyber
<p>TL;DR: When powered off (default state) the Pi powers the Ender's MCU through USB and all is well, but when I switch on the power through G-code I get</p>
<blockquote>
<p>Lost communication with MCU 'mcu'</p>
</blockquote>
<p>I'm quite certain I'm not the first one to have this happen, but searching hasn't gotten me the answer yet, probably due to the fact that searching for the error message only gives unrelated answers. My Ender 3v2 (4.2.2 mainboard) is set up such that my Raspberry Pi 3 B+ switches on the power supply through a relay controlled by GPIO.</p>
<p>Macro (which seems to run fine as it does the switching):</p>
<pre><code>    # Turns on printer
    [output_pin printer_power]
    pin: rpi:gpio17
    
    # Printer power ON
    [gcode_macro POWER_ON]
    gcode:
        SET_PIN PIN=printer_power VALUE=1
    
    # Printer power OFF
    [gcode_macro POWER_OFF]
    gcode:
        SET_PIN PIN=printer_power VALUE=0

gpioinfo pin 17:

     line  17:     &quot;GPIO17&quot;    &quot;klipper&quot;  output  active-high [used]
</code></pre>
<p>I use the commands <code>POWER_ON</code> and <code>POWER_OFF</code> in the slicer G-code, where they are either first or last. (edit: don't power off the printer through the slicer if you want to see succesful prints in your overview - practically it works fine but it's much better to let the printer auto power off from idle, see <a href="https://github.com/jschuh/klipper-macros" rel="nofollow noreferrer">https://github.com/jschuh/klipper-macros</a> for example)</p>
<p>When I use my slicer to send a file to the printer it starts and runs for about three seconds as it starts homing axes, and then the error</p>
<blockquote>
<p>Lost communication with MCU 'mcu'</p>
</blockquote>
<p>appears and the printer hurts itself in its confusion, but when I use the commands through mainsail it works just fine.</p>
<p>I hope someone knows how to avoid this, might just be an electrical issue (immediate instructions/power draw on startup?) that I need to circumvent somehow.</p>

<creality-ender-3><raspberry-pi><klipper>
Switching power ON with RPi loses connection with MCU (Ender 3v2/Klipper/Mainsail)
Sasquatch-cyber
# Switching power ON with RPi loses connection with MCU (Ender 3v2/Klipper/Mainsail)

(Asked by: username_0 on 2023-07-10)

TL;DR: When powered off (default state) the Pi powers the Ender's MCU through USB and all is well, but when I switch on the power through G-code I get

> Lost communication with MCU 'mcu'

I'm quite certain I'm not the first one to have this happen, but searching hasn't gotten me the answer yet, probably due to the fact that searching for the error message only gives unrelated answers. My Ender 3v2 (4.2.2 mainboard) is set up such that my Raspberry Pi 3 B+ switches on the power supply through a relay controlled by GPIO.

Macro (which seems to run fine as it does the switching):

```
    # Turns on printer
    [output_pin printer_power]
    pin: rpi:gpio17
    
    # Printer power ON
    [gcode_macro POWER_ON]
    gcode:
        SET_PIN PIN=printer_power VALUE=1
    
    # Printer power OFF
    [gcode_macro POWER_OFF]
    gcode:
        SET_PIN PIN=printer_power VALUE=0

gpioinfo pin 17:

     line  17:     "GPIO17"    "klipper"  output  active-high [used]

```

I use the commands `POWER_ON` and `POWER_OFF` in the slicer G-code, where they are either first or last. (edit: don't power off the printer through the slicer if you want to see succesful prints in your overview - practically it works fine but it's much better to let the printer auto power off from idle, see <https://github.com/jschuh/klipper-macros> for example)

When I use my slicer to send a file to the printer it starts and runs for about three seconds as it starts homing axes, and then the error

> Lost communication with MCU 'mcu'

appears and the printer hurts itself in its confusion, but when I use the commands through mainsail it works just fine.

I hope someone knows how to avoid this, might just be an electrical issue (immediate instructions/power draw on startup?) that I need to circumvent somehow.

**Tags:** creality-ender-3, raspberry-pi, klipper


---

## 1 answers

### Answer by username_0 on 2023-07-26. Score: 1

Fixed it.

As expected and completely reasonable, the MCU needed some time to wake up, clocked it at 6-7 seconds so gave it a total 10 seconds in code. Found the most graceful way of doing it was in the same macro, also included a nice little beep to let me know the game is afoot. I also added an ATX power supply to the rig in the mean time so that is switched first, and I only turn on the 24V PSU after the MCU woke up because **control before power**.

```
# Switches 24V PSU through physical relay gate 1
[output_pin 24V_power]
pin: rpi:gpio17

# Switches 12V PSU through physical relay gate 2
[output_pin 12V_power]
pin: rpi:gpio27

# Switches power ON
[gcode_macro POWER_ON]
gcode:
    SET_PIN PIN=12V_power VALUE=1
    G4 P9000 # Give MCU time to wake up
    SET_PIN PIN=24V_power VALUE=1
    G4 P1000 # Give 24V PSU time to wake up
    BEEP_STARTUP

# Switches power OFF
[gcode_macro POWER_OFF]
gcode:
    BEEP_POWEROFF
    SET_PIN PIN=24V_power VALUE=0
    SET_PIN PIN=12V_power VALUE=0
    

```

Included the extra bit because it might help a stranger, as the original question is simply answered by adding:

```
G4 P10000 # Give MCU time to wake up

```

directly after the power supply turns on, either after the macro in the slicer or in the macro as I did, and before any action from the MCU is requested. Note that this time can vary based on your MCU, and I refrained from tuning this further to prevent errors down the line.


---

