Sunday, September 22, 2013

33. A Raspberry Pi Bird Cam in the Making

I saw an offer for a Raspberry Pi Model A / RasPiCam board bundle from CPC and it seemed like a good offer - £26.14 including VAT & delivery.  I am currently running my Pi (Model B) on top of my field scope, and it has been producing some interesting results, so rather than disturb it, I thought I would go for the CPC offer.

In the back of my mind is some sort of bird cam.  My peanut bird feeder is well established - the tits, finches, wrens and robins (and even a grey squirrel) seem to trust it now, in fact they probably depend on it.  The only hazard to them is our cat.

If the bird cam is to be placed remotely beside the feeder, it will need to be battery powered, and the best Pi for the job is the Model A as it uses less power than the B.  Measuring the power consumption while running a test program revealed that the Model A used 0.795 W while the Model B used 2.09 W. (Ref: http://www.raspberrypi.org/phpBB3/viewtopic.php?f=29&t=32955).  This is obviously important when powering the Pi by batteries.

So the CPC Model A seemed to be the one of choice.  Now to get the best out of a bird cam.  I thought it would have to be up close.  The problem with the RasPiCam is that it will only image objects sharply if they are at least 0.5 m away, at and this distance they occupy only a small portion of the field of view.

This problem can be remedied with some optics.  A couple of posts on RasPi.TV some time back (Ref: http://raspi.tv/2013/adapt-your-raspberry-pi-camera-for-close-up-use and http://raspi.tv/2013/raspicamcorder-software-released-on-github) featured a Raspberry Pi camcorder developed for close-up and personal video.  So, based on that advice, I ordered a set of close-up lenses and an adapter ring.  The 49 mm to 52 mm step-up adapter ring cost £2.54 delivered, from Ultra Sales Global.  The lenses have a diameter of 52 mm and have screw threads for mounting on SLR cameras etc.

The idea is to house the Pi in a case (another one from ModMyPi Mix 'N Match as before (£2.49 before VAT & delivery), and this time they sent me a clear bottom and blue top, again thankfully not pink).  I had already purchased a 50 mm CSI DSI Camera Ribbon Cable (£2.50 delivered, from AlienSpec), so I replaced the 150 mm one that came with the bundle, with that.  The 50 mm one is very handy and just right for this job.

I assembled the Pi in its case.  The new Pi has bolt holes through the board for fixing so that it can be bolted to the case bottom.  With the short ribbon cable coming up through the special slot to the camera, the camera board could be mounted on top of the case, but to do this effectively, I had to drill a couple of holes in the case so that 2 screws could pass through it and into the RasPiCam board.

To keep the camera board parallel to the case top, I padded it with some plastic foam (the sort that ICs come with, with their legs pushed into, to protect them).  This also allows for a little angular fine tuning if necessary, by adjusting the screws.




On aligning the adapter ring, and close-up lenses over the RasPiCam, I realised that some of the lenses would be too close to the camera itself, so I had to improvise some sort of spacer.  A quick root in the pantry, and the plastic cap of a Cadbury's Cocoa Powder container was 'borrowed'.  I cut the centre out of this and was left with a lovely red spacer ring.  This I hot-glued so that the camera was as dead centre as possible, and then I hot-glued the adapter ring in place.  Centring the assembly over the camera is not critical - the main thing is that it looks nice.  And it does - don't you think?  The hot-glueing job isn't very pretty, but that was my first hot-glue job.

The close-up lenses came from XCSource (£11.15 delivered) in a handy protective soft case, with compartments for the +1D, +2D, +4D and +10D lenses.  OK - now a short lesson in optics:  The D in +1D, +2D etc stands for dioptre (diopter in the USA).  It's a way of describing the Optical Power of a lens.  A +4D lens is a converging lens (described by the + as opposed to a - for a diverging lens) with a focal length of 250 cm, ie f = 0.25 m.  1/f = 4 dioptres, so the power in D is the inverse of the focal length in metres.  1/1.0 m = 1D, 1/0.5 m = 2D and 1/0.1 m = 10D.




The other cool thing about these lenses, is that some (but not all, due to the construction of their mounts - the +1D and +2D lenses cannot accept further lenses in front of them) can be piggy-backed together, and the total power is the sum of the dioptres.  So if you screw together the +10D, +4D and +2D, you end up with a +16D combination - equivalent to a single lens with a focal length of 62.5 mm - about 2½ inches.  Now that's what I call close-up!

Now it's time to put the whole thing together and try it out:  I want it to run 'headless' so I borrowed the SD card from the other Pi, plugged in the power mini-USB connector, attached the Edimax wifi dongle to a 25 cm Male to Female USB A cable (a thing I learned earlier, to allow the dongle to be optimally positioned).

The I ran Xming and PuTTY on the PC, and while I was at it, WinSCP also.  These all had the same log-in details as before, because it was the same SD card that was being communicated with.  Then I ran the VNC server on the Pi, and the VNC Session on the PC, and up popped the Pi's desktop!

On double-clicking the Geany icon, I ran the Python program MotionDetection.py which I had been using for motion detection, and lo and behold - pictures started recording.  I quickly checked these on ImageJ and yes - all is working - magic!  The pictures are quite good, and I took a series with:
No close-up lens (sharp imaging from 50 cm to )

+4D close-up lens (sharp imaging around 25 cm)

+4D & 10D close-up lenses (sharp imaging around 7.14 cm)

+4D & +10D & +2D close-up lenses (sharp imaging around 6.25 cm)

and you can see that the magnification is going up, the field of view is getting smaller (naturally) and, most importantly, the focus is getting shorter.  You can also see in the last three images, the internal reflection of the RasPiCam LED.  There are ways of turning this off, but for the moment, it's not a problem.  When it comes to spying on birds, I'm sure they won't like the flashing light.  The point of maximum sharpness is getting closer and closer.  So now I should be able (eventually) to see the birds within inches!

While writing this up, I remembered that the pictures were a little dark, and that I had forgotten to remove the protective plastic from the camera board lens.  So I removed it and took some more pictures, and to be honest, I couldn't see much difference!!

Here's a picture taken by the Bird Cam of motion-detected images of my Charlieplexed LED array at a distance of about 3 inches:




And here's the close-up set-up:


When I get time, I'll do a raspivid video.

ADDENDUM:  The Bird Cam project didn't get much further, as my 6 x 2400 mAh AA rechargeable power source didn't last more than a few hours.  I will have to look at the power end of things.  

I came across this post by Dave Ackerman (the chap who puts Raspberry Pi's into space) and it is very interesting and useful.  However, it does entail a bit of risky modification to the Pi, (voiding the warranty) and I haven't rustled up the nerve to go through with it.  However, it is an excellent article and worth coming back to for the next phase of this project, or indeed, any remote application.  Here's the link: Running The Raspberry Pi On Batteries and here's Babbage the Bionic Bear on his flight into near space at 41km high:
ascent96

It may be possible to get up to something like 28 hours with 6 x AA (1.5V) batteries (a bit less with 1.2V rechargeables) using his modification and an MCP1825S 3.3V regulator. 

Hmm interesting....

No comments:

Post a Comment