Showing posts with label webcam. Show all posts
Showing posts with label webcam. Show all posts

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...?


Friday, 28 November 2014

Weather Report

My weather station has been running virtually without a hitch for several months. The few problems I had encountered with the weewx software running on the Raspberry Pi had been ironed out (due to my errors, not the software's - see posts passim). The Pi has occasionally frozen and needed a reboot, but for a £30 device running 24/7 for months on end that's remarkable. It would be stupid to mess with it; best leave well alone now it's stable.


A Silver Lining in Every Cloud

No, of course I couldn't leave it alone. About two years ago I had a Maplin weather station feeding data to Sandaysoft's Cumulus software that was running on a Windows PC (see Where's the Time Gone). Whilst I liked Cumulus I wasn't prepared to leave the PC running in order for it to upload regular updates to the website, due to the noise it generated and the power it consumed, which is why I moved to the Pi. I always wanted to use Cumulus again and had considered building a mini PC using a low-power CPU and mini-ITX board. However, although mini-ITX motherboards are relatively cheap, by the time a hard drive, memory, a case and Windows, annoyingly the most costly component of all, had been added, the total cost had become eye-watering.

That would have remained the status quo were it not for my daughter complaining that her laptop had starting misbehaving: a blue screen of death that ultimately required a restore from a backup. Then the 'e' key stopped working; which causd hr quit a problm as it's th most common lttr in th languag. My suggestion of only using words without an 'e' didn't go down well and she resorted to using an on-screen keyboard until her new laptop arrived.

There are no problems, only opportunities, as some management wnkers (sorry, the 'a' key's playing up now) are wont to say. I realised I could use her old laptop as a way to run Cumulus; it would be quiet and fairly frugal with power too. Better still it had a large hard drive so it could also be utilised as a media server.

Cloud processing - Laptop running Cumulus software

Speculate to a Cumulus

After I had rebuilt the laptop from the factory image (then removed the cruft and bloatware that was included - I'm talking about you, Dell) I downloaded the latest version of Cumulus, 1.9.4 build 1085, from the Sandaysoft website. Cumulus is donationware: free to download and use, but you're encouraged to give the author some money to at least keep him in tea and biscuits. Considering the polished nature of the software, its features and the level of support that Steve, the author, provides it would be churlish not to donate something (I have). Although judging from a couple of justifiably testy comments Steve has made in the forum, many people are too cheap to do so (but probably still expect him to sort out their problems).

Like any weather software worth its salt, Cumulus doesn't just provide a regularly updated display of information from the weather station, it also includes FTP to allow the data to be uploaded to a website. A set of quite attractive web pages are provided (although the graphs are rather ugly) and the tags (used by Cumulus to embed the weather data into the web pages) are documented so you use the ones you want and design your own web pages. Simply put, to create the web pages the program uses template pages that it processes by embedding the tag data and then FTPing the resulting page. So, for example, the tag #temp is replaced by the temperature reading from the weather station. The Webtags page in the Wiki explains this in some detail.

There isn't a manual for Cumulus but there are a fairly comprehensive set of instructions on the Cumulus Wiki, plus there's a forum that's well frequented by knowledgeable weather enthusiasts and Cumulus users.

Once again I used the web server on my trusty old QNAP NAS to make the information available to the whole wide world. And if that wasn't enough, regular updates are being sent to Weather Underground, whose pages are rather attractive and have some cool graphs too.


My Cam and Yawcam Too

Something else I had wanted to do for a while was reinstate a webcam feed. For some time my Raspberry Pi had happily processed images from a Logitech C270 webcam as well as running Weewx. Unexpectedly I started seeing problems with both Weewx not running and the webcam images not being uploaded; I have no evidence for this, but I suspect this corresponded to changes in Raspbian to accommodate the Raspberry Pi camera. My Pi is an early (not the earliest) Model B, only has 256Mb of memory and possibly struggled with the demands expected of it.

A Windows OS meant I was able to use Yawcam again. This is a neat, unassuming and free program that will take a feed from a webcam and send images, either still or streaming. I use it to grab an image every 10 minutes and squirt it to my web server where it forms part of the weather webpages on my site and Weather Underground.