All things Raspberry Pi and Time Lapse

Archive for October, 2012

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.

# 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 ]
# execute the download script to download that picture
/root/download_pics $2

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.

# 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/
grep CANON)
# for every directory in DCIM do these actions
for x in $dir
# except for this directory so that the card ALWAYS has
# one picture on it so it doesnt stop taking pictures
if [[ $x == 157* ]]
# Use another here doc to list the files in each directory
img=$(gphoto2 –shell << EOF |
cd store_00010001/DCIM/$x
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
# 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

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!

Sparkfun Electronics

I was sitting around today wishing that my Gertboard was here… But its not. One of the things I am planning on doing is messing around with temperature and humidity sensors. It is possible to do this without a Gertboard, but I would like to have that hardware experience before I try anything directly on the GPIO pins. There is a very good forum discussion on the Raspberrypi site here.

There is a temperature sensor and a humidity sensor on SparkFun that look like they would work. There is also a waterproof temperature sensor on SparkFun as well. These sensors are different in that some are a 1 wire interface and others are a 2 wire interface. These sensors would be extremely helpful for the case of a timelapse camera. The current case turns the heater on at a certain temperature and the fan on at a certain temperature. This works, but I cannot change/edit that temperature. One of the major problems is humidity, especially in a greenhouse environment. If I could control the fan I could have the fan cycle every X minutes no matter what the temperature.

Currently when I need to download the pictures from the timelapse project I plug in the Ethernet cable. This works, but would not work for the v2.0 case. I am thinking of building a case similar to these here. However these cases are very expensive, and do not offer much flexibility for a Raspberry Pi and other electronics. And so I would need another way to connect to the Raspberry Pi. As mentioned on this forum/article the Edimax adapter looks like it is a good choice.

Hoping to have some more pictures, maybe a short timelapse of the project so far up soon!


Raspberry Pi case for test Pi

I recently bought a second Raspberry Pi to experiment with (and hopefully connect to a gertboard) while the original Raspberry Pi is taking pictures. And I decided to buy a case for this one. And in this post I am talking about a real case, as in a case meant for a Raspberry Pi and not  a security camera like my other Raspberry Pi is housed in. After lots of searching I finally found a case I liked, but it had bad reviews. So I decided against that one. I really liked the clear case idea because hiding the Raspberry Pi in a colored case seemed pointless. Then I found Built-toSpec’s case and I really liked it – except it was black or a somewhat transparent purple. On his website it mentioned that his custom laser services offered clear acrylic so I contacted him and ask how much it would cost for a clear version of the Raspberry Pi case. Turns out he had already made some that were clear. So I ordered a clear one and it arrived really fast. It took awhile to put together because of having to peel all of the protective layers off, but it went fast after that. It is held together by 4 screws in the ends and fits together nicely. It has slots in the top for the expansion pins and a slot for a GPIO cable.

The gertboard is supposedly being shipped by Newark. However, it was supposed to ship around the end of November, then that changed to first of November, and now it is back to end of November. So maybe by the end of the year I will have one… Hopefully…

Below are pictures of the Raspberry Pi in the case.


Everything is accessible, but the Pi is still nicely protected. And it is clear and study. This case is awesome!

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.

Tag Cloud