How to know if your coral is growing!

One of my biggest problems is impatience.  My reef is in my living room and I see it for a couple hours each day.  For this reason I never notice my coral growing, consequently I fiddle with things trying to get more growth, until I stumble across an old picture and I'm stunned to see how much things have changed.  In order to track growth better I devised this little camera which takes pictures every day, I can then look back at the photos to see how things have changed. 

Here is an example, this shot flips through 3 images that were taken 12 days apart.  From the first to the last shot there is a 24 day gap:

Click to see a larger image

Pretty cool eh?  Really helps with my growth OCD.

You can do this as well, it's made with a Raspberry Pi and the Raspberry Pi Cam, total cost of the project is around $100.  The Raspberry Pi runs Linux, a free open source operating system.  These instructions are designed for someone that has some understanding of the Raspberry Pi and Linux already, but if you are patient and you are willing to google some of the steps I skipped over then this can be done by anybody.

First, the setup.  I used a Raspberry Pi B+ to do this, you don't need more power than that, but if I were to do this again I would use the faster Raspberry Pi 2. 

Keep in mind, this is kind of a junky camera, if you are looking for nice pictures with perfect white balance you will need to use something much better.  Many DSLR cameras can be setup with a time lapse feature to take pictures every 24 hours, and you would need a setup like that for perfect shots.

Once you have Noobs installed on your SD Card you need to enable the camera, it is one of the options in the initial setup, or you can run the raspi-config program if the Pi is already setup to enable it.  I would set a static IP address on the Wireless network card, or create a dhcp reservation on your router so that you can remote connect to this device and get the pictures off without touching it (and risking moving it).

Now you can take a sample picture.  If you still have a monitor plugged in simply typing:
raspistill -o test.jpg
Into a Terminal window will show what the camera is seeing for a couple seconds on the screen then save the image as "test.jpg" in whatever folder you are in currently.  If you have the GUI loaded you could open it and look at the image, if you are using the command line then we will look at that picture in a bit.

Now, Move back to your Windows PC, you will need to download a couple of tools to connect to your Raspberry Pi without touching it.

First is Putty, this will allow you to SSH into your device to change configurations and do tests:
Next is Win SCP, this program allows you to do file transfer over SSH and will allow you to recover your images:
With these tools installed, test that you can connect using the static IP you setup earlier.  If all is good then we can move onto the physical setup of the camera.

I mounted mine to a Cell Phone windshield mount that I bought at Radio Shack.  This one is nice because it gives me lots of different tie down spots, and adjust ability, but I'm still looking for a better method so if you have one I want to see it!  Use your creativity here, but to get you started this is what I came up with:





I did eventually trim off the Zip Ties BTW.  I just left them on there for a bit so I could tighten them if I needed to.

You can see the Camera on the front side of the mount, an the Raspberry Pi itself is on the back side.

 







Now that the device is all in place power it up, and connect through Putty.  I am assuming that you no longer have a monitor connected.  From this point on this device will be controlled remotely.  From your home folder once again run this command in the putty terminal window:
raspistill -o test2.jpg
Now connect using WinSCP and navigate to your home folder if necessary.  Copy the picture to your desktop and open it up.  This will show you what kind of changes are necessary. 

Camera Adjustments
  1. The first thing we need to deal with is that Red LED on the front of the camera board.  It will reflect off your glass and ruin every picture.  Some people have used electrical tape to turn it off, but it's better to shut it off in the system.  Here is how that is done.
    Logged in as "PI" in putty type:
    sudo nano /boot/config.txt
    Scroll to the bottom of the file and add this line:
    disable_camera_led=1
    Don't forget to save before you exit, if you hit ctl x it will ask you if you want to save.
    If you need more through instructions on this step click here
  2. Change the orientation.  If you find that the picture is upside down or sideways you can use these additional switches.
    -vf for vertical flip
    -hf for horizontal flip.
    For example if your picture is upside down and sideways you can run this command to take the picture correctly:
    raspistill -vf -hf -o test3.jpg 
    I'm running that command myself.
    Click here for informaiton about all the useful camera switches and how to use them
  3. Now that your picture is oriented correctly it's time to change what you are taking a picture of.  Take another shot using the proper command and copy it to your computer using WinSCP and open it up.  Make a small adjustment to the camera and try again.  Do this as many times as necessary until you are taking a picture of what you want. 
  4. White Balance.  This is really tricky to get correct, and mine is far from perfect, but the closer you are the better off your photography will be.    The trick is to get it close enough that you can fix the rest in Photoshop.  The way this is set in the Raspicam is you set the gain on the 3 primary colors, Green is set and you can't change it, but you can change Red and Blue relative to Green.  We start with our command to get a picture in proper orientation, lets say that looks like this:
    raspistill -vf -hf -o test3.jpg
    Now we add a couple things, -awb off turns off auto white balance, -awbg num1,num2 sets the gain manually.  We now have this command:
    raspistill -vf -hf -awb off -awbg 2.03,0.56 -o test.jpg
    That is the command I use, but for your lights you will need to play with those numbers to get the white balance correct.  The only way to do this is take a single shot with a starting point, then adjust up and down to see what numbers look best.  Move one at a time and you will get the hang of it.  Sorry, I really wish I knew a better trick, but I don't.
  5. Once you find a command that works best for you, make note of it and move onto the next section.


Setting the Pi up to take pictures automatically

  1. First we need to create a script, in the Putty console create a directory in your home folder (this location is important because you have full permissions there), create a folder for all your images using this command:
    mkdir camera
    Now create a script for taking the images by using nano using this command:
    nano takeshot.sh
    In nano write these three lines:
    #!/bin/bash
    DATE=$(date +"%Y-%m-%d_%H%M")
    raspistill -vf -hf -awb off -awbg 2.03,0.56 -o /home/pi/camera/$DATE.jpg
    The first line denotes it as a Bash Script, the second creates a variable named date so we don't overwrite each image with the next one, and the last line would be replaced with your command, and uses the vairable you created to give each shot a unique name.
    Now, save and exit Nano.
    The next step is to make your script executable.  You can do that with this command:
    chmod 777 takeshot.sh
    That gives everyone full permission over that file.
    Finally, run your script with this command:
    ./takeshot.sh
    It should take a picture, and in about 10 seconds you should have a new jpg file with a name that is simply the date it was taken.  Copy this picture to your desktop using WinSCP and make sure everything looks good.
    If it does, congratulations!  You now can take a picture with a single command!
  2. Now that we have a script to run the last step is to setup Crontab to run it automaticly.  This will ensure that even if the Pi is restarted when it boots back up it will go right back to work.  First enter Crontab by running the command:
    sudo crontab -e
    Move to the bottom of the file and enter this command, we will edit it for your specific instance in a min:
    0,15,30,45 12,13,14,15,16,17,18,19,20 * * * /home/pi/camera/takeshot.sh 2>&1
    The spaces in this command are very important, what this does is take a picture:
    At 0 min, 15 min, 30 min, and 45 min of
    Hour 12, 13, 14, 15, 16, 17, 18, 19, 20
    Of every month, year etc.
    You will need to change this to match your lighting schedule and your path if you named things differently of course.  The reason I take so many photos is I want to make a time lapse video eventually, plus it gives me enough shots to make sure I get a good one on any given day.  You can change this if you like to take only one shot an hour, or take shots during only one hour per day if you want it to run longer without filling up your SD Card.  I use a 16 gig one now to give myself more space.
    If you have trouble a quick google search of how to use Crontab will answer all your questions.  The trick is to make Crontab run the script you created during the times you want to shoot.
  3. Now you test!  Let it run during the times you should be getting pictures and use WinSCP to ensure your pictures are coming in.  You can then copy them to your desktop, or do what I do which is wait until the card is almost full and copy them all in bulk.

What to do with the pictures once you have them

There are plenty of online GIF creators, just Google "Online GIF creator" and you will get a ton to choose from, but they are usually limited in picture quality, so I typically use Photoshop to to this.    Though I post the "internet" quality image, I use the high res one to zoom in and inspect how things are progressing.

This is how to create a GIF in Photoshop CS6, but I have done the same thing in CS4
  1. Take your photos and save them into a single folder, I like to work off my desktop.
  2. Click File, then Scripts, then Load photos into stack.
  3. Browse to your folder, highlight all the files you want to make a GIF out of, and click Ok, then Ok again.
  4. Photoshop will load all your photos into Layers.
  5. Click on Window in the top menu, then put a checkmark next to Timeline.  This will open a new bar at the bottom.
  6. In the top right hand corner of the new window there is an icon with 4 lines in it (circled below), click on that then click "Make frames from layers"
  7. Click through the frames listed in this window and make sure they are in the right order, if they are not drag them to the proper place.
  8. On the bottom of each image there is a little icon that probably says 0sec, drop down the little arrow and select how long to delay on each frame.
  9. When your done it will look something like this, the word "Forever" that is circled tells the browser how long to play the GIF, you can have it run only a few times but I prefer to have it go forever.
  10. Finally click "File" then "Save for Web", in the first window you can set the image size, for the web I prefer something with a height or width no greater than 800px just to keep the file size downloadable in a reasonable time.  Once you click "Ok" you will be able to name your GIF.
  11. Now share with all your friends!!!  I'd love to see what you come up with! 





Comments