Skip to content

Instantly share code, notes, and snippets.

@looxonline
Last active February 22, 2023 20:41
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save looxonline/fd260bfc29c124f22fe7613311ae3a79 to your computer and use it in GitHub Desktop.
Save looxonline/fd260bfc29c124f22fe7613311ae3a79 to your computer and use it in GitHub Desktop.

BIQU BX (OR ANY PRINTER) PI AUTO SHUTDOWN MOD

So you bought a raspberry pi and have it connected to your printer. Nice! You may have even gone one step further and decided to power it using the printer PSU (which is by default if you are using a BIQU BX). Also nice. However, the downside to that is that your pi will now turn off without a safe shutdown process when you power off your printer.

While this is never going to brick your pi it most definitely can corrupt the SD card and require you to reinstall the OS as well as any other tools that you have installed on top of the OS. Since nobody wants to spend half a day doing that I developed this mod which will safely shut down the pi when the power to the machine is cut.

Take note that this mod is currently in beta but is in it's third iteration so it should be relatively stable. Installing this mod while this message is still a part of this gist means that you are signing on as a beta tester. Please share your experience, positive or negative, in the comments below so that it can be refined.

Required hardware

Of course the pi takes some time to shut down. We therefore cannot simply shut off the power to the machine and expect that the pi will magically be able to shut down safely before the 24V rail collapses. The BIGTREETECH mini UPS 24V solves this issue for us. Connecting it to your printer will provide enough time for the pi to safely shut down before the 24V rail collapses completely. This is only true if there are no heaters on at the point that the power is cut. If heaters are on then the drain from the 24V UPS will be too much and the rail will collapse before the pi can complete the shutdown process.

Also take note that if you are running a pi then you are most likely printing from octoprint. Since octoprint does not support power loss recovery this means that the mini UPS will not be able to offer that functionality at all. However, if you are using octoprint merely as a remote monitoring solution and are initiating the prints from the printer SD card then power loss recovery will be supported since Marlin is taking the lead and octoprint is simply reporting on the Marlin status.

You'll also need a single, dupont jumper lead that is female to female and about 15cm long.

Install the mini UPS in an appropriate location. With the BIQU BX there are mounting holes right within the motherboard enclosure that sit just to the left of the motherboard.

Wire the UPS to the motherboard using the Z max input which is shown in the image below. It's the last input along the line of endstop inputs. The connectors that come with the mini UPS are keyed so there should be no issue with incorrect insertion orientation.

IMG_2163

Once you are done installing the mini UPS you'll need to run a signal to the pi which will let it know that it is time to shut down. This is where the dupont jumper cable is used. On the motherboard side connect the jumper cable to the second pin from the right on the SWD header. This pin is marked by the red arrow labeled 'A' in the image below. The arrow labeled 'B' points to an LED which will indicate when the pi has been instructed to shut down by Marlin.

IMG_2162

Run the jumper lead along the same path to the raspberry pi that is mentioned for the serial cable jumper leads in this gist: https://gist.github.com/looxonline/89e79b2554771eee8aa8b6492f30400d

On the pi side, connect the female end of the jumper lead to GPIO 4 which is shown in the image below.

Screenshot 2021-04-25 at 13 25 07 copy

That's it for the hardware.

Software

To implement this mod you need to be able to ssh into your pi. Learning how to do that is left as an exercise for the user since the internet is full of info on how to do it.

Once you have ssh'd into the pi you will need to run the command below. Note that if you are updating from a previous version of this mod then you will need to re-run this command and it will update the software on the pi side so that it works with the latest version of the mod.

bash <(wget -qO- https://raw.githubusercontent.com/looxonline/Marlin/BIQUBX_ALMOST_STOCK/pishutinstall.sh)

The pi will prompt you for your admin password which is "raspberry" unless you have changed it. The installation may take a few seconds to a few minutes depending on the state of your system. The command prompt will show the activity as it progresses.

Once the installation is complete you will need to reboot your pi using "sudo reboot".

If you are using this with the BIQU BX then you will need to use the firmware branch over here which has been customized for this functionality. Read all of the associated gists before you use that firmware.

https://github.com/looxonline/Marlin/tree/BIQUBX_ALMOST_STOCK

Using the mod

Once the above steps have been completed you should be able to turn off the printer and watch as the raspberry pi gracefully shuts down before the 24V rail collapses.

If you press the reset button on the BX TFT the pi should remain powered up which allows you to control Marlin resets separately to the pi. If you hold the reset button on the TFT then the pi will shut down. This allows you to force a pi shutdown without actually turning the power off. This can be used to safely shut down the pi if you have an older pi which takes longer to shut down than the mini UPS can keep it powered for.

@Ranney1
Copy link

Ranney1 commented May 9, 2021

I've installed it as described. Firmware is installed, script is installed on the pi (pi is rebooted). When I turn off the power, the red led will turn on after some seconds, but the pi is not shutting down. Any idea what is going wrong? (I've installed the ups firmware for the bx without any modifications). Thanks for help!

@looxonline
Copy link
Author

I've installed it as described. Firmware is installed, script is installed on the pi (pi is rebooted). When I turn off the power, the red led will turn on after some seconds, but the pi is not shutting down. Any idea what is going wrong? (I've installed the ups firmware for the bx without any modifications). Thanks for help!

If you've installed it all as described then it will work. Quite a number of people have had installed it and reported back that it works first time. I suggest double checking your wiring to the pi. I also can't guarantee anything if you've got a non standard octopi installation.

@Ranney1
Copy link

Ranney1 commented May 10, 2021

Dear,

Thanks for help! After a lof of testing I found 2 problems. I had to disable a plugin that I use for an emergency stop button (connected to the pi) and I had to enable auto login to pi user for console in raspi-config. Now it is working. Thanks for the great mod!

@CasparTheBridge
Copy link

Should I only wire the 24v UPS to themotherboard using the Z max input (with the white 3 wire cable) or should I also connect the power wiring to the PSU (black & red wires)?

I would expect also the power wiring but it is not mensioned..?

@Ranney1
Copy link

Ranney1 commented Oct 27, 2021

I have connected them to the ups. 👍

@looxonline
Copy link
Author

Should I only wire the 24v UPS to themotherboard using the Z max input (with the white 3 wire cable) or should I also connect the power wiring to the PSU (black & red wires)?

I would expect also the power wiring but it is not mensioned..?

You most certainly have to connect to the UPS. It's not mentioned because that is a given.

@CasparTheBridge
Copy link

CasparTheBridge commented Oct 27, 2021

Thank you this is now working correctly 👍

@looxonline
Copy link
Author

Thank you this is now working correctly 👍

Good to hear. It's one of my favorite mods. Makes things so much more convenient.

@Maximummach
Copy link

Followed the directions and everything seems to be working as advertised. While I was there I did the UART mod and like the clean look! Thanks for sharing this work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment