Saturday, 24 January 2015

Pi-Eyed

Since changing my weather station monitoring software from Weewx to Cumulus (see Weather Report) my Raspberry Pi has been a forlorn object, nestling dejectedly on a shelf against its redundant power supply. It had worked flawlessly without a reboot for weeks on end and for this its reward was to be cast aside.

My original plan for its reuse was as a DAC; the Pi's lackluster native sound handling being bolstered by adding a HiFiBerry DAC. There's a DAC+ for the Model A+ and B+ and a DAC that works with Model As and Bs with a P5 connector, '...that old Revision 1 versions don't have'. What luck, I have an early Revision 1 Model B. On to Plan B, then.

 Second Stage Lensman

For some time I've owned a Raspberry Pi camera which recently has been stored in its box on the same shelf as the Pi. Many and great are the applications for which people have used this device; my requirements, to use it as a webcam, were somewhat humbler. It's trivial to do this - typing:

raspistill -w 800 -h 600 -o /home/pi/webcam/picture.jpg

into the terminal causes a jpeg image called picture.jpg 800 by 600 pixels to be output to the folder /home/pi/webcam. And if the following line is added to crontab:

*/10 * * * * raspistill -w 800 -h 600 -o /home/pi/webcam/picture.jpg

the image is output every 10 minutes.

By increasing the rate the picture is taken and then streaming the image you can use it as a simple security camera.

There were two reasons I hadn't continued to use the camera; firstly, I had issues with it running with Weewx, possibly because I have an early version of the Pi, with only 256Mb of memory (in fairness I had similar problems with a Logitech C270 webcam). Secondly, as you can see from the picture below, the design of the camera is pretty basic; in essence it's just a lens and sensor on a small PCB attached to a short ribbon cable. This makes it awkward to use as it stands: its surface mounted components are unprotected and the ribbon cable is too short. Again, to be fair, the camera is meant to be used in projects, rather than be a finished consumer item.

A Raspberry Pi and its Camera
Mounting Climbing

I realised that to use the camera for any length of time without damage it would be sensible to find a way of mounting it; the blob of Blu-tack I had been using just wasn't up to the job. A search for 'Raspberry Pi camera mount' didn't bring up a huge number of novel and innovative products, surprisingly. The cheapest, simplest and arguably the best is the Pimoroni mount (£3, plus £3 postage - what!), which is essentially two bits of plastic and four plastic screws. At the other end of the scale is the all-in-one Pi and camera enclosure from Nwazet - a snip at £25.

The Nwazet gave me the idea that I could adapt the case I already had. This is a cheap, clear plastic object - unpretentious, but has fulfilled its purpose perfectly. And indeed I wasn't the first to have this idea with the very same type of case. Instead of double-sided tape (good grade!) I decided to use screws to fix the camera to the lid. Using the camera as a template I marked the position for four holes, then drilled them. Here's the first two:

First two of four holes drilled in case, top left.
I decided to make a square hole for the lens assembly so it would poke through the case. This probably made things unnecessarily complicated when a simple, single drilled hole would have served equally well. Measuring the position for the lens was awkward and I eventually created a paper template and used it to mark the outline of the lens hole. Cutting out the hole was achieved by drilling through the case at the four corners and using a small router bit in a electric mini drill to cut the plastic between them. Take my advice - just drill a round hole big enough for the lens assembly...

Square holes are more trouble than they're worth
The pre-drilled holes in the camera circuit board are only 2mm in diameter and even the smallest bolts I could find were too big. Widening the holes was a non-starter as there are wiring tracks that run very close to the edge of a couple of them, so I had to buy some nuts and bolts from a model shop in the local town. The reaction to my request for size M2 nuts and bolts was scornful, 'We only stock BA sized fixings.'. I admitted that these Imperial sized bolts would be far superior to the metric rubbish and the chap helpfully measured one with a micrometer to make sure they would be OK - you don't receive that sort of service when shopping online.

They were a tight fit, but fit they did and I tightened them carefully so I didn't crack the case. The finished result isn't too shabby: the camera is protected and is now a single unit with the Pi itself, making it look not unlike a digital camera.

The Golden Age of British engineering is still with us.
Now, how can I mount the Pi's case on a tripod...?


No comments:

Post a Comment