Enginursday: Time-lapse with the Raspberry Pi

How to create a simple and cheap time-lapse rig with the Raspberry Pi.

If you missed the most recent installment of Engineering Round Table, I showed off my latest creation: my Aquaponics system. As you can imagine, designing and creating the system itself was a fun, albeit time-consuming, project. However, building it was just the beginning. Now that my system has made it through the cycling process, it's been amazing to see the results.

plants

The state of my aquaponic plants as of 11/19/2013.

It's been about 40 days since I germinated my first seeds. I planted three waves, each about a week apart. Some seeds I germinated in my Aerogarden, and some I planted right in my grow bed. Shortly after I transplanted the last of my seedlings from the Aerogarden (around 11/7/13), I decided that I wanted to setup a time-lapse camera to capture every moment of plant growing goodness.

sprouts

Here we have some basil seedlings planted directly in the grow bed (left) and some seedlings -- parsley, thyme, and Romain lettuce -- germinated in 3D printed seed pods with the Aerogarden (right).

After a failed attempt at hacking an old point-and-shoot camera (I'm pretty sure it didn't work before I got here), it was back to the drawing board. I tried using a Kodak Zi8. I have a remote for this camera, and that remote can be used to capture still photos at will. I tried hacking the IR codes to get an Arduino to do my bidding for me. Once again, I hit a wall, and all the while I was missing my plants' first steps. I didn't have time to go sniffing around IR protocols, I needed a camera now.

Finally, I remembered the Raspberry Pi Camera Module. I strung up some Ethernet cable and taped the Pi and the camera to my grow bed. Getting the camera to take stills was easy enough with the quick start guide, but I wanted this process to be fully automated. My plants are currently on a 14-hour sunlight cycle. The lights turn on at 6:00am and shut off around 8:00pm. I'm rarely up by 6, and sometimes I'm not home in the evenings. Thus, I sought out a python script that would eliminate the need for me to start and stop the script manually.

Pi taped to grow bed

Here is the Pi and Camera taped to my grow bed.

After a little searching, I found this tutorial for a time-lapse camera in a coffee can using the Pi. The python script accompanying the tutorial, written by James Moore, was just what I needed. When this python script runs, it creates a folder with the date and time in the name, and then it stores all the photos taken in that folder with the date and time in the name of the photo. Editing the script for my needs was a breeze. I simply changed the time.sleep() value to 300 to give me five minutes in between each shot instead of one minute. I also changed the if statement on line 76 to trigger if d.hour is between 6 (am) and 20 (8pm). Now, I can call the python script and just let it run for days. The downside to my changes is that all the photos end up in one folder (the folder created when the script is first executed). However, since the time stamp is in all the photo names, it's easy to tell where one day stops and the next begins. It would be easy to alter the script to automatically create a new folder for every new day. As I said, I was in a hurry to get it up and running, so there is lots of room for improvement.

And, here are the results:

ReplaceMeOpen

ReplaceMeClose

The video was taken over the course of ten days. It starts off kind of slow, but the action really picks up about halfway through.

All in all, the video turned out pretty well. There are a few things I am going to tweak for the next round. First, I would probably set the interval between shots to ten minutes instead of five. Ten, I think, would have made for a shorter video with more action. Second, I would mount the camera better. The masking tape held up the entire time, but I was always afraid it was going to come undone and ruin my whole setup. I am also going to increase the resolution next time. I wasn't sure how full the Pi would get, so I kept it at the lowest setting for the first run. Last, I want to start my lapse before the next round of seedlings emerge, so I can get the whole life cycle on film.

We'd love to see what kind of projects you're creating with your Raspberry Pi Camera Modules. If you have some time-lapse footage taken with a Pi, or some other project involving the Pi Camera such as object avoidance or face recognition, we'd love to see it. Share in the comments below, or send us an email describing your project. It just might get featured on our blog.

P.S. if you're in the Boulder area and want to get more hands-on with aquaponics, check out my new Meetup group, Boulder Aquaponics Enthusiasts. Thanks for reading!