-
Notifications
You must be signed in to change notification settings - Fork 100
V0.4 Configuring a Raspberry Pi Camera
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!
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
Follow the steps below to get your Raspberry Pi Camera (tested with the V2) working with the new custom image preference screen:
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.
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
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
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
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.
Open your octopi.txt file with the nano editor by entering the following command followed by the Enter key:
sudo nano /boot/octopi.txt
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):
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:
Next, using the arrow keys move down to the bottom of the octopi.txt file and find the following section:
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:
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:
**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.
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
You should see something similar to the following:
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:
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
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.
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:
Next click on the Add Profile... button.
Name your profile Raspi Camera, or something similar, and click on the Save button.
Now exit the OctoPrint settings popup by clicking Cancel at the bottom right hand corner.
Click the edit icon next to your 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 that the Camera Type dropdown box is set to Webcam. Your settings will look something like this:
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:
If the test failed, you will see this message:
If your test has failed, see this troubleshooting guide for help getting the Snapshot Address Template working.
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:
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:
Now, save your profile by clicking the Save button:
Next, select your timelapse preview camera in the dropdown on the Octolapse tab found here:
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:
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:
If the stream is not working, you will see something like this:
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.
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.
- Camera Stream - Here you will find your live camera stream. Any changes you make to your camera settings will appear here after a brief delay.
- Stabilize Extruder - This will first home your extruder's X and Y axis according to your printer profile's *Home Axis Gcode Script *. Next your extruder should move into the snapshot position. This should make it easier to focus your camera properly for your timelapse. If you are using one of the the Snap to Print smart triggers or if stabilization is disabled, this will not work.
- Apply All Settings Now - Octolapse must remain in sync with your camera, but sometimes things go wrong. For example, if you change your camera settings with another application or if you disconnect and reconnect it after booting your Pi, the settings might not be applied to your camera. Clicking this button will force all settings to be applied to your camera.
- Switch to Default Page/Switch to Custom Page - A few cameras have special custom pages associated with them. Currently, several Logitech webcams and Raspberry Pi cameras have custom pages that are enhanced with grouping, validation, and other features that enhance usability. This button can be used to switch between the two if a custom page is available. If the button says Switch to Custom Page but no page is available, you will see an error message.
- Switch to Single Column/Switch to Two Columns - By default, your controls will be shown as two newspaper style columns. If you prefer a wider format, you can switch to single column mode, which can make it a bit easier to control the sliders.
- Specific Camera Detected - If Octolapse knows what kind of camera you are using, it will be shown here. Octolapse detects cameras based on their feature set and default settings, and these can change with driver or mjpg-streamer updates. If Octolapse cannot detect your camera type, you won't have access to a Custom Control Page.
- Cancel - This will undo all of the changes that were made since you opened the popup, but only if your camera settings were properly synchronized when you opened the popup (see item 3).
Important Note: The Raspberry Pi controls can be finicky. Cancel will not always be able to reset your image because of glitches in the controls. See Settings You Should Probably Not Use below for more details.
- Defaults - Here you can restore your camera's default settings. Please note that some cameras do not properly report the default settings, so this may not work perfectly for all cameras or versions of mjpg-streamer.
Important Note: The Raspberry Pi controls can be finicky. Defaults will not always be able to reset your image because of glitches in the controls. See Settings You Should Probably Not Use below for more details.
- Save - If you are happy with your settings adjustments, click save to store them.
There are three types of controls you may see within the image preferences popup:
- Sliders - All settings that are associated with numeric controls will appear as a slider. Each slider has a minimum and maximum value as well as a step. For example, my camera allows the focus to be set between 0 and 250 in increments of 5. Because of this, a value of -10 or 32 is invalid, so the slider will not allow you to select these values. Note: A few people have asked for the option to use a text box to manually enter a value. This is not possible at the moment, but I am considering adding this feature.
- Check Boxes - These are toggle controls that can be on or off.
- Dropdown Boxes - These contain a list of possible values that you may choose from.
Sometimes the camera controls interact with one another. For example, the Exposure Time, Absolute setting will only work if Scene Mode is set to None and Auto Exposure is set to Manual Mode. The custom page (if they are available) will usually make this a bit easier to figure out by enabling some controls based on other settings. Custom pages also contain help links (blue question marks) next to each setting, which you can use to learn more about each control. The default pages do NOT do this.
I recommend spending a lot of time tuning your camera settings. Some settings are more important than others, and your settings may need to change based on lighting, camera position, the color of the filament you are printing with, etc., so they will need regular adjustments. I pretty regularly see people asking what settings they should use, but it's very unlikely that my settings will work for you, even if we have the exact same camera. For this reason, it's easier to explain my method for adjusting my own camera settings. That way you can come up with the best settings for your unique situation.
This step is critical to getting good image quality. A good rule of thumb is that you should use more lighting than you think is necessary. You should also make sure that the lighting conditions will not change during your print, so I recommend closing the blinds and shutting the doors. Avoid turning lights on and off during your print or else you will definitely notice this in your video.
This is a bit more art than science. Ideally, you want to choose an angle that will show the entire print. Play around with your positioning and see what works best for you.
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:
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.
Now it's time to adjust the focus. By default the Raspberry Pi camera is set to focus on the horizon, which means items that are up close will appear to be blurry. This is not ideal for 3D printing, since your camera will most likely be very close to your printer. You should check your focus any time you adjust your stabilization position or if you move your camera.
In order to get the focus right, it's important that your bed and extruder are in the right position. Fortunately, Octolapse can stabilize your bed on demand, making this pretty easy.
Important Note: Octolapse cannot stabilize your bed if you are using any of the Snap to Print triggers or if stabilization is disabled. In this case it may be a bit trickier to focus your camera because the stabilization position is unknown until after the snapshot plan is generated. Additionally, for Animated stabilizations, Octolapse will stabilize to the first position in the animation.
Before you attempt to stabilize your extruder, make sure that your bed is clear! If not, your extruder may crash into whatever is sitting on your bed, potentially damaging your printer. Octolapse will ask you to check your bed before sending any Gcode to your printer.
Once you have checked your bed to make sure it is totally empty, click on the Stabilize Extruder button:
Octolapse will now ask you to confirm that you want to home and stabilize the XY axis. Click Ok only if your bed is clear. Your printer should immediately home and then move into the stabilization position:
In order to make it a bit easier to adjust the focus, I recommend putting an object on your bed in the same position that your printed object will be located. Preferably this object has some text on it because I find that it's easier to tell if an object is in sharp focus if it has text on it. You may need to raise your Z axis in order to fit an object on the bed depending on where your extruder is. Use the OctoPrint control tab for this:
First select the Control tab. You can move your Z axis using these controls:
- Raise your extruder
- Lower your extruder
- Control how far your extruder will move in MM.
Important Note: Some printers move the entire bed when the Z axis is changed. If your printer is like this and you find that your controls are flipped (up appears to lower your bed and down appears to raise it), you can correct this by editing your OctoPrint (NOT Octolapse) printer profile, enabling the Invert control option to correct this:
Now place the object of your choice on your bed and adjust the focus until it is sharp. It can be a bit of a pain to adjust the focus on a Raspberry Pi Camera, but there are numerous guides and videos on the internet explaining how to do this. Please note that the exact model of your camera will affect how you adjust the focus (v1, v2, etc...). I will link to a good guide for this at some point.
Next, adjust your exposure. Exposure controls how much light will reach your camera sensor. Automatic exposure can cause flickering in your timelapse, so I recommend using manual settings. To enable manual 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):
Important Note - At least for the version of the Raspberry Pi camera that I have, manual exposure only seems to have an affect between 1 and about 350. Anything above 350 seems to look just like the 350 setting.
Auto balance can cause flickering, so I recommend using manual balance. First you need to enable manual balance:
Important Note: There is currently a bug in the USB driver for controlling the Red/Blue balance. Once you switch to Manual mode, you cannot switch to any other mode without switching back to Auto, saving your settings, then rebooting the camera. This is unfortunate, especially since getting the red/blue balance right is very tricky and time consuming. If you have figured out a way to do this without a reboot, please let me know!
Once manual balance is enabled you can control the red and blue channels individually. It is a bit tricky to adjust the balance, so expect to spend quite a bit of time getting this right. Here are the settings I came up with for my camera:
Other obvious settings you may want to look at include Brightness, Contrast, Saturation, Sharpness, Flip/Rotate Image, and Power Line Frequency. Your camera may not support all of these controls and may have other interesting things you may want to try.
- Brightness - Controls how bright or dark your image will be. This is independent of the Exposure setting discussed above and should be adjusted after you set your exposure.
- Contrast - This controls the difference between the brightest and darkest parts of your image. A higher contrast means that shadows and highlights will be more clearly defined. A lower contrast makes the image appear a bit flat.
- Saturation - This is the lightness or darkness of a specific range of colors. Some cameras have separate saturation settings for the red, green, and blue (or CYMK) channels, and some have a single saturation setting that applies to all colors evenly. Increasing this will make colors appear more vibrant but less true-to-reality. Lowering the setting will eventually remove all colors from your image, leaving you with a black and white image.
- Sharpness - This setting enhances brightness along edges. It can make features more defined at higher settings, but it may create an undesirable halo or jagged edges if it gets too high.
- Flip/Rotate Image - Here you can flip your image horizontally or vertically. You can also rotate your image in increments of 90 degrees. All three controls can be combined, so you can flip your image both horizontally and vertically, and then rotate the result.
- Power Line Frequency - The frequency of your power may cause flickering in your image. Many cameras have built-in correction for this. Check out this link to find out what frequency is used in your area, and select the appropriate frequency for this setting if it is available.
The Raspberry PI controls are are finicky and a bit buggy. I'm leaving the Balance setting out of this list, since it really should be set manually, though you cannot change back to auto settings through Octolapse once you set it to manual (discussed above).
Here is a potentially incomplete list of controls with bugs severe enough that I don't recommend you change them:
- Exposure - Image Stabilization - Once this setting is enabled, your camera will appear to zoom in slightly, which is required for image stabilization to work. However, you cannot disable the setting without a reboot, and it is pretty much useless for timelapses anyway because the stabilization itself will cause a jerky looking timelapse.
- Effects - I recommend you leave this set to None. Some of the effects work as expected, but others seem to affect your image until reboot.
Congratulations! Your Raspberry Pi Camera is all configured!
Octolapse is provided without warranties of any kind. By installing Octolapse you agree to accept all liability for any damage caused directly or indirectly by Octolapse.
Use caution and never leave your printer unattended.
If you have a great new guide, see a typo, or have other suggestions for improving the existing documentation, please let me know! You can either submit a feature request or submit a pull request. I would appreciate it greatly!
Consider supporting Octolapse by becoming a Patron, a Github Sponsor, or by sending some coffee/beer money, I would REALLY appreciate it. Almost all of the donations go towards offsetting the cost of development, which are substantial. Plus it always makes my day!
If you cannot afford to leave a tip or just don't want to, that is fine too! Octolapse is free and open source after all. There are other ways you can help ensure that Octolapse continues to be updated and improved:
- Share your Octolapse videos, and be sure to leave a link and explain that the timelapses were captured with Octolapse and OctoPrint (you will be asked how you made the timelapse, so this will also save you some time answering questions). This is not necessary, but it is greatly appreciated.
- Subscribe to my youtube channel.
- Post any bugs you find to the Issues Page. I would like to eliminate as many bugs as possible!
- Participate in the OctoPrint Community Forums, and help all the noobs get OctoPrint and Octolapse working and help expand the hobby. The more people use OctoPrint and Octolapse, the better the software will become!
- If you've created a working and tested printer profile for any printers that aren't in the make/model list, please send it to me! I want to make it as easy as possible for new users to get their printers configured quickly.
- Help me make this documentation better! Octolapse has a LOT of documentation, guides, tips, etc., both here in the Wiki and integrated with the Octolapse plugin. If you find inaccuracies, typos, gaps, or have ideas for improvement, I'd love to hear about them.
- If you have any special talents that could be applied to Octolapse development, like graphic design, video production (think tutorials), programming, etc., maybe you'd like to participate more directly in Octolapse development/documentation?