Wednesday, 11 February 2015

Spring 2015 nest boxes - early interest

We've seen daily interest in our side-view bird box, but this has been limited to a 'once daily' blue tit.
Today up'd the ante with a pair of Great Tits in addition to the usual mid morning Blue Tit.

Both these clips are from the same day (Feb 9th 2015).  You can see I may need to do a bit of a Spring clean too...

Blue tit



Pair of great tits


Of note is that its the first time I've seen any bird inspect the window at the top of the nest box.  As you can see, the window does not overlook the nest site directly, evident in the ramp up which the Great tit is attempting to climb.  Oddly, both birds attempt the same thing for the first time on the same day.  Front view of this box as shown (although its mounted on the side of the house).

'pre in-situ' picture last Spring.
See the following posts of more detail: Inception, activity counter,

Squirrel box update

Over the  Autumn and Winter, the squirrel box continues to be used as an occasional refuge from rain and windy weather.  They've been only intermittent visitors recently, but lots of activity approx 1 month ago.  Periodic addition of nesting material continues as show in this series:






...or with the squirrel:



Next job is to get this year's bird nesting box completed and up in time for Spring...

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 image: Some 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...