3D printer control with a Pi
Build it step by step
0 of 8 doneFlash OctoPi
With Raspberry Pi Imager, add Wi-Fi in the settings.
Boot and open the page
http://octopi.local.
Run the setup wizard
Create an account with a strong password.
Connect the printer
Choose the serial port and baud rate.
Fit the camera
Check the live view.
Print a small test
Watch it from your phone.
Enable time-lapse
And save a clip.
Try the status script
With your own API key.
How do you build a 3D printer control with a Pi?
A Pi runs OctoPrint with a camera, so you can watch prints, make time-lapses and stop them from your phone. You need Raspberry Pi 4 Model B (4 GB), SanDisk microSD card 32 GB (A1, Class 10), Raspberry Pi 15 W USB-C power supply, Raspberry Pi Camera Module 3 and USB A to micro-USB cable (data). It takes 8 steps and about 120 minutes.
- Level
- Intermediate
- Time
- About 120 min
- Parts
- 5
Parts list
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Pi 4 | USB cable to the printer's USB port | Printer control |
| Pi camera ribbon cable | Pi CSI camera connector, contacts facing the board as the connector shows | Video of the print |
| Pi power | Official USB-C supply, not the printer's USB | Stable power |
| Network | Wi-Fi set in Raspberry Pi Imager, or Ethernet | Browser access |
Code
OctoPrint is free software that lets a Raspberry Pi control a 3D printer over USB and show a web page with the job, temperatures and a live camera. With Raspberry Pi Imager choose Other specific-purpose OS, 3D printing, OctoPi, and in the settings give the Pi a name, your Wi-Fi details and a strong password for the account. After boot, open http://octopi.local in a browser, run the setup wizard, and connect to the printer. Power the Pi from its own official supply rather than from the printer's USB port. Add the camera, then enable the time-lapse plug-in to get a short film of each print. The small script uses OctoPrint's API with a key read from an environment variable, so the key is not stored in the file. SAFETY: remote monitoring does not make a printer safe to leave alone. Only run prints unattended if the printer has thermal runaway protection in its firmware, keep a smoke alarm nearby, never print on a cluttered shelf, and be able to cut the power by hand. Do not expose OctoPrint to the internet directly; use your home network or a trusted VPN. Switching the printer's mains power from software must be done with a properly rated device fitted by a qualified electrician, so this project leaves that out.
# printer_status.py: check the OctoPrint job from any computer on your network.
# Create an API key in OctoPrint (Settings, API) and export it, do not write it in the file:
# export OCTOPRINT_KEY="paste-your-key-here"
import os
import requests
BASE = "http://octopi.local" # your OctoPrint address
KEY = os.environ["OCTOPRINT_KEY"]
HEAD = {"X-Api-Key": KEY}
job = requests.get(BASE + "/api/job", headers=HEAD, timeout=5).json()
state = job["state"]
progress = job["progress"]
print("State:", state)
if progress.get("completion") is not None:
print("Done: %.0f percent" % progress["completion"])
secs = progress.get("printTimeLeft")
if secs:
print("Time left: %d min" % (secs // 60))
printer = requests.get(BASE + "/api/printer", headers=HEAD, timeout=5)
if printer.status_code == 200:
temps = printer.json()["temperature"]
for name, t in temps.items():
print("%s: %.0f C (target %.0f C)" % (name, t["actual"], t["target"]))Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Open the page | Login page appears |
| Connect to the printer | Temperatures show |
| Start a small print | Progress bar moves |
| Look at the camera | Live picture of the bed |
| Run the script | State and temperatures print |
If it does not work
octopi.local not found
Use the Pi's address from your router.
Printer will not connect
Choose the right serial port and baud rate (often 115200 or 250000).
Camera black
Reseat the ribbon cable and check the camera is enabled.
Print stutters
Weak power supply or a slow SD card; use the official supply.
API error 403
Wrong or missing key in OCTOPRINT_KEY.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the 3D printer control with a Pi?
Raspberry Pi 4 Model B (4 GB), SanDisk microSD card 32 GB (A1, Class 10), Raspberry Pi 15 W USB-C power supply, Raspberry Pi Camera Module 3 and USB A to micro-USB cable (data).
How long does the 3D printer control with a Pi take to build?
About 120 minutes for a intermediate maker, in 8 steps.
How do I know the 3D printer control with a Pi works?
Open the page: Login page appears. Connect to the printer: Temperatures show. Start a small print: Progress bar moves.
octopi.local not found: what should I check?
Use the Pi's address from your router.
Printer will not connect: what should I check?
Choose the right serial port and baud rate (often 115200 or 250000).
Camera black: what should I check?
Reseat the ribbon cable and check the camera is enabled.
Print stutters: what should I check?
Weak power supply or a slow SD card; use the official supply.
