1 / 2
Ender 3 NG v1.2 C14 and 22 mm power button mount — image 1
1 / 2

Ender 3 NG v1.2 C14 and 22 mm power button mount

Order a print of this model

We calculate the final price from your selected file. You review and accept it before payment.

Saved on this device.

Control your printer's power from your SoC's power signal

Rating
0 / 5
Likes
20
Downloads
29
Makes
0
Views
365
Reviews
0

Updated at source:

Model information

License
Creative Commons — Attribution — Noncommercial — Share Alike

In the Ender 3 NG v1.2, the build guide instructs the user to use the power connector and power switch from the original Ender as a donor.  This works fine for on-controller firmware for a factory Ender (i.e. Marlin), but on most Ender 3 NG v1.2 builds, a SoC module is also used (i.e. a Raspberry Pi).  When powering off the printer with this switch when an RPi is present, the RPi experiences cold shut downs, which can lead to filesystem inconsistencies and data loss.  Additionally, the printer should ideally cool off parts before cutting power, too.  If the heatbreak or the chamber heaters are hot when the power is cut, there may be filament jams and some parts may melt.

The solution to all this is to have the printer shut down when it's safe to shut down.  We can send the ACPI shutdown signal with a power switch to the SoC module, and the OS will power down by itself.  When this occurs, the AC power can safely be cut.  For parts that require additional cooling, a script can be used that watches for temperatures to drop before shutting down.

The parts in this model are for a press-fit C14 power connector and a momentary 22 mm DPST power switch with an indicator light.  Here are Amazon links to the parts that fit onto this model:

The original Ender 3 power connector also includes a fuse, which is removed with this model.  You should still include a fuse directly after the power input, and it's a little cleaner to simply mount a fuse holder on the DIN rails.  Here's a DIN rail-mounted fuse holder with a popped fuse indicator that you can mount inside your electronics panel:

Here's a relay module that is powered by 24V, and will accept a signal-level voltage from your SoC module to trigger power:

You may also be interested in this mount for the 30A relay module above.

To install this panel, place the panel and the backer together, and install the connector and switch onto the models (including adding the switch nut).  Then, remove the right vent from the printer, slide the models into the lower vent, then reinstall the right vent.

If you want a simpler build, a latching variant of the switch is available.  This will simply offer a push on, push off toggle without any power management control.  A relay module won't be needed for this setup.  As always, use a fuse for this setup, too.

Here's a shell script you can use that waits for all important fans to stop, then power off the machine.  This script pulses the printer's LEDs at a low brightness to show that it's “working.”  I opted to monitor the fans instead of monitoring temperatures, because the printer deliberately turns the fans off when the important parts are cooled.

Edit the FANS array with the fans you want to monitor, the LED variable with the LED you'd like to pulse, and optionally, you can change LED_CYCLE to use a different “working” cycle, and LED_OFF to a different LED state when the printer is powering off.

I personally keep this script in /etc/moonraker/poweroff-when-fans-are-stopped.  Make sure it's executable by calling chmod +x /etc/moonraker/poweroff-when-fans-are-stopped.

#!/bin/sh

MOONRAKER_BASE_URL="http://localhost:7125"

FANS=( "controller_fan controller_fan" "heater_fan heatbreak_cooling_fan" "temperature_fan _chamber_fan_left" )

LED="Enclosure_LEDs"

LED_CYCLE=( "RED=0 GREEN=0 BLUE=0 WHITE=0.01" "RED=0 GREEN=0 BLUE=0 WHITE=0.02" )

LED_OFF="RED=0 GREEN=0 BLUE=0 WHITE=0"

POWEROFF_COMMAND=(sudo /usr/bin/systemctl poweroff)

query=("${FANS[@]/%/=power}") query=$(IFS="&"; echo "${query[*]// /%20}") fans_url="$MOONRAKER_BASE_URL/printer/objects/query?$query"

function pulse_leds() { while :; do for led_values in "${LED_CYCLE[@]}"; do curl -sX POST "$MOONRAKER_BASE_URL/printer/gcode/script" -H "Content-Type: application/json" -d "{"script": "SET_LED LED=$LED $led_values"}" > /dev/null

  sleep 0.5
done

done }

echo "Polling Moonraker API until fans stop..."

while :; do fans_response=$(curl -s "$fans_url")

if ! jq -e '.result.status | with_entries(.value = .value.power)' <<< "$fans_response"; then echo "Moonraker API unavailable."

"${POWEROFF_COMMAND[@]}"

fi

jq -e '.result.status | map(.power) | all(. == 0)' <<< "$fans_response" > /dev/null && break

if [ -z "$pulse_leds_pid" ]; then pulse_leds & pulse_leds_pid=$! fi

sleep 1 done

if [ -n "$pulse_leds_pid" ]; then kill "$pulse_leds_pid" unset pulse_leds_pid

curl -sX POST "$MOONRAKER_BASE_URL/printer/gcode/script" -H "Content-Type: application/json" -d "{"script": "SET_LED LED=$LED $LED_OFF"}" > /dev/null fi

echo "All fans stopped."

"${POWEROFF_COMMAND[@]}"

To trigger this script when you push the power button, you need to tell systemd to ignore the power button first.  Do this by changing /etc/systemd/logind.conf to include the configuration below, then restart systemd-logind.service.

[Login]
...
HandlePowerKey=ignore
...

Then, make sure acpid is installed, and create the file /etc/acpi/events/poweroff-when-fans-are-stopped:

event=button/power
action=/usr/bin/sudo -u moonraker /etc/moonraker/poweroff-when-fans-are-stopped

sudo is used here because I want the script to be called as the moonraker user.  If you're okay with the script running as root, you can omit sudo -u moonraker.  Then, ensure that acpid is set to start on boot, and restart it if needed to see the new event file.

If necessary, make sure that the user calling /etc/moonraker/poweroff-when-fans-are-stopped has access to call power commands with sudo.  This is my sudoers file called /etc/sudoers.d/moonraker.  %moonraker means any user in the moonraker group.  If you want to grant a specific user, you can omit % (i.e. moonraker).

%moonraker ALL=(ALL) NOPASSWD: /usr/bin/systemctl poweroff,/usr/bin/systemctl halt,/usr/bin/systemctl reboot,/usr/bin/systemctl restart moonraker

Now, when you push the power button, the lights will pulse while the fans cool the parts off, then the printer turns off.  And when this happens, the relay turns off, and shuts off all power to the printer.  Neat!

Tags