Sunday, December 15, 2013

Roundup: Best Raspberry Pi add-ons: the top extras for your Pi

Roundup: Best Raspberry Pi add-ons: the top extras for your Pi

The Raspberry Pi is probably the most successful British computing product in a decade, but it's also one of the most misunderstood.

Too many people think of the Pi as just a cheap desktop, but by the time you've bought a monitor, keyboard, mouse and SD card, you'll have spent almost as much as you would buying a cheap laptop - and it's a whole lot less powerful.

The real innovation of the Pi, then, isn't its cost, but its form factor. It's small, it can be run off a few batteries (or solar cells), and has GPIOs (General Purpose Input and Output pins) exposed. This trio of features is almost unprecedented in computing, and before the Pi, it had never been done at this price point.

Because it's not just a new device, but a new type of device, a lot of people struggle to understand how to use it, though. This was a particular problem when the Raspberry Pi first came out: there were few tutorials explaining how to use it, and if you wanted to use the GPIO you had to build any add-ons for yourself.

Fortunately, times have changed quite rapidly, and a whole ecosystem of components for the Pi has sprung up. Every day, it seems, we hear news of some new device that connects to the Pi to enable some function or add some feature.#

Many of these haven't been developed by large companies, but by hobbyists who saw a need and filled it. It's been great to see just how quickly new and innovative devices have come on to the market.

Here, we're going to look at three of our favourite add-ons, so if you've got a Raspberry Pi acting as a paperweight, blow off the dust and put it to a more productive use; if your Pi project is already complete, well, you know it needs just one more feature don't you?

Pi Lite

A multi-purpose LED display

Pi-Lite

When the folks at Ciseco mulled over the problem of underused Raspberry Pis, they came up with a simple solution: stick a shedload of LEDs on a board and create a simple way for people to turn them on and off. Why? That's up to the user's imagination, but it made the Pi stand out from a regular PC and forced people to think about its particular niche.

From this simple idea, the Pi Lite was born. It contains 126 red LEDs (and there's a white LED version coming soon) on a board that plugs into the GPIO pins on the Pi, and then sits neatly over the top of the main board so the unit doesn't take up any more space than a naked Pi. It's not quite a plug and play add-on, and there's a little configuration needed to enable the board to use the serial port, but it's not too complex as long as you're using the Raspbian OS, and it's well documented on Ciseco's openmicros.org website.

It should take no more than 10 minutes, though you will need a network connection to install some software which could make it a little tricky on a model A. With all that done, you can control your Pi Lite over the serial port.

From the command line type:

minicom -b9600 -o -D /dev/ttyAMA0

and you will have an interface to the LEDs. Anything you type will scroll across in glorious red light. This is pretty cool by itself, but it's only the beginnings of what the Pi Lite can do.

As well as text, you can also send commands to the unit. These are anything preceded by three dollar signs. For example: $ALL,ON will turn all the pixels on the Pi Lite. There are additional modes to display vertical and horizontal graphs, and to manipulate individual pixels.

This final mode takes a string of 126 1s and 0s, each of which represents a pixel, such as:

$F000000000000000000000111000011111110011111110111111111111101111
111101111011000110011000110000000000000000000000000000000000000

This final mode allows you to draw any images that you like, though it's probably most useful when used with scripts rather than through typing.

Since all communication to the Pi Lite goes through the serial port, you can access it using any language that supports serial communication. Python (using the serial module) is probably the easiest to try, and there are plenty of examples to get you started, again on Ciseco's Open Micros website.

Since the Pi Lite is driven from a serial port, it's actually quite portable, and can be run from any device with such capabilities, whether that's Raspberry Pi, Linux PC or almost any other computer (such as via a USB FTDI connection). Getting this set up will require a little soldering, but shouldn't be too complex.

Pi Lite emulator

If you're interested in seeing how the Pi Lite works, but aren't quite ready to part with any money, Ciseco has made an emulator so you can try out the hardware before you purchase it. This is available from (yes, you guessed it) Ciseco's Open Micros website.

The Pi Lite has one more trick up its sleeve: it uses an ATMEGA chip to drive the LEDs. This just happens to be the same family of chips that are used in the popular Arduino boards, and the Pi Lite comes with the Arduino bootloader installed. In other words, you can program the microcontroller on the board to do whatever you want. In fact, you could even run the Pi Lite board as a standalone unit without any other computer attached.

The board also exposes the five analogue inputs from the ATMEGA, which means that with a bit of programming, you can make those accessible for your project. This is a bit more complex than the standard use of the Pi Lite, but it is an excellent example of how a single piece of hardware can help you develop a wide range of technical skills.

Camera module

Take pictures on your Pi.

Raspberry Pi camera module

Before we get on to what the camera module is, let's first clear up what it isn't. If you're looking for a cheap webcam to Skype with your family, the Raspberry Pi camera module isn't for you. Not least because Skype doesn't run on the device.

The Raspberry Pi camera is easy to use, but not in a plug-in-and-use-graphical-tools kind of way. Instead, it's designed to be scriptable. Now, with that cleared up, let's get started.

The camera module comes as a ribbon interface that slots into the vertical connector between the Ethernet port (or the Ethernet port-shaped gap on the model A) and the HDMI connector. Lift the top of the connector up, slot the ribbon in with the silver side facing the HDMI port, then push the top back down.

With this done, you'll need to make sure you've got the latest version of Raspbian with:

sudo apt-get update
sudo apt-get upgrade
sudo rpi-update

Then run raspi-config and make sure that the camera is enabled. Finally, restart and you should be ready to go.

All the magic is done with two commands: raspistill and raspivid. It should be pretty obvious which one takes still images and which takes videos. You can, of course, just run it like this, and type the command each time you want to use the camera. To capture a still image, it just takes:

raspistill -o image.jpg

However, that's not where the fun lies. Because you can run these from the command line, you have full power to include it in your programs. For example, if you never know what white balance to use, why not use all of them with the following Python script:

from subprocess import call
for awb in ['off','auto','sun','cloud','shade','tungsten','fluoresce nt','incandescent','flash','horizon']:
call(["raspistill -n -awb " + awb + " -o image" + awb + ". jpg"], shell=True)

As you can see from the above, you can control the camera from Python, even though there aren't any Python bindings, by using a system call. You can do this in most languages, so hack away in your language of choice. Since all the options are available as command-line switches, you should easily be able to build the options you want into the system call.

Pi cartoon picture

Next, how about trying to make a stop-motion cartoon of your life?

raspistill -ifx cartoon -ISO 800 -t1 100 -t 10000 -w 300 -h 300 -o test_%04d.jpg

Here we're using quite a few of the command line options. -ifx is image effects, and it allows you to do all sorts of cool stuff. In this case, we're using it to render the pictures in a cartoon style. -ISO sets the ISO sensitivity. We've used a high one since image quality doesn't matter too much in this case. -t1 sets the timeout between the photos in milliseconds, while -t sets the total time for the timelapse capture, again in milliseconds. -w and -h are width and height in pixels. Finally, -o is the image filename (the _%04d is a number that's incremented with every picture).

These, of course, are just a few examples to get you started. For a full list of options for the camera, just run raspistill from the command line (with no options). Some of them won't make any sense unless you've got some photography experience, but with a bit of fiddling, you should get the hang of things.

As we mentioned before, raspivid can be used in a similar way to capture videos. To capture a simple video, run:

raspivid -t 5000 -o video.h264

and the more advanced options are similar to raspistill. Once you've mastered the basics, you can try out some more advanced projects. How about facial recognition using OpenCV? There's a OpenCV tutorial from the Think RPI blog to get you started.

Quick2Wire GPIO expansions

Extra ports to improve your Pi's connectivity.

Quick2Wire GPIO

One of the best features of the Raspberry Pi is the exposed GPIO pins. These allow you to add whatever circuitry that you want to your Raspberry Pi. They're both easy to use and easy to understand; with a single line of Python or Bash, you can turn them on or off, or read their input.

While they're good, though, they're not perfect. You can see a lot of pins, but not all of them are available to use, and there's no analogue input or output. They also have very little protection, and if you apply the wrong voltage (or even if you accidentally link the wrong two pins together) you can fry your Raspberry Pi a little too easily.

Several companies have developed products to help simplify the process and each works better in different situations. For example, Ciseco's Slice of Pi gives access to 16 GPIOs that are protected to work at both 3V and 5V; the Pi Face adds some useful features, such as buttons, LEDs and relays (to control motors etc); and the Gertboard adds a wide range of input and output features that are useful for learning about the various applications.

You can even hook up an Arduino and use this to control input and output, although this will require programming in C. However, we're going to look at Quick2Wire's I2C and SPI board.

GPIO expanders

SPI and I2C are both Serial Peripheral Interface and Inter-Intergrated Circuits (often written I2C and pronounced 'eyesquared-C').

In its basic usage, the Quick2Wire setup comes in two parts: the main board breaks out the I2C and SPI ports as well as adding protection for the Pi and voltage selectors. The company also makes I2C boards that add GPIO ports and analogue input and output to your device. These boards can also be daisy-chained to add even more ports to the Pi. You will have to do plenty of work yourself and solder the boards on your own but, once done, connecting them is simply a case of plugging in the ribbon cables.

There's quite a bit of setup to get a Quick2Wire board up and running. Not least the need to configure kernel modules. You will find an online guide on the Quick2Wire website, though it did miss a few things, such as the location of the Python library.

We also found that we needed to install the python3-setuptools package. Once up and running, though, it was straightforward to program the board with Python.

Right now, it's not a question of which Raspberry Pi GPIO board is best, but which is most suitable for your project: Ciseco's Slice of Pi is a great, low-cost device to make Pi GPIO use a bit safer; the Pi Face is a really good board for experimenting with physical computing, especially if you don't have a specific use in mind; while the Quick2Wire boards are incredibly useful if you need the power of SPI or I2C to daisy-chain peripherals and port expanders.


    






No comments:

Post a Comment