0
$\begingroup$

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.

$\endgroup$

1 Answer 1

1
$\begingroup$

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.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .