Page 2 of 12

Re: DIY Timelapse project

PostPosted: Wed Oct 09, 2013 9:48 pm
by godzilla
hi folks, managed to find some time to make up a wiring diagram showing the contents of the control box and the connections to the Pi ;

ControllerWiring2.jpg

Re: DIY Timelapse project

PostPosted: Wed Oct 09, 2013 10:19 pm
by godzilla
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.

Re: DIY Timelapse project

PostPosted: Fri Oct 11, 2013 11:04 pm
by godzilla
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 ... p-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.tu ... 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.

Re: DIY Timelapse project

PostPosted: Fri Oct 11, 2013 11:39 pm
by ledbud
looking good bro, bit high tec for me.
keep up good work,
:cool: :cool: :cool: :cool: :cool:

Re: DIY Timelapse project

PostPosted: Sat Oct 12, 2013 7:45 pm
by LEDDWCRigger
This is quite impressive. As an electronics person, I absolutely approve of this entire thing. Nuts.

Re: DIY Timelapse project

PostPosted: Sat Oct 12, 2013 10:14 pm
by godzilla
cheers ledbud. yeah I guesse it is a bit techy, but hopefully some will come along and it might be real useful to them. raspberry pi at least was a board designed to help get kids into programming but has found a real home with the hacker/maker/diy/amateur electronics. there is lots of info out there on how to do this and that and the other, and google usually yields an answer you can follow step-by-step.
still, one for the techies and tinkerers for sure.

tell you what tho, id love to see your kind of plants under the timelapse dude - you got something seriously awesome going on!! Id swap some of my tech skills for your grow skills anyday :grin:
once this camera is done im going to set it up on a grow, so be good for your input then!

Anyway back to the project for now - I addressed storage today. 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.
ExFAT is a windows filesystem, and by default the Pi wont be able to read it. So the first thing to do was sort that;

sudo apt-get update (update the APT installer to start with)
sudo apt-get install exfat-fuse (install exfat filesystem support for Linux)

Now when hard drive is plugged in, it should auto mount. Mines appeared at /media/HITACHI.

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. Im hoping the addition of a hard drive rather than going mental on the SD card, will aid that process. lets see....

Re: DIY Timelapse project

PostPosted: Sat Oct 12, 2013 10:53 pm
by godzilla
LEDDWCRigger wrote:This is quite impressive. As an electronics person, I absolutely approve of this entire thing. Nuts.


lol it is quite nuts, and incredibly fun. cant wait to be gathering some awesome timelapse footage, this thing could do something eye-popping im sure. I will have to try and make it a good grow to justify it for sure now!

Re: DIY Timelapse project

PostPosted: Sat Oct 12, 2013 11:30 pm
by teetee
Godzilla,

If you can put that pilapse together like that, you have No WORRIES regarding the grow.
Good luck, I'm sure you will get all the help you need from the Guys here.

FYI I'm sure it's common knowledge, but I didn't know... If you're doing DWC, Koi suppliers do fabulous airstones and way way way better air pumps than hydro shops and aquarium centres. I ditched my Hailea 4 output 10L/min pump for a couple of 'super silent' 60L/min pumps and got some chunky fat airstones (Angel Aqua). coastal-koi.com recommended by Autoberry.
:grin:::::

Re: DIY Timelapse project

PostPosted: Sun Oct 13, 2013 8:53 pm
by godzilla
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.
bs.png
bs.png (29.35 KiB) Viewed 65826 times

bl.png
bl.png (46.44 KiB) Viewed 65826 times


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

bst.png
bst.png (35.88 KiB) Viewed 65826 times

blt.png
blt.png (54.7 KiB) Viewed 65826 times


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.

Re: DIY Timelapse project

PostPosted: Tue Oct 15, 2013 1:00 am
by godzilla
short update today, been making some headway.
pretty much sorted out how this one is happening now ;
2)encoding a bunch of images into a timelapse vid

This will take a while on the Pi, but its going to be on full time so it can turn the shots into timelapse vids as it goes, in the background. ie at the end of each day it can grab the daily images and pull them together into a daily avi file.
so it will be a case of checking the NAS drive that the Pi has put up, and waiting for the next update to magically appear, then we can see the last days progress.
Made a few tests, encoding 100 frames of highest res from the Pi-Cam to 1080p HD avi file took about 7 mins to do, and looks fantastic - the pi cam really is much better than these average webcams.

to encode the file its necc to download and install mencoder ;
sudo apt-get install mencoder

you also need a bunch of stills, all in a folder. run the following cmd to create a text file with a list of them ;
$ls *.jpg > stills.txt

Now mencoder can join them up for you into an .avi file ;
$mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:aspect=16/9:vbitrate=8000000 -vf scale=1920:1080 -o test.avi -mf type=jpeg:fps=24 mf://@stills.txt

With that lot proven time to scrap all these functions together into something which starts to work how we need. I've consolidated to having 2 scripts at the moment, one fires very regularly and monitors stuff, sets the lighting in the correct state, the second will handle the capture.

Just finished getting the monitoring script working well tonite, and a locking system so it wont clash when the capture script is running. getting there!