All things Raspberry Pi and Time Lapse

Archive for the ‘year long time lapse’ Category

Updated scripts

I made some pretty major changes to the scripts after I figured out the problem with the camera card filling up. The changes were partly because of this, and partly to consolidate code to make it easier to make a minor change. The changes are as follows.

This is the main script to take a picture with gphoto2. Instead of having a separate script for each time the camera takes a picture I added the ability to add arguments to the script. This is represented by the $1 and $2 and so forth. When executing the script it now looks like this on the command line:

/path/to/script argument1 argument2

And as you might assume “argument1” gets assigned to $1 and “argument2 gets assigned to $2. This makes it possible to increase the flexibility of a script and reduce the number of scripts needed to the project to work. It also adds the ability to make a small change to the script and affect everything. Like for example if I want to change the aperture I only have to make one change instead of changing it in every script. The updated script is shown below.

#!/bin/bash
# jamesmiller
# 6-22-2012
#
# change directories to the correct folder to save the image
cd /root/$1
# check how many images are in the folder
before=`ls -l | wc -l`
# take the picture using gphoto2
gphoto2 –set-config shootingmode=3 –set-config aperture=9 –set-config shutterspeed=37 –set-config focusingpoint=0 –set-config imagequality=2 –capture-image-and-download –filename “%Y%m%d%H%M%S_$2.jpg”
# wait for 30 seconds to give the camera time to take the
# picture and save it.
sleep 30
# then check how many images are in the folder
after=`ls -l | wc -l`
# compare the before and after image count. If it is the same
# number then we assume that the image did not get downloaded
# and stayed in the folder on the camera card.
if [ $before == $after ]
then
# execute the download script to download that picture
/root/download_pics $2
fi

And the script that gets executed if the number of pictures stays the same is shown below. It is not commented at all, so I will update that when I have some time.

#!/bin/bash
# jamesmiller
cd /root
# use a here doc to list all directories in the main
# DCIM directory on the camera
dir=$(gphoto2 –shell << EOF |
cd store_00010001/DCIM/
ls
exit
EOF
grep CANON)
# for every directory in DCIM do these actions
for x in $dir
do
# except for this directory so that the card ALWAYS has
# one picture on it so it doesnt stop taking pictures
if [[ $x == 157* ]]
then
continue
else
# Use another here doc to list the files in each directory
img=$(gphoto2 –shell << EOF |
cd store_00010001/DCIM/$x
ls
exit
EOF
grep IMG)
# change directories to the camera card and the correct folder
gphoto2 –shell << EOF
cd store_00010001/DCIM/$x
# download the image to the main folder (/root) of the raspberrypi
get $img
# delete the image from the camera sd card
delete $img
cd ..
# remove the directory
rmdir $x
exit
EOF
# get the time stamp information from the image that was downloaded
tstamp=`stat $img | grep Modify | cut -d ” ” -f2,3 | cut -d “.” -f1 | tr ‘ ‘ ‘_’`
# rename the image that was labeled like IMG_1398 to a filename with the
# timestamp inforamation
mv $img $tstamp$1
# move that image to another folder to keep /root clean
mv $tstamp$1 canon_pics
fi
done

The general idea of the script is that it uses a Here document to accomplish its goals. It changes directories to the camera card, then gets the folders listed there. Then for each folder it downloads the images to the Raspberry Pi, deletes the images from the camera, and then deletes the folder. After that it renames the images (which needs some work) and saves them in a separate folder.

The crontab changed as well because of the changes to the main script.

@reboot /root/set_camera_time
@reboot /root/focuslock
1 12 * * * /root/camera pics_1day 1day
31 7 * * * /root/camera pics_7am 7am
31 15 * * * /root/camera pics_3pm 3pm
*/2 5-20 * * 3 /root/camera pics_2min 2min

This shows how the one main script is being used to take four different sets of images. And it labels them correctly and saves them in the correct folder so they do not get mixed with another time.

These scripts work using Arch Linux and a canon PowerShot A510. It should work with other setups, but I have not tested it with anything else.
I downloaded all of the pictures so far and it is looking amazing. It is possible to see the plants grow daily. The one issue I am having is with flicker. This is caused by a sunny day, then a cloudy day, then a sunny day. The camera is set to manual because on the auto feature it can change drastically between two sunny days, and cause more drastic changes than dealing with the problems of the manual settings. I am looking into the GBS (Granite Bay Software) plugin for After Effects which smooths the exposure across multiple images. From the initial test it looks like it did a very good job, but before I buy it I am looking to see about any other options (if there is any) and how they compare.

More about those images soon!

Back up and running

It is all setup again – as of Saturday – and should be taking pictures. Here is a shot of what it looks like now. All of the tomato plants have been removed and the new ones will be planted soon.

Something that started to concern me was Daylight Savings time. This would be a problem if the camera changed time and then the power went out. The raspberry pi would pull the new time and it would be an hour off of what it was before. I contacted Canon about this potential issue. And they tried to sell me one of their newer cameras that has this feature. But they said that the Canon Powershot A510 does not have this feature. I could not find this option on the SX100 either. However this is a good thing as it means I am safe from having to worry about that. It will definitely be something to think about in the future however.

I changed the way the scripts were written and so I will post them and the updated crontab hopefully sometime early next week.

Some pictures that it shot before stopping

Here is the first image that it took on 8-26 at 12noon.

And this image was taken on 9-3 at 12noon.

It is not very clear in this format, but if you download both images and then flip back and forth there is a major change in the plants in the 9 days from the first one to second one. I am hoping to see more of these differences as the plants grow!

Unfortunately it only took pictures for 9 days and that is too short to make into a timelapse…. And when it was taking a picture every 2 minutes it had focusing problems. There is no way to set a manual focus, however I thought I had that accomplished using focuslock in gphoto2. The focus lock seemed to work just fine for the once a day picture but not the other. There was nothing that was moving drastically from each shot so it was weird that it didn’t focus right.

Still planning to setup for the second time this weekend!

Problem Solved!

I now know what the problem with the time lapse setup was. For some reason Canon decided to put every like 100 pictures into a new folders and name the folders 157CANON and 158CANON and so on. So it was leaving these pictures on the camera card and not downloading them onto my card. This causes a problem because the card (in the camera) filled up and then it stopped taking pictures. That makes sense why it wont take a picture when the card is full, but it doesn’t make sense why Canon operates this way. However this is the easy part of the problem. The harder part was getting it to take a picture again. I would reformat the SD card using the cameras reformat option and then try to take a picture from gphoto2. It would give an “unspecified error” and that was not very helpful in figuring out the problem. The solution (which took me forever to figure out) was that the first picture has to be physically taken from the camera. After that first picture is taken by actually pushing the physical button on the camera, then gphoto2 will take pictures just fine.

So the solution is to make sure that I take that first picture and then make sure that the SD card does not fill up. This is possible to achieve from gphoto2 because it is possible to naviagate into the sd card that is in the camera by issueing the command

gphoto2 –shell

and then some* of the regular linux commands work. I say * because very few work and those that do have minor quirks. The main command “cd” works like normal, but there are some issues with tab completion. I wrote this script that uses a here document to actually execute the commands. This was the only way I could figure out how to get it to work. This script is not finalized because I think I will actually want to save the pictures that it is leaving in this folder until I can be certain that it is downloading the same picture onto the Raspberry Pi. (UPDATE) I setup and let it shoot for a day as a test and I confirmed that it is starting a new folder every 100 pictures. And it is NOT saving a copy of it to the Raspberry Pi. It takes the 100th picture and leaves it on the card. And leaves it in the terrible naming format as well.

#!/bin/bash
# jamesmiller
To be updated….

Hopefully going to install the project back in the greenhouse this weekend!!

Update… And its not good…

I went to check on how the time lapse setup was working. And it was not. It worked for not quite a week and then stopped taking pictures for some reason. So I brought it home and have been working to see what was wrong. And so far I cant figure it out. I cannot get the camera to take a picture using gphoto2 anymore. I tried a whole new installation of Arch (I kept the previous one separate) and it still wont take a picture. The other camera that I had bought previously (Canon Powershot SX100) will work just fine though. So that would lead me to believe that the Powershot A510 wont work. However, the camera will still take a picture just fine when it is disconnected from the Raspberry Pi and functioning like a regular camera.

So now I am not sure what to try. It seems like it is a problem with the camera, but the camera will still take a picture so it didnt completely die. Anyone have any suggestions?

Pictures and Yesterday’s Time Lapse

The enclosure is setup outside my window and it taking pictures of our garden. This is so I can test it and make sure everything works correctly. Here are some pictures of the setup.

Here is the time lapse video that the setup shot on 7-16-2012. It was taking a picture once every 5 minutes.

https://vimeo.com/45938391

Raspberry Pi – how to set the system clock using a Canon Camera

Now that I have my Raspberry Pi I wrote and tested the script to set the time on the Raspberry Pi using my Canon Powershot A510. This is a follow up of my previous post. This is tested and works with a Canon Powershot A510 but it may work with other Canon Cameras, however some may require a little modification to the script.

#!/bin/bash
# jamesmiller
# 2012-07-16
# this script works with the Canon Powershot A510
# other models may or may not work
#
# use gphoto2 to get the camera time
camera_time=`gphoto2 –summary | grep -i “unix time” | cut -d ” ” -f4`
# for some reason I had to subtract some time to get it to be correct
camera_time=$(($camera_time – 3592))
# convert UNIX time to readable time
time=`date -d @$camera_time`
# the next four (4) lines cut the timestamp into specific parts so
# that it can be used when setting the time
b=`echo $time | cut -d ” ” -f2`
c=`echo $time | cut -d ” ” -f3`
d=`echo $time | cut -d ” ” -f4`
f=`echo $time | cut -d ” ” -f6`
# this sets the variable real_time equal to the values from gphoto2
# and puts them in the correct order
real_time=`echo $c $b $f $d`
# set the system time equal to the time from gphoto2
date -s “$real_time”

And this script is put into a cron job that is set to run at startup using these details here.

@reboot /path/to/script

If the power goes out and the camera and the Raspberry Pi shut down, when the power comes back the camera should startup faster than the Raspberry Pi and when the script runs it can set the time correctly. The camera has a small battery to keep time, and it will last for a long time with no power and still keep time.

Everything is setup outside my window taking pictures of our garden today. This is my chance to test and get all of the bugs worked out before I setup for a long period of time. Already I have changed several things and I updated the scripts post to reflect these changes.

I will probably post pictures of the setup tomorrow along with the time lapse that it is taking today.

Tag Cloud