DIY DIY Timelapse Camera : Pi-Lapse

ciao vaporhaizer. yes start out with the webcams, should be fine. best way to check compatibility suck it and see.
my system will already be a well endowed I guesse, but the minimum spend really is just the Pi board, and any webcams you have lying around etc. R-Pi camera module not bad for the resolution really, 19 bucks so comparable to a cheap webcam.

im running of a powered USB hub, keep the load on the Pi less. The SSR are powered directly from the IO pins as they don't need much current to activate. In you case if you have a relay board already, makes sense to interface it.
make use of the parts bin where possible, so long as your cat allows :)

SSH yes, basically run the shell commands remotely instead of plugin in local, its a secure socket connection. Connectivity wise, I reckon probably all we need is already there. The LAN Jack!
I figure if this is Linux I should be able to get SAMBA up and running - this is like windows fileshare, so effectively I can create a NAS type network drive on the Pi. Any time, we can open that network drive from the local folder and see the snaps or timelapse vid, and pull them off the R-Pi.

it will be on the local network only, so remote funky stuff beyond that - so its up to whoever uses it to make sure their general IT security is tight. Use MAC filtering and proper passwords on WiFi, change your SSID to something that doesn't give away your router type, like BT yada yada router.

Also it should be able to live stream - so preview from tablet/phone LOCALLY , to get the camera set up right. web-cam server. If you trust what you are doing you can allow a remote access from externally also.

pan-tilt , I thought about but for this one not essential. Nice to add though, and I can see that being useful. I probably have most if what Id need to run that already, redirect a couple PWM outputs and we're good. But for this one my concern is starting close and backing the camera away as the plant grows. Need a sliding platform of some kind.
Techy as we are ... I will use a manual method and mark up over the weeks where to bring the camera back to.

I guesse there will be time to expand on this later, and plenty of scope for it. But always you have to put the stake down somewhere to stop it becoming a never-ending over engineered nightmare!!! Plus bro, I got to get some growing going on soon so once its up and running there will be more time to add goodies.

here's another example, which I wont implement just yet for sakes of getting it up and running ;
In the last grow I had the things spinning on turntables, nice since I don't need to keep rotating things about, but that would complicate the timelapse a little bit. every shot from a different angle don't work so good.
so the plan was hatched about a stepper driven turntable, can sync the rotational position with the shot, even timelapse vid where the plant gently rotates through the grow. hell you could collect several "tracks" of timelapse like this in parallel !!!

nice to have you aboard dude, and glad its coming through easy to follow. I wanted to inspire folks less brave with this kind of stuff with a step-by-step style how to. couple guys on the DIY EC meter thread also pulling their arduino out for some fun so, its starting to get more fun as we go.

will get some more work done on this later and check in with an update!
 
hi guys. just thought Id check in and let you know things are moving along nicely. got the IO settings persisting through reboots now and bunch of scripts to drive the lighting for now. the first thing to do was get it operating our grow lighting cycle. since the box is in charge of that we wont need a timer switch thing anymore. so there is script to do that now and some others that will combine, building up to the snapshot capture. Should be worthy of an update soon.
 
managed to get some work done this evening, just wrapping up (I hope) a box containing the mains electronics, switches and indicators, also the low level night lighting. this will go on the wall and a cable runs down to the Pi (since the Pi and its camera cant be separated to a long distance, it needs to be able to be moved)
needed to get this done now as I can test with the right combo of switches and sort out the disable function. Also, I reckon couple more days SW tweaking and Im almost ready to deploy, so makes sense to get it together in a safe and sensible way.
I'll post some pics tomorrow and a circuit of whats in there.
 
managed to get a few more things sorted on the control box tonite, still got the usb hub to fit tomorrow but the rest looks good to go.
I'll post a wiring diagram tomorrow, running short of time :(

16.jpg

Now the only power in is into the control box, the Raspberry Pi is fed 5V from the beefy 3.8A PSU, which also powers the LED "night light" and will power the USB hub and the camera's once they attached. Nice that it avoids having to plug the micro USB power into the Pi to power it. there will be two cables in the end between the Pi and the control box, the power+gpio white cable, and USB from the Pi back to the hub. usb cameras will branch out from there.

17.jpg18.jpg

In the control box there are the two solid state relays on their heatsinks. they switch the mains to the grow lighting and white lighting under control of the raspberry pi. I added an LED drive using a MOSFET driver to take R-Pi's 3.3V output and drive fully on the IRF830 power MOSFET. That thing will drive a lot more than we're asking of it, I just had these bits so made use of them here. The flash LED is an Osram single chip, kind of thing you might get in your mobile phone. This will be used to continue timelapse during lighting offtime hours.

19.jpg


This shot is taken in darkness, lit only by the flash LED.

20.jpg

The setup so far. No longer a bundle of wires and stuff on the end of the desk :dance:

21.jpg
 
tried to run some tests on the box today, finally plugging it into the mains and checking the two relays. but I found they were not switching the load on :(
As it turns out the GPIO drain current available from the Pi is not enough to drive the SSR to ON state. Although they are in the voltage spec to drive the SSR, it requires 7mA @ 12V , so 25mA or so at the 3.3V we have.
Managed to get around that with the mosfet driver IC TC4427 again, its got two channels so I added another of these and let it drive a 5V outputs with more than enough current to switch the SSR's. It works well now :)
mini USB hub is in there now also, and everything seems to test fine, so final screw together (I hope!) and next to finalize the scripts.
also want to look into a way to preview the camera image, so you can set up the camera easily.

ckt diagram will have to wait till tmrw.
 
ok took a while to put it together like this, hopefully its clear ;

ControllerWiring1.jpg
 
heres a little talk through that diagram ;

going from the top
mains power comes in to the box and is split in two ways, one side powers the SSR's and the other is fed to an internal 2-way mains extension block. With the SSR side negative is fed directly to the sockets and the live is switched through each SSR.
On the extension side, there is a 5V 3.8A power supply plugged and hardwired in, it delivers the 5V to power the Raspberry Pi (power is fed BACK up the GPIO port to the R-Pi - DONT attach power directly to the r-pi in this case) , it also feeds 5V to the TC4427 MOSFET drivers and the IRF830 MOSFET, which powers the flash LED. Also the 5V supplies the USB hub built inside the control box.

on the low voltage side, there is an indicator LED driven directly from GPIO25. Figure the correct resistor for your LED, the GPIO voltage is 3.3V
GPIO25 is ALSO connected to one of the TC4427's which allows it to also drive the IRF830's gate with enough voltage (5V) and current to fully switch it on properly. The IRF830 controls a larger current to the flash LED.
these two share a GPIO basically because I ran out of spare cores in the cable I used, will logically work fine for me, but you could use separate GPIO if you need.

to drive the two SSR's the drain current from R-Pi's GPIO pins is not enough. The second TC4427 is used to take these signals and boost to 5V with higher current sourcing capability.

SW1 and SW2 are latching push switches, they can connect directly to the GPIO but care to attach to switch 3.3V back to the R-Pi, not 5V, it wont tolerate it.

USB is connected to the Pi and fed back into the control box where there is a hub and the webcams can be connected here along with any storage devices etc. I saw it easier to branch from the control box since the Pi and its Cam would be moved during the capture. its tidiest this way , between the control box there will be only two cables (bundled together) , the GPIO link and the USB.
 
back to the setup of the raspberry pi.

before getting back to the main job though, its useful to setup the Pi for remote access. We will use two ways, SSH and VNC. SSH is a secure terminal, we can connect from another computer on the network and send the commands like in LXTerminal.
VNC is a remote desktop server, we'll install tightvncserver on the Pi, enable that to startup automatically after boot and then we can log in using a client like tightvnc client for pc or mac or android etc. This way we can either get to the terminal or the whole desktop interface if we prefer, without having to plug in a monitor, mouse, keyboard etc. Handy when its screwed up on the wall out the way.

To get those working though we will need to fix a static IP address on the Pi. Right now its probably getting its IP dynamically from your router. But if it changes we wont know which IP address to connect our SSH client or VNC client, we wont be able to find the Pi so easily on the network.

To fix a static IP address follow this tutorial ;
http://www.raspberryshake.com/raspberry-pistatic-ip-address/

Next you an test the SSH connection. Putty is a popular client , download it here : http://www.chiark.greenend.org.uk/~sgtatham/putty/
Start it and enter the static IP you set for the Pi and connect. You should log in with the Pi's username and password (default is Pi/Raspberry)
If all is well you logged in and can access the terminal, send commands, see your scripts, edit them with NANO etc.

To enable the remote desktop is a little bit more work. Here's a couple useful links to get you there;
http://gettingstartedwithraspberrypi.tumblr.com/post/24142374137/setting-up-a-vnc-server
http://elinux.org/RPi_VNC_Server

Did have to fiddle with it a bit before the update-rc.d vncboot defaults command ran without error. The file I ended up with in /etc/init.d/vncboot is as such ;

### BEGIN INIT INFO
# Provides: vncserver
# Required-Start: networking
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts VNC
# Description:
### END INIT INFO

# First configure the user you want to run this under - this will generally be pi, unless you've created your own users
export USER='pi'

eval cd ~$USER
# Check the state of the command - this'll either be start or stop
case "$1" in
start)
# if it's start, then start vncserver using the details below
su $USER -c '/usr/bin/vncserver :1 -geometry 1280x800 -depth 16 -pixelformat rgb565'
echo "Starting vncserver for $USER "
;;
stop)
# if it's stop, then just kill the process
pkill Xtightvnc
echo "vncserver stopped"
;;
*)
echo "Usage: /etc/init.d/vncserver {start|stop}"
exit 1
;;
esac
exit 0


Then it runs the update-rc.d command OK and after reboot I could connect to the Pi using TightVNC client. Download and install on your PC or laptop from here. Choose custom setup and just install the client rather than the server as well ;
http://www.tightvnc.com/download.php

Ok great. If all is well you can reboot the Pi, disconnect the mouse/keyboard/display and just leave the network connected. After some bootup time, you can connect to it over SSH or VNC to do any administration.
 
Next thing I addressed today was storage. The shots coming off the Pi's camera are high res (2592x1944) and consume something like 2.5MB each. The shots from the webcams are around 300Kb (1280x720)
I am going to end up taking up thousands of shots with the timelapse if I have it my way...

Im planning to record several "tracks" in parallel, so actually there will be several timelapse clips being gathered, later I can see which works best;

day under white light , night under low power LED flash (lpf)
day under grow light and night under lpf
days only under white light
days only under grow light

all for CAM0 (the Pi) , CAM1 and CAM2 (webcams)

Im imagining that CAM0 footage will form the main part of the timelapse vid when its done, it should be single unbroken sequence start to finish. CAM1 and CAM2 will be repositioned as necc and capture some close up angles. Parts of those could be overlayed later on the footage from CAM0 , so you see the big picture and synchronised, some close ups.

So, I decided to put a spare USB backup drive to use. Cleared up and reformatted to exFAT in windows, 300Gb of storage.
Then installed SAMBA (allows windows filesharing) and configured it to work.

This was covered fairly well in the tutorial here, so not much point repeating it ;
http://www.dingleberrypi.com/2013/05/turn-a-raspberry-pi-into-a-nas-network-attached-storage-server/
http://simonthepiman.com/how_to_setup_windows_file_server.php
http://www.cyberciti.biz/faq/adding-a-user-to-a-samba-smb-share/

went with the first guide with user account control for better security btw. other links are useful ref.

Having done that, things are looking good. From a local PC on the LAN , or on my Android tablet over WiFi, I can access the hard drive as a networked-attached-storage (NAS) device. This means later when the thing is busy I can look at the content of that hard drive over the network, pull off images, alter a config file, or read off the daily timelapse vid and see the progress over the last day :)

Most of the basics of what I need to make this thing good, are nearly there. its collecting images, can now store it somewhere useful, I have remote access by the NAS function, SSH terminal and VNC remote desktop. Plenty of good options there.
Now there are two more details I want to look at, if the Pi can do this on-board would be fantastic;

1) overlaying some text on the captured images (eg Day 1, Day 2 ....) while its capturing them
2)encoding a bunch of images into a timelapse vid. right now I don't know if the pi is going to be up to that, and how long it will take to encode a video so I need to run a few tests.
 
Made a bit more progress today, got this bit working ;

1) overlaying some text on the captured images (eg Day 1, Day 2 ....) while its capturing them

To do it I needed "imagemagick" package and to figure some commands in there. to download it and install use

sudo apt-get install imagemagick

Also I created two blank icons, which I want to stick the day number and time on, and overlay them on the images. I made a small and larger icon called bs.png and bl.png to be used on the webcam and pi-cam images.
bl.png
bs.png

Now I have a script that works out what day of the grow it is on, and put this info onto the background icon, and creates new icons with that data on it ;

#!/bin/bash
source ~/bin/pilapse.cfg
today=$(date +%j)
ctime=$(date +%T)
day=$((today-startDay+1))
echo "Updating timestamp Icons..."
convert -pointsize 32 -draw "text 15,39 'Day: $day $ctime'" -fill white -stroke grey bs.png bst.png
convert -pointsize 42 -draw "text 15,51 'Day: $day $ctime'" -fill white -stroke grey bl.png blt.png
echo "Done"

The start day needs to be entered in the pilapse.cfg file
You can figure the current day of the year by entering this command in the terminal : "date +%j"

The result of running the script is couple of new images that look like this ;
blt.png
bst.png

Finally the new icons can be stuck on the images with the convert command ;

#timestamp the new images
convert -draw "image SrcOver 0,0,388,75 blt.png" cam0.jpg cam0t.jpg
convert -draw "image SrcOver 0,0,307,58 bst.png" cam1.jpg cam1t.jpg
convert -draw "image SrcOver 0,0,307,58 bst.png" cam2.jpg cam2t.jpg

The resulting output looks like this when all is done;
cam0t.jpg

Awesome that's another thing ticked off. This will run with each capture, generating new icons and touch each image after capture to timestamp it in this way.
 
Last edited:
Back
Top