Raspberry Pi Camera Tuning Guide

From 3dPrintingWiki
Jump to navigation Jump to search

The raspberry pi camera is great for monitoring prints when you're using octopi, but it has a few out-of-the-box issues you can fix:

  • The focus is typically set to infinite or 1-2m. Now this is good for most use-cases, but it's bad for ours: objects typically less than 30cm from the camera sensor.
  • It's pretty lousy at outputting resolutions other than it's native resolution

Assumptions

  • You know how to edit files on a linux system
  • You know how to do tasks with elevated privileges (su to root or use sudo)
  • You know how to open video streams in VLC media player
  • You know the IP address of your octopi system

Steps

  • Set camera to native resolution
  • Manually adjust camera focus until it's more suitable to close proximity

Tuning webcamd to use the native camera resolution

  1. On your octopi instance, open /boot/octopi.txt - look for camera_raspi_options
  2. Note the defined values (if any) for -fps , -x and -y - adjust -fps , -x and -y: If you have the v1 camera module (5MP), enter 2592 and 1944 as the X and Y values respectively. If you have the v2 camera module (8MP), enter 3280 and 2464 as the X and Y values. In both cases, set the fps value to 15. No higher or it won't output the native resolution.
  3. Save your changes and restart the webcam daemon using service webcamd restart (or with sudo before it).
Inspecting the camera feed
  • Open VLC Media Player and select File->Open Network In the URL field, enter http://[ipaddress]:8080/?action=stream , replacing [ipaddress] with the IP or DNS name of your octopi instance.
  • Click Open. You should now receive a live-feed (with perhaps some lag) from your raspberry pi camera. Make it full-screen.
Adjusting focus
  • If you're using the official camera modules, the lens might be glued to a fixed point. You can remove this glue or resin with very fine pliers. Note this does void any warranty you have on the camera module. Also note thingiverse is littered with focus adjustment tools you can use to twist the lens.
  • If you're using a Waveshare or Arducam module, the lens usually isn't glued, but it might use a focus lock ring. Look up the camera's documentation nonetheless.
  • Rotate the lens of your camera clockwise or anticlockwise in small steps, each time looking at the camera feed after you made a change to determine if you're getting a sharper image. Do consider a slight lag between what your camera module registers and what's visible on the stream.
  • Putting an object with many details on the heated bed can help in determining improvements here.
  • Keep working in small steps until you're satisfied with the image sharpness.
  • If your camera has a focus lock ring, fasten it back in place.
Further Adjustments
  • You can further improve your camera feed by adjusting more camera_raspi_options in /boot/octopi.txt. For a complete list of options, consult https://www.raspberrypi.org/documentation/raspbian/applications/camera.md
  • Values worth exploring are -awb, -ex, -ISO, -drc. Change one thing at a time, restart webcamd and if the result is worse, undo your latest change.
  • For getting higher framerates than 15 fps (i.e. to reduce motion blur), you will need to use a "binned" resolution. Consult https://picamera.readthedocs.io/en/release-1.13/fov.html#sensor-modes for ideal binned resolutions for your camera module. Do note this binning happens on the camera sensor module and generally leads to rather grainy images no amount of focus adjustment can fix. It's not optical, it's the sensor module itself.
  • Consider using an external light source. Small image sensors generally have poor low-light performance.
  • If you have a NoIR camera module, you can use an 850nm infrared light source

Thanks to @JohnnyricoMC for providing this via r/Prusa3d Discord.