Skip to content

V0.4 Configuring a Raspberry Pi Camera

FormerLurker edited this page May 30, 2020 · 11 revisions

Starting with Octolapse V0.4, the Raspberry Pi camera (tested on the V2 camera) is fully supported. You can now control the camera settings directly within Octolapse!

Prerequisites

Custom image preferences will only work if you are using mjpg-streamer, which is installed by default if you are using OctoPi.

There are a few plugins that create their own camera stream, and these will prevent custom image preferences in Octolapse from working. If you are running one of the following plugins and are having trouble getting custom image preferences working, consider disabling these plugins to see if there is a conflict:

The above plugins are excellent, but they are unfortunately incompatible with custom image preferences currently

Setting up Your Raspberry Pi Camera

Follow the steps below to get your Raspberry Pi Camera (tested with the V2) working with the new custom image preference screen:

Step 1 - Connect to Your Raspberry Pi

If you do not know how to establish a terminal connection to your Raspberry Pi or to any remote Linux instance via SSH, see this guide.

Step 3 - Upgrade Your Raspberry Pi Software

It is very important that your Raspberry Pi is on the latest firmware and is running the latest software/distribution. The required driver does not exist in some older versions.

The following commands may take a while to complete. You will probably need to enter your password (the same one you used to connect) at least once when prompted.

Note: You can paste copied text into Putty with a single right click.

To upgrade your Raspberry Pi, enter each of the following commands followed by the enter key:

sudo apt-get update

Update installed applications

You might be asked to confirm the updates at some point. If so, press Y to confirm.

Next, we will upgrade the distribution. Enter the following command and press the Enter key.

sudo apt-get dist-upgrade

Update your distribution

You might be asked to confirm the updates at some point. If so, press Y to confirm.

Now reboot your Pi for the update to take effect by entering the following command, followed by the Enter key:

sudo reboot

Reboot

The reboot command will reboot your Pi. If you are using Putty, your session will end with an error. Wait a few minutes for your Pi to reboot, then connect again by following Step 1 above. If you are using Putty, you can restart your connection by right-clicking over the title bar (it will say PuTTY (inactive) in the title bar) and selecting restart session. You will be prompted to sign in again if your Pi has booted completely.

Step 4 - Edit Your octopi.txt File

Open your octopi.txt file with the nano editor by entering the following command followed by the Enter key:

sudo nano /boot/octopi.txt

Open octopi.txt in nano

You may be prompted to enter your password. After the command completes, you will see the nano text editor. Use the arrow keys and edit this section (it may look slightly different than what is pictured here, but it should be close):

Default camera settings in octopi.txt

Change the following text towards the top of the file that looks like either #camera="auto" or #camera="raspi" to this:

camera="usb"

Be careful to remove any # characters from the beginning of the line! It should look like this when you are finished:

Octopi.txt configured for a usb camera

Next, using the arrow keys move down to the bottom of the octopi.txt file and find the following section:

Octopi.txt without access to control.htm

change the following text

#camera_http_webroot="./www-octopi"
#camera_http_options="-n"

to this:

camera_http_webroot="./www"
camera_http_options=""

Be careful to remove any # characters at the beginning of the lines! It should look like this when you are finished:

octopi.txt with control.htm access enabled

While you're here, you might want to adjust your camera's resolution and frame rate. Find the camera_usb_options section and edit those now. For example, if you want a 1080P image at 30 frames per second, you would use the following:

camera_usb_options="-r 1920x1080 -f 30"

Make sure to remove any # characters from the beginning of the line!

The end result will look something like this:

1080P at 30 FPS

**Note: The higher the resolution and frame rate, the more bandwidth and CPU power will be used. Higher frame rates will reduce the image acquisition time (possibly improving quality, especially when using a smart trigger with snap-to-print enabled). Also, some versions of Firefox will have trouble showing a high frame rate mjpegstream, but Chrome seems to do just fine. Your mileage may vary, but if you have problems, try lowering your frame rate from 30 frames per second to 10 frames per second.

Now we want to save the file and exit nano. Hold down the ctrl key and press the letter O (so ctrl+O) to save the file. Press enter to confirm. Then press ctrl+X to exit.

Step 5 - Edit the modules file and add the Raspberry Pi camera driver

Next we will add the Raspberry Pi Camera Driver to your modules file, which will cause it to be loaded at boot.

Open up your modules file in the nano editor with the following command followed by the Enter key:

sudo nano /etc/modules

Open modules file in the nano editor

You should see something similar to the following:

Contents of the /etc/modules file

At the very bottom of the file add the following text:

bcm2835-v4l2

When you are finished, your /etc/modules file should look like this:

ect/modules file with the Raspberry Pi camera driver added

Hold down the ctrl key and press the letter O (so ctrl+O) to save the file. Press enter to confirm. Then press ctrl+X to exit.

Finally, reboot your Pi by entering the following command followed by the Enter key:

sudo reboot

Reboot

You may need to enter your password again if prompted. If you are using Putty, your session will end with an error. Wait until your Raspberry Pi has rebooted completely and then verify that OctoPrint is ready by opening it in a new browser window.

Step 6 - OPTIONAL - Add a New Camera Profile

If you don't want to change the settings of an existing camera profile (perhaps because you have multiple cameras), the steps below will walk you through adding a new camera profile. If you only have one camera, you can skip this step and move on to Step 7

Open up OctoPrint in a browser window and click on the Octolapse tab. Make sure the Current Run Configuration is expanded. If they are not visible, click on the Current Settings link.

Then open up the camera profiles page within the Octolapse settings by clicking on the 'Cameras' link:

Open the camera profiles page

Next click on the Add Profile... button.

Add a new camera profile

Name your profile Raspi Camera, or something similar, and click on the Save button.

Name and save your new camera profile

Now exit the OctoPrint settings popup by clicking Cancel at the bottom right hand corner.

Close Octolapse settings popup

Step 7 - Editing and Configuring your Raspberry Pi Camera Profile

Click the edit icon next to your your Raspberry Pi camera profile.

Edit your raspberry pi camera profile

This will open up the existing camera profile settings. If you want to rename your profile, feel free to do so now.

Next, make sure that you are not using an imported profile by selecting `Not Selected' from the dropdown box.

Make sure "no profile to import" is selected

Make sure that the Camera Type dropdown box is set to Webcam. Your settings will look something like this:

Camera type and address

Now we need to verify the Snapshot Address Template. Make sure your camera can take snapshots by clicking on the 'Test' button. If it is successful, it will look like this:

Camera test success!

If the test failed, you will see this message:

Camera test failed :(

If your test has failed, see this troubleshooting guide for help getting the Snapshot Address Template working.

Step 8 - Enabling Custom Image Preferences

Find the Custom Image Preferences section within the camera profile and check the Enabled check box:

Enable Custom Image Preferences

If you see an error like this, follow the troubleshooting guide here:

Enable custom image preferences failed

If custom image preferences were successfully enabled, you will see three new options:

  • Apply Preferences at Startup - When this option is enabled Octolapse will apply the saved image preferences after OctoPrint boots. I've gotten a few reports that some USB cameras take a long time to come online, preventing Octolapse from applying the settings after a reboot. I've since altered the routine so that Octolapse will retry for a minute or two.
  • Apply Preferences Before Print Start - Enabling this option will cause Octolapse to apply the camera settings at the start of a print.
  • Apply Preferences When Camera is Disabled. You can disable cameras selectively within Octolapse, but you may still want your custom image preferences applied. When this option is enabled, Octolapse will still apply settings to disabled cameras according to the Apply Preferences at Startup and Apply Preferences Before Print Start settings.

All three should be enabled by default. Your settings should now look like this:

Custom Image Preferences are enabled and will be applied after boot and before a print starts, even if the camera profile is disabled

Now, save your profile by clicking the Save button:

Save camera custom image preferences

Next, select your timelapse preview camera in the dropdown on the Octolapse tab found here:

Select the raspberry pi camera as your current timelapse preview camera

You will now see a message explaining that no snapshots are available for the Raspberry Pi camera. This is normal, and you won't see any snapshots here until you run a print with Octolapse enabled.

Next, click the edit pen to the right of the camera you just selected to open the image preferences:

Edit the custom image preferences for your Raspberry Pi camera

If everything is working properly, you will be able to see your camera stream at the top of the popup, which will look similar to this:

An example of a working camera stream

If the stream is not working, you will see something like this:

This camera stream failed to load

If your camera stream will not load, see this troubleshooting guide.

Finally, save your profile by clicking on the Save button at the very bottom.

Step 9 - Editing Your Camera's Image Preferences

Dialing in your camera settings is very important for getting a high quality timelapse. Before you start, it is important that you have adequate lighting. Good lighting is critical for getting a high quality timelapse, and it might even improve your print quality by reducing the snapshot acquisition time! Photography LEDs work great, but cheap LEDs that use low frequency pulse width modulation (PWM) might result in a lot of flicker in your final timelapse. Incandescent and halogen bulbs will work well, but they use a lot more power than LED lights. In general, you will want your lighting to be much brighter than is necessary to just see your prints.

I also recommend that you close any blinds in the room with the printer because the light levels in the room may vary, messing up the exposure and leading to a lower quality timelapse.

Once you have improved your lighting, it's time to adjust the camera settings.

Open the Octolapse tab, and select your camera from the dropdown box. Then click the edit pen in the upper right hand corner of the Latest Snapshot image:

Edit image preferences from the Octolapse tab

If you do not see the edit pencil, custom image preferences have not been properly enabled. Go back to step 7

Here you will find a couple options regarding how the image preferences will display. Feel free to toggle between Single Column and Two Column Mode. You can also switch between the default and custom image preference screen. Please note that this guide assumes you are using two column mode _and _the custom page, so your settings should look like this:

Custom, two-column mode is enabled

Note that the button above will say Switch to Single Column when it is in two column mode.

For the Raspberry Pi camera, the first thing you should do is increase the Video Bitrate. Increase the value by moving the slider next to this control all the way to the right until it looks similar to this:

Codec controls with video bitrate maxed

You should notice an immediate improvement in your image quality. Try moving the slider slowly up and down to see the effect. Note that higher bitrates mean more bandwidth will be used, so keep that in mind.

Next, adjust your exposure. Start by setting the Scene Mode to None. Then select Manual Mode from the Auto Exposure dropdown box. You will now be able to adjust the Exposure Time, Absolute setting. You want to use as low an exposure setting as possible while maintaining good image quality. Here is an example of what you might end up with (your exact settings might vary):

Manual exposure with a low exposure time

Next you can play around with the rest of the settings. If you run into trouble, you can click the Defaults button at the bottom to restore all of the default camera settings. When you are finished adjusting your image, click 'Save' at the bottom to store the settings and close the popup.

Congratulations! Your Raspberry Pi Camera is all configured!

Other Useful Things to Know

If you completed step 7, your camera settings will all be automatically applied when your Raspberry Pi reboots, as well as when a new print starts. You can change this by editing your camera profile.

You can adjust your camera settings at any time, but be sure to save them when you're finished. Also, be careful when adjusting your camera settings in the middle of a timelapse. Changing the settings during a print may be quite noticeable in the timelapse video. It is much better to adjust your camera _before _starting a print.

Clicking Cancel while editing custom image preferences will undo any settings you have applied by re-applying the old settings.

Cancel Your Changes

You can always press the Apply All Settings Now button to ensure that every setting shown is applied to the camera image. It is possible for the camera to become out of sync with the Octolapse settings, and this button will correct the problem.

Apply All Settings Now

The other interesting button you might want to use is the Stabilize Extruder button, which will move your extruder to the snapshot position. This works as long as you are not using the 'Snap To Print' smart trigger option, and as long as stabilization is not disabled. Make sure your printer bed is clear before using this feature, else you may run into your print!.

Stabilize Extruder Button

Note that the 'Home Axis Gcode Script' within the printer profile will be executed before your extruder moves into position. You can edit this script within your current Printer Profile. It is important that your printer is homed and in absolute mode before Octolapse can stabilize safely, so make sure that your printer is in absolute xyz mode by using a G90 command. Also make sure it has been moved to the home position (usually accomplished via a G28 command).

Lastly, it may be useful to know that Octolapse dynamically creates the controls on the Custom Image Preferences screen based on the functionality reported by mjpg-streamer. It reads the available options and values from a file called input.json that can be found by navigating to a page whose URL has the following form: {camera base url}/input.json. Octolapse also contains a few custom camera pages that have improved over the default dynamic page. You can see if your camera was detected by looking under the camera stream:

Camera Type Detected

To check for a custom page or to switch to the default dynamic page, click this toggle button:

Check for a Custom Camera Page

If a page is available, you will see the following popup message:

Webcam Type Found

If a page is not available, consider creating an issue, and be sure to download and provide the input.json file mentioned above, and include your camera model. I can't guarantee I will be able to test it (odds are I don't have the same camera you do), but I will add it to a list for consideration.

Clone this wiki locally