Weather camera database

At the top of this page, you may have seen the weather station link, showing up-to-date temperature, pressure and more. The page updates automatically every 10 minutes, 24/7. The weather station was installed 31. Jan 2010 taking readings every 10 minutes. Beginning 04 Jan 2012, the frequency of readings was increased to every 5 minutes, and it has been doing that since then, almost without any pause.  31 January 2015 will mark the 5th anniversary of the weather station and the associated web page, pumping out graphs like this:

image

On 03 Sep 2014, my new Raspberry PI based weather camera became operational, it has been capturing images every minute 24/7 since then, adding visual context to the other data. It is easier to understand the causes of the temperature fluctuations when you see what the weather actually looked like at the time.  The weather camera construction and setup will be subject of later post(s) here.

The database for the weather station has collected only  24MB of data since 2010, but capturing images is something completely different, even though the weather camera is set up to save images at half resolution and as JPEG with high compression. Keeping all those images as individual files in the file system, eventually causes trouble. It is also cumbersome to review old images that way.  Therefore, I have started developing a database & viewer for the images and other data produced by the weather camera. Eventually, this will be merged with the weather station data, but first we need to handle the substantial volume of image data coming from the camera.

As a first test of some ideas, I created a prototype database and viewer application to see how responsive it would be. I took all images from October 2014 – more than 44 000 individual images! – and put them all in the same database, resulting in a file size of 2.95GB. Here is a small glimpse of the responsiveness, which I find quite adequate.

Testing the weather camera database

Even though this appears to be working fine, I would like to find ways of compressing the data more, without compromising on the final image quality, so there will be more tests before I settle down on the “final system”. I am thinking of presenting temperature or other graphs alongside the images, to give better overview. The image database is based on SQLite, but I have added my own C++ layer on top of it, which makes it more suitable for object orientation. This layer may become open source at some stage, if it turns out the way I want it.

The next video below, isn’t really about the database as such, but it illustrates with better image quality what the weather camera can do. Of course, producing such time lapse videos from the database is a possible goal.

Weather camera time lapse 04. September 2014

If you are interested in any of this, and want to know more detail, tell me about it!

Raspberry Pi – Controlling a Relay

I have no background in electronics, but the Raspberry Pi has given me an incentive to learn. Some time ago I made a Raspberry PI weather camera (it will be subject of a separate post here at some later stage) which has now operated continuously for over two months in very mixed weather. Sometimes, the camera develops dew on its front cover window, it may be inside or outside or both.

imageCould I do something to fix that, for example using a window heating circuit controlled from the Raspberry Pi  camera?  This post is exploring how such an external circuit could be controlled.

First, one might be tempted to think the GPIO pins could provide enough power to drive such a circuit, but that is a sure way to short circuit and terminate the PI, so don’t even think of trying that!

When looking for answers, I found an extremely instructive post on the subject, Raspberry Pi – Driving a Relay using GPIO . It provided a solution: The GPIO pins cannot drive a heater directly, but they can be used to control a relay – which works as the on/off switch of another circuit isolated from the PI, i.e. using its own power supply.  I recommend reading that original post carefully, this post should be regarded as mere ‘replication’ as done by a novice. A circuit diagram was also provided, but how does it actually work, would I be able to use it in practice?  I set out to try and understand.

Starting at the relay end, the switch in the relay opens and closes as the relay coil, an electromagnet, is powered. It turns out that the Raspberry Pi 5V GPIO pin can provide enough power to activate this coil, but we need a way to turn the power on/off so the relay can be opened or closed from software running on the PI. For this purpose, a transistor is ideal, as it may be used as yet another on/off switch, only at lower power. image By combining the relay coil and the transistor circuit one should be able to control the external circuit.

A transistor has 3 pins or “legs”, and there are 2 kinds of transistors, NPN and PNP types, we are here using the NPN type. You may want to look up the difference.

The current that goes through the relay coil goes to the collector  pin of the transistor and exits via the emitter pin, on the condition that the base pin is powered. The emitter pin is grounded.

Even less power, just a couple of milli-Ampere at 3.3V is required to “turn on” the transistor . Using U=R*I, U=3.3V, R=1.2KOhm we find that it corresponds to about 2.75 mA of power from the GPIO pin to the transistor base pin. Turning this GPIO pin on/off will control the transistor switch, and therefore also the relay.

We are almost done, but one component is missing: the diode labelled D1 above. The diode is there to protect from power spikes when switching off the relay, when the coil magnetic field collapses. The diode dissipates the power spike and makes sure the PI survives another on/off cycle!

Ok, that’s all talk, how about the real thing?  First, some components are needed, and for this Ebay is quite nice. I got most components from Asia with free shipping. For the relay, it is important that the coil circuit is 5V, I used a SRD-S-105D relay. The transistor must be NPN type, and the post above mentions the BC337 NPN transistor. Before receiving them, I found that I had a couple of BC547 transistors in a drawer, and it turns out they can both be used for this purpose.  The diode I used was 1N4004.

With all the parts collected, you just solder on, right?  Well, some do…. I had a strip board with holes connected in groups of 3, and I found it quite hard to imagine how to layout the circuit on the board without making a big mess.  imageTherefore, I got the idea of placing the strip board on my flatbed scanner, copper down, so that I could create an image to draw on.  I used Photoshop layers to experiment with layouts. I am sure much more suitable software exists for this purpose, but it worked for me.

I created the drawing at left this way. It is a little funny, because you are looking at the copper side and the components are really supposed to be on the opposite side, as in the photo further down. The black rectangle corresponds to the relay, and inside it you find the 5 relay legs as black dots.  The thing that almost looks like a grey resistor inside the relay rectangle is supposed to represent the relay coil, and the red line is the switch itself. The green show connections between strips.  The other symbols are perhaps more understandable. Observe that the diode and transistor legs must be soldered correctly, look up the data sheets! I am not suggesting you duplicate this way of working, it is highly non-standard, it simply shows how I was able to layout the components. Once again, remember that you are looking at the components from “under” the board (copper side), the components are really on the other side, as in the photo below-left.

image

I had to drill an extra hole for the 5th centre pin of the relay, as it hit right between 4 holes. I am no soldering expert, but the end result seemed quite ok to me.  But looks is one thing, more important is: Would it work?

Testing

In the image below, the +5V pin on the relay board is connected to the +5V GPIO pin (pin 2) using the black jumper cable.  The blue jumper is connected to GND (pin 6) and the green is connected to pin 11 (GPIO 17). The photo was taken before the green contact was added to the relay board.

image

As for testing the controlled circuit, I connected an external power supply to one of the green contact sockets on the relay board, and coupled a LED in series on a breadboard. The test was performed using the C program available from the article mentioned in the beginning of this post. Here’s an animated GIF showing that the relay did in fact respond as required. Success :-)

DSCN2905_crop

Raspberry PI model A+

Today this blog debuts with some very modest technical content. The Raspberry PI single board Linux computer has taken the world by storm, and it also fascinates this author.  The plan is to share some PI experiences and perhaps even inspire.  What is then more fitting than opening this series by mentioning a brand new member of the Raspberry PI family? Today, it was announced that the PI family got a new baby weighing only 23 grams, i.e. the smallest of the main boards. The baby’s name is Model A+.

I have only read about it, but it is clear that it is an improvement on the original model A. It is significantly smaller, uses less power (20-25% less than the original model A), has more GPIO pins (40), uses a Micro SD card and is cheaper! Other than that, it is in many ways similar to the Model A with 256MB RAM. There is also an audio port and a slot for the PI camera board, plus a HDMI socket and a single USB port.  This means you need a powered USB hub if you need to connect more than one USB device. The computer can run Raspbian  linux just like the other models.

Although the A+ resembles the model A, it is also closely related to the Model B+, the mounting holes are the same distances from each other, and the model A+ could be said to be virtually identical to the model B+, minus the Ethernet port, minus 3 USB ports and minus half the RAM. Given the form factor, this model is probably targeting dedicated embedded projects such as small robots or other applications that don’t need to be networked (it can be networked via a USB wireless dongle).

Clearly, it is imagination that limits what people can do with these things, and best of all: It is a great way of learning new stuff. I have already learned things about electronics I didn’t know earlier, and it is a great feeling to observe yourself getting a little bit wiser every day. Let us see what imaginative people can do with this baby!

This modest post will be followed up with examples from using the Model B, and things it and its cousins can do. Stay tuned!

To my father

Today is the birthday of my late father Carsten Arnholm Sr., he would have turned 85 years today. He was a caring grandfather to our children and came to visit us very frequently for more than 20 years. He also travelled with us several times abroad, and always had something interesting to say. He was someone who never stopped learning and we could sometimes sit and talk about history, technology, politics or anything else for hours.

carsten_sr

Although he was educated as a lawyer, and spent his professional time in the Ministry of Finance working with oil taxation laws, his passion in life was photography.  He was born in 1929 and tried photography at a very early stage, and it never stopped fascinating him. He went through all the phases of technology from simple cameras in the 1940s, to more elaborate laboratory techniques in the 1950s and 1960s.

His great tragedy in life was the loss of his sister, father and mother over 18 months in 1947-1948, when he himself was only 17 years old. You don’t go through such an experience without scars, but he managed to get a good education and his passion for photography quite naturally became even deeper. He became very active in photo competitions world wide and won many prizes. He also became very active in local clubs such as Oslo Kamera Klubb where I saw him enjoy himself in the late 1970s.

Although never being formally educated in science or technology, he never had any problems following technological trends. Spending many long nights in the darkroom in the 50’s, 60’s and 70’s gave him a deep insight into what constitutes a good photography and how to process an image. Sometimes he used very elaborate lithographic techniques with marvellous results. The image below was made in the 1970s without any digital techniques. The raw material is an image of an elderly portuguese woman, which he turned into his famous “Ektepar” (“The Couple”). It shows his humorous side!

02_Ektepar When people complained about “image manipulation”, he rarely agreed. He claimed all images are heavily processed in one way or another, “raw” presentations really do not exist.

When digital photography arrived, he was thrilled. At first he gave me long lessons about the superiority of negative film over the first digital cameras, but he really embraced digital image processing from day one.  He scanned films into digital files and spent much time exploring Photoshop. He became such an expert of Photoshop that when he was more than 80 years old, he routinely gave courses to people less than half his own age.

Later, the films were abandoned in favour of the top-of-the-line digital cameras. He had fully converted from simple box cameras, black and white film and a chemical lab, into someone who naturally spoke of bit depths, unsharp masks and many other things.  Although his techniques were superb and detailed, he also had an eye for what is a good image. He travelled with friends to both Antarctica and Svalbard in the far north. Arctic photography of natural life became one of his specialties.  Some of his portraits and other images can still be enjoyed at his personal website Carsten J. Arnholm . Have a look yourself.

In 2011, it became clear that he suffered from cancer. I cannot quite comprehend how he at once accepted his situation, and never ever complained although he insisted on receiving the treatment that doctors could give. His struggle lasted for 18 months, during which time he even found ways of doing photography from bed.

On the first day of 2013 he passed away quietly.

Thank you for being who you were. Happy birthday from your son.

My corner of the universe…