Add a second camera to OctoPi

OctoPrint is a great tool to control your 3D printer but offers by default only one camera (which can be the native raspberry one or a usb one). But one camera is not enough to be able to monitor the hotend and to take a nice timelapse of your item while printing. So I decided to add a second camera to the raspberry. There is an excellent plugin “MultiCam” that does most of the job, but there is still some configuration to do.

First you need another camera 🙂  As the camera slot is already used by the main camera we will need to use a USB camera. There is very cheap ones like this one I bought for about 2€. It is a very low quality and the image is not very good, but it is good enough for what I want to do (note that you may need to adjust focus). Depending on your raspberry’s number of USB ports and if you are connected by ethernet or with a Wifi USB key you may also need a USB Hub. You will also find cheap ones for about 1€. Note that the USB power from the raspberry is low, and you may experience some problems. You need to be able to connect through SSH to your raspberry to have access to the command line and to be able to modify some configuration files.

Once connected you must first check your USB camera is working properly. We will use mjpg_streamer for that :

You may then check on http://octopi.local:8090  that you are viewing an image properly.

Please note that :

  • You may need to adjust parameters of input regarding your camera (like size, framerate,…)
  • The position of the quotes is not an error : the plugin and its parameters should be in the same parameter, so you have to quote it. If you must add a framerate paramater is will be : -i “input_uvc.so -f 10”
  • It is mandatory to use another port than the default 8080 because this one will be used with the raspberry camera

If the camera is working well we will automate the launch of the camera by modifying the /root/bin/webcamd script. As it is in root folder you must first sudo to root (with ‘sudo su’). Here is the resulting script :

I have modified three sections delimited by the comments “# BEGIN/END MODIFICATION” :

  • In the parameters sections I have added parameters to be able to run both cameras and disabled the use of /boot/octopi.txt  to have to modify only one file
  • I commented the wait just after the mjpg_streamer command to be able to run another one
  • I modified the script to support both cameras at the same time. Note that the script should work if you disconnect one of the cameras (or modify back the camera parameter to another value than ‘both’)

Then you will need to modify the /etc/haproxy/haproxy.conf  to add an URL that may be used in octoprint.

It adds /ubscam/ to access the new port :8090 we created above.

It is now time to go to OctoPrint to finalize the configuration. To ensure the new files are taken in account, you must restart the corresponding services. If you are not sure, just restart the raspberry. In OctoPrint, add the “MultiCam” plugin. Then go to its configuration and add another camera with URL “/usbcam/?action=stream”. Save, and that’s it !

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Close Menu