Skip to content

Configuring an External Camera

FormerLurker edited this page Sep 3, 2018 · 35 revisions

Note: These instructions are in beta. Please notify me with any issues or corrections, or just to say things worked for you.

Octolapse now supports external cameras by calling an external script. The script is responsible for acquiring an image. Optionally the script can put the resulting image in the proper place so that Octolapse can render the resulting timelapse.

Installing the Latest Octolapse and OctoPrint

First, install the newest version of OctoPrint (1.3.9 currently). This is very important, so don't skip it!

In order to access the new feature you need to download latest experimental version: 0.3.4rc1.dev0. This is currently not available as a public release, but can be installed here for the time being:

https://github.com/FormerLurker/Octolapse/archive/fb3b8ec076e801827a7ce5ba8f241df1852c509a.zip

Simply go into the plugin manager, click 'Get More' and enter the above url into the box labeled '... from URL'. Restart when prompted. After the restart, make sure you clear your browser cache by pressing ctrl + F5

Step 2 - OctoPi Installation

Similar steps would be needed for a non/raspberry pi Linux setup. This example install uses GPhoto2 to acquire the images from your DSLR. I had some trouble with installation on my pi, so let me know if you have problems installing.

Here is a list of compatible cameras.

Use SSH or some other method to open a shell and execute the following command:

sudo apt-get install gphoto2

Note: If you have problems with the above install command you might need to install libgphoto2. Please let me know if you need to install it by running this command and then retrying the gphoto2 install:

sudo apt-get install libgphoto2-dev

Now plug in your DSLR via usb, power it up, and execute the following command to make sure GPhoto2 is detecting your camera:

gphoto2 --auto-detect

If things are working properly You should get something similar to the following:

Model                          Port
----------------------------------------------------------
Nikon DSC D5200                usb:001,016

If there are no cameras detected you will get the following output:

Model                          Port
----------------------------------------------------------

If things are working you should be able to run the following command to acquire an image:

gphoto2 --capture-image

Your camera should take a picture and save it on the camera. You should also be able to download an image to the current directory with the following command:

gphoto2 --capture-image-and-download

You should now see a new image in the current folder. If you have problems here they will need to be corrected before continuing.

Now you will need to create a script to download your images. Below is a sample script I used on my pi that creates the proper directory if it doesn't exist, and saves the resulting image to the new directory:

#!/bin/sh
# Put the arguments sent by Octolapse into variables for easy use
SNAPSHOT_NUMBER=$1
DELAY_SECONDS=$2
DATA_DIRECTORY=$3
SNAPSHOT_DIRECTORY=$4
SNAPSHOT_FILENAME=$5
SNAPSHOT_FULL_PATH=$6

# Check to see if the snapshot directory exists
if [ ! -d "${SNAPSHOT_DIRECTORY}" ];
then
  echo "Creating directory: ${SNAPSHOT_DIRECTORY}"
  mkdir -p "${SNAPSHOT_DIRECTORY}"
fi

# if sudo is not required (it shouldn't be, but I couldn't get it to work without it)
# uncomment this line and comment out the next
# gphoto2 --capture-image-and-download --filename "${SNAPSHOT_FULL_PATH}"
# Capture and download a snapshot with sudo
echo "PUT_YOUR_PASSWORD_HERE" | sudo -S gphoto2 --capture-image-and-download --filename "${SNAPSHOT_FULL_PATH}"

if [ ! -f "${SNAPSHOT_FULL_PATH}" ];
then
  echo "The snapshot was not found in the expected directory: '${SNAPSHOT_FULL_PATH}'." >&2 
  exit 1
fi

For some reason I can't get gphoto2 to work without using sudo, but it could be an installation problem. I could download images within the shell, but the image download failed with a permissions error when running through Octolapse (even though creating the directory worked fine). You can either:

  1. Put your root password (the same one you use for SSH) in the above script.

or

  1. comment out this line

echo "PUT_YOUR_PASSWORD_HERE" | sudo -S gphoto2 --capture-image-and-download --filename "${SNAPSHOT_FULL_PATH}"

and uncomment this line

gphoto2 --capture-image-and-download --filename "${SNAPSHOT_FULL_PATH}"

by removing the # at the front of the line.

I put my script in /home/pi/scripts like so:

cd /home/pi/scripts

nano take-snapshot.sh

Paste in the script above and press ctrl + o and then Enter to save. Then press ctrl + x to exit.

Now we need to add execute permission to the script with the following command

chmod +x take-snapshot.sh

Open OctoPrint and open your Octolapse camera profile. Change the drop down box at the top of the page from 'Webcam' to 'External Camera - Script'

Next enter the following for 'Snapshot Acquire Script'

/home/pi/scripts/take-snapshot.sh

Set the 'Snapshot Delay' to 0 since the script won't exit until the photo is taken and downloaded. It's a good idea to turn the snapshot timeout up to 10000 (10 seconds) while you are testing to make sure your camera has enough time to take and download the photo, especially at higher resolutions. Finally save your profile.

That should be it as far as configuration goes! Now run a short test print. You should hear your camera snapping away during the snapshot phase. Also, there should be some snapshots going into a new folder created within the following directory:

/home/pi/.octoprint/data/octolapse/snapshots/SOME_GUID_HERE/THE_CAMERA_GUID_HERE

If images aren't going into the above directory you may need to use the 'sudo' version above. I need to figure that out.

Windows Installation

The instructions for this are coming soon!

Clone this wiki locally