Using OctoPi with USB Camera

OctoPrint is an amazing little app with a simple web interface that controls your 3D printer. It has the ability to manage your gcode files or even take STL files and “slice” them into gcode files (which I’d never use since I like to visualize the layering in a tool first). OctoPi is a Raspberry Pi distribution of the tool that runs on the Pi. I had an older Raspberry Pi B that was perfect to throw at my need to remote control/monitor my longer 3D prints.

FullSizeRender 17

View of interface on iPhone

Disclaimer: I know the Raspberry Pi camera using the camera interface is “the way to go”. But an older camera you have (or $5 Playstation Eye camera) is worth a try right? No way, CPU will be too high, you won’t have enough USB ports, system will run too hot, will cause printing to pause … or will it?

The way OctoPrint integrates with a camera is by pulling into its page a video stream from mjpg_streamer (a web server running on a different port). This tool takes content from your web camera and creates a web video stream.  This software is distributed with the OctoPi build, no extra install required. Building the stream is a much more efficient if your camera is newer and has support for MJPG – otherwise you’re using YUYV encoding and the Pi has to do a lot of extra work. Nevertheless you can make this work. I use the following options to run the streamer:

./mjpg_streamer -i "input_uvc.so -f 1 -q 50 -y -r 640x480" -o "output_http.so -w ./www"

The important parameters above is the “-f 1” which says do one frame per second (I’m not looking for high quality video – I just want to see if print has lifted and get a feel of progress). The “-q 50″ controls quality of the result compression.

You can update settings in /boot/octopi.txt so these are used by default. This can be done by ssh to your machine or shut the machine down and edit the file on your computer after putting in the SD card.

camera_usb_options=”-f 1 -q 75 -y”

The advantage of changing the settings in the boot config file is every time you unplug the camera the process dies, and when it starts it will use this setting (there is a background process called “webcam” that handles this).

I tried changing the resolution and surprisingly  didn’t find a change in CPU usage so opted to keep it. As far as CPU, the system is running high at 85% and most of that usage is from the mjpg_streamer process.

Command to check temperature:
vcgencmd measure_temp

So yes, it runs the CPU pretty high (80%+) and the temperatures run a few degrees higher (but at 54’C well below limits), and the initial OctoPrint interface loads a bit slower. If you don’t want to spend money on a $30 Pi camera or a more expensive USB camera I think you can make it work.

Useful Documentation Page on Settings per Camera