Skip to content

V0.3 Configuring a Raspberry Pi Camera

FormerLurker edited this page May 25, 2020 · 1 revision

UNDER CONSTRUCTION

This page is about a feature that is not yet available in any current release. This feature will be available starting with Octolapse V0.4rc1dev0.

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!

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

You can connect to your Raspberry Pi one of two ways:

  1. Connect a keyboard, mouse and monitor directly to your pi.
  2. Connect to a terminal (you can download and install putty if you are working in Windows). To connect, open putty, click on the 'Session' category. Then enter the IP address of your pi in the Host Name (or IP address) box. Select SSH from the Connection Type radio button list, and make sure the Port is 22. Then click Open.

Connect to your Raspberry Pi.

Note: Other ways of connecting to your Pi exist, but are not covered in this guide.

Step 2 - Sign into your Raspberry Pi.

Once you are connected to your PI, you will be asked to sign in. The default user name is pi and the default password is raspberry.

Sign into your Raspberry Pi.

Note: The cursor will NOT change while typing in your password, which makes it difficult to enter correctly. Alternatively, you can copy your password and paste it into putty with a single right click.

Optional step - change you password

I strongly recommend that you change your password if you are using the default. You can use the command passwd to change your password.

Change your rpi password.

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 your Raspberry Pi.

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 framerate. 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!

and the end result will look something like this:

1080P at 30 FPS

**Note: The higher the resolution and framerate, 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 framerate mjpegstream, but chrome seems to do just fine. Your mileage may vary, but if you have problems, try lowering your framerate 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+Z 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 complete 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+Z to exit.

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

sudo reboot

Reboot your Raspberry Pi.

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 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.

The Octolapse tab with current settings expanded.

Make sure the Current Settings are 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 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 your test has failed, follow this guide for determining your webcam addresses. The link is somewhat old, and will be replaced soon (if not, create an issue and remind me please!)

Step 7 - Enabling Custom Image Preferences

Find the Custom Image Preferences section within the camera profile, and check the Enabled check box. 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 two new options: Apply Preferences at Startup and Apply Preferences Before Print Start. Enable them both. Your settings should now look like this:

Custom Image Preferences are enabled and will be applied after boot and before a print starts.

If everything is working properly, you will be able to see your camera stream right under the Apply Preferences Before Print Start setting, 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 8 - 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 drop down 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 of 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 using the custom page, so your settings should look like this:

Custom, two-column mode is enabled.

For the Raspberry Pi camera, the first thing you will want to 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 should look similar to this once you are finished:

Codec controls with video bitrate maxed.

You should immediately notice an 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 this in mind.

Next you will want to adjust your exposure. Start by setting the Scene Mode to None. Then select Manual Mode from the Auto Exposure drop down 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 Rasberry Pi Camera is all configured!

Other useful things to know

Your camera settings will all be automatically applied when your Raspberry Pi reboots, and when a new print starts. You can adjust your camera settings at any time, but be sure to save them when you're finished.

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

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.

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!.

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, and that it has been moved to the home position (usually accomplished via a G28 command).

Clone this wiki locally