Using the Raspberry Pi to Control an ATX Power Supply

28,722

107

15

Introduction: Using the Raspberry Pi to Control an ATX Power Supply

I’m really enjoying my new 3d printer, but I just can’t leave my laptop connected to the printer all the time. I know that i could simply use SD cards or use another host computer, but there are better options. In order to untether myself from the printer I am using a Raspberry Pi and the OctoPrint printer host. This allows me to take g-code that I have generated and upload it to the Pi. Now I can start a print, check on the status, and view the printer through an attached webcam. The webpage also works well on the iPhone so I can keep track of what is going on from anywhere. I can also easily abort failed prints without having to come home to find a stringy mess. As great as that is I don’t like to leave the printer powered on if I’m not using it and I don’t like to leave the lights on when I’m not home.

Step 1: Circuit Layout

The solution that I came across was to leverage the different power modes of the ATX power supply (see Ugifer's Arduino treatment of the topic at Instructables). ATX power supplies have a standby mode that allows them to supply 5v at 2.0A while not fully on. This is the ‘standby power’ mode that most PCs use to sense the button press that turns them on. It provides more than enough power to run the Pi and still have the printer off. The printer runs off the 12V power rail when the power supply is in full power mode. The only issue to contend with is that the Pi’s GPIO pin that I want to use to turn on the power supply is 3.3V and the ATX supply needs to sink 5v to turn on. Using just a 2n3904 transistor and a couple of 1k ¼ watt resistors I am able to turn on the powersupply from the Pi.

Step 2: Physical Layout

The lights that I am using are some 12v white LED panels that came from Ebay. They are inexpensive, less than a dollar each, and are common in automotive world for interior car bulb replacements. They can be wired to any black and yellow connector on the ATX supply.

I didn’t want to have a separate board with the components on it or have to buy an ATX connector so I put the parts inline with the wiring and then sealed them in tape and heat shrink tubing.

To get a good connection to the ATX header I pulled some pins off a broken motherboard and put them on the ends of my wires. To hold them in place I just used nylon zip ties around the connector.

Step 3: Software: Wiring Pi and OctoPrint Configuration

To control the GPIO pins on the Pi I installed WiringPi. This library makes it easy to read and set GPIO pins. I chose pins 5 and 6 on the Pi so that I could have a GPIO right next to GND.

The Pi will default to Input mode on GPIO pins so the first step was to issue a command to set the pin mode to Output. (note that the WiringPi pin numbers are different from the physical pin locations on the Pi. The ‘gpio readall’ command will provide a chart of software to software pin mappings. Pin 5 on the board is really 9 in software) From the command line:

‘gpio mode 9 out’

To make this change permanent I added ‘/usr/local/bin/gpio mode 9 out’ to my ‘/etc/rc.local’ file before the ‘exit 0’. (rc.local requires the full path to gpio)

To test the setup:

‘gpio write 5 0’ (set the pin LOW)

‘gpio write 5 1’ (set the pin HIGH)

If the wiring is correct the ATX power supply fan will come on, the printer will turn on, and the lights turn on.

Octoprint config:

Adding the buttons to the OctoPrint system menu to turn the printer on and off is straight forward. The new commands ‘Printer On’ and ‘Printer Off’ are added to the ~/.octoprint/config.yaml in the ‘system:’ section as follows:

system:

actions:

- action: shutdown

command: sudo shutdown -h now

confirm: You are about to shutdown the system.

name: Shutdown

- action: reboot

command: sudo shutdown -r now

confirm: You are about to reboot the system

name: Reboot

- action: restart

command: sudo service octoprint restart

confirm: You are about to restart OctoPrint

name: Restart OctoPrint

- action: Printer on

command: gpio write 9 1

name: Printer On

- action: Printer off

command: gpio write 9 0

name: Printer Off

Restart the Octoprint host software and the new buttons should show up

2 People Made This Project!

Recommendations

  • Retro Tech Challenge

    Retro Tech Challenge
  • Organization Contest

    Organization Contest
  • Lamps and Lighting Contest

    Lamps and Lighting Contest

15 Comments

0
peadamsca
peadamsca

Tip 8 months ago

Using a Gigabyte P650B ATX power supply to power my 3D printer and PI but had to drop the 1K resister from the +5v ATX Green (Collector) down to at least 330ohms to get the power supply to finally turn on. Thanks so much for the nice clean solution and great article on how to implement it!

0
phillbond82
phillbond82

Reply 5 months ago

Thanks @mfoster for the detailed design and instructions.
Same as @peadamsca however, I swapped the +5v Green Collector-Resistor down to 390ohms to make it work with my Thermaltake 550W PSU. Works perfectly from there using the OctoPrint OctoRelay Plugin instead of writing my own script changes.
Thanks again!

0
BeardyTechie
BeardyTechie

9 months ago

I have a PC in the loft running TV Headend, and adding an old Pi would be a great way to allow me to remotely power it on after a power failure, and also give me a remote serial console; this article has helped provide the information I need!

0
CharlesP160
CharlesP160

Question 2 years ago on Step 3

Can we get the making it permanent part and the adding it to octopi in slightly more lay man's terms. Do you do it through putty? On a PC? I'm a noob to linux

0
tailslide
tailslide

3 years ago

Tried this on a pi3 and it almost works.. I turn on the PSU and everything powers up.. as soon as I get to the step of gpio mode 9 out, it powers everything off then gpio write doesn't turn it back on. I tried the up/down/tri options with no effect. Also, I think you have a typo in the article it says gpio write 5 1 in one part then gpio write 9 1 in another part.

0
tailslide
tailslide

Reply 3 years ago

Swapped out the 1K resistor to ATX for a lower one and it's working now.

0
dschonnie
dschonnie

6 years ago on Introduction

wow, exactly what i was looking for for nearly 2 weeks now!

I tried it out immediately, unfortunatley it does not work. I used a bc547c transistor instead of the 2n3904 you used.

When i set up gpio and write the output high, it switches on, stays on for 10 seconds and then powers off again. I know that ATX PSUs need a load connected, i have that, it workd fine before when i just shorted the power on.

Any idea what i am doing wrong?

0
AndersJ3
AndersJ3

Reply 3 years ago

You might want to change the resistenta on the base to 330 ohm. U / I = R.
3.3 / 0.01. = 330

0
dschonnie
dschonnie

Reply 6 years ago on Introduction

i tried another gpio, which fixed the error temporarily.

somehow i think the values of the resistors might be off? could it be?

0
mfoster
mfoster

Reply 6 years ago on Introduction

I wouldn't be surprised at all if the 1k that connects to the ATX is too low. Some people have trouble with the ATX switching off if there isn't enough load. Try and increase the value and see what happens.

0
mfoster
mfoster

Reply 6 years ago on Introduction

Weird. I'm not sure about the characteristics of that transistor, but they look suitable. To troubleshoot it I would try to connect the base of the transistor directly to the 5v standby power on the ATX supply. If the power stays on then either 3.3v is not enough for the transistor or something is up with the Pi.

As a note the Pi has internal pull up/down resistors on each GPIO. They can be up, down, or tri(none). They can be set with 'gpio mode 9 up/down/tri' The settings don't have any effect on my setup, but they might have some impact with a different transistor.

Let me know what you find out and thanks for checking out my instructible.

0
PerryS16
PerryS16

4 years ago

For anyone struggling with the transistor circuit, or if you want to avoid some soldering, why not try an SSR (Solid State Relay) module designed to be used by Rasberry Pi or Arduino? The 2 relay modules are only a couple of dollars on Anazon or eBay. I haven't tried it yet myself, but it is on my list of things to do.

0
turbochardged
turbochardged

Reply 3 years ago

Because gpio pins output 3.3v at 20ma. Only arduinos ouput 5v at 100ma.

0
CK101
CK101

6 years ago

I want a 3d printer do u recommend anything

0
S_aver
S_aver

Reply 4 years ago

anet a8, i have that and the community around it is massive.

Best price/quality you can get.