Wednesday, July 9, 2014

Small Refinements

Over the last couple of weeks, I've been making some small tweaks to the time lapse system. I've noticed some shakiness in the final videos for one thing. Also, I wanted to do something to help reduce the heat buildup in the Pi over prolonged outdoor use, especially in a desert environment. Lastly, I wanted to fine tune the workflow of video creation.

Stability

There were 2 weak spots where I saw obvious room for improvement:
  1. The mounting bracket, which attaches the outer weather shell (e.g. food storage container) to the tripod
  2. The tripod base (legs)
The mounting bracket I was using until now was a simple piece of lightweight aluminum with a 90 degree bend in it. The problem was that it was rather springy whenever the wind blew. I decided to use some steel angle bracket I had on hand and bend into an "L" shape for a much more rigid mounting bracket.
Old bracket

New bracket
The next thing I wanted to address was the tripod base. I was using a lightweight point-and-shoot collapsible tripod with ball head, intended for point-and-shoot cameras. I was concerned that it might be causing some of the shaking and decided to use my heavier entry-level Manfroto tripod base, which can support a great deal of weight. The Pi is very light, but if it is unattended all day long, It will be safer. I decided to purchase an inexpensive ball head for this tripod, and went with the Oben BD-0.
The Oben BD-0 is cheap and small, but can support 6.6 lbs!

Temperature Control

A couple of times after bringing in the Pi after shooting for hours on hot days (temps into the low 90's), the Pi smelled kind of funny. I'm not sure, but it seems like the circuitry was getting baked. I considered installing a fan, but didn't want to draw extra power or introduce a separate power source. So to keep things simple, I went with a heat sink. This came in a 2-piece set for $7 on eBay. The Model A Pi only needs one. I have not done any measurements to know how effective this is, but it gives me piece of mind.
Aluminum heat sink on the Pi's 700 MHz ARM CPU

Workflow

I experimented using gstreamer to take advantage of the Pi's onboard video encoding. I got it to work (after building from source) -- and it is faster -- but the quality disappointed me. Maybe I haven't got the commands just right, but I decided to continue with mencoder. 

I realized that I was taking full resolution (5MP) still images at 2592×1944, which were then being reduced during video encoding to 1920x1080. So, I decided to go with 720p, and shoot at 1280x720 and encode the video to that same size. This saves space and time.

I also added the encoding to the shell script, after raspicam finishes taking the pictures, so an AVI will be automatically created. Further, I wrote a simple shell script to walk through the stills directory tree and delete jpegs and subfolders that are over a specified age.

I think the Pi is ready for the Colorado trip, so hopefully I will have some new time lapse videos to share of a cool place.

Video Conversion

Once I've transferred the avi from the Pi to my workstation (Mac Book Pro), I can convert it to a .mov using ffmpeg (free) like so:
ffmpeg -i "path/to/input.avi" -acodec libmp3lame -ab 192 "path/to/output.mov"

...or if I want to add music:
ffmpeg -i "path/to/input.avi" -i "path/to/music.mp3" -map 0 -map 1 -codec copy -shortest "path/to/output.mov"

It isn't necessary to convert to .mov because YouTube can understand the avi codec, but it makes the video playable on a mac, and allows the addition of music. It is also possible to use Audacity to trim and fade the music to fit the video length for a nice presentation.

Sunday, June 22, 2014

Long duration time lapse

After a couple of trials, I was ready to try a full day time lapse. Using the 7-day USB timer in my Cottonpickers solar project kit (see previous post), I set the timer to wake up the Pi at 5am and off at 10:30pm.

The Process

The Pi has a boot task in rc.local to immediately start a simple shell script that takes a few variables and kicks off the raspistill program. Here it is, if you are interested:

#!/bin/bash
# start a series of time lapse pictures every x seconds for y minutes
test_file=/home/pi/.timelapse
start_date_folder=$(date +%Y_%m_%d)
start_time_folder=$(date +%H_%M)
time_stamp=$(date +%Y-%m-%d-%H-%M-%S)
stills_path=/home/pi/stills/$start_date_folder/$start_time_folder
interval_sec=20
interval_ms=$(($interval_sec*1000))
#ONLY INTEGERS ALLOWED FOR VARIABLES (NO FLOATS)
run_hrs=17
run_mins=0
total_mins=$((60*$run_hrs+run_mins))
echo "total_mins = $total_mins"
duration_ms=$(($total_mins*60*1000))
echo "duration_ms $duration_ms"
shutdown_min=$(($total_mins+2))
echo "shutdown_min = $shutdown_min"
if ! [ -d $stills_path ]; then echo "make dir $stills_path"; `mkdir -p $stills_path`; fi
echo "starting raspistill"
raspistill -rot 90 -o ${stills_path}/still_%04d.jpg -tl $interval_ms -t $duration_ms && echo "shutdown now"


After all the pictures are taken, I run a separate shell script to encode the video from all those stills:

#!/bin/bash
path="/home/pi/stills/${1}/${2}"
#echo $path
output="timelapse_${1}_${2}.avi"
#echo $output
ls ${path}/*.jpg > list.txt && mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:aspect=16/9:vbitrate=8000000 -vf scale=1920:1080 -o $output -mf type=jpeg:fps=24 mf://@list.txt

I usually do the encoding later, but I could have it automated. I can also automate copying the resulting video to my dropbox folder.

Protecting the Hardware

The last photos of my Pi had it encased in the Nwazet camera case. I have taken steps to protect it from the elements. To keep expenses down, I used an old Lock & Lock food storage container that was large enough. Joey says my new case looks ghetto. My neighbor wondered what the hell it was. "It's a scientific experiment, yo!"

To get a clear viewport, I used a 2" hole saw to cut a hole into the lid, where I press fit a 52mm UV camera filter (and screw-on lens hood). I used aquarium silicone I had laying around to seal the fitting. I picked up the Chinese-made filter and hood for $6 on eBay.

It was also necessary to add additional holes in the case to attach the tripod adapter bracket. The tight fit prevents from using my larger USB Wi-Fi dongle, so I'm getting a right-angle USB adapter for that ($3 on eBay). In the mean time, I have my stubby one in place, which, I usually remove during photography to save power. However, the solar kit, which has 1500ma panel and (4) 3400mAh Li-ion batteries easily handled the Pi with the Wi-Fi running!

Notice also the bubble level attached to the top of the camera. This allows me to get it level with the horizon quickly. The next order of business will be to plug up those holes to keep out bugs and moisture. I'm afraid of introducing a microclimate that creates moisture, so maybe I'll use some extra window screen material or open cell foam. I may thrown in some silica packets too for good measure.


The Result

This 17 hour time lapse probably took around 2 hours to encode (also done on the Pi). Once complete, I upload to YouTube for sharing. This time, the color balance was a bit off, skewed to warmer temperatures. I made a correction in youTube, but I'm not sure if this was because of the UV filter. I used the filter on a previous trial without this side-effect.


Tuesday, June 10, 2014

Solar Goodies Arrive

A few days ago, my solar kit arrived. I purchased the Solar Project / Timer Box Combo (#2), made in the UK by an independent person(s), who goes by the moniker of Cottonpicker. This kit comes with the following items:

  1. 1500ma Solar panel with USB port
  2. Empty Li-ion Holder for 4x18650 rechargeable Li-ion batteries (stores about 40 watt hours)
  3. 7 Day timer to switch the Pi on and off at set times (or anything else USB powered)
  4. A4 sided box to hold it all in and keep the worst of the weather out.
  5. Simple plastic holder for the Pi
I purchased the 4 Li-ion batteries from Orbtronic.com (Panasonic 3400mAh 18650), which arrived a week or so before the package from the UK.

image
Complete view

image
Battery pack / charge controller with Li-ion batteries installed.

image

The charge controller prevents overcharging. The maker's claim, "It will charge the pack (up to 13,000mah) in around 10 hours of good sun and can power the Raspberry Pi B model for around 20 hours or the Raspberry Pi Model A for around 40 hours with fully charged batteries. If you use the timer to switch the Pi off at night or only switch on a few hours a day you could run all year in a remote location."

The kit has met my expectations so far, with no surprises. The quality seems to be quite good, and the little Pi case, which appears to be a basic 3D printed one-piece design was a nice touch. If you're wondering what this set me back, it was $95 US for the solar kit (incl. shipping) plus $43 for the Li-ion cells (shipped). For the money, I don't think you can do any better. Just look at the stuff sold by goalzero, and I think you'll agree. Of course, this is at the expense of going with stuff that won't be serviced & supported in the same way.

I've had the panel charge in the sun for a couple of days and will soon be ready to test with my Pi model A just how long it will run. I am also working on a DIY weatherproof enclosure for my Pi so I can run it without worry of water damage.

Cottonpicker's Place - Solar kit
Orbtronic - Panasonic 3400mAh 18650 product page

Monday, June 2, 2014

Legit case; weather time lapse videos

I invested in a case for my model A Pi so that I can securely mount it to a tripod. I decided to go with the nwazet case, which is laser cut plastic pieces.
So far, my USB battery unit has easily powered my Pi for 4 hours, leaving 2 bars left. I may soon try a 5 hour use. I always remove the wifi dongle when I use it off battery power to reduce power consumption.
Here are a couple of 4 hour time lapse videos

Monday, May 26, 2014

Color issues solved!

A quick update on the issues with auto white balance in my previous post. The more I thought about it, the more I suspected there was a problem with the camera module itself. I drove over to my local MicroCenter and they exchanged it for me. Gotta love that local advantage! I tested it with default settings out on the porch again to replicate the conditions, and my hunch was right. There was likely some manufacturing defect with the camera module -- the new one looks normal:
No more alien worlds!
Now, I can skip all the headache of conversions.

Soccer time lapse / AWB issues

First off, I decided to do a time lapse during my daughter Lindsay's soccer game. I have noticed that while indoors, the camera module with default settings in raspistill does a decent job with auto white balance, but outdoors, it is a mess. Greens are non-existant...

raspicam with default settings
-awb sun (auto white balance = sun)
-awb sun -sa 20 (saturation = 20)
-awb sun -sa 70 -co 50 (contrast = 50)
-awb sun -sa 70 -co 50 -mm matrix (metering mode = matrix)

Obviously, I have some more trial and error to do. It's a shame that the camera doesn't cope well with sunny conditions. Anyhow, here is the time lapse of the soccer game without any correction:


Thursday, May 22, 2014

Time Lapse Test

After first testing the camera, it didn't take long for me to hook the Pi up to a battery power (I'm using a solar-powered USB phone charger) and test it outdoors. First, I found a suitable "case" to house the Pi & camera temporarily.

This Gatorade packet canister will work as a case for now
I taped the camera module to a piece of plastic with a small hole cutout and slid a used spool from a roll of Gorilla tape to hold the camera in place (and it makes a nice lens hood too). I routed the USB cable out the other end to the battery pack/charger.
Powering up the Pi in a makeshift case from battery
After powering it up I ran a quick test by ssh-ing to the host and commanding series of pictures. I wrote a very simple shell script to do this, and it works, but there is a built-in option within the raspistill program for timelapse. Having verified that this works, it's time to set it outdoors and make a short time-lapse.
Front porch time-lapse test in progress
Just a random thought about using this in various places. It could be easily mistake for an explosive device, so keep that in mind if you do something like this to prevent a panic.