Tag Archives: Computers

260 000 images on a Raspberry Pi

In the previous post the op_lite object oriented database library for C++ was introduced.  I have been testing this library on Windows and Kubuntu using images from the Raspberry Pi1 Model B weather camera. The camera captures a JPEG image of size 1296×972 every minute, which means that each day there are 1440 additional images to put in the weather camera database. The database now has a viewer written in C++ based on op_lite and wxWidgets, It works fine on both Windows and Linux.

The PI weather camera has been  running steady for just about 6 months now, it has so far accumulated just over 260 000 images (database size is > 20GB) showing the daily weather plus stars at night. Today I wanted to try op_lite and the viewer on another Pi1 Model B, so I compiled the database viewer application there. This is straightforward as Raspbian is a debian derivative, just like Kubuntu.

The the 20GB database was copied from Windows across the LAN network to the PI which has a 320GB USB hard drive connected, formatted as linux ext4. The copy took a few minutes and the compilation of the software took longer, but it worked!  It shows that the database is compatible and can be freely copied around Windows/Kubuntu/Raspberry PI.

260 000 images captures on a PI1, viewed on another. It doesn’t work as fast as on a desktop, but it is certainly usable. I have a new PI2 Model B coming soon, and  it will be interesting to see how things performs there.  As the PI2 is said to be about ~6 times faster than the PI1, it should be good!


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.


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?


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.


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 :-)


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!