Help Setting up Resume after power failure and Bed leveling.

  • Hoping that someone could possibly help me with setting up Resume after power failure as I have had 2 long prints fail in 2 days due to power cuts and it is very frustrating.

    I would also like to setup bed leveling using 2 optical endstops on the either side of the bed for the bed leveling so I can minimise how much Mesh bed compensation is in use.

    I have a CoreXY hypercube Fusion with a clone BMG extruder & Genuine E3D V6 hotend, dual Z axis screws, DC42 Ir Probe for probing the bed and setting the Z height, with a print volume of approx 305 x 270 x 480. Running
    Duet 2 Wifi with Board: Duet WiFi 1.02 or later
    Firmware: RepRapFirmware for Duet 2 WiFi/Ethernet 2.05 (2019-12-13b1)
    Duet WiFi Server Version: 1.23

    My setup currently homes the Z to the center of the bed using the DC42 Ir probe.

    I have tried to get my head around the power failure resume but I am not sure about it as I can't get how to probe the bed again without causing it to foul against the print without having endstop switches on the bottom of the Z axis hence why I thought it would be a good idea to setup the Bed leveling at the same time.

    So if someone would kindly be able to help me setup the bed leveling using dual optical endstops and the power resume I would be very appreciative. ( @Phaedrux is probably hiding already )

    If I need to post any of the sys files please let me know and I will.

  • Moderator

    @RAM What you want should be feasible, as many others have done this, and perhaps those with similar hardware can step in and show their resume settings.

    This page is pretty clear and detailed about how to set up resume:
    If you have any specific questions about this, please ask.

    It sounds like dealing with the Z axis is the most difficult part for you. What happens to Z when the power is cut? Does it drop? If not, you'll only lose 1 full step of accuracy on Z at resume, as re-powered motors will jump to the closest full step. This is the easiest way to do it, and losing/gaining one step is pretty trivial unless you have a very low steps per mm on Z. There isn't really any way to combat this, unless you home the Z axis.

    If your bed does drop or move when power is removed, or you really want to rehome Z, you need a way of homing it accurately that does not need the bed to come up to nozzle height (you could, but you'd need to know that the printed part wasn't going to hit the XY gantry). There really isn't any way to probe the bed, either, with a print already on it. Usually the way to do it is to home at the far end of the Z axis, with the bed at the bottom of the printer. You can install an endstop (optical or mechanical) on each motor, and home them independently; see
    You can do this just for Resume, instead of using your probe to find Z, or use it all the time, though you might get bored of your bed going up and down! You can fit the endstops, and use bed probing to accurately set the offsets for each side.

    Alternatively, reconfigure your Z axis to have only one motor, connected to leadscrews by belt, and manually level the bed. It's unlikely to go out of level, and many forum users swear by this. Then you only need one lower Z endstop.

    Lastly, if power cuts are a common occurrence, and they are not too long, consider getting an Uninterruptible Power Supply, of sufficient power to run the whole printer. They can also smooth out the power supply and reduce other problems!


  • @droftarts Thanks for the info, I was reading through the dozuki again to see if I could get my head around it but I am a little confused as it talks about sys/resurrect.g at the very start on how it works but I have looked in my DWC and in the backup /sys folder on my PC to make sure that I am not going blind but I do not have this file at all and it doesn't state that you have to create it.

    The only file that I have that I might think it could be is resume.g would this be the file instead of resurrect.g ?
    Sorry if this sounds a bit trivial but I want to be certain that I am not missing anything before I put this into place.

    As for the bed dropping when the power is cut I don't think it moves at all as the last print I had to remove was still stuck to the nozzel when I had to home the X / Y Axis to get it out of the way to remove the print from the bed.

    I mainly wanted to add the dual optical endstops to the bottom end of the Z Axis lead screws so that I could use True Bed Leveling mainly & for the purpose of the resume function. If there is another way that I could only have to home say the X & Y axis for the resume function to work and not have to do Z at all then I would be fine with that or to have the Z axis to only probe the front left corner of the bed where the X & Y axis also home as I can't actually use my full bed because of using a glass bed & having to use clips to hold it in place.

    I think the power cuts lately are due to the fact that we are in lockdown and the place where I live has a substation that is not man enough as they have built loads more houses but didn't upgrade it. 😠
    I will look into geting one for the printer as I do use one for my 2 NAS setups, But I can't really add the printer to it as it is over the other side of the loft ( attick).

  • Moderator

    @RAM said in Help Setting up Resume after power failure and Bed leveling.:

    I am a little confused as it talks about sys/resurrect.g

    Any time you pause a print from SD card, the state of the print is saved to a special file on the SD card, sys/resurrect.g

    It's created by the firmware when it has to save the current print progress, as in, when pause is initiated, or when the power fails.
    Resume.g is used by the firmware to resume a paused print.

    ; pause.g
    ; called when a print from SD card is paused
    ; generated by RepRapFirmware Configuration Tool v2 on Sun May 05 2019 17:25:18 GMT-0600 (Central Standard Time)
    G10 ; retract
    G91            ; relative positioning
    G1 Z5 F360     ; lift Z by 5mm
    G90            ; absolute positioning
    G1 X10 Y10 F6000 ; go to X=10 Y=10
    ; resume.g
    ; called before a print from SD card is resumed
    ; generated by RepRapFirmware Configuration Tool v2 on Sun May 05 2019 17:25:18 GMT-0600 (Central Standard Time)
    G1 R1 X0 Y0 Z5 F6000 ; go to 5mm above position of the last print move
    G1 R1 X0 Y0          ; go back to the last print move
    G11 ; unretract

    Pause saves the current position, retracts some filament, lifts the head, and moves it out of the way.
    Resume moves the head back to the saved position (5mm above it at first, and then drops to the print height, unretracts, and resumes printing the gcode file.

    The power save function behaves in a similar way, except that a few extra steps are needed to prepare the printer before it can resume printing because the power loss has turned off the heaters and the motors have lost position. This is where resume-prologue comes in. This is a file you customize to tell the printer what to do do get ready to resume the print again. This includes rehoming the axis safely, getting up to temp, etc.

    How you want to home Z axis is entirely up to you. There are many ways to do it. You can do it with zmax endstops, or you could do it entirely manually.

    Bed leveling and power loss recovery are two seperate things, but can be used together. Bed leveling would usually be scripted in the bed.g file which gets called by G32. Part of that process would be homing the Z axis and you probably won't want to use the same process to home Z in normal situations as you would during a power loss recovery (due to the bed having a print on it, and probably not wanting to home to Z max every time).

    So I would suggest you start by spliting the two processes up in your mind first. Either get power loss recovery working, or bed leveling setup first, and move on to the other.

    If your bed isn't dropping at all at power loss you have the option of simply using a G92 Z command to set the print height manually. You can use a caliper or something to get the height of the printed part and then go back to the slicer to compare and find the exact layer number and z height that way.

    See here for an example of setting up a z max endstop.

    You probably only need a single z max endstop, since if the bed isn't dropping, you could just use the z probe to level the bed before the print as decribed by, and it will stay pretty even after a power loss, so you really only need to reliably set the z height. Any attempt to correct for tilt at that point may introduce more height error than it solves.

  • @Phaedrux said in Help Setting up Resume after power failure and Bed leveling.:

    Any time you pause a print from SD card, the state of the print is saved to a special file on the SD card, sys/resurrect.g

    It's created by the firmware when it has to save the current print progress, as in, when pause is initiated, or when the power fails.

    I have used the Pause on the DWC before where I had to sort something out and then resumed the print, so does the resurrect.g file get deleted once it has been used or am I missing something as I don't have the ressurect.g file within my /sys folder.

    I Just want to be sure that I am getting this right before I implement it into the setup. I will deal with just the power failure resume function 1st then deal with the True bed leveling after.

    I add this to the config.g file
    M911 S21.0 R23.0 P"M913 X0 Y0 G91 M83 G1 Z3 E-5 F1000

    (Here ok ? or does it need to be in a certain area)
    ; Miscellaneous
    M501 ; Load saved parameters from non-volatile memory
    M911 S21.0 R23.0 P"M913 X0 Y0 G91 M83 G1 Z3 E-5 F1000

    Then create the file /sys/resurrect-prologue.g file containing the following

    M116 ; wait for temperatures
    G28 X Y ; home X and Y
    M83 ; relative extrusion
    G1 E4 F3600 ; undo the retraction that was done in the M911 power fail script

    Also do I need to create a macro for running the resume function ? As I can't seem to find this information.

  • Moderator

    @RAM said in Help Setting up Resume after power failure and Bed leveling.:

    When the power supply voltage drops below the auto-pause threshold voltage, the heaters are turned off to conserve power, the state of the print is saved to file sys/resurrect.g on the SD card, the power fail script specified in the M911 command is run, and the print is left in a paused state

    After the power is restored, you can use command M916 to resume the print from where it stopped. This command runs file sys/resurrect.g which calls sys/resurrect-prologue.g at an appropriate point to home the printer

    I suggest re-reading the documentation link.

  • @Phaedrux

    I have re read the documentaion for about the 10th time, I did the following.

    put the M911 information into the config.g

    ; General preferences
    G21                                     ; Work in millimetres
    G90                                     ; send absolute coordinates...
    M83                                     ; ...but relative extruder moves
    M911 S21.0 R23.0 P"M913 X0 Y0 G91 M83 G1 Z3 E-5 F1000 ; Power Loss Function
    M550 P"HEVO"                            ; set printer name

    Then created a ressurect.g file with nothing in it as I couldn't find one in my sys folder anywhere.

    Next I created the resurrect-prologue.g file so it looks like this.

    M116 ; wait for temperatures
    G28 X Y ; home X and Y, hope that Z hasn't moved
    M83 ; relative extrusion
    G1 Z-3 E4 F3600 ; undo the retraction that was done in the M911 power fail script

    made the macro with the M916 command and then set off a print test cube then killed the power at the wall socket to simulate power failure.

    Guess what nothing worked. it didn't move the Z axis, didn't write anything to the resurrect.g file so I guess I am totally stupid to the point where I can't even understand the english language which is why I don't get what the instructions are telling me on the

    I will say thanks for the help in trying to get me to setup this function as I know you have given your time but I will be leaving this alone and leaving the printer at the stage that it is in as I really can't be bothered anymore with beating my head against the wall.

  • Moderator

    Now now, don't be so upset. Persistence will always payoff.

    resurrect.g should be created by the firmware when power is lost. You don't need to create it. Now if it's still not being created when power is lost we need to look at the M911 command first to make sure it's correct. If it is, and it's still not created, then it's possible that there's not enough juice left at power loss time to move the motors and save the file. If that's the case we might be able to modify your M911 to do a little less motor movement.

    Here's my M911 for comparison: M911 S21 R23 P"M913 X0 Y0 G91 M83 G1 Z3 E-1 F500"

    Less extruder movement and slightly slower. Try changing yours to match. If that still doesn't help, try reducing the Z motor movement. If that doesn't help remove all motor movement entirely by removing the G1 Z E F part. If that still doesn't help, we can adjust the voltage range that it will trigger at so that it triggers earlier, by changing the M911 S21 to S22.

    Once it's reliably creating the resurrect.g file on it's own at power loss then we can test resuming.

    Your resurrect-prologue looks ok. Only thing that is missing is a way of homing Z, which as mentioned before is fine as long as you're manually setting the Z height before resuming the print with M916.

  • @Phaedrux I have tried it again and though it is creating the resurrect file now it is not resuming, I think my power supply maybe the issue here so I will have to leave this where it is until I can purchase a better power supply for the printer.

    Plus I am waiting on a new e3d brass hotend nozzel as I think a lot of my stringging issues could be due to the hardened nozzel I have from what I have read elsewhere.

    Thank you for taking the time and trouble to help me with this.

  • @Phaedrux So this in interesting - I had a power failure last night and I had remembered that started but never really figured out how to configure things in the duet-wifi to resume. I looked in my "system directory" folder and at the bottom of my config.g file i have the following line:

    ; Automatic power saving
    M911 S10 R11 P"M913 X0 Y0 G91 M83 G1 Z3 E-5 F1000" ; Set voltage thresholds and actions to run on power loss

    So I looked further down in the "system directory" folder and I do see a "ressurect.g" file, however it's a 0 bytes file and if I open there's nothing in there or so it seems....

    If I created a resurrect-prologue.g file like the one RAM did where would I put it and how would I call it or execute it?

    I did have a 4-day print and sure would like to try and recover it if at all possible. I have a Folgertech FT-5 (twin lead screw single stepper Z axis and it doesn't move even with a bowling ball on the build plate =).

    any guidance would be appreciated

  • Moderator

    @nzimmers said in Help Setting up Resume after power failure and Bed leveling.:

    I did have a 4-day print and sure would like to try and recover it if at all possible.

    If the resurrect.g file is 0 bytes it doesn't sound like the exact progress was saved. So I don't think you'll be able to use this method to resume, but you can use a more manual method that involves measuring the height of the finished model, finding the layer in the slicer, dropping/cutting the model to that height (with no bottom layers) and then adjusting the the sliced gcode to remove any homing etc, manually homing the axis and preheating the heaters, and then starting the print. Start with a slow speed factor so you can use baby stepping to get it to stick to the existing model. If all goes well you can probably save the print, though you might have a visible line there, but it is doable if you take your time.

  • @Phaedrux Thanks Phaedrux, I might give that a try!

    • nz

  • @RAM and @nzimmers

    Just as a "thinking out of the box" my solution to this is to use a 1500VA UPS (also erroneously called Battery Backup). That's big enough to handle most 3D printers for a short while.

    That has two benefits, the obvious one is power glitch and outright failures are not a problem unless they're long, so you implement Resume Print, as was being discussed, in case the battery runs down.

    The second benefit is UPS in general has better surge protection than your average cheap surge strip, The better units (but they're expensive) completely isolate from the power line.

    They also take care of a subtle problem, brown outs. Most of todays units incorporate AVR - Automatic Voltage Regulation which handles when the line voltage lowers (or raises) for an extended period, without switching to battery. The newer units also have adjustable sensitivity if you've got generally perfect power or really crappy power, prevents frequent short battery switching.

    A good source for UPS units in the US is your local Costco warehouse, most carry them, great prices. Don't get a small unit, aim for 1200VA minimum.

    Buying online is often not cheap since they're heavy, so shipping is usually not free (Amazon, etc).
    "Office" stores and BestBuy run sales.

    There are some good online 'UPS only' businesses that offer deals and sometime refurb units that are a REAL deal. Getting a retired high end unit can be a deal, but make sure it has AVR, and if looking at higher end units, 'Sine Wave output' is great too.

    I live in an area that has a LOT of power drops, haven't had a failed print yet from that. Now from OTHER things ... LOL!

  • @PuterPro Another alternative if you have a mains powered bed heater is to use a DC UPS to run the printer. Depending on the choice of batteries, it could last a day or more but of course, the bed will eventually cool which might or might not cause the object to fall off depending on a number of factors. The advantage of using a DC UPS is that there are no losses due to conversion efficiencies from battery DC to AC mains via an inverter and then back to DC by the PSU. They are also relatively cheap compared to mains UPSs because there is no need for the inverter.

    That's what I did anyway ......

  • @deckingman

    That's a great idea and cheaper than an standard UPS!

    I just took a peek at your blog post, that's quite a setup, done with your usual thoughtfulness and detail. You do tend to grab the bull by the horns! LOL I'll read the whole thing later today.

    Nice chatting with you after all this time, good to see you're still helping out here, I've been out of the loop for some time. Life changes ...

    Edit: speelling 😉

Log in to reply