Thursday 27 February 2014

Night time wildlife cam.

Ive been meaning to make this since the pi noir camera came out but only got round to it this week.

Firstly I needed an old pi case I could drill holes in, a small hole for the pi camera and a bigger hole for the ir pir to poke through. 

The pir is connected to positive, negative and out to gpio7 (pin26)

I then got a huge camo bag from one of my old geocaches and cut it up, one into a smaller bag to house batteries and give infra red 48 led light some protection and some material to glue around the case. I used some poly filler to waterproof the case, used a micro sd adapter to protect sd card slot.


That was the easy bit, it was the coding I struggled with, well easy to get gpio 7 to trigger and easy to save the file but I couldn't get it to save under a different name each time just the same name and then delete the file before by overwriting.  


After speaking to zac an excellent teenager programmer we started to run into other difficulties with the code before I found a snippet that I could bend and mould to this project and bingo, the files saved as date-time.h264

Here's a screenshot of the code:


So yes simple in the end,I don't have any video to put up yet but a screenshot of it detecting my finger whilst facing the small monitor I had been using.


To convert the .h264 file format to mp4 I had to do the following:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install gpac

then to use it and convert the file:

MP4Box -add nameofh264file.h264 nameyouwanttocallyourconvertfile.mp4

Here is the results of the cam, about 5 seconds my dog comes into view as he wonders the house in the middle of the night.


 or linky for youtube



Coding for cam.py file:

#www.mypifi.net/blog
#code for mypifi pir wildlife cam
#please if used acknowledge me please
#by Paul Brown
import RPi.GPIO as GPIO
from time import sleep
import datetime
import os

GPIO.setmode(GPIO.BCM)
GPIO.setup(7, GPIO.IN)

while True:
  if (GPIO.input(7)==True):
    timestamp = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
    os.system ("raspivid -o /home/pi/v"+timestamp+".h264 -t 20000")
    sleep (5)


You will also need to set this file to run automatically on start up  for when you power it up in the wild.  Also a good powered usb battery, my 8000mah one lasted 24 hours and my 20000mah one dropped one bar in 24 hours, also remember to try and keep all this dry as water and electronics don't mix.

Enjoy.

Blog update, I have done more to this on my blog post: http://smstextblog.blogspot.co.uk/2014/03/wildlife-cam-part-2.html?m=1

No comments:

Post a Comment

Please feel free to comment would love to hear your ideas.