Page 1 of 12

DIY Timelapse project

PostPosted: Wed Oct 02, 2013 9:03 am
by godzilla
Hi Folks,
Im on a quick turnaround putting together a little timelapse kit for my next grow, so I thought I would blog this as yall might find it useful.
Im doing it in a way which others could reproduce quite easily I hope, and get to a decent good quality and low cost.

I did a mini time-lapse for my last grow, but only a small vid early on before the grow lighting was turned on and saturated the poor little IP camera that was tasked with it.
Check it out here ;



http://www.youtube.com/watch?v=ElwBn52pXSQ

Doing that I had lots of other ideas how I would like it done properly, showing much more of the growth, start to finish if possible! So here I am, and for this grow im going to give it a crack.
Im going to use an airpot and have a Think Different in there. the camera will have to pan out as it gets older.

At the moment im awaiting a couple of gizmo's to arrive so I can hobble the solution together from relatively standard components. Im going to be using the now famous Raspberry Pi board to run things, and its optional camera module to collect some snapshots at regular intervals and store them away. I might also attach one or more Hd webcams and thus collect several angles at once.

The 5MP camera module of the Raspberry Pi looks quite decent spec for what I need (cant block up my DSLR for months!) , will snapshot a resolution of 2592 x 1944 , very nice compared to the 800x600 I was getting previously on a Tenvis PTZ IP camera. Since the cam will be close at start and physically be stepped back to keep the growing plant in shot, this should give incredible clarity and a HD 1080p video at the end.

So the R-Pi board is en route, also the camera module. As well as this a couple of sold state relays, the R-Pi will drive these and control the grow lighting and white lighting , switching back to white for each time-lapse shot.

That's the plan anyway, I'll post some pics when stuff arrives and as I go along with this project.

Re: DIY Timelapse project

PostPosted: Wed Oct 02, 2013 3:13 pm
by ledbud
:cool: :cool: :cool: :cool: :cool: :cool:

Re: DIY Timelapse project

PostPosted: Thu Oct 03, 2013 12:07 pm
by godzilla
ok the bits are here, so can get started putting the timelapse system together. Im calling it, Pi-Lapse :)

Heres the parts I have now ;

Raspberry Pi Model B (512MB) + Pi Camera Module £54.90
8GB SD Card with Raspian Wheezy OS Preloaded £6.80
Raspberry Pi Clear Enclosure £2.80
2 x SSR Relay Heatsinks £11
2 x FOTEK SSR-25 DA , 25A Solid State Relay £9.80

TOT £85.30

I should mention a few other bits are required but I have those to hand so no need to order. Power supply, a 2A micro USB power supply, Ethernet cables, HDMI cables, a spare USB hub and USB keyboard & mouse, and a HDMI monitor. Most of that stuff will be needed only for the setup and testing, later we will leave the R-Pi to run by itself without most of this stuff.

I think I could make use of a spare USB HD webcam maybe even two, and have this thing taking several timelapse vids from >1 angle. I'll focus first cam on the whole plant and another up close to the top bud.
OK so not bad on spend so far. For what it'll do I think its good anyway, not so long ago this would have required a spend of thousands im sure.

1.JPG


2.JPG


3.JPG

Re: DIY Timelapse project

PostPosted: Thu Oct 03, 2013 3:05 pm
by teetee
OMG Godzilla, you make it look so easy.
You said that not so long ago this would all have cost thousands, well also the kit required would have taken up half your growroom. You crammed all that into something the size of a fag packet!!!
That Raspberry Pi is amazing, I googled it just now, and now your thread makes total sense. Its just a tiny basic computer, but the way you have decided to adapt it is pure genius. I am looking forward to seeing this evolve.... I've said it before on other threads, man you should market some of this stuff!!
:cool: :grin:::::

Re: DIY Timelapse project

PostPosted: Thu Oct 03, 2013 5:49 pm
by ledbud
this is crazy man.
:cool: :cool: :grin:::: :grin::::: :grin:::: :grin:::::

Re: DIY Timelapse project

PostPosted: Thu Oct 03, 2013 8:09 pm
by godzilla
Ok things are getting up and running! the Raspberry Pi is a great little thing really.

I connected the board up, HDMI to my TV for the moment, LAN, USB hub with mouse and keyboard. I also attached the Pi's camera module on, inserted the SD card which is pre-loaded with the operating system "raspian wheezy".
Time to power up :)

The R-Pi boots up looking like a typical Linux startup, then you're hit with a menu about the install.
4.JPG

5.JPG


We need to make some setup here. Go to the internationalisation settings and correct the locale and timezone, keyboard layout if needed. I went with en-GB and London timezone, standard 105key layout.
Back in the main menu, use the enable R-Pi camera support option
Then expand FS to fill the card (option 1)
Also, enable boot to desktop.

Go to advanced options, change the hostname to "pilapse" and enable the SSH interface in case we need it later.

Fine so far then in the menu go to finish and select to reboot the Pi.

After the restart it will load the GUI and things look a bit prettier :
6.JPG


Great, time to test the camera module we've got plugged in. The software needed for it is already on the raspberry pi, so all we need is to see it work. Open the LXTerminal , we have to type some commands.
Also open the File Manager (icon near bottom left) and leave that around, it open in default at your home folder, we'll try to take some snapshots in a second, we'll see them appear here and be able to open and check.

In the LXterminal, issue this command ;

>raspistill -o test.jpg -w 2592 -h 1944

It does its thing and an image appears in the folder we've got open. The camera module is 5 mega pixel, so it has a pretty decent 2592 x 1944 resolution. So far so good.

8.JPG


Next up is to see that the Web cams I want to use in addition can do the same. I have two sat here, a SWEEX WC061 and a Microsoft LifeCam HD-5001. These are now plugged in.
!
7.JPG


In the LXTerminal issue this cmd and see if the devices are picked up OK ;

>ls -l /dev/video*

I can see
/dev/video0
/dev/video1

9b.JPG


these are the two webcams. time to install a software which can take the snapshots for us. we will use the fswebcam package, it is installed from the internet so make sure you are connected.
install the software ;

>sudo apt-get install fswebcam

now we can test taking some snaps :

>fswebcam -d /dev/video0 -r 640x480 testWC1.jpg
>fswebcam -d /dev/video1 -r 640x480 testWC2.jpg

10.JPG


We have a couple of snaps now from the webcams in the same folder, nice.

Now double checking the specs on my assortment of camera's

Raspberry Pi Camera Module : 5 megapixel : still res 2592 x 1944 : fixed focus
Sweex WC061 : 2 mega pixel : still res 1600 x 1200 : manual focus ring
Microsoft HD-5001 : still res 1280 x 960 : auto focus

All three have different qualities so might be good or bad depending on the type of sequence you want to take.
Time to test the webcams at their full spec ;

>fswebcam -d /dev/video0 -r 1600x1200 testWC1.jpg
>fswebcam -d /dev/video1 -r 1280x960 testWC2.jpg

Now we are able to collect the snapshots, the raspberry pi made that pretty simple. other webcams should work same way. Next is to get the SSR relays working from the Pi then these things automated :)

Re: DIY Timelapse project

PostPosted: Fri Oct 04, 2013 1:31 am
by godzilla
Ok peeps next update, I have now connected the extra hardware that we need - the relays to control the lighting, an LED so we know when its "live" , and a switch to stop it being live (so we dont get caught in shot).

To do it I connected to the Raspberry Pi's P1 interface, where there is some I/O pins we can use. I have connected like this ;

P1 - pin 4 , +5V VCC, in case we need it.
- pin 1 , +3.3V , we'll need this to run the switch off at least, since R-Pi does not tolerate 5V input.
- pin 18 - GPIO24 - this connects to a latching switch, push turns on, push again turns off etc. The other end of the switch connects to +3.3V. So the switch is between pin 1 and pin 18
- pin 22 - GPIO25 - this connects to anode (long leg) of an LED to show the "live" status. I used a blue LED and put a 47 ohm resistor in series.
-pin 24 - GPIO8 - this connects to the first SSR's + input on the low side.
-pin 26 - GPIO7 - this connects to the second SSR's + input on the low side.

-pin 20 - GPIO23 - connected it while I was there, maybe could be used to drive some power white or IR led's , perhaps during the darkness hours the timelapse can continue without disturbing the plants too much?

Heres how it looks now at the Raspberry Pi end ;

11.JPG


the cable used was some 8 core alarm cable. This is the other end wired into the relays, LED and switch ;

14.JPG


You can see the LED is ON and so are the Relays, since I took the shot after testing. There is nothing plugged in their high side yet, but the LED's on the SSR's shows the status.

Next to interact with that stuff. I will rely on the Kernel driver for the GPIO, it means we can do it with the similar commands in LXTerminal like before.


To setup those pins we used for use, we need to configure them and set their direction as so


>sudo su (get root permission otherwise next commands will fail)

>echo "7" > /sys/class/gpio/export

>echo "8" > /sys/class/gpio/export

>echo "25" > /sys/class/gpio/export

>echo "24" > /sys/class/gpio/export

>echo "out" > /sys/class/gpio/gpio7/direction

>echo "out" > /sys/class/gpio/gpio8/direction

>echo "out" > /sys/class/gpio/gpio25/direction

>echo "in" > /sys/class/gpio/gpio24/direction


Now we are ready to use those IO! First lets try read the switch ;

>cat /sys/class/gpio/gpio24/value

toggle the switch and re-run and confirm the return value changes.

Finally lets switch on the SSR's and the indication LED to verify all is working OK ;


echo "1" > /sys/class/gpio/gpio7/value

echo "1" > /sys/class/gpio/gpio8/value

echo "1" > /sys/class/gpio/gpio25/value



Heres what it should look like ;
15.JPG


After the next reboot of the Pi, all the export and directions will be default again. We want this configuration to be applied on startup. To do it those commands need to be entered into a bash script, and set the script to auto run.
In /home/pi/bin I create a new file called startup_script.sh which contains this ;

#!/bin/bash
#script to manage startup actions

source /home/pi/bin/pilapse.cfg

echo "Performing PiLapse startup actions..."

echo "7" > /sys/class/gpio/export
echo "8" > /sys/class/gpio/export
echo "25" > /sys/class/gpio/export
echo "24" > /sys/class/gpio/export
echo "23" > /sys/class/gpio/export

echo "out" > /sys/class/gpio/gpio7/direction
echo "out" > /sys/class/gpio/gpio8/direction
echo "out" > /sys/class/gpio/gpio25/direction
echo "in" > /sys/class/gpio/gpio24/direction
echo "in" > /sys/class/gpio/gpio23/direction

chmod 777 -R /sys/class/gpio/gpio7
chmod 777 -R /sys/class/gpio/gpio8
chmod 777 -R /sys/class/gpio/gpio25
chmod 777 -R /sys/class/gpio/gpio24
chmod 777 -R /sys/class/gpio/gpio23

#set LED indicator and Flash LED to OFF state
echo "0" > /sys/class/gpio/gpio25/value

stateDN=$(./resolveDN.sh)

if [ "$stateDN" -eq "1" ]
then
echo "DAY"
else
echo "NIGHT"
fi

echo "Done"


Then you need to edit the /etc/rc.local file, and set this script to start automatically. This is what the updated rc.local file looks like ;
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
/home/pi/bin/startup_script.sh
exit 0


Now all is well, straight after reboot you can fire any command to change the IO state, they are already set up correctly.

Gonna have to call it a night there but that's not a bad place to leave it. Most of the immediate HW challenge is done I think, next some software config will get us taking the timelapses , and other cool stuff. Looking pretty good so far.

Glad I finally found a reason to get acquainted with the raspberry pi, im growing to like this little gem very quickly :)

Re: DIY Timelapse project

PostPosted: Mon Oct 07, 2013 2:08 am
by godzilla
looking good guys. have got some of the software scripting sorted out over the weekend so that the Pi now controls the lighting ON/OFF period for a start, and building up more scripts that manage the other functions.
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.

Re: DIY Timelapse project

PostPosted: Mon Oct 07, 2013 4:51 pm
by ledbud
good work bro.
will be nice grow from start to finish on time-lapse.
:cool: :cool: :cool: :cool: :cool:

Re: DIY Timelapse project

PostPosted: Mon Oct 07, 2013 11:59 pm
by godzilla
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.JPG


18.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 :grin:

21.JPG