Official THE RASPBERRY PI PROJECTS BOOK 200 PAGES of ideas & inspiration FROM THE MAKERS OF THE OFFICIAL RASPBERRY PI MAGAZINE Welcome WELCOME ust over seven million Raspberry Pis J have been sold around the world. That makes this credit card-sized PC one of the most successful computers the UK has ever made. It’s quite amazing really, that a tiny UK charity, dedicated to making computing and computer science affordable and available to people from all walks of life, should end up with such an incredible success story on their hands. You can learn more about the Raspberry Pi Foundation’s charitable and educational aims at raspberrypi.org, but regardless of what you want to do with your Raspberry Pi – be it for fun, for education, or as a proof of concept for a multimillion-dollar invention – The Official Raspberry Pi Project Book has something to inspire, help, and guide you on your journey. Whatever you decide to do with your Pi, I hope you have fun doing it. Russell Barnes FIND US ONLINE raspberrypi.org/magpi GET IN TOUCH [email protected] EDITORIAL DESIGN PUBLISHING Managing Editor: Russell Barnes Critical Media: criticalmedia.co.uk For advertising & licensing: [email protected] +44 (0)7904 766523 Head of Design: Dougal Matthews [email protected] +44 (0)7904 766523 Technical Editor: David Whale Designers: Lee Allen, Mike Kay Publisher: Liz Upton Sub Editors: Laura Clay, Phil King, Lorna Lynch Illustrator: Sam Alder CEO: Eben Upton DISTRIBUTION MAGAZINE SUBSCRIPTIONS CONTRIBUTORS Seymour Distribution Ltd Select Publisher Services Ltd Alex Eames, Sam Aaron, Gareth Halfacree, 2 East Poultry Ave PO Box 6337 Lucy Hattersley, Richard Hayler & Son, Phil King, London Bournemouth Simon Long, Martin O’Hanlon, Les Pounder, EC1A 9PT | +44 (0)207 429 4000 BH1 9EH | +44 (0)1202 586 848 Richard Saville, Richard Smedley, Sean Tracey, Rob Zwetsloot & many more Pi-loving people! This bookazine is printed on paper sourced from This official product is published by Raspberry Pi (Trading) Ltd., Mount Pleasant House, Cambridge, CB3 0RN. The publisher, sustainable forests and the printer operates an editor and contributors accept no responsibility in respect of any omissions or errors relating to goods, products or services environmental management system which has referred to or advertised in the magazine. Except where otherwise noted, content in this magazine is licensed under a been assessed as conforming to ISO 14001. Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0). ISSN: 2051-9982. rraassppbbeerrrryyppii..oorrgg//mmaaggppii The Official Raspberry PiM Parrocjehc 2t0s 1B5o ok 33 Contents GET STARTED WITH RASPBERRY PI Learn everything you need to know to become a pro with your Raspberry Pi PAGE 06 Projects 60 64 16 MEET THE MAKERS The Raspberry Pi is inspiring a new generation to learn how to hack 20 LEGO-LUTION OF PI The history of the Pi in the form of a Lego diorama 22 RASPBERRY PI CLUSTER A computer cluster built from 40 Raspberry Pis 54 MCMASTER FORMULA HYBRID 64 PIPLATEBOT 24 IDATA TRUCK Raspberry Pi provides the telemetry Unique mini-robot built in an off-the- The Pi-powered lorry that tweets for this smart racing car shelf Pi case back to base 57 PROJECT AQUARIUS 66 COFFEE TABLE PI 26 SNES PI CASE A Pi paludarium to recreate the Amazon An arcade cocktail table for authentic Raspberry Pi disguised as a Super rainforest in the home retro gaming Nintendo console 58 ONE CONTROLLER TO RULE THEM ALL 68 JOYTONE 28 SOUND FIGHTER Retro gaming console-cum-arcade Unique musical instrument made from controller in one box joysticks and lights Duelling pianos battle it out in Street Fighter Alpha 59 DIGITAL ZOETROPE 72 RASPBERRY PI NOTEBOOK A modern take on the classic Beautiful retro-styled mini-laptop 30 RASPBERRY PI VCR animation device computer based on Pi Pi digital media centre in a 1980s 60 IOT CHESSBOARD 74 NIN10DO portable video player A smart physical board for playing This 3D-printed NES homage can 32 LED MIRROR internet chess also play Sega games This Pi-powered panel 61 FLAPPY BRAIN 76 PISCAN is no ordinary mirror Control a Flappy Bird-style game A home-made Amazon Dash product 34 RASPBERRY PI ARCADE with just your brainwaves scanner for rapid restocking Get nostalgic with this wooden 62 LIFEBOX 78 CROWDFUNDING’S GREATEST HITS arcade cabinet Two species battle it out on this The Raspberry Pi plays a pivotal role in 36 #OZWALL ingenious LED box some of the best crowdfunding stories Retro art installation built from antique televisions Tutorials 38 H.A.L. 9000 Fully functioning homage to 2001: A Space Odyssey 88 WATCH IPLAYER 100 HACKING THE RASPBIAN DESKTOP – 40 PWNGLOVE Download BBC TV shows PART 1 Nintendo’s notorious Power Glove as high-definition MP4 files Explore Raspbian’s LXDE desktop is reinvented environment 90 SHOOT IN SLOW-MOTION 42 MATHEMATICA TELESCOPE Shoot slow-motion videos with the 102 HACKING THE RASPBIAN DESKTOP – Use Wolfram’s Mathematica language Camera Module PART 2 for stargazing Change the desktop appearance 92 FACE DETECTION WITH OPENCV using LXPanel 44 #HIUTMUSIC Detect faces in photos using the Retro-style Twitter-powered internet radio OpenCV library 104 HACKING THE RASPBIAN DESKTOP – PART 3 46 POCKET PIGRRL 94 WATER DROPLET PHOTOGRAPHY Customise Raspbian’s Openbox Portable retro gaming in a compact Capture split-second photos of water window manager Game Boy case droplets colliding 106 HACKING THE RASPBIAN DESKTOP – 48 SPACED OUT 96 MAKE A PWM CANDLE LANTERN PART 4 We speak to the Raspberry Pi’s own Simulate a flickering candle with Alter the appearance of desktop near-space expert, Dave Akerman pulse-width modulation applications in Raspbian 52 CANDYPI 98 BUILD A STROBE LIGHT 108 SONIC PI: TIPS & TRICKS Trigger this classic candy dispenser Control multiple LEDs with a transistor Sam Aaron shares top tips from your phone for a strobe effect for his marvellous music box 4 The Official Raspberry Pi Projects Book raspberrypi.org/magpi Contents The Official Raspberry Pi Projects Book Reviews 172 178 148 PI DESKTOP SUPER-TEST Which operating system should power your Raspberry Pi? 154 SKYWRITER HAT Gesture-based control with a wave of your hand 155 ANONYMEBOX Stay anonymous online while using 174 PI-DIGIAMP+ WITH PI-CASE+ any connected computer Hi-res audio DAC and amplifier in one 164 RASPBERRY PI CASE SUPER-TEST small board 156 PIPSTA Four third-party Pi cases are tested 176 SWANKY PAINT Turn your Raspberry Pi into a portable to the max Retro-style paint program for pixel artists printer with this clever case 157 4TRONIX PLAYHAT 166 4TRONIX AGOBO 177 THE FUZE A no-solder, low-cost robot to build Raspberry Pi workstation comprising Beginners’ board for physical computing and play with a case and keyboard 158 DISPLAY-O-TRON 3000 167 KANO OS BETA 2.0.0 178 VELLEMAN 3D PRINTING PEN Stylishly decorated mini LCD display Learn computing concepts via games Is this pen an affordable alternative for your Pi and challenges to a 3D printer? 159 RASPIO DUINO 168 MEARM 180 ADAFRUIT HDMI BACKPACK An easy way to wire up your Pi to an Portable touchscreen available in 5” Affordable open-source robot arm Arduino microcontroller board and 7” models for beginners 160 WEAVED IOT KIT 181 WITTY PI 169 UBUNTU MATE 15.04 Package designed to take the fuss out Set your Pi to routinely switch itself of port forwarding Lightweight version of Ubuntu for the Pi on and off 161 PROPELLER HAT 170 FUZE BASIC V3 182 RETRO GAMING GROUP TEST A handy HAT to help you rapidly Try out the classic BASIC language Three of the best emulator packages prototype projects on your Pi for the Pi 162 PIBORG ULTRABORG 171 PI SUPPLY PAPIRUS 186 EXTRA LIVES Combined ultrasonic sensor and servo Build an e-reader with this low-power The Raspberry Pi is helping to revive driving board E Ink display HAT some age-old gaming classics 163 CAMJAM EDUKIT 2 172 RASPBERRY PI TOUCHSCREEN 192 BOOK REVIEWS Explore the world of sensors with this The official 7˝ touchscreen has A stack of computer books reviewed affordable kit impressive capabilities and rated 112 128 130 110 SCRATCH MULTIPLE-CHOICE QUIZ 128 MOVE A SERVO BY WAVING Amaze your friends with your own YOUR HAND Scratch quiz game 120 PRINTING WITH RASPBERRY PI Control a servo with a flick of the wrist Learn how to install and configure using UltraBorg 112 ADD A SCRATCH GAME TITLE SCREEN a printer on the Pi Make your Scratch game look more 130 STREAM STEAM GAMES TO PI professional with a title screen 122 3D PRINTING WITH OCTOPRINT Play PC games remotely from your Control your 3D printer from any browser Raspberry Pi 114 ADD A SCRATCH HIGH-SCORE TABLE Keep a record of players’ best scores 124 CONTROL YOUR PI REMOTELY WITH VNC 132 MINECRAFT PI CODING TIPS in your Scratch game Learn how to control your Raspberry Pi Pro coding tips and mini programs from afar for Minecraft Pi 116 BUILD A SPACE SHOOTER IN SCRATCH 126 SCROLL TEXT ON THE UNICORN HAT 140 MINECRAFT SPLAT Create an impressive 3D space shooter Use the 8×8 matrix of RGB LEDs Create an exciting two-player paintball using Scratch to display messages game in Minecraft Pi raspberrypi.org/magpi The Official Raspberry Pi Projects Book 5 Feature GET STARTED WITH RASPBERRY PI Raspberry Pi GET STARTED WITH RASPBERRY PI Learn everything you need to know to become pro with your Pi 1 The little Model A+ The ingredients you need ongratulations! You’ve C got yourself a brand 2 Set up your Raspberry Pi new Raspberry Pi and As well as the ‘standard’ Raspberry you’re ready to start using it Pi, the Raspberry Pi 2 Model B, there’s 3 for learning code, creating also a smaller version of the Raspberry A tour of Raspbian amazing projects, or just simply Pi that you can use. The Raspberry to power a home theatre. While Pi Model A+ is a cut-down version of 4 Installing & updating software the Raspberry Pi is generally the original Raspberry Pi, with a little very easy to use once you know less power at its disposal and fewer 5 Use the GPIO pins how, it’s that initial learning connections on it. It’s favoured by experience that can be a bit people who like to make big physical tricky for some. projects, due to its diminutive size and Have no fear, though: we’ve low power requirements. It also has put together the ultimate guide only one USB port and no Ethernet port, Let me help to getting started with your making it slightly less useful to some. you get started very own Raspberry Pi, from learning what all the ports and pins on your Raspberry Pi are for, to actually getting it up and running with your own monitor, mouse, and keyboard. Whatever you want to use your Raspberry Pi for, you need to start here with the basics. 6 The Official Raspberry Pi Projects Book raspberrypi.org/magpi Feature GET STARTED WITH RASPBERRY PI THE INGREDIENTS FOR A RASPBERRY PI 2 USB ports Ethernet port 1 The Raspberry Pi 2 has four USB ports, The traditional way to allowing you connect it to keyboards, mice, connect to the internet WiFi dongles, and USB sticks containing is via a wire called an all your files. Since the ports don’t provide Ethernet cable. You’ll much power, if you want to add a USB hub find a few similar ports to the Pi you’ll need to find one that comes like this at the rear of your with an external power supply. router at home that will let you connect the Raspberry Pi directly into it. This method GPIO header is easier to set up than WiFi and This comprises the general- may provide faster internet, but purpose input/output you’re then limited by the length (GPIO) pins. They’re a set of of the cable. connections that have various functions, but their main one is to allow you to connect to the Raspberry Pi with an electronic circuit. You can then program the Pi to control the circuit and do some amazing things with it. Audio out This looks like a headphone socket because that’s exactly what it is. A 3.5mm jack to be precise, this allows you to connect the Pi to computer speakers, or you could even plug in your favourite headphones and have a Raspberry jam. MicroSD card slot A little SD card is used as the Raspberry Pi’s hard drive. This is where the operating system will live once you’ve put it on there. Most computers won’t be able to directly connect to a microSD card, but you can get an adaptor that plugs into normal SD card slots. Power This is the kind of small charging port you might find in your HDMI port smartphone. This micro-USB This is an HDMI port, the kind you’ll port means you can power the find on the back of most modern Pi with the right kind of mobile TVs and computer monitors. Use phone charger or directly from a standard HDMI cable to connect your PC – however, it’s best your Raspberry Pi to your chosen to use the official Raspberry Pi screen, to see (and hear) whatever power supply to make sure the Pi it’s doing. You’ll definitely need to is getting enough power. plug it in to set up the Pi. raspberrypi.org/magpi The Official Raspberry Pi Projects Book 7 Feature GET STARTED WITH RASPBERRY PI CONFIGURATION TOOL TABS The four tabs in Raspberry Pi Configuration allow you to set up various aspects of your Pi… SYSTEM Here, you can set whether your Pi boots to the desktop or the command line (CLI), set up autologin, and change password. There is also an overscan setting which is useful for getting rid of the black border around your desktop if there is one. INTERFACES Under this tab, you can enable or disable various interfaces on the Raspberry Pi, including the camera and other connectors. PERFORMANCE Here, you can set up overclocking and SOFTWARE GPU memory allocation to optimise CONFIGURATION TOOL performance for the particular task you Once Raspbian has booted and is Since Raspbian doesn’t take up want to perform (e.g. HD video playback). showing the desktop, click the much space to begin with, you Menu button at the top left of need to tell it to use your entire SD LOCALISATION the taskbar to open the main card if you want to make use of all This tab enables you to set up the correct menu. From there, select the the free space on it to store files. language, time zone, and keyboard layout. Preferences option and then So, click the Expand Filesystem Raspberry Pi Configuration from button under the default the submenu. System tab of the Raspberry Pi Setting up a media centre This opens a tool which can be Configuration menu, and then used to configure various options reboot your Pi when prompted – on your Raspberry Pi. Note that choose Shutdown from the Menu, you don’t need to change most then select Reboot and hit OK. of these options at this point, Read more about the but one that is important is the configuration tool’s other options ‘Expand Filesystem’ option. at the top-right of this page. We touched on OpenELEC on the previous page, and how it can be used to make a home theatre PC. This is a PC that hooks up to your TV and powers all your media needs. You can find OpenELEC on NOOBS, and installing it is very similar to Raspbian: you select OpenELEC and hit Install! OpenELEC runs on Kodi – software that lets you connect to your other computers over the network, as well as some online web services such as YouTube. It can play just about anything, but you need to show it where the files are. When adding folder locations to either Video or Music, you can find any shared folders via the SMB option, or you can simply plug in a USB Various options are available under the hard drive full of videos and music and play them four tabs, including straight from the menus. enabling interfaces 8 The Official Raspberry Pi Projects Book raspberrypi.org/magpi Feature GET STARTED WITH RASPBERRY PI SET UP YOUR RASPBERRY PI 01 DOWNLOAD NOOBS Hook it up, The Raspberry Pi comes with many 02 install it, operating systems you can use, use it! which you could manually install INSTALL SD CARD yourself if you wish. There’s a While that’s downloading, you’ll much easier way to install these need to get your SD card ready to OSes, though, and that’s via work on your Raspberry Pi. This the New Out Of Box Software, will require you to format it, so or NOOBS. It holds all the latest if there are any files on the card versions of the Raspberry Pi you want to keep, now’s the time operating systems and you can to take them off. You’ll need to grab it from the download page at: install the SD Card Formatter 4.0 raspberrypi.org/downloads. tool to prepare the card, which We prefer to use the full version can be downloaded from the SD of NOOBS, as it comes with Association: bit.ly/1alC3Wp. Raspbian already downloaded, Once you’ve formatted your making the process slightly faster SD card, extract the files from than with NOOBS Lite. However, the NOOBS zip folder and put all the other operating systems will them all on the card. That’s it: be downloaded as they install, on NOOBS is installed to your SD both versions of NOOBS. card and ready to use! 03 CONNECT THE CABLES Take the SD card adaptor out, retrieve the microSD card, and slot it into the Raspberry Pi; this is very important, as the Raspberry Pi won’t be able to turn on properly otherwise. To start with, you’ll need to plug in an HDMI cable between the Raspberry Pi and your screen, an Ethernet cable for your router (or a USB WiFi dongle), along with a mouse and keyboard. 04 Finally, when everything you need INSTALL RASPBIAN is plugged in, you can attach the power cable to the Raspberry Pi. The Raspberry Pi will turn on and display some text on the screen – you can ignore this until it gets to Alternative operating systems a menu which lists all the available operating systems. It allows you to PIDORA ARCH OPENELEC RISC OS select multiple OSes at once, but A bit like Raspbian, A very basic operating An OS to turn the A throwback to your right now we just want to use the but based on a different system that works entirely Raspberry Pi into a school days, RISC OS one that’s called Raspbian. This is core operating system. from a command line, home theatre PC, is what used to be on the main operating system for the This is something no mouse and keyboard complete with the Kodi old Acorn computers. Raspberry Pi, with all the official people a bit techy required. You’ll really need software that plays The Raspberry Pi is in apps, software, and learning can use for a slightly to know your computers music and videos as many ways derived documents. Upon selecting different Raspberry Pi. to start with this. well as web video. from them. Raspbian, click on Install and it will begin the Raspbian installation process, which may take a little while to complete. raspberrypi.org/magpi The Official Raspberry Pi Projects Book 9 Feature GET STARTED WITH RASPBERRY PI A TOUR OF RASPBIAN Access the various These icons let you quickly The various open windows This area offers Top menus, programs launch certain programs, are listed on here; much quick access to right and settings for such as the browser, like in other operating tools such as WiFi icons Raspbian; almost the terminal, and the systems, you can click to ensure your everything you do Mathematica programs for between them when you Raspberry Pi is will start here hardcore maths and graphing need to change location running just fine WIRELESS INTERNET This shows the state of your internet connection; solid blue lines means it’s connected! VOLUME Control the volume of your Raspberry Pi from here. This will work whether you’re getting sound from the HDMI port or via headphones. PROCESSING POWER Programs and apps are Windows here work just The Raspberry categorised to make them like any other kind of Raspbian should Pi, while small, easier to find – if you can’t operating system: you feel familiar to has a lot of find the app you’re looking can drag them, change most PC users processing for, you might need to go their shape, and close power. This through all of them them using your mouse tells you how much is in Raspbian looks and works very The Menu is where all the programs software. The globe picture is the use, so if it’s similarly to the kind of operating and apps live; just like in any other Raspberry Pi browser, your access running a little systems you’re used to, except operating system, you can access point to the internet. The cabinet slow and this that the menu is now at top of them from here and they’ll open represents the file system of gauge is at the screen! Raspbian is based on up in a new window. You’ll find all Raspbian, allowing you to browse 100%, you’ll something called Debian, which know why. is a version of Linux, a highly The cabinet represents TIME customisable operating system that Set the time to can be tweaked enough to run on the file system of Raspbian be anywhere the Raspberry Pi. It works extremely in the world! well, and even on the tiny Raspberry The Raspberry Pi it will almost feel like using the settings in here as well, in case any documents or images you have Pi relies on the a normal computer! you want to tweak the way Raspbian saved onto your Raspberry Pi. The internet to tell There are a few important icons looks and works. picture of the screen is the terminal, it what time on the top panel that you should Next to the menu is a row of and it’s what you use to run it is. make sure you’re aware of. quick-start icons to quickly launch commands via text on the system, 10 The Official Raspberry Pi Projects Book raspberrypi.org/magpi