EMERGENCY STOP and GPIO pins to set at micro-controller startup

Hi, I have defined (PF6) GPIO pins to set at micro-controller startup.
This pin is used to control the source using the PS-ON connector.

The problem occurs with M112 or EMERGENCY STOP.
The output [mcu] PF6 goes from log “H” to “L” and the relay on the MKS PWC board turns off the 230V supply to the source.

Is it possible to exclude the PF6 pin from the “EMERGENCY STOP” so that it remains always at the “H” level?

How can it be solved?

Thanks.

Means: All down. And fast. At once. And so it’s not bad when the power goes off too.

Going through an exception list can cost some important milliseconds.

I thought of using the GPIO pins on the Raspberry.
Do they also go to “L” during EMERGENCY STOP?

You may test that with a LED.

Hi,
I don’t think it should be a problem.

Because during EMERGENCY STOP, the heater fans switch from log L to H,
so I think that leaving the PS_ON pin in the “H” state will not have such an effect on “milliseconds”.

FYI @koconnor : What do you think Kevin ?

Use your Pi to control the power supply pin using Moonraker instead of an mcu.

https://moonraker.readthedocs.io/en/latest/configuration/#gpio-device-configuration

Edit: Here’s my configuration for reference

[power printer]
type: gpio
pin: gpio2
bound_services: klipper
initial_state: off
on_when_job_queued: True
locked_while_printing: True
restart_klipper_when_powered: True
restart_delay: 3

Hi
And will this “gpio” pin be in log level “H” when the Raspberry is first turned on?

To keep the relay on the MKS-PWC module closed.

How will I control this “gpio” from the Klipper macro?

I have this connection, the 5V supply for the Raspberry is after the PWC module

image

Generally people power the Pi separately from their board as there is little sense in turning the Pi off every time you turn the board off. It keeps the Pi in control of everything and prevents you from having to wait for the Pi to reboot every time. Plus the wear and tear on the SD Card.

Easiest way is to have a separate “always on” 5V supply connected to your power outlet. A common one is

https://www.amazon.com/MEAN-WELL-RS-25-5-Supply-Single/dp/B00DECXUD0

There’s also a 3 amp version for a few dollars cheaper but I didn’t trust that to keep up in all power draw situations.

Then you use a Pi GPIO to trigger the relay/SSR (SSR is safer in this regard, if you want to use a relay you’ll need to ensure the board has protection so the inductive kickback doesn’t kill your Pi/GPIO).

https://www.raspberrypi.com/documentation/computers/raspberry-pi.html

Just make sure your GPIO is setup as an output in Linux and configure it in Moonraker in the guide I listed above.

I’ve found that the Pi GPIOs can’t reliably drive the input of an SSR/Relay so I used a small level shifter/buffer. You can just as easily make a quick BJT/Mosfet switch, optocoupler circuit, Single buffer gate, etc.

Then you can power on your printer and everything else via the Pi and your mcus wont interfere with it.


2nd option is use the Pi and configure the GPIO to be high at startup using a boot overlay as described here. Then if you restart things you’ll know that GPIO is High.

Name:   gpio-poweroff
Info:   Drives a GPIO high or low on poweroff (including halt). Using this
        overlay interferes with the normal power-down sequence, preventing the
        kernel from resetting the SoC (a necessary step in a normal power-off
        or reboot). This also disables the ability to trigger a boot by driving
        GPIO3 low.

        The GPIO starts in an inactive state. At poweroff time it is driven
        active for 100ms, then inactive for 100ms, then active again. It is
        safe to remove the power at any point after the initial activation of
        the GPIO.

        Users of this overlay are required to provide an external mechanism to
        switch off the power supply when signalled - failure to do so results
        in a kernel BUG, increased power consumption and undefined behaviour.
Load:   dtoverlay=gpio-poweroff,<param>=<val>
Params: gpiopin                 GPIO for signalling (default 26)

        active_low              Set if the power control device requires a
                                high->low transition to trigger a power-down.
                                Note that this will require the support of a
                                custom dt-blob.bin to prevent a power-down
                                during the boot process, and that a reboot
                                will also cause the pin to go low.
        input                   Set if the gpio pin should be configured as
                                an input.
        export                  Set to export the configured pin to sysfs
        active_delay_ms         Initial GPIO active period (default 100)
        inactive_delay_ms       Subsequent GPIO inactive period (default 100)
        timeout_ms              Specify (in ms) how long the kernel waits for
                                power-down before issuing a WARN (default 3000).

Hi @TheFuzzyGiggler so the config will look like this?

2nd option:

# RPi as a secondary MCU
# https://www.klipper3d.org/RPi_microcontroller.html

[mcu host]
serial: /tmp/klipper_host_mcu

# Set GPIO23 to be an output set to 1
# ... boot/config.txt add this line
# gpio=23=op,dh

#--------------------------------------------------------

# configuration for MKS PWC V3.0 module

[output_pin PW_OFF]
pin: host:gpio23
value: 1

It should, My only question would be how are you going to turn it ON?

You use the power switch on your printer every time?

Nothing wrong with that per say, the first option I described above just works around that for those of us who are lazy.

For example, I have a separate 5v supply (what I linked above) that is “always on” and powers my Pi. I have my Pi connected to an SSR which then can turn on my 24V PSU that runs everything else.

That way Mainsail is always “running” just not active, and the Mainsail interface has the power button built in that I click to turn the printer on from my PC/Phone/Laptop whatever.

I turn on the printer with the main switch and the MKS-PWC module control button. I print about 4-6 hours a day. Sometimes the printing takes a while, but I can’t stay longer. That’s why there’s that MKS-PWC module for automatic shutdown using gcode_macro from Klipper.

Yes, it’s not bad, but for safety reasons I don’t leave the printer under voltage when it finishes printing. Sometimes it happens that I don’t print for a week.

The PS_ON setting as I have it now (i.e. via GPIO on the MCU of the printer) suits me. Unfortunately, it is unpleasant when you are tuning the printer and an EMERGENCY STOP occurs. And inventing a switch there, when it could be solved at the level of FW Klipper

… if it is possible to turn on the “heater fan” why wouldn’t it be possible to leave the “PS_ON” pin at the “H” level ?

I overlooked this option:

[output_pin PS_ON]
pin: PF6
value: 1
shutdown_value: 1
#   The value to set the pin to on an MCU shutdown event. 
#   The default is 0 (for low voltage).

I’ll try it.

HI, yes it works, in EMERGENCY STOP the pin will stay in “H” level and the power will not be disconnected.

2 Likes

You got me on that one too, I never noticed that option. Interesting.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.