Raspberry Pi Time Lapse Camera: How To Instructions


#1

OK, since some people wanted it, and I suffered a boot loop last night which means I have to reinstall everything to get back on track fro myself anyway, I have decided to write this tutorial as I set up the new Raspberry Pi time lapse so that you could have instructions to do it too.

I could potentially troubleshoot my issue, but that will take time that I want to continue the time lapse. Since I retrieved almost all the photos already via google drive, I have lost nothing but time. Using open source DIY oftentimes has you acting as your own support desk. I offer no long term support beyond helping you get set up (I might help out), as I am not at that level. I can tend my own garden OK, but when I come into your yard I usually will mess it up. Remember kids, google is your friend.

On that note, some of the software used to prepare your SD card is listed as WIndows only, because that is what I use as my main computer. If you are using Linux, you should already be done setting your Pi up by this point and don’t need me. If you are on Mac, you will likely have to use a program that you find with a google search.

Ok, you will need:

Hardware

  • 1 Raspberry Pi (any model will work, but we are going to use Raspberry Pi Zero W because it is super cheap, does the job, and has wifi and bluetooth built in so we won’t need a wifi dongle)
  • 1 Power Supply, 2.5 amp micro usb (don’t skimp or try to repurpose a questionable phone charger. Many problems on this platform are because of insufficient power, and like PH lockout, the symptoms often mimic many other problems. i have been a victim of this and is often the 1st troubleshooting question asked when Pi’s go loopy)
  • 1 micro SD card 16gig minimum, 32 gig recommended. Also recommend Class 10 or better, Sandisk seems most reliable. Don’t skimp here either as all your data relies on a good SD card
  • 1 Camera Module and appropriate ribbon (Raspberry Pi Zero W will work with any camera module, but most camera modules come with a full size ribbon cable. In retrospect, I would have bought a wide angle camera lens as I lose some plants because of the tight confines of the grow space. Consider that before you order)
  • Wifi
  • Computer to prepare the SD card (if your computer does not take SD cards, external USB card readers can be purchased fairly cheaply)
  • Pi Case (optional, but I strongly recommend it)
  • Tripod or stand of some kind (since the camera will be static, tape can easily replace a tripod)

I recently bought 2 of these, as they had most of the accesories that I needed and at a good price (including the Pi Zero camera ribbon)

It comes with a power supply, the actual Raspberry Pi Zero W, a case, and the Pi Zero camera ribbon. You will only need to buy a camera module and SD card for the actual Pi to have all you need to go, and the price is pretty much perfect, especially if you have Prime)

BE AWARE, ASSUME THAT EVERYTHING THAT FOLLOWS IS CASE SENSITIVE

Software

  • Download SD card formatter. You will likely need this to prepare an SD card if a device has set up a file system that windows cannot use. Download at https://www.sdcard.org/downloads/formatter_4/eula_windows/index.html
  • Download https://sourceforge.net/projects/win32diskimager/ to install the operating system on the SD card
  • Download The current version of Raspbian from Raspberry Pi (a custom Linux operating system made for the Raspberry Pi based on the Debian OS.) We are only going to use the command line, so you will want to skip the desktop version and just grab the Lite version https://www.raspberrypi.org/downloads/raspbian/ (these instructions should work with whatever Raspbian version that will come out in the future. should)
  • Download Putty: http://www.putty.org/ This is your SSH client, or where you will connect to the device and give it command line instructions. You will use this often, so make a shortcut to find it easily.

Prepare the SD card:

Put the SD card in the computer. Open SD card formatter. Set the drive to the correct slot for your SD card.
IMPORTANT: MAKE SURE YOU ARE POINTING IT TO THE CORRECT SLOT OR YOU RISK DELETING THINGS YOU WOULD LIKELY PREFER TO KEEP.

You can skip the volume label, but click option. Quick format will work, but you can take some extra time if you would like and change it to full if you like.

Change Format Size Adjust to on and click OK

Once again ensure that the drive is pointing at the correct drive, and click format, then click OK. Then click OK again.

Recently, I have had a problem where SD Card Formatter would give me an error message saying it couldn’t format the card. If that happens to you, just repeat the previous steps and try again and it should work the 2nd time. Close all the windows and warnings before trying again.

Exit SD card Formatter

Download Raspbian Lite and Unzip it. Remember where you unzipped it.

Open Win32 Disk Imager

Ensure that device reflects the correct drive, and click the folder next to the “Image File” entry, and navigate to where you saved the unzipped Raspbian .img file. Click on the file and once again make sure that the device field reflects the correct Drive for your SD card to avoid deleting things you might want to keep. Then click write and then click yes. Wait until finished.

Set Up Headless networking and SSH

Once the SD card is written to, maneuver your file manager into the SD card drive. It should be named “boot”

Right click and click New-> Text Document.

Rename that file “ssh” without the quotes. Remove the .txt extension so the complete name is simply “ssh” without the quotes. When windows complains, just say yes.

This allows remote log ins through putty. Otherwise you would have to attach a keyboard and monitor and edit config files to open ssh up. We are running this in “headless” mode, which means it really shouldn’t ever have to be attached to a keyboard or monitor. Raspberry Pi includes this shortcut to open the device to remote connections for headless setup.

Once again. right click and click New-> Text Document in the boot folder.

Rename the file wpa_supplicant.conf

This file will help run headless by configuring the Pi to use your wifi and logging you in so you can connect locally with putty.

Open the file, and add the following text, replacing YOURSSID with your own wifi SSID and replace YOURPASSWORD with your wifi password.

network={
ssid="YOURSSID"
psk="YOURPASSWORD"
key_mgmt=WPA-PSK
}

This should work for 99% of cases. If you have a more complicated network setup, you may need to consult your IT tech. If you are the IT tech, you may need to consult google to make this work. It does work for most people right out of the gate tho.

Safely eject your micro SD card and get ready to go.

To power a Raspberry Pi up, plug it in; there is no on/off switch.

Prior to inserting the power cable, I would advise you to hook up the camera and place the Pi in its case, if you bought 1. I would not do a full install, in fact, when setting a Pi up, I leave it right next to my computer. I make sure everything works perfectly before installing in the final position. It is easy to make a simple mistake and have to start the process from scratch because you don’t exactly know what you did wrong. At least, that is what happens to me.

Make sure not to plug the power in until after you put the SD card in. There is no hard drive on that board. The SD card is it. After you place the SD card in, plug the power in. Give it a couple minutes. You can read a bunch of stuff if you plug in a micro HDMI cable, but it likely wont interest you.

Now determine the IP address of the Raspberry Pi on your local network. The easiest way to do this, is to log into your router software and look for the device named “raspberrypi”. Consult google for other ways. If you cannot find any way, your last resort is attaching a keyboard and monitor to the Pi. you will likely need special cables/adapters for this. It is very easy and free to log into your router and find the info.

Open Putty

In the host name, type the IP address which will look similar, but not be 127.0.0.1 . Leave 22 in the box. Give it a name and click save.

Click open, and if you are greeted with huge wall of text ominously warning of a potential security breach, you are connected and so far everything is working as it should, beleive it or not. So click yes and you are in!

If you are not seeing the big wall of grey text, you may need to go back to the beginning and try again. This is the most crucial part of the process, so we are lucky it happens pretty quick. Problems are less likely from this point on, so don’t get discouraged if you have to start over at any point in this process. It would blow your mind if I told you how many attempts to get everything working exactly the way I wanted it to?

Anyway, if you were succesful, it will now be asking you to “login as:”

username = pi
password = raspberry

we are going to change that, dont you worry!

You should now see this!

pi@raspberrypi:~ $

That is your prompt. You are now in command line on a legit linux machine!

1st thing we are going to do is go through the native Raspberry Pi configuration utility.

So copy and paste the following (when you see entries formatted like this from now on, it usually means to copy and paste that line into putty)

sudo raspi-config

the word sudo is telling the computer that you are an administer and are doing administrative work. It gives you root access. Be very careful with this command. We will be coming back to this later, as it is used often. You will notice many times that you use the sudo command, it will ask for your password. The first time it asks for your password, it will come with a warning. Read the warning. Raspi-config is the name of the program to configure the pi. We are doing so as administrators because we are controlling everything about the device. We will ONLY use sudo when necessary, however.

Ok, back to the config. Use the arrow buttons to go up or down to scroll entries. Do #1, and use a secure password. I don’t think I need to remind you that you plan on putting these cameras 12-20 hours a day onto your precious babies, so let’s be smart and lock things down with a secure password. Once you change it, you will be asked to repeat. That is now the password for user: pi . Under no circumstances should you move on until this password is changed. Until that point, you are potentially heavily exposed. Change the password!

Next, on #2, change the hostname. I suggest you do, but that is optional.

4 is likely optional, but I suggest changing all to reflect you correctly. I am in california, so my locale would be en_US.UTF-8 (try to use UTF-8 specific to wherever you are), my timezone US_>Pacific Ocean, and my Wifi country is US United States.

5, on interface options, you want to go to P1 camera and enable the camera interface. That is all you need to do in 5 (you already did ssh, which is what you are using to connect through putty). If you don’t enable the camera here, it will not work later.

You will want to go to advanced under 7 and then A1 to expand filesystem to use the entire SD card (the Pi OS image is designed to fit on small SD cards. You arent using a small SD card, so this step allows the OS to use the entire SD card instead of a couple gigs after the next reboot).

Go back to advanced under 7 and go to memory split. Change it from 128 to 16 . (there is a limited amount of RAM in a raspberry pi. The Pi Zero only has 512. And that must be split for video memory, such as when playing games or operating on a desktop. We will NOT be doing any of those things so we are decreasing video ram to allow our operating system more RAM to work)

Then click 8, Update. Depending, you may want to start breaking up some weed. Maybe locate your papers and smoking equipment.

After it is done updating, click finish.

Creating a New User

Ok, now we are going to create a new user. In this example, we are going to call the user ILGM, so when you see that in this post, I am referring to the user, not the website. :wink:

you should customize your user name for yourself and replace ILGM with your own username

anyway, type the following

sudo adduser ILGM

give it a different password, and you can just click enter and skip everything until it asks you if the info is correct. then type y for yes

now, we want to make sure the new user has admin permissions, cuz we are going to reboot the pi and move our operations over to the new user. so we need to add ILGM to the “sudo” group, so that ILGM can execute the “sudo” command. Otherwise, new users are prevented by default from that access. So type

sudo adduser ILGM sudo

Great. You should see status messages indicating success, so now type this to reboot

sudo reboot

that putty window is now dead, you may close it and yes you are sure.

wait a minute or 2, then reopen putty and double click on the name you gave it earlier, and log into your version of the ILGM user account

Installing & Setting up the System & Camera

now we want to do any updates the software needs. Without getting into anything, as far as my tutorial goes, whenever you want to add new software, run the next command prior to that. It is also a good idea to log in every now and then and run this command to make sure everything is updated and secure. It should be noted that linux, while in putty, has your past commands stored over time using the up arrow. So once you type the following command, it will be available by pressing up arrow a number of times. This makes things simpler.

Anyway, run the following command, then type your password when asked (READ THE WARNINGS). After sometime, it will ask you a y or n question about proceeding. Type y to proceed and update. You may want to puff on that weed you prepared earlier, but put it out about halfway through and come back. Or watch the status messages. I admit, as a geek, I sometimes puff and just watch the messages roll by. Paste the following

sudo apt-get update;sudo aptitude safe-upgrade

I like to use some software to monitor things, and some intrusion prevention in case I accidently or on purpose decide to expose this computer to the internet. I am going to add those programs real quick, and you can too by typing the following once everything is updated

sudo apt-get install htop fail2ban

then ok it with a y

type htop into the command line to see what it does. At it’s heart, it is a resource monitor. It can do other things. to get out of htop, click ctrl-c

linux comes with a more basic version if you type the word top into the command line. it is useful in its own way and i often use both.

remember, to get out of a program in the command line, like top and htop, click the ctrl button and c button at the same time. ctrl-c

fail2ban is a basic prevention to brute force attacks by giving unique users a time out if the try and fail to connect too often. it just works without configuration

now we are going to continue to make sure the Pi is upgraded fully. paste the following in the command line, then ok it with a y if need be

sudo apt-get dist-upgrade

If you are lucky, there will be nothing to download

Then we are going to make sure the we have a firmware update in case the camera has been updated. paste the following

sudo rpi-update

stretch the old legs by taking a quick run to look on your girls. take a moment to reflect on the smell. then do a walk around your house and head on back. reboot the pi to use the new firmware by pasting

sudo reboot

After a few moments, close the old putty window and fire up putty once again and log into the ILGM account. It is fast to reboot now, but from this point on, you will want to give it a minute or 2 between reboots before putty will let you sign in

we are now going to install git, which is a way of github to share code as it is developed. We will first install git by pasting

sudo apt-get install git

now, we are going to clone the camera software into our own folder. paste

git clone https://github.com/silvanmelchior/RPi_Cam_Web_Interface.git

At this stage, we are going to install most if not all of the software needed to run the camera. So that weed you put out earlier, go ahead and get ready to fire that up. Also, have a project or tv show or some gardening to do after you ok it with a y. it will likely be awhile. Paste the following:

cd RPi_Cam_Web_Interface

then

./install.sh

type your sudo password, then after a few moments, a configuration utility will pop up. You may replace html with a custom folder name if you would like, just remember what you called it. Leave autostart yes. Leave apache unless you know what you are doing. add a user: and a STRONG password and click OK (remember where this camera will be pointing, lock it down).

Now fire that herb up and walk away for awhile. This will not be quick.

If you want to take a look at some documentation, you can find that here: http://elinux.org/RPi-Cam-Web-Interface

When it is done, click yes when it asks start now? Notice the light on your camera is on. We appear to be operational. Let’s test and get into the programing of the settings.

open a browser (like chrome or firefox) and enter the IP address you entered into putty earlier. You can open a new putty to refer to it if you forgot.

after the IP address, type a / and then the cam subfolder name you entered into the camera setup. If you left it alone, it would be html. If you changed it, you will need to type what you changed in. If it was left alone, you would type something that looks like the following into the browser address bar

192.168.1.1/html

If you get a password prompt, you did it and are in! Type the username and password you used during the camera config and you will now be seeing your camera, live. If you do not get a password prompt, double check the IP address and try again. If that doesn’t work, check to make sure everything looks ok by using up arrow and running the following again

./install.sh

make sure the cam subfolder is correct. I may need to refer you to another support forum if these 2 steps do not fix it for you.

Garden Specific and Advanced

Basically, the instructions so far have been used to set up a live webcam. If you know what you are doing, you can set up port forwarding to see this outside of your network. Make darn sure that you know what you are doing if you make this decision. I will not be teaching you how to do that. I will say, that if you have followed me so far, you are about to be hosting your own website. If you have never even set up a website before, you are past that already. :wink:

From now on, the instructions will focus on setting up a time lapse for a grower. You have a lot of options at this point for the device as a utility around the house. Google will help you with instructions. From now on, we are doing stuff specifically to capture your grow

Ok, I am assuming you are looking at your webcam on the browser. Click camera settings and a drop down appears. These are the setting I modify:

I change video res to 2592x1944 . It is a square format, but it is higher res than 1080. Time lapse interval is seconds, so i use 300 for 5 minutes, meaning that 1 image is taken every 5 minutes. Annotation I change for my tent (Big Top Garden in My case). I also change the size and a custom black text color, but these are all things you can decide on. Notice the wild cards for date and time in annotation. This can be expanded on, for instance, a temp/humidity module could be added and the info also embedded, if one was so inclined)

I keep stabilization off because you lose pixels and your camera should be stable anyway for a time lapse. Things like white balance, brightness, saturation, and expose compensation will likely be needed to make your images look nice and not washed out by the bright lights. I can’t really help you with that other than just try things until you find what you like. You have the ability to rotate the camera so as far as mounting your camera in the final space, you have flexibility.

I wouldn’t mount it just yet, we have more to do and test. But we are getting close. You will have plenty of time to come back and tweak this later.

Next, click Edit Schedule Settings. On the bottom right type “tl 1” without the quotes. This tells the time lapse to initiate on startup.

click save settings at the top, then click the back button on the top of the webpage to go back to the camera screen. The time lapse has now initiated. After 5 minutes, click the download videos and images, and you will see your timelapse. You can now download photos from your timelapse here (be aware that when in time lapse mode, groups of pictures will only be displayed as a single thumbnail because internally, this software can actually make your time lapse video for you. I do not recommend this. Downloading a time lapse thumbnail will download all photos in that set, zipped.

So, I need to automate some things. I am going to plug this on the same circuit as the lights. That way, it will not record time lapse of a dark tent and will start up each day at lights on. I would like to shut it off gracefully, tho. To do this, we are going to use a function in linux called cron, which does specific tasks at predetermined times. My lights out is at 2 am, so I like to initiate the shutdown sequence just prior to the Pi losing power, like at 1:58 am.

This is when things get a bit more difficult. You will need to consult additional resources to use the editor.

To do that, paste the following into the putty command line

sudo crontab -e

now, a tutorial on using an editor is beyond my ability and the scope of this. this can be a pain. please consult with documentation for whatever editor you chose. Most people chose nano, i did not. i can’t help you there

but to shutdown my pi at 1:58 am every morning, i am going to want the line at the end to say

58 1 * * * /sbin/shutdown -h now

The first number is the minute, and the next number is the hour expressed in 24 hour format (midnight hour would be 0, 11 PM would be 23). You can easily customize that based on your own schedule.

I noticed, for whatever reason, on my last build, that the time lapse stopped after midnight every night. So I set up a cron to reboot the Pi at 2 minutes after midnight every day with the following using sudo crontab -e

2 0 * * * /sbin/reboot now

That successfully restarted the time lapse for me.

Once you know how to use the editor and configure the cron, I suggest doing a test reboot and shutdown prior to installing, at a current time

Ok, you have what you need to go. I can help get going, but I can’t provide support once you are set up. You are your own tech guy here. It’s not that I am against helping, it’s just out of my ability range. I could try, but don’t count on me.

If you have any questions, please feel free to ask. If you set it up and something doesn’t work, let me know in case I made a mistake. I wrote this as I set mine up today, so I hope and think I covered everything as well as a little info to get you more comfortable with command line.

I also use a paid product called insync. It costs about $30, but there is a free 15 day trial. What I use it for is to upload all of the time lapse photos to my google drive. Doing this, I can have the photos backed up and downloaded to my drive and local computer in case anything happens (something happened last night, hence I am redoing my time lapse camera. stuff happens all the time, so be aware of manually or automatically backing up)

AFAIK, all Pi Zeros are armhf

The other advantage is that I can monitor the girls in semi real time without opening up the raspberry pi to the internet by checking the most recent photo of google drive. I keep my thermometer in view so I have a pretty good idea of the last 5 minutes, max. I do recommend this software, but they are going to have to provide support for it. It is beyond me.

There are other alternatives that do the same or similar, but I can’t speak to them.

Once again, I will try to help you, but my expertise is limited. I simply researched, followed directions, and put it together.

If anyone does this, please let me know and let me see the videos. I love this stuff. Thanks, good luck and happy gardening!

And here is a repeat of my time lapse from earlier this week if you haven’t seen the final result.


Menojuana (aka: A middle aged woman’s attempt at a better quality life grow)
Step Right up to the Big Top Tent, See 8 Unique Strains Perform in Coco for Your Entertainment under the Bright LED Lights!
#2

@BlackShirt @BIGE


#3

Thank you, sir! Looks like I have my reading cut out for me!


#4

I wish the instructions were just for the time lapse part I will need to filter out the other stuff. I have a pi and the camera so all I need is the time lapse part


#5

Go to this heading. If you don’t want to install raspbian on a new card, you should have no problem starting there


#6

also, if you are already competant or advanced on the pi, go directly to the cam software

http://elinux.org/RPi-Cam-Web-Interface

the garden specific stuff is pretty easy in concept, i just took the built in tools. Make sure you know nano or vi ir vim if you want to edit the cron like I have it set. Or use something like webmin to set cron or edit directly in a file manager


#7

Yes I already have the camera working just looking for the time lapse part


#8

set your interval for 300 seconds for 5 minutes (or whatever you want) under camera settings

go to “edit schedule settings” and on the final parameter, “period start,” add the following

tl 1

Your time lapse is working. Put it on the same timer as your lights. Use cron to have it shut down correctly 2 minutes before lights out. It boots and starts on lights up

My timelapse stopped at midnight for a reason i couldnt figure out. If this happens to you, use cron to reboot at 12:01 am

if you want each photo uploaded to google drive, check the following link or explore other alternatives. I paid for and use the following and am happy with it

you are probably armhf, but double check, i do not know for sure or what model you have

there you go, condensed


#9

Probably a memory leak

Watch out for red lights in the device during night time


#10

memory leak?

you put the pi on the same timer as the lights. No red light when the lights are off because the Pi has no power


#11

Yes do you know what a memory leak is? It was the first thing that came to mind when you described your problem


#12

if you are talking about the midnight stoppage, no, it wasnt a memory leak.


#13

Ok it sure sounded like resources were getting drained.


#14

nah. i have an obsession with htop

plus, the live camera stream was always fine which is why i didn’t notice for awhile


#15

Awesome thread! Very good information on setting one up!