Sunday 16 November 2014

Part 2: How to make your own Raspberry Pi Trail Camera 'PiTrailCam': Basic design model

In part 1 of this series, I outlined how a Trail Camera is made, and what might be used to make a home-brew version.  

I've put together a basic functional trail camera, a very early prototype if you like. 
I'm testing with a standard Raspberry Pi camera, not the IR version.  I do have an IR version, but haven't got around to using it yet.  For now, I'm limited to daylight triggering since I've not yet incorporated my IR illuminators since the box (tupperware - no expense spared) was too small to incorporate all the required bits.

This shows the prototype build so far (lack of hot glue gun skills notwithstanding).  This will be hardwired into my home network, and uses power-over ethernet (PoE) hence the wire going to into it.

Simple front view showing PIR and RasPi camera with LDR detailed in insert

PiTrailCam ver1 - Inside
This is a cut-down version of the version I had planned out on my desk, which included a relay that triggered a separately powered IR LED array, which unfortunately does not fit in the box.  Version 2 will probably be in a wooden box that is a bit more roomy and durable, and can accommodate a relay switch for the IR LED arrays.

Kit used in RasPi TrailCam version 1
Raspberry Pi model B
Raspberry Pi camera + supplied ribbon cable
Power over ethernet & connectors
I'm planning on directly splicing a hacked microUSB cable to the TP-Link power-out but bought the wrong cables...so have to make do with more bulky cables following this guide
  Micro USB (male) to USB cable (female)
  USB (male) to barrel power connector
Small prototyping breadboard
Female to male breadboard wires (various)
PIR motion sensor: Components, wiring and code described here
Mechanism to measure light level: code + components from here
Not strictly necessary in this build, but will be used to measure ilght level to activate IR led array in version 2:
  1x 2.2 kOhm resistor
  1x 1uF capacitor
  1x Light Dependent resistor

Prototype board layout as follows.  Note, I significantly slimmed this down to a small prototype board, but tend to use a larger breadboard with GPIO breakout at the 'drawing board ' stage.  this also shows a possible layout that will incorporate a relay to operate a pair of IR LED arrays:


For now, I'm just using the PIR (motion sensor) and LDR (measure light level) aspects .

First imageSome things I'm very happy with, others not I'm less so..

The observant among you will spot something wrong with this image...
Whats really cool is that I've got the time and date stamp included at the top (erm, bottom?) of this image.

Timstamp - just to prove it....
How the image capture works
I've coded the scripting side of things in Python.  I'm relatively new to this, so its a fun way of learning a new programming language, and to be fair most of this is mercilessly cribbed from other websites/blogs.

The Raspberry Pi camera is a described here, and can be used to capture video or stills, or both at the same time (may come back to this).  You'll mostly see the two programs Raspistill and Raspivid referred to which are used to capture still images and video respectively.  There are also several third party libraries built for it.  For this application I've used the PiCamera library.
My limited Python skills will likely show here, but as I understand it this offers a way for python to directly access the camera hardware, versus using calls to external software (such as to Raspistill and Raspivid).

In your python code, you have the option of either calling Raspistill as follows:
os.system ("raspistill -o /mnt/SHARE/captures/TrailCam.jpg")

or using PiCamera module, where you can see I've added a camera.hflip and camera.vflip command to fix the upside down and back to front image above.
def recordImage2():
 
 timestamp = dt.datetime.now().strftime('%Y%m%d%H%M%S')
 print "Motion Detected: " , dt.datetime.now()  
 
 with picamera.PiCamera() as camera:
  camera.led = False
  camera.resolution = (2592, 1944)
  camera.framerate = (1, 1)
  camera.vflip = True
  camera.hflip = True
  camera.quality = 100
  camera.exposure_mode = 'auto'
  camera.awb_mode = 'auto'
  camera.image_effect = 'none'
  camera.color_effects = None
  camera.start_preview()
  time.sleep(2)
  camera.annotate_bg = True
  camera.annotate_text = dt.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
  camera.capture_sequence(['/mnt/savelocation/TrailCam_'+timestamp+'_image%02d.jpg' % i for i in range(3)])

By calling recordImage2() on a PIR activation event causes 3 images (image1, image2, image3) to be saved to a network location that I've mounted to a folder in /mnt, and am currently saving files there.  Not sure how that will pan out if I switch to video though.

How to get text overlay working with picamera python library
I'm quite pleased that I have been able to get the text overlay working.  The next thing to do is see if I can get a dark background behind the time & datestamp, as date and time in white over a white sky isn't much use to anyone.

At first I could not image overlay to work, and could not see why the instructions here did not work.  Turns out I was running an version 1.5 of PiCamera, and need at least the current version (1.8 at this time).  You can tell which version you're running by following these instructions here.  You can update that by doing sudo update then sudo upgrade, you may need to update the Raspberry Pi's firmware : sudo rpi-update.

How to mount network drive to Raspberry Pi
For info, to setup network mounting you need to edit /etc/fstab as follows:

sudo nano /etc/fstab

Then add the following line:
//XXX.XXX.XX.XX/SHARE/TrailCamPi /mnt/SHARE cifs username=RasPiUser,password=RasPiPwd,uid=1000,_netdev 0 0

Ctrl & O, then Ctrl & X exits the nano text editor.
At a reboot, (or sudo mount -all) the network folder will be mounted at /mnt/SHARE

/XXX.XXX.XX.XX/SHARE/TrailCamPi = IP address of target PC with save file destination folder.  Although its not strictly necessary, and you could setup a network share with no user password protection, I've set mine up with a dedicated user RasPi user + password on the destination machine, and pass those credentials with the mount command.

I'll sign off with another badger video from my commercial Trail cam, captured a couple of days ago:




Next step is to swop out the standard RasPi camera to the PiNoir, and add some LED arrays.

Monday 27 October 2014

Part 1: How to make your own Raspberry Pi Trail Camera 'PiTrailCam': Design Brief

Edit 16/11/14: Part 2 of this series is here

In a previous post, I've described my Trail Camera, which has been doing a sterling job of photographing the wildlife at the bottom of my garden.  We've been introduced to deer, badgers, foxes, mice and occasionally my neighbours dogs who periodically escape and have a romp through the woods.


I've taken inspiration from the AfraidOfSunlight.co.uk blog.  The author used a Raspberry Pi + camera + PIR combo to create a home-brew equivalent of a trail cam, with some great footage of birds.  Check out the Kingfisher and Sparrowhawk clips.

Why do this?
First of all, a commercial Trail Cameras are not cheap.  While mine is great, it has a lot of plus points but has a few limitations:

Commercial Trail cameras


Commercial Trail cameras: PLUS points
  • Simple interface - no tinkering required
  • Very long battery life (especially if stills setting used)
  • Durable - has lived outside for most of this year without problems.
  • Day vs. Night image capture issues taken care of with automatic IR cut-out filter (more later on that).

Commercial Trail Cams: Limitations 
  • Simple interface - no tinkering required (did you see what I did there !?)
  • Limited to only stills or video - not both at the same trigger point.
  • Its a closed device - i.e. cannot communicate with/trigger actions on other devices
  • EXPENSIVE

My plan is to build one around a Raspberry Pi, which is an open-source linux-based mini computer, available for approximately £30.  Along the way I'll go into detail for kit, configuration and any coding used, referred to from this point as "PiTrailCam"


What makes a Trail Camera ?

I've attempted to detail the various components that go into making a Trail Camera, and my thoughts about options for custom designs.

The glue that hangs it all together: Some sort of processing device.  I'm going to use a Raspberry Pi mini computer (RaspPi).  I've been tinkering with these for a while and there's loads of stuff out there that you can do.  My projects have been limited mainly to video streaming nest boxes and timelapse movie creation, however this project will expand to include relays, voltage conversion and MQTT messaging (more later).

1) Camera - Several options here.  Could use any/some of:


a) Raspberry Pi camera module
Small, compact wide community of users to troubleshoot.  Limited to one RaspPi Camera board per Raspberry Pi, however could use webcam in addition.  The PiNoir version has IR filter removed which opens up the option to do Night imaging + IR illumination
b) Webcam 
I'm currently using Microsoft Lifecam Cinema webcams in two bird boxes which stream video to my home network from which I can extract images/video, currently using iCode's iCatcher software (commercial).  Video and/or still images can be captured dirently from webcams and saved to the Pi's SD card.
c) Compact camera (with facility to control over USB).
The argument for this is the better optics and zoom of a compact camera.  The ShallowSky.com blog  combined the Raspberry Pi camera with a Cannon Powershot A520 to create a  'CritterCam'.  This used the  Raspberry Pi camera as a trigger (via image movement detection) with the better optics and zoom of a compact camera.  The downside is that 'as is' they wont work for night shots since the cameras infra-red (IR) filter will be intact.  While its is possible to hack your own, I'm not planning this.  This particular model can be picked up relatively cheaply on ebay.

Power source (battery vs. wired)
'In the wild' TrailCams are usually battery powered.  My commercial one takes 8 x AA batteries and also has a 12V DC in as an option too.  I'm going to use wired as this is only planned to be used near a mains power source.  In past projects I've used a power-over ethernet kit (PoE) from TP-link which means only need one cable is required to the device.

Illumination

For night time imaging, we'll need some sort of artificial illumination.  Options are visible light or infra-red light (IR).  IR has the advantage of being less likely to disturb the wildlife.  My commercial Trail Camera  uses a ring of IR LEDs set around the camera.   The downside my existing TrailCam is that the IR leds ring surrounds the camera, which means that at night all animals get the IR equivalent of red-eye.  My design will use IR illuminators away from the camera to avoid this.

In order to use IR illuminators at night, you need a camera that has had its IR filter removed (This filter is called an IR bypass filter).  There are several mods out there to the IR filter from various webcams, but I'm not going to attempt this.
Luckily, there is a version of the Raspberry Pi camera without an IR filter, called the Pi-Noir which I'll be using alongside some IR LEDs.

IR bypass filter
The downside of using the Pi-Noir is that I'll need to add back in an IR bypass filter for daytime imaging.  While this isn't strictly necessary, there will be an odd colour cast to the daytime images without one.

Commercial Trail Camera: Night minus IR filter with IR LEDs on, Day time with IR filter in place 

This is taken care of nicely in the commercial kits, they probably use a CCTV IR cutout filter module that integrates with CCD board cameras.  I'm not yet clear how I'll do this but essentially I'll need to move an IR filter infront of the camera, or camera in front of an IR filter (my commercial trail cam does the latter for IR-illuminated night shots).  I came across this IR bypass filter on ebay, designed for CCTV CMOS camera boards that I may try.

File Storage
Options: 1) On the Pi's SD card; 2) On local storage media (eg USB stick); 3) On local network.
My commercial TrailCam has an SD card slot.  I have 2x 32Gb SD, I swop one in whe the other comes out.  Although I've yet to fill one, its a bit cumbersome when I want to review footage as I have to physically swap cards, and copy images/video to my PC.  Since PiTrailCam will be connected to my home network (remember I'm using PoE), I'll copy / save captured images/footage directly to my home network.  I also want to get away from having to physically remove storage media since a home-brew affair may be less open-uppable!

Facility to live view captured footage/images
Commercial Trailcams often have an LCD screen which allows you to review captured footage.  I plan to make my PiTrailCam accessible remotely over my network so won't need to do this.

Mechanism to detect movement

Passive Infared sensor (PIR)
A Trail camera is essentially useless without some means to detect movement.
This can be achieved either 1) Using software to compare sequential images for changes, or 2) Using physical sensors such as a passive infrared motion sensor (PIR) - the same thing that switches on your outside lights on when you put the bins out at night.


Water-tight enclosure
Various takes on this out there including cardboard, wood and plastic: from Tupperware to a more rugged case such as the Pelican 1040 case, as used in these commercial 'build your own' TrailCam kits).  I'll probably go for a wooden one as I'm more comfortable working with wood (see my previous side-view nest box project, which remains water-tight to this day!)

Trigger one trail cam from another
One cool thing that I would like to do is cause one PiTrailCam to trigger another.  This might be to capture the same event from different angles, or to utilise different cameras from the same viewpoint; or maybe to capture the progression of a subject from A to B to C.  The bonus of the low cost of these devices is that several PiTrailCams can be built for the cost of a commercial one.

I plan to use MQTT to do this.  This is machine-to-machine (M2M)/"Internet of Things" connectivity protocol, it sounds a bit complex but conceptually its quite simple.  One machine publishes a message to specific 'listening' machines, the message might be triggered by a PIR activation event on PiTrailCam1.  The listening machine (PiTrailCam2) can be configured to carry out a particular task (e.g. take a picture) when it receives the message from the first machine.


Over the next few weeks I'll post my progress.  In my next post I'll expand on the trigger and image capture side of things, the prototype of which is merrily clicking away in my office when I move about, taking pictures of the back of my head....

Edit 16/11/14: Part 2 of this series is here

Tuesday 12 August 2014

How to grow your own butterflies

Butterfly kit

For Christmas we were given a "Grow your own butterfly kit".

<- Something like this

Included is a net (grandly called a "Pavillion").  You then send away for caterpillars, which arrive in a self-contained pot containing an agar-like food substrate which sees them through to the point that they form the chrysalis, which you then transfer to the pavillion to hatch.

Our kids have done this at school and we thought we would have a go at home.

The supplier guarantees that you should get some butterflies.  With each pot containing five caterpillars, from two pots, we got 5 to butterfly stage.  Some were lost at the pupating stage, and some didn’t make it at emerging from the chrysalis, having got tangled up in web.  We did have a couple of 'Special-needs' butterflies with deformed wings due to this problem.

The supplier used  Painted Lady caterpillars, which turn into butterflies like the one below, tastefully feeding from an Echinacea.


The kids gave all the caterpillars names.  'Ninja Guy',  'Weapons Guy', 'Hairy' and 'John' (I kid you not) made it to the butterfly stage. 

I thought it would be cool to film the key events of pupation and hatching - which proved trickier than I had thought.  I used a Microsoft LifeCam Cinema webcam & Raspberry Pi, with video stream captured using iCatcher Software on a networked PC.

Pupating
This has got to be the grossest thing I have seen for a while....


This  action took place over a 30 minute period, and is speeded up.  Basically the skin of the caterpillar splits at its head, and then sloughs off up its body.  It then wriggles about to push off  the shed skin after which it settled down and the crysalis hardens.  Unfortunatey this was one of our failed attempts since the crysalis formed a really odd shape and it didn't progress.

Butterfly emerging
Much less gross this time, I missed the first one to hatch, but caught two others. Of interest is the red fluid which is ejected which is apparently all the left-over bits of caterpillar that it didnt need to become a butterfly.  I'm sure there is a more technical description, but it was good enough for the kids!

Speeded up over two hours, shows hatching, and wing expansion and expelling of the 'caterpillar juice'.... cool eh?


Release
There are two schools of thought on whether or not to release into the wild.  Some advocate not doing this as these are essentially not wild.  My view is that at worst, we're contributing to the food chain... This is 'Ninja Guy' posing for the camera.



I'm told this is Hairy, but to be honest it could be any of them...


The butterfly net is packed away for next year... ant farm anyone?

Wednesday 4 June 2014

How to make timelapse trail cam videos

I've had my Trail Camera sited in a variety of places in my garden for a few months now, with varying degrees of success.  The camera is described in this post, and can be configured to capture either video or images.

The theoretical maximum resolutions of each mode are:
Video: 640 x 480
Image:  8 Mega Pixels - I'm not sure how this translates to an actual resolution

It has night and daytime modes, Night time illumination is achieved via the in-built infra-red (IR) LEDs that surround the camera.  Not surprisingly, captured image quality is much better in daylight.  The following images are the full 8MP.


It also has a weird intermediate mode, which seems to be in low light where the IR illuminators haven't come on, however its IR filter has come off which give some interesting images.  In the following set, the top image is low light in the evening.  IR illuminators havent come on, but the internal IR filter is off the camera leading to this 'ghostly' image.  The one below is a true night time image - illuminated by the camera's IR LEDs.


Interestingly, it looks like the image resolution is automatically dropped for night time images as the field of view seems narrower - these two images are taken approx 6 hrs apart without the camera having been moved.  For the best quality images I've found that a cloudless sky with a full moon gives the best images, producing a more evenly lit scene.  My favourite bit of footage so far is that of a badger mother + cub tucking into a slow worm.  I've uploaded the original clip here:


Pros & cons
Using a trail cam is a great way of observing wildlife behavior that you wouldn't normally see (I did cheat a bit and put down peanuts in the area in front of the camera an in the long grass to keep the badgers interested).  One limitation is that once its set to video or images, it stays that way until changed.  A cool option would be to have it take a high res image, then capture a video clip - unfortunately not an option.

Make a time-lapse of still images
I've found that on some nights I have a load of okay-ish images, but nothing that would win any prizes.  I took a leaf out a stop-frame animation project I did with one of my kids on her Raspberry Pi.  I used the same approach generating the video in a post I did on how to make time lapse videos of clouds.
The advantage of doing this is that you effectively increase the resolution of the video, since I'm using the higher resolution still images.  The result is kind of jerky but I think its an interesting effect.  The following clips are encoded at 4fps:

To achive this, I've used mencoder in Ubuntu - but this should work on a mac PC too.  There's an install guide for mencoder on the Rapsberry Pi here, but you're better off running in a full-fat linux system such as Ubuntu or on a Mac PC.

ls *.jpg > list.txt
mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:aspect=16/9:vbitrate=8000000 -vf scale=1920:1080 -o video.avi -mf type=jpeg:fps=4 mf://@list.txt

Selection of 'Time-lapse' videos from Trail cam still images: 
These are best viewed full-screen with HD option selected

1) Adult female badger 'in-milk'.  You can see that this badger's udders are clearly visible suggesting she has cub(s)


2) Soggy female badger and her cub.  I cant be sure this is the same female badger, but if so, this is one of her cubs with her.


3) ...and finally badger cub on its own:



Make use of poor quality inages
I had one night where many badgers stopped by for peanuts, but unfortunately I either had rain on the lens, or its was misty.  The resulting images were no use, but strung together into a time-lapse, gives an idea of what is going on.... Lots of badgers

Still used to create the following time-lapse


I'll sign off with a couple of new additions:




Wednesday 28 May 2014

Squirrel nest box update for May 2014

We've had quite a lot of activity in our squirrel box this month, and a fair few 'awwww' moments...

Snuggled up with squirrel chums

I had hoped earlier in the season that extended periods of mating seen in April would have lead to lots of baby squirrels, but we're not there yet.  This box is located approx 80ft up a conifer tree at the bottom of my garden, which backs onto woods. There's no passing people traffic, so they get very little disturbance.

Squirrel box behind conifer tree 

The box was originally designed with owls in mind, but the squirrels chase everything else away - I don't mind much as its a slice of nature you don't normally get to see.  In 2013 we had a family of Great Tits nest raise a brood... I had to add a squirrel-baffle (= plank of wood with small hole over the entrance) to keep them out.

Great tit nest in the same box (2013)

Shelter from the rain:  I can usually predict if the squirrels are in residence by checking the weather. They usually move in when it rains, and this weekend was no exception.  Watching them go from soggy rats to fluffy squirrel is entertaining! The interesting thing is that they move in en-masse.  We had four sharing over most of this Saturday during a downpour.  I don't know such communal living is normal behaviour, but they spend their time playing, grooming and sleeping in a jumble.


How to tell squirrel from squirrel?
One squirrel looks very much like another - so its difficult to say if the same ones keep coming back.  We do have one with a notch out of its ear, but the others don't have any distinguishing features

Squirrel with ear notch

Boys or Girls? The camera is top down, and does not give the sort of angle that can readily tell boy from girl: See Great British Bake off Squirrel for what I mean - maybe something to add to my to do list?

Other (non-squirrel) species
This isnt an exhaustive list, but I thought it would be fun to list all the other bugs/birds that have found their way in.  We get quite a lot of wasps - its not beyond the realm of possibility that it would make a good wasp nesting site - I don't fancy having to do any camera mintenance if that were to be the case.
Other creatures seen include flies, bumblebees, spiders, woodlice and other birds (eg Coal tit & some miscellaneous feet in one of the pics below.. so I'm not sure what it is).  I also snuck squirrel feet in the mix too!

Non-squirrel species (+squirrel for good measure)

Camera: Information on camera setup can be found in this post

The next thing we're waiting for is baby squirrels.  I'm not sure how 4 squirrels will manage a litter though?

Saturday 24 May 2014

Woodpecker rescue

Normally I wouldn't advise 'rescuing' young birds from the wild.  In a previous job I worked closely with animals and used to get people bringing me wildlife that they had helpfully 'rescued-from-certain-life'.  The most memorable was someone who 'rescued' a baby deer, found in a field, and thought it really needed bringing to the vets... Its parents were likely in the vicinity, and if left alone would have gone to them.  The best thing to do in that sort of situation is to leave them alone, see the sensible advice here.

Nature - Tooth-and-Claw
So back to this today.... Early this morning, there was a sudden racket outside the house, the sort of noise you might get if you repeatedly step on a piglet.  A quick glance outside identified a magpie pinning down a small bird.  Its likely lunch-time-snack making all the noise.

This is where my normal perspective of 'leave-nature-alone' diverged from what I might have done, had the stood-upon bird been a common species...  Close examination showed that squawking bird to be a Greater Spotted Woodpecker, so disregarding my normal principles, I rushed out and 'rescued' it.  I think what had happened was that a young, newly fledged woodpecker had been caught out in the pouring rain, been unable to fly and had been caught by the Magpie.

Magpies have every right to a meal, but my abstract logic considered the relatively common magpie vs the less common woodpecker, which clinched the deal - to the advantage of the woodpecker!.

Our rescued woodpecker (imaginatively now named 'Woodie' by the kids) was limp, soaked through and bloody. My assumption was that it was not long for this world, so I brought it in and put in in a quiet place in a quiet spot in the garage in a cardboard box over a heat-mat.

Having assumed that it was likely to die, I did feel a little sorry for the magpie, who would have to find some other fledgling to eat today.  I was also a bit concerned that if it survived for a few days I may have been in the following situation, and didn't relish the prospect of hand feeding it...

Not a desirable outcome!

Disappearing, reappearing woodpecker
Later in the day I popped back into the garage to check on it, to find that the (closed) cardboard box was empty.   My first thought was that my son had become the proud owner of a dead Woodie, to be found somewhere in the house later as a 'special surprise' for me... this turned out not to be the case, as I found it flapping about in rafters of the garage.  After opening the garage door it flew off as if nothing had happened.


'Woodie' the woodpecker in the rafters

Woodie will hopefully live to fight another day...

Tuesday 20 May 2014

Badgers, peanuts and ticks

So this is what happens after applying peanuts to the back garden, in the hope of getting some good badger footage (I did get a load of badger + badger cub footage, but haven't had time to upload it yet)


It looks like the deer like peanuts too, and the badger family are quite happy to share with it/them.

I'm in two minds about the deer - aside from eating all the buds off my roses when I forget to close the garden gate, they are infested with ticks. If I walked through that long grass in shorts I would have to spent the next 5 minutes flicking the little devils off, then hooking out the ones I missed later...


At some point I'm going to have to bite the bullet and fence the bottom of the garden off - hopefully the badgers will still be able to get in, but the deer wont....

Monday 12 May 2014

Badger cub goodness

Well, I recently lamented the fact that all we get to see of our badgers is their bottoms as the walk away from the trail cam, last night brought us this delight of Badger with its cub:

Badger with cub, May 2014

The kids and I found we were whispering when reviewing the footage 'in case we disturbed them'....


... so I take back my previous moan at only getting badger's bottoms.

Edit 15/04/14: As spotted by SteveDee it looks like our badger cub is playing with, then eating a slow worm.  The cub plays with it a lot like my dog would play with a feather - pokes it with his nose for a bit, then pounces on it, then eats it.

:)

Saturday 10 May 2014

Badger's Bums

In a recent blog post I described some of the wildlife (& cats) that frequent the bottom of my garden.
The most elusive of these is our badger(s).  My trail cam has been positioned in the same place for approx six weeks now, pointing downhill across a patch of scrubby grass.  In that time I've seen the badger several times, but its always been plodding away from the camera, downhill - Giving us the now familiar "Badger's Bum" view.  I've a theory that he does a routine 'route', always in the same direction.



In an attempt to get a head-on video clip, I had the bright idea of moving the camera to the bottom of the hill, facing upwards, so I jury-rigged it to a post.  The result is shown below:


Aarrrgh ! I feel a back-garden-conspiracy of sorts going on.  There is a brief sideways glance, but no good view of the classic white stripes (the badger, not the band).

I've invested in a second high capacity SD card, and swop one out when reviewing footage on the other, so the camera is always on now in the hope of catching the elusive full face view:

I cant take the credit for this pic, but one can always hope

Sunday 4 May 2014

Bird Box activity counter


UPDATE Sept 2019: I wrote an updated version of this here (v3)

Activity counter v1

I've been working on getting the activity counter working on my side-view bird box.

This works on the basis of 2 infra-red beams built into the entrance hole.  The front panel  of the box is constructed of several layers of plywood with channels cut for cable inclusion.


The IR beams interface with a PiFace add-on board on a Raspberry Pi.  The principle is that by breaking outer and/or inner beam its theoretically possible to distinguish between entrance, exit, head bob in/out.

My design is based on that described in chapter 17: "The Techno-BirdBox: A Wildlife Monitor" of Andrew Robinson and Mike Cook's book: Raspberry Pi Projects.

Parts
2x IR LEDs: SFH484-2
2x IR photodetectos QSE113
2x 1k ohm resistors
2x 330 ohm  resistors

RaspberryPi + PiFace in-situ
For full description on wiring guide and setup, please go buy the book!

Activity counter scripts
I did feel slightly aggrieved that the included python scripts for recording and processing the beam breaks has quite a few printing errors in the book,and does not work as-is.  I have made corrections such that I think it now all works fine.  You can find my versions of these scripts in a GitHub project page together with some sample activity log data, which I've used to create the graph below.

One cool thing about Andrew's scripts is that he describes a way of programatically generating  graphs of activity.  The following is generated from my version of these scripts:

Activity graph generated from sample activity data

The plus side of having had to tweak these scripts is that I have learned some python and I now have some idea of what a state machine is.  All I need now are some bird box visitors!


Tuesday 29 April 2014

Side-View bird box, early interest

Well, I am usually genuinely surprised when things actually work, so it was with great excitement that we spotted this fella poking his head into our new bird box to take a look.

Blue tit inspecting potential home


We're pretty sure its a blue tit.  My first thought was to check the activity log that is generated via the two infra-red beams at the entrance hole.  There are two IR beams, an inner and an outer one, so theoretically one should be able to distinguish between entrance / exit / head-in / head-out.  Why you might ask...? ;)

Nest box in situ, and activity log.  Yellow activity is this blue tit.

The log shows the activity to date, where the two numbers represent the beam, then the beam state:
1=Outer, 0=Inner  and 1=Whole, 0=Broken, for example 1,0=outer beam broken.
On closer inspection of the log, I seem to have mis-coded that...


I originally thought Mr Blue tit was the first look-in I'd had, as it was the first caught on camera, however the log showed otherwise, with some interest five days ago.  A quick re-visit of recorded footage showed a shadow briefly obscuring the entrance hole at the exact time of the logged event on the 24 April.  There's no way I would have spotted this so it shows the IR beams are doing their jobs.

I'm considering putting up a miniature gallery along the lines of 'Birds & insects that have made brief appearances in our nesting boxes'.  Fascinating viewing I'm sure !

?Coal Tit making brief appearance into owl squirrel box

Wednesday 23 April 2014

Squirrel montage collages

Just a quickie today,  My squirrels have been spending quite a lot of time in the owl squirrel box recently. They can usually be found in it when it rains and spend most nights in it at the moment.

I've been playing with the photo collage tool in Picassa, and have made these 'delightful' montages.  My wife thinks that one of them isn't suitable for my work desktop background, see if you can figure out which one it is.

Squirrel Montage 1

Squirrel Montage 2

I've linked to high res versions of these if you too want to offend your work colleagues.

Sunday 20 April 2014

Side-View, Raspberry-Pi powered bird counting bird box

As I mentioned in an earlierpost, I've been looking to setup a small bird nesting box with camera feed that can be viewed from any internet-enabled device (PC, tablet, phone).  While there are plenty of solutions out there to directly connect an analogue camera to a TV, there are no affordable compact off the shelf 'stream-across-the-web' (or home network options).  

My 'Mark I' box is based on the side view 'Odd-Box' design, variants of which are available commercially from various UK retailers.  This design is interesting as it gives a 'side-on' perspective, rather than the usual 'top-down' view from the traditional nest box with camera at the top.  I've added an entrance counter which should allow me to monitor coming & goings from the box.   

My side-view, Raspberry-Pi powered bird counting nest box

As described in an earlier post, I've taken advantage of the Raspberry Pi's flexibility to connect to a variety of devices, and have hooked it up to a webcam to stream live footage of an owl nesting box, which  is currently intermittently occupied by squirrels.
  
Bird Activity Counter
I've also incorporated two entrance hole infra-red beams that when used together should be able to detect entry and exit from the box.  This is based on the bird box project in Andrew Robinson and Mike Cook's Raspberry Pi projects book:


The final chapter ' Chapter 17 - The Techno-Bird Box, a Wildlife Monitor' describes a method of utilising the PiFace interface board with the Raspberry Pi to record entry and exits to the box.  This YouTube video shows the sort of thing that is possible.
Update May  4 2014:  Python scripts for this aspect of the project are described in this post
   
Box Construction
The wiring, IR illuminators and detectors are housed in the multi-layer plywood section on the LHS of this picture.


All wiring is goes via a terminal block to the PiFace interface board + Raspberry Pi.  The box is powered via power over ethernet (PoE) using a TP-LinkTL-POE200 PoE kit.  The camera is a Microsoft Lifecam cinema.   The box is linked into my home network, and can be viewed from any connected device as a motion jpeg stream.

Video streaming
The LifeCam is capable of 1280x720 video, but unfortunately the viewing angle is too wide, and there's a gain in frame rate if I drop it to 800x600.  At this resolution I can also zoom in, which isn't possible at the higher resolution using the LifeCam.  I'm using mjpeg_streamer to stream the video across my network, and can get a framerate approaching 20fps, but limit it to approx 12fps as this is still perfectly adequate.

View from each end of the box (not web-cam view)
I haven't gone for artificial light in the box, and have instead cut a window into the box lid and put a sheet of transparent acrylic over the lid.  This seems to give plenty of natural light, and we'll see if the skylight puts them off or not. 

For a future 'Mark II' box, I'm planning to use the Raspberry Pi camera board as its a good resolution, cheap and much more compact.

Motion detection
The Raspberry Pi is essentially a small computer running Raspbian, a version of Linux.  This is an open-source operating system that benefits from a wide community of open-source software (read = free).  I'm currently taking advantage of the Lifecam's facility to stream mjpeg natively, which puts very little load on the Pi.  Optionally, you can run a program called 'motion' which analyses a video stream for movement configured to record any detected activity.  I haven't used this, as a while ago I setup a PC running iCode's iCatcher Console software which does the same thing.  This is windows based, commercial software, which operates on a per-camera licensing basis, so there is a per-camera cost involved. I have maxed-out my available iCatcher per-camera licences at the moment, so may look at using motion for the next nest box / feeder / whatever build.  Using this software, I can capture any activity and export to a video file, for example this week has seen plenty of squirrel mating in my Owl nest box.



If you exclude the motion detection (which can be setup for free on the Pi), the cost for this build would be approx £100, which when you compare to how much the cost of a TV-only analogue kit would cost is very favourable.  The 'downside' is that you have to build & program this yourself, but there are plenty of guides out there to help with that.

Mounting
Since we're not dealing with a battery or solar powered box, this had to be put up near a network point and power.  The advantage of a PoE setup is that I can run an ethernet cable a long distance from the house and send power and a data signal through it.  The TP-Link kit I've used allows a step down to either 12, 9 or 5V at the destination, so I've assumed that it must send a higher voltage down the wire.  My assumption is that since the step down occurs at the destination, there's no need to fiddle about with voltage drops if you planned to send 5V from the power source. 
To keep it simple, I'm mounting this one on the side of the house, and running ethernet cable through the wall.  My other similarly setup owl-come-squirrel box is set up exactly the same way, and is a good 150ft from the house.

This is a view from the lifecam camera with the box outside:

View from Bird box camera at 800x600 resolution

My main concern is that the electronics compartment gets a little warm, and I don't want to kill the Pi... hopefully being on North-East facing wall, it shouldn't get too hot.  The next version will incorporate some better ventilation.

I hope that I haven't left it too late putting this nest box up, but last season we have great tits nesting in May, so I'm ever hopeful!
  

Thursday 17 April 2014

Trail Camera / Scouting camera

Last Christmas my lovely wife gave me one of these:

KeepGuard KG-680V, 8MP Trailcam

For the last few weeks, I've had it set up at the bottom of my garden, which backs onto woodland.  Before this point, in the garden, we've had occasional fleeting glimpses of foxes and a badger once.  When I forget to close the gate, we often get deer into the garden that like to eat all the flowers.

The aim was to see if we could get footage of any of these with the trail cam...

I set it up overlooking a clear 'passageway' through an overgrown patch of land:



It has two settings: image or video capture (not both).  I've set it onto its highest resolution settings, which produces some nice images and the video is okay too.  It has built in IR illuminators which should illuminate up to 15m from the camera.  I'm using a high capacity SD card so can afford to leave it running for a long time

To begin with I thought this could double as a way to document the local cat population, 3 regular cat visitors cats so far..

Anyway, the wild animals caught so far:

1) Deer: We seem to have two regular visitors, we've called these two "Itchy" & "Scratchy" as they spend a lot of time doing just that.  There's a lot of ticks in the woods, so I wouldn't be surprised it they're covered in the things...


2) Fox: This is pretty cool - I'm keeping an eye out for more of him/her ?


3) Badger: Our favourite yet.  Unfortunately my only sighting is him/her? walking away - we're hoping to get better views over the next few weeks.


All in all, I'm really pleased with the results.  Not quite the 'Big 5' but there's time for a Lion yet...

The main limitation as far as I can see with my trail cam is that I need 2x SD cards so I can swop cards when reviewing footage.

Pi Trailcam
I felt quite inspired by this Raspberry Pi trailcam variant on this blog, which I might at some point consider emulating.  I particularly like the sparrowhawk.



Sunday 6 April 2014

Squirrels mating, Spring 2014

Now, I've been thinking of a tasteful way of putting this... but frankly have yet to find any option that does not degenerate into boyish giggling when passed around my family... so a quick update on the Owl Squirrel box.  All has been fairly quiet, except for an occasional peek.

However, this changed this morning with some frantic squirrel-on-squirrel action:

Yes I realise this is a little childish of me....
Had a particularly interesting moment when dealing with the observation from one of my (young) kids, that "Daddy, they really do like a long fight, don't they?".  From the short video clip below this is evidently true.

This is the first time they've been filmed as a pair, and I hope it bodes well for the possibility that we'll hear the pitter-patter of tiny squirrel feet.  According to Wikipedia (so it must be true, right?), gestation is approx 40 days, so expect squirrel babies mid May.  We're quite excited here!