2015-12-24



Introduction

Note: Our supercharge your Raspberry Pi article has been fully updated. This feature was first published in February 2013.

We've loved the Raspberry Pi in all its forms since it first launched back in 2012. And it's increasingly obvious that the rest of the world loves these devices too. Back when the Pi first came out, we didn't think that anyone other than enthusiasts and educators would…

The Raspberry Pi has struck a chord with hobbyists the world over, in a way no other device in recent years has. Initial production runs of all the various models – from the original Raspberry Pi all the way to the latest Pi Zero model – sell out so quickly that most of us have to wait a few months before they're generally available, although even then they sell as fast as factories can make them.

This isn't surprising, given that it's a fully functional computer capable of running Linux and – in the case of the Pi 2 – even Windows 10. The Pi Zero can be purchased for under a fiver, while for £30 (around $45, AU$60) you can get a quad-core Raspberry Pi 2 with 1GB RAM and all the connectivity you need on a credit card-sized board. No wonder that the project's goal of revolutionising outdated computing education in the UK appears to be working.

One thing is for sure, though – the world of amateur hardware hacking has never been the same since the Pi first appeared. These diminutive, but fully functional, systems are perfect for adding processing power to unusual places where space and electricity are at a premium.

Find out what else you can do with the tiny PC by exploring our collection of Raspberry Pi Projects

The recent Astro Pi project is just the latest example of Pi's being sent into space, while FishPi sees them readied for crossing the ocean, but they're also finding uses in more mundane settings, helping to brew home beer or drive remote control cars. We're going to look at some cool projects for the Pi and introduce you to the techniques you'll need to turn yours into the device of your dreams.

Thanks to the versatility and depth of Linux tools, it's easy to tune your Pi to be anything from a desktop computer to a media centre or hardware controller.

Distro guide

Distro guide

As you probably expect, there's a wide range of operating systems – known as distros – available on the Pi, and new ones seem to pop up every week. Here, we're going to take a look at some of the most popular, as well as a couple of novel ones.

You install a distro in a slightly different way than on a normal computer. Since everything runs off an SD card, all you have to do is write the new operating system to this card. The simplest way is to useNOOBS, or you can write images of other compatible distros to the card too.

If you're running Windows, then Win32DiskImager is your best friend, while OS X and Linux users can use the command-line tool dd. This tool does a bit-for-bit copy of data between a device and a file (or for that matter, two files or two devices).

Distros are supplied as image files (a bit like ISO files for CDs) that can be written to the disc, after being unzipped if necessary, with:

$ sudo dd if= of= bs=4k
$ sudo sync

The second line ensures that all the data is written to the card and not stuck in any buffers. So, for example, on our test computer, which has two hard drives (sda and sdb), the SD card comes up as dev/sdc, so replace with dev/sdc. If you aren't sure which device your SD card is, rundf –h at the terminal, and it will list all the devices. You should be able to see which one it is.

Similarly, refers to the full path and filename of your image file – for example/home/nick/downloads/2015-11-21-raspbian-jessie.img.

To back up your Raspberry Pi setup, you can create a new image file by reversing the if (input file) andof (output file) flags in the dd command. That is:

$ sudo dd if= of= bs=4k

This image can then be compressed, using gzip or bzip so it doesn't take up too much hard drive space.

Raspbian

This is the recommended distro by the Raspberry Pi Foundation. Unless you have a good reason to use a different one, it's probably your best bet. The latest version is based on Debian 8 (codenamed ‘Jessie'), and so you can easily install anything from the huge Debian repositories.

The default desktop environment is LXDE, which is very lightweight, but a little basic for some tastes. Xfce is available for people who like a few more graphical niceties. Raspbian also has the raspi-config program, which is probably the easiest way of configuring your Pi.

The Raspberry Pi was designed to get children into programming, and Raspbian was designed with this in mind. You'll find Idle (a Python IDE) and Scratch (a programming environment for young children) on the desktop – see our beginner's guide to programming for more details. You can download the distrohere.

Arch Linux

While Raspbian has been created to try to shield users from the internal setup of the operating system, Arch Linux is designed to help users understand how the system works. Special versions for the Pi's ARM processor can be downloaded from archlinuxarm.org – choose ARMv6 for the original Pi and Pi Zero, and ARMv7 > Broadcom for the Raspberry Pi 2.

The initial image includes just the basic system to get your Pi running and connected to the network. It doesn't include much of the software you may require to use the system, such as, for example, a graphical environment. You should find all the information you need at the Arch Linux Wiki.

Taking it from this initial state to a working system will require a bit of work, but along the way you'll learn about how the internals of a Linux distro fit together. Whether or not this is worth all the work is, of course, up to you.

OSMC

The Raspberry Pi may have been designed as an educational tool, but hobbyists have been pretty quick to make it a toy. This distro is designed to turn your Pi into a media centre that can be used to control your TV.

It's based on Kodi, which allows you to play music and videos that you have as files, or stream them from the internet. The image can be downloaded from: https://osmc.tv/download. As for details of how to install and set it up, we'll cover that a little later in this article.

If you have a MythTV back-end set up, you can use Kodi to provide a front-end interface. Depending on what you want to play, you may need to purchase the codec packs that provide access to patent-protected video and audio algorithms.

Android

An official version of Android – endorsed by the Raspberry Pi Foundation – died a quiet death after it was first announced back in 2012. In its place, the community has been working on an unofficial version. The performance is hampered by a lack of hardware acceleration support (the developers describe it as “barely useable”), but it's available now. Check out: www.razdroid.net.

You might also want to check out: 5 of the most popular Raspberry Pi distros

Installing Raspbian and overclocking

Installing Raspbian

For the majority of people who use it, Raspbian will be the graphical face of the Raspberry Pi. It can be obtained and installed onto an SD card by following the instructions on the previous page.

Once it's up and running, it's a good idea to grab the latest versions of all the software by connecting your Pi to the internet and doing one of two things – either open Menu > Preferences > Add/Remove Software and choose Options > Refresh Package Lists followed by Options > Check for Updates… or open a Terminal and enter the following two commands:

$ sudo apt-get update

$ sudo apt-get upgrade

The killer feature of Raspbian is the raspi-config program, which can be run at any time by typing sudo raspi-config in a terminal. Again there's a friendlier front-end available through the default desktop environment – click Menu > Preferences > Raspberry Pi Configuration to access the GUI.

It has got quite a few options, but the most important are:

Expand Filesystem – because of the way Raspbian is installed, it will only create a 2GB filesystem, so if you have a larger card, any remaining space will remain unused. You can use this option to expand the filesystem to take advantage of any wasted space. Click Expand Filesystem on the System tab to achieve this in the GUI.

Boot options – this changes whether your Pi boots into a graphical environment or a text one. Choose ‘To Desktop' or ‘To CLI' respectively from the GUI's System tab to achieve the desired effect.

Overclock – get extra performance at no extra cost! See the section below for more details – this option is on the Performance tab of the GUI.

Advanced Options > Overscan – this option can be used on some displays to make the graphics expand to fill the whole screen. You can safely ignore it unless you have problems.

Advanced Options > Memory Split – the Raspberry Pi uses the same chunk of memory for both the main processor and the graphics chip. Using this option (GPU Memory under the Performance tab on the GUI) you can specify the amount to allocate to the graphics. You'd typically lower this figure if you were running the Pi headless, allowing you to free up more memory to the main processor.

The installed software has been kept to a minimum. This is a good idea, but you may find that tools you use on other desktop distros aren't there. Fortunately, as Raspbian is linked to the Debian Armhf repositories, you have access to more software than you're ever likely to need. Just open the Menu and choose Preferences > Add/Remove Software.

14 cool Raspberry Pi hacks

Convert a Pi into a laptop

Use a Kindle as a screen

Build a Pi-powered wall-mounted Google Calendar

Low-cost HD surveillance camera

Build a synthesiser

raspbAIRy – the Raspberry Pi-based Airplay speaker

Control a solar power setup

Converse with a foreigner

Send a payload into (near) space

Control a house from the web

Brew beer

Play old games

Learn to build an OS

Make a photobooth

Overclocking

The processor at the heart of the Raspberry Pi is designed to run at anything from 700MHz (older models) to 900MHz (the newer Pi 2 and Pi Zero). In other words, to perform between 700,000,000 and 900,000,000 operations per second in the single-core models, and – in theory – up to 3,600,000,000 operations per second in the Pi 2's quad-core model (in practice it's unlikely to do this).



Of course, ‘designed to run' doesn't mean ‘has to run'. You can increase this speed. However, doing this will increase the power consumption, which in turn increases the amount of heat generated. If it gets too hot, you're liable to end up with a smoking pile of silicon rather than a functional processor.

Fortunately, later versions of Raspbian now include a tool to help you ramp up the speed while keeping an eye on the temperature. Since this is an official tool, using it won't void your warranty (unlike earlier unofficial methods). Note that this doesn't apply to the Pi Zero – it's already clocked at its theoretical maximum, and attempting to overclock it will actually slow it down.

Overclocking your Pi is simply a matter of opening the Raspberry Pi Configuration tool from Menu > Preferences, switching to the Performance tab and selecting the faster clock speed from the Overclock dropdown menu.

If you find that your Pi becomes unstable, reboot with the [Shift] key held down to disable overclocking, then change the option back to . The maximum setting should give owners of the original Pi model a whopping 50% extra speed, which we found makes a real difference to the desktop user experience, especially for web browsing.

If you want to keep an eye on your core temperature, you can add the Temperature widget to the LXDE panel. However, your Pi will automatically turn off overclocking once it reaches 85 degrees C.

OSMC and going further

OSMC

You can install a media player, such as VLC, onto Raspbian, and use that to play videos. This works fine if you're using your Pi as a general computer and giving it occasional multimedia functions. However, the small size of the hardware, and the fact that it runs silently, makes it a good choice for building your own entertainment centre.



You could start from Raspbian and customise it to your needs, and this is a good idea if you have any unusual functions in mind. However, if you're looking to press a Pi into service as an exclusive media centre, then life couldn't be simpler than to use OSMC.

OSMC is built on the open-source Kodi media centre, and is incredibly easy to install. Go to thedownload page to grab the installer for Windows, Mac or Linux, which will do the hard work of copying OSMC to your microSD card. Once done, pop it into your Pi and boot.

You'll be taken straight to the Kodi desktop interface, where you can start configuring it and adding your own media libraries using media stored locally on a USB or network drive (see below). You can also install add-ons to access media from elsewhere – including catch-up TV streams and more besides.

Once your Pi-powered media centre is under your TV, controlling it using a mouse and keyboard won't be practical – you could use a wireless model of course, or simply install a Kodi-friendly remote for your Android or Apple smartphone.

Be aware that OSMC may draw as much power as your Pi can muster – before you plug in any USB peripherals. It makes sense, therefore, to attach a powered USB hub to your Pi and then plug in any external drives to that.

If you want to know more about building your own OSMC-powered Raspberry Pi, check out our handy article: How to build a DIY OSMC media player.

Taking it further

It's possible to take complete control of your TV viewing using Linux, including watching live TV, and recording shows for later. This can be done using MythTV.

You'll need a separate computer with the appropriate cable connections to act as the server. A word of warning, though: MythTV is renowned for its pernickety installation. The stresses of this procedure are responsible for more than a few grey hairs.

You can play video files that you have stored on other computers on your network, for example those on a Network Attached Storage (NAS) box. The exact method for doing this will vary depending on how you share the files, but they are configured through the Add Sources buttons. For more information on this, check out the Kodi wiki.

Camera controller

Back up your photos using your Pi

The size of the Raspberry Pi means we can use it to take control of other embedded devices. This may seem a little redundant – the embedded devices obviously have some form of controller already – but it means we can script and extend them in ways that aren't possible (or are, at least, very hard) without the extra device.

Almost anything that you can plug into a normal desktop can be scripted by a Pi, but we're going to look at cameras for a couple of reasons. Firstly, there's support for most in Linux, and secondly there's a range of useful projects you can do once you've grasped the basics.

The best command-line tool for manipulating cameras in Linux is Gphoto2. Get it with:

$ apt-get install gphoto2

Before getting stuck into the project, we'll take a look at this useful tool to see what it can do.

The desktop environment can try to mount the camera, and this can cause Gphoto2 a few problems, so the easiest thing to do is run without it. Open a terminal and run sudo raspi-conf, and under Boot Options, select B1 Console, then reboot.

On our test system, we found that running this way, we could just run everything off the Pi's power supply, but if we tried to use a mouse as well, we needed to upgrade to a powered hub. Obviously, this will depend on the particulars of your peripherals and power supply.

In the new text-only environment, plug in your camera and run:

$ gphoto2 –auto-detect

This will try to find any cameras attached to the Pi. Hopefully, it will pick up yours. While it does support an impressive array, there are a few cameras that won't work. If yours is one of the unlucky few, you'll need to beg, steal or borrow one from a friend before continuing.

Not all supported cameras are equal, and the next step is to see what the camera can do. To list the available actions, run:

$ gphoto2 –auto-detect –abilities

There are, broadly speaking, two main classes of abilities: capture, and upload/download. The former let you take photos with your scripts, and are present mostly on higher-quality cameras. The latter let you deal with photos stored on the memory card, and are present on most supported cameras. In this project, we'll deal only with the second set of abilities.

The simplest command we can send to the camera is to get all the photos stored on it. This is:

$ gphoto2 –auto-detect –get-all-files

Running this will download all the files from the camera into the current directory. This would be fine on a normal computer, but you may not want to do it on a Pi, as you run the risk of filling up your memory card pretty quickly. Instead, we'll copy them onto a USB stick.

To do this in an interactive session, you could simply use a GUI tool to mount the stick then run df -h to see where the USB stick is mounted, and cd to the directory. However, since this will run automatically, we need to know where the device will be.

There are a few ways of doing this, but we'll keep it simple. We'll mount the first partition of the first serial disk, and store the photos there. Here, we're assuming that you're using the default user pi. If you're not, you'll need to adjust the script.

First, we need to create a mount point for the drive. This is just a folder, and can be put anywhere – we're going to spurn convention and put it in our home folder. So before running the script, run:

$ mkdir /home/pi/pic_mount

With this done, we're ready to go. The script to mount the drive and get the photos is:

#!/bin/bash

if mount /dev/sda1 /home/pi/pic_mount ; then
echo “Partition mounted”
cd /home/pi/pic_mount
yes ‘n' | gphoto2 — auto-detect –get-all-files
umount /dev/sda1
else
echo “/dev/sda1 could not be mounted”
fi

yes ‘n' is a command that simply emits a stream of n characters. This means that when Gphoto2 prompts to overwrite any previously downloaded files, it will decline. The umount is essential, because it ensures that the drive is properly synced and can be removed.

We've called the script get-pics.sh, and saved it in Pi's home directory. To make it executable, run:

$ chmod +x /home/pi/get-pics.sh

You should now be able to run it manually. You'll need to use sudo because it needs to mount the drive.

The final piece of the puzzle is to get the script to run automatically. To do this we add it to the file /etc/rc.local. This script runs when you boot up, and it executes as root, so there's no need to worry about permissions.

The quickest way to open the file as root is as follows:

$ sudo nano /etc/rc.local

Once done, add this line just before the line exit 0:

/home/pi/get-pics.sh
///end code///

Now all you have to do is plug in your camera (making sure it's turned on) and USB stick, and it'll back up your photos when you boot up.

Taking it further

If you want to run the device headless, as will most likely be the case, you could attach LEDs to the GPIO pins, as shown later in this article, and use these to indicate statuses. As well as saving images to the USB stick, you could upload them to an online service, such as Flickr. See the section on wireless networking on the next page for information on how to connect your Pi to your phone.

You could include some sort of switch to tell your Pi which photos to upload, and which to store on the USB stick – for example upload low-resolution images, and store high-res ones. Or you could create low-resolution versions of the images, and upload those.

Gphoto2 has far more capabilities than we use here, including bindings for Java and Python. For full details, check out the project website here.

Of course, you don't have to stop there. If you have a wireless dongle in your Pi, you could use it to run an HTTP server. With some PHP (or other web language) scripting, you should be able to create an interface to GPhoto2 that will allow you to connect from your mobile phone.

Taking it in a different direction, if your camera supports capture options, you could use your Pi to take photos as well as copy them.

Power to the Pi

Powering your Pi

The Raspberry Pi gets power from its microUSB port. This supplies 5V, and the Raspberry Pi Foundation recommends an available current of at least 700mA. This can easily be delivered via a mains adapter, or a USB cable from a computer.

If you want your Pi to be portable, then there are other options. Four AA batteries should provide enough power, provided you have the appropriate housing and cables to get the power into the microUSB port.

However, we found the best solution was to get a backup power supply for a mobile phone that plugs directly into the Pi.

Ohm's Law

There are two key ways of measuring electricity – voltage and current. Voltage (measured in volts) is the amount of energy a given quantity of electrons has, while current (measured in amps) is the amount of electrons flowing past a point. The two are intimately connected by Ohm's law which states: Voltage = Current x Resistance, or V=IR.

You can use this connection to make sure you don't accidentally toast your Pi by pushing too much current into it. The exact setup of the Pi is a little complex. If you wish to delve into it, Gert van Loo (one of the designers) has put together an explanation, which can be found here.

As a rough rule of thumb, you can expect to draw voltage out of a GPIO pin at 3.3V, and you shouldn't draw more than 16mA, or push more than this into an input pin. Remember, this is the maximum current, so you should aim to use less.

So, with Ohm's law we know V=IR, so R=V/I. If we put in the data from the Pi, and want to ensure we don't damage it, we know that R must be greater than 3.3/0.016, which is 206.25 Ohms. Remember, this is the smallest amount of resistance it's safe to use with a GPIO output.

You should aim for a margin of safety several times above this unless absolutely necessary. In our circuits, we've used 1,000 Ohms, which gives us a safety factor of almost five.

Networking

All Raspberry Pi models – with the exception of the Pi Zero – come with a wired Ethernet connection, which is fine for most occasions, but sometimes the cable just won't reach. You could use a USB wireless dongle. However, if you've got an Android phone, and your carrier hasn't disabled the feature, you can use this as your networking device.

This has an extra advantage of not drawing as much power from the Pi, and so makes it easier when running from batteries. You should be able to share your phone's connection to Wi-Fi as well as 3G, so it won't necessarily eat into your data allowance.

Of course, it's best to check the connection type before downloading large files. To do this, connect your phone to your Pi, and enable USB tethering from your phone under Settings > Wireless and Networks > Tethering & Mobile Hotspot. If it remains greyed out, try a different cable.

Back on the Pi, if you type sudo ifconfig, you should then see the interface usb0 listed, but it won't necessarily have an IP address. Networking interfaces are controlled by the /etc/network/interfaces file. By default, there may not be an entry in here for USB networking, so you'll need to set one up.

Open the file with your favourite text editor as sudo – for example, sudo nano /etc/network/interfaces– and add the lines:

iface usb0 inet dhcp
nameserver 208.67.220.220
nameserver 208.67.222.222

This uses the OpenDNS nameservers, but you could use others if you wish. You can now either restart the interfaces or restart your Pi to pick up the changes. You should have an internet connection up and running.

Sending output

Use the GPIO pins to light up some LEDs

The Raspberry Pi's diminutive size means that it's ideal for making your own embedded devices. This can be a great way of creating small computing devices to solve specific problems, as we saw with the camera controller earlier.

However, there is the slight problem that it can be hard to know what's going on inside your Pi without a screen. Fortunately, the designers of the Pi thought of this problem and have added the facility to get information on and off a Pi without the bulk of usual PC peripherals. This is done via General Purpose Input and Output (GPIO).

(Note: if you have a Pi Zero then its GPIO header is unpopulated – you'll need to solder this in yourself).

You may have wondered what the spiky pins near the SD card reader are for – well, you're about to find out. This basic circuit can be used to display information from any source, but here we're going to use it to solve a problem we often have at techradar – finding the final byte of the IP address.

This is useful if you want to remotely access your Pi, but can't configure it with a static IP because, for example, you have to move it between networks. Typically, you can find out the first three bytes from the netmask, but the final one can be elusive unless you have a monitor.

We're going to use the gpio program, which is part of WiringPi. You can find out more about this from theWiringPi website.

It comes as source code, so we'll have to unzip it and compile it with:

$ tar xvf wiringPi.tgz
$ cd wiringPi/wiringPi
$ make
$ sudo make install
$ cd ../gpio
$ make
$ sudo make install

We'll also use bc, so install it with:

$ sudo apt-get install bc

Now, that's enough about software – on with the hardware! Just a quick word of warning before we start – it is possible to break your Pi by connecting the wrong wires together, so make sure you double check before powering up.

The circuit for this is very simple – you just have to connect each output to the positive leg of an LED, then the negative leg of the LED (shorter) to a 1K Ohm resistor, and finally the other leg of the resistor to the common ground. See figures 1, 2 and 3 on this page for details. Once you have your fully-set-up board connected to your Pi, you can make things happen.

To start with, we'll just use the final pin. This is pin 7 (the layout of the pins doesn't follow a numbering pattern). Open up a terminal, and set it to output with:

$ gpio –g mode 7 out

Then you can turn it on with: gpio –g write 7 1

And off again with: gpio –g write 7 0

If you're like us, you'll do that repeatedly until the novelty wears off.

Once it has, you're ready to run the script. It contains four parts. The first just sets the pins to the right mode and makes sure they're turned off:

pins=”7 8 25 24 23 18 15 14″

for x in $pins
do
gpio -g mode $x out
gpio -g write $x 0
done

The second grabs the IP address from ifconfig, converts it to binary, then pads it out with leading zeros, if necessary.

ipaddress='ifconfig eth0 | grep ‘inet ‘ | awk ‘{print $2}' | cut -f4 -d'.”
binary='echo “ibase=10;obase=2;$ipaddress” | bc'
paddedBinary='printf %08d $binary'

The next part uses cut to extract the part we want from this binary string and outputs it to the appropriate pin.

bit=1
for x in $pins
do
out='echo $paddedBinary | cut -b$bit'
gpio -g write $x $out
bit=$((bit+1))
done

And finally, we tell the script to sleep for five minutes, then turn the LEDs off.

sleep 5m
for x in $pins
do
gpio -g write $x 0
done

That's all there is to it!

Create the showIP.sh script, make it executable with:

$ chmod a+x showIP.sh

Then type sudo ./showIP.sh to display your IP. To get this to run automatically on boot, you just need to add this line to rc.local:

/home/pi/showIP.sh &

See the previous Camera Controller section for details on how to do this.

Need more input

We've shown you how to send output via the GPIO, but as the name suggests, they can also receive input. With this, it's even more important to ensure you don't send too much power into the pins.

To get input, just set the mode to input with gpio –g mode in then read the value withgpio –g read .

This hardware can display any eight bits of information, so you don't have to limit it to displaying just IP addresses. For example, you could make a modified version of the earlier camera controller script to use the LEDs to indicate its progress. You can find details on the full selection of GPIO pins here.

The pins we've used are the same in both revision 1 and 2 of the Raspberry Pi, but some have changed between the two versions. If you design your own circuits, or use ones from the web, make sure you use the right pins for your board.

You don't have to limit yourself to just switching pins on and off. The Pi supports a few methods of passing larger amounts of data through the GPIO. The two most common of these are Serial Peripheral Interface bus (SPI) and Inter-Integrated Circuit (I2C).

There are a number of devices available that use these, and plenty of information online to help get you started. So what's stopping you? Get out your soldering iron and build a robot army.

Gertboards and Arduinos

Connecting directly to your Pi's GPIO pins can provide you with basic input and output control, but there are limitations. There are two additional items that you can obtain to help you interact more precisely with the world around you.

The Gertboard is a fairly complete expansion pack for connecting between your Pi and the real world, including a micro controller, and a range of input and output options. It comes as an unassembled kit, so you will have to get your hands on a soldering iron to put it together.

Meanwhile, the Arduino is a micro controller that can connect to your Pi (or any other computer) via the USB port. Typically, it comes assembled, but kit forms are also available. In its raw form, it has fewer features than the Gertboard (which includes an Arduino microcontroller), but it can be expanded with a huge range of shields.

Also check out the official Sense HAT, a plug-in board that provides your Pi with sensors to monitor the outside world. It even comes with an LED matrix to allow you to display data without the need for a monitor.

Last, but not least, the RasWIK is a wireless kit specifically designed to teach you how to build wireless sensors and actuators – and many of its included projects don't even require any soldering.

Raspberry Pi: Everything you need to know

The post Updated: Supercharge your Raspberry Pi appeared first on Tech News Cloud.

The post Updated: Supercharge your Raspberry Pi appeared first on 3Tech | Tech news and Reviews.

Show more