You are on page 1of 78
NEW EASY TO FOLLOW USER GUIDES tag A aNd RASPBERRY PI Se Enea een eee eg PES En aie MC cam aruker tea you have no-one at hand to help. Conversely as the complexity CoRR eee ele Ae MU Rem at Cy instruction manual decreases or in some cases it simply disappears. Pa lee Ce ae a RICE) Pesca ore A Cd PM ccseu hee CMCC) FT le F- Lolo MLC Lae (RUT ecole OFM Nae (or cine nr aol cae a ee h eM nee h UL ee ee aCe Pe RET en RICE seine antec Naeg SECU Reu eeepc eas ee tea Co scatter De Coes ate ecm eRe RUC co aN MMR Ce Deemer ueeaMCie F-11f aspects of the technology that you may have been previously EEC a eetcat cs Nett at WC One Ene ae hte nic PRT cnent iced Over the page our journey begins. We would wish you luck but Rerun cust ass Contents Contents 10 7] 4 16 7 20 2 ry 26 rr Et) 7 ASlice of Raspberry Pi Say Hello to Raspberry Pi mean oda eran owe} eee eon Ore ecu) canta aca ced oso so) Pann Exes ted Sayer aE Po onan) ee ciad io enc CRU Pc Pega Debian Stretch Nee wu barmpublications com 2 44 cy Pe eeRC Exploring the Command Line Src a err Conca y eae Poesia ca Get More from the Terminal App Terence Ee ea RT aaiale) 48 50 52 34 56 58 a 2 Cy cy 6 7) 7 Bilt Meenas Citi nao sca Tee Dn cd Coronas Cer ih et ec Corer Renaming Files Ceci Er ae Cour ece! Cicero emacar ics Perec ead Bieta Input, Output and Pipes OTE Oh lke es ‘where to buy’ rN "unleash or TOY ano with the power of: the Raspberry Pi..." V ordmpubs Teeter een 3 New to Pi? Where to Buy? New to Pi? Where to Buy? TMCS Reus MeN Ree ete ok me Pt esa iar ats ete eeu tac ge ee internationally. Let’s look at the top four Pi sellers. ‘Opena browser and navigate to https:// [uxsibby thepihut.com/collections/raspberry-pi. The Pi Huts one ofthe most popular online shops for al things aspery Including the tse ares HAT, kts nd bundles cables, addons and much more Prices vary depending on what youre Looking or, but theyre some oF the est round Q Be] On its release in 2012 CPCFarnell was one ofthe original resellers of the Raspberty Pi, Therefore, not only does CPC stock ahuge amount of Prelate goodies, butts also one ofthe premier global online electronics stores. Browse the Pi section at: hetps//cpcfarnelL.com/c/maker-circuit-development/sngle-board- computers-microcontrolles/raspberry-p Q Ee ‘With its huge range of Raspberry Pi products, including all manner of maker accessories, kts, parts and ‘addons, Odo is one ofthe top go-to stores For all the tinkerers, ‘outthere. Youll find the Pi section of the shop at https://www. ‘okdo.com/product-category/raspberry-pif, so hunt around and see what's available, Poneto ie onmteoney Pmaisasipesrtefrtiees ne anos ‘everywhere, Found at httpsi//shop.pimoroni.com/products/ Sionyseanenstryn beste eye a - - Q a les Saad] Naturally, you don't have to go through any ofthese recommended stores. Look around the Internet and youll Find plenty of other De Oe ce eS ne ed Ceca Coletta NP) = ans A Slice of Raspberry Pi Do you already own a Raspberry Pi but don't know what to do with it, or are you on the verge of purchasing your first Pi? This section of the book will help you build the foundations required to get the most from this amazing, tiny computer. 8 A Slice of Raspberry Pi fete} Treat ene Geeta ee eee ee eer ertaeca mat) eee eet eee Rear Per orate ere echo ciate teeter tee Pour reer Mem r eC ena crear Ethernet, improved mass storage, USB booting, improved thermal oe eee cer ae et Bein eee eer arene pics eee Ponerinae cre etree eet ‘The Raspberry Piis a British built low cost computer that enables everybody to learn computing, start programming and ‘explore basic electronics. I’s the size of 2 credit card but capable of running a full, ‘operating system and doing everything a desktop does. ‘More importantly, withthe Raspberry Pi you install your own operating system, Connect all your devices and create your ‘own programs using languages like Scratch ‘and Python. There's no case so you can hook ‘up electronic circuits to the pins and control them to get input and output, so you can hack together electronic projects at home. Setting up a Raspberry Plis pretty simple, {and throughout this book we'lltake you step-by-step from unboxing your Raspberry Pi to setting it up and getting started There are many different models of Raspberry Pi available and each has slightly different Features (see opposite). ‘The fundamentals of each Raspberry Pi are Peer ee antec geer ere Tos Seer tie Cees Say Hello to Raspberry Pi 8 similar though. Each models a lightweight computer on asingle board that’s roughly the size ofa credit card, Each Raspberry Pi board features a processor made by ARM, which s similar to the madels you find in ‘mobile phone. The ARM processor's Fast and lightweight butt runsa different set of software than you might be used to. There are many different operating systems (05) available, but for most ofthis book well Focus on one called Raspbian JESSIE wth PIXEL, which isthe OS recommended by the Raspberry Pi Foundation, “There's no hard drive on the Raspberry Pi, instead the operating system is installed ‘on an $O Card (the cards typically used in cameras). The operating system is installed ‘onto the SD Card by copying the files to the SD Card using a computer. Well show you how to set up Raspbian JESSIE with PIXEL {end other 05'5) using a Mac, Windows or Linux computer. (Once you have an OS installed on the SD Card you can set up your Raspberry Pi. The ‘There's also an Improved CPU, dualmonitor support inthe form of Bitiece ire sear inmec enc RY eens Phere et H Brenna Se nee Raine) Goer Raspberry Pils connected to a monitor via HDMI socket whist akeyboard and mouse isattached to the USB socket. Asmaller Micro USB connection is used to provide power to the device. Most Raspberry Pi models Feature an Ethernet connection, ‘and an Ethernet cableis connected from your Raspberry Pito a socket on your modem router. ‘The Raspberry Pi 3has builtin wireless networking and Bluetooth, making it easy toget online. You can attach a USB WiFi dongle or Ethernet adaptor to older models. First will help to know which Raspberry Piyouare using. This can be tricky as there have been several distinct models so far. The layouts opposite will help you determine hich Raspberry Pi you have, ‘This book covers all the different models, and they offer largely similar Features, although newer models offer additional ‘extras. Once you know which Raspberry Pi you own, you can gett up and running. inle-core CPU and fang inna pee cor Brerens ceed Pcie ge ores 8 A Slice of Raspberry Pi Get to Know the Raspberry Pi While the Raspberry Pi 4 is the newest model, the Pi 3 models are the most popular among the community. They're cheaper, more compatible with current hardware and software, and still pack a significant performance punch. Here's what powers the fantastic Pi 3. Get to Know the Raspberry Pi 8 8 A Slice of Raspberry Pi Up Close with the Raspberry Pi 4 Model B FASTER AND CONNECTED ‘There's lotto like about the Raspberry Pi 4: Upto 4GB of on-board memory a aster quad-core CPU, support For dual 4k displays via a pair of micro-HOMI ports, and more, Lets take a look atthe Pi 4 and see whatits got under-the-hood Lease ne) Se aetna’ See aera ee eens De eee ae ne Creer nt Neier een) ‘£44, while the top-end, 4GB memory version will set you ‘backin the region of £54. Together with the cost oF the Pi ee een ee eee tec ‘ables (depending on whether you want to connect one oF ‘two monitors), each costing roughly €Splus. Up Close with the Raspberry Pi 4 Model B a USB 3.0 See ener Pret om Faster data bandwidth of get Toe Petoee eto) Suen Cec prea rs esas Pare om) See Reed memory: 1GB, 2GB, cave teeny CeCe Bein Pee eer err the Pi Ws ASlice of Raspberry Pi Raspbian: The Complete Operating System Dagon Curse une Tees oe Om the Pi is primarily an educational and project board, with Raspbian, it does become a fully- cco ao tect POWERING THE PI “The Raspbian OS has been powering the Raspberry Pi since release bbackin2013.Atits core, Raspbianisa Linux operating system, basedon the hugely popular Debian Flavour of Linux (Mike Thompson and Peter Green created Raspbian in2012, to workon the low-performance ARM CPUs found in the early Pi models. Toward the end of 2014, Raspbian was Further improved to work on the then ‘new model Pi, the Raspberry PZ; utlsing the 3.18 Linux kemel while stilhaving Debian 7 (codenamed Wheezy) asthe base. ‘Mid-way through 2015, Raspbianstartedusing Debian ‘8 Uesse) asthe base, with kermels4.1,44, and 49, Kernel 49 was also used From 2017's Raspbian release, which has since used Debian 9 {Stretch asthe foundation distribution. More recently, from November 2018, the Raspberry Pi Foundation has split ‘the Raspbian OS project into three separate distributions. Although these ‘are essentaly the same core operating system, those avalable now are a Lite, ‘Minimal and Full desktop set of images. ‘One ofthe primary reasons forthethree- way spit is due to the overall size of the ‘continually improving Raspbian. nts early years, the Raspbian desktop image size \was 2 little under 1B. This image contained ‘everything the Pi user of the time needed to get their projects up and running, 2s well as enjoying third-party applications such as LibreOffice. Slowly, 2s the Pi itself evolved, the Raspbian image increased. These days the image weighs in at around 1.8GB and it's kely to continue to expand over the coming years as new software is improved on and ‘added, alongside changing hardware. However, the three-way split addresses the ise ofan everexpanding OSimage, while stil enabling the userto get the most from their Raspberry i. ‘The Lite version image comes in at roughly 350MB in size. While it may seem lke 3 logical choice to opt forthe Lite versio, i's not recommended for every user. The Lite version basically intals without ‘any ofthe software you expect from the previous versions of Raspbian, It doesrit even come with the graphical desktop. This makes it an Incredibly streamlined and efficent version of the OS that's ideal for those who run headless Pi servers (a Pi without a monitor, keyboard or ‘mouse attached, that the user remotely connects to in order to input commands). You will need to know your Linux commands in order to get the most From the Lite version, o for most beginners it's not a ‘900d place to stat. The more advanced users will however, be able to setup their Pi projects without the unnecessary baggage ofall the ‘ther applications logging up the Ps precious system resources. l’s worth noting thatthe Lite edition can be made upto afuly Functional File Explorer and choose the SD Card inthe sidebar. The drive should be empty, but we will copy the files to tin the next steps. For now just make sure that you can ‘access the empty root ofthe SD Card COPY THE SOFTWARE Continue making your SD card by copying the files across. 'ANOOBS folder should appear in your downloads err eee tS Tere ee meee ry ea ee eter ons Porter ister2 Click Extract Alto expand the zipped File and extract Peete Cent ete Een ree en atte eet nee ete te eee oy be copie directly from the zip ile to your SD Card. Ee Now it’s time to download the NOOBS software from the Raspberry Piwebsite. Opena web browser and enter https://wwwraspberrypiorg/downloads/noobs/ into the URL field Scroll down to find the NOOBS section (not NOOBS LITE) and click Download Zip and Save. A zip ile containing the NOOBS filesis copied to your Dovinioads Folder. lick Open Folder when itis done. a Core eee Ton the sidebar to display the contents. It should now Peter re can Pe eee eee rat ee ar and BUILD-DATA files along with the other Files shown here. Remove the SO Card from your Windows PC l’snow ready tobe inserted into Seana 8 A Slice of Raspberry Pi The Raspberry Pi Desktop: What You Will Need 12016, the Raspberry Pi Foundation started work on an x86 version of its popular Raspbian operating system. By the end of the Following year, there was a lnk on the Downloads page and nor-Pi owners could now install and use Raspbian in almost the ‘exact same way as if they were in Front ofa Raspberry Pi. ‘The Raspberry Pi Desktop (x86 version) allows you to view the ‘same desktop and pre-installed software as the Full Desktop version avalabe for the Raspberry P. You can instal on any decent PC, or laptop, one thats at least six or seven years old would be perfect andasa PC that age usually struggles with the latest version of Windows 10, you can now install Raspbian instead of boxing that old kit and resigning it toa life of satheringdustinthe oft me ~ ee The major differences that this version has been compiled to run (on x86 processors, that's Intel and AMD PC processors. Whereas, the version of Raspbian that you wil Find ona Raspberry Pi has been compiled and created exclusively for ARM processors the type of (CPUa Raspberry Pi uses. These CPUs use afferent architecture tothat ofan intel or AMD CPU, so the software required to un on ‘one won't run on the other unless the developer has specifically made either an x86 or ARM version In short, iFyou've Found a piece of software that you enjoy using on your Raspberry Pl you won't be able to use ton the Raspberry Pi Desktop x86 version - UNLESS, there's a dedicated x86 version ofthe software. Since then, the Raspberry Pi Desktop, or asit's correctly called: Debian Stretch with Raspberry Pi Desktop, has followed the same release path asits Prbased sibling. However, there are some differences you need to be aware of prior to throwing your away and opting for this version instead. ‘Another caveat worth mentioningis that you wontthave access to the 40-pin GPIO thatthe Raspberry Pi features, a this isn'ta standard piece oFhardware on a normal PC, There is, however, a way around this. Ifyou own a Raspberry PiZero (ether with or without the W), then you're able to connect the Zero toa spare USB port onthe PC, via the Zero's miro USB port and the Raspberry Pi Desktop 05 wil recognise the Zero as extended hardware and allow you access tothe Zero’ 40-pin GPIO, which, you have to admit, pretty clever stuf. The Raspberry Pi Desktop: What You Will Need 8 WHAT YOU WILL NEED Here's alist of items needed if you want to test out the latest version ofthe Debian Stretch with Raspberry Pi Desktop OS on your PC. sonnet fet ans sees raspberrypi.org/downloads/raspberry-pi-desktop/. ‘node destopPCor laptops anes (Ngo edue candidate For running the Raspberry Pi Desktop Os. whieyoucan easy uethe ates Pcfaptn sat ovr for tisparticar operating sytem Pe yfatd The best method of transferring the 50 toa PC for installation isto use a combination of atool suchas. Rufus (found at https//rufusie/en_IEhtm), whichis apiece oF sofewate that can crete a bootable USB driver From an ISO ile and, at least, an 868 USB stick Pia aente) Although not strictly a necessity, a spare Raspberry Pi Zero will allow you toaccessthe 40-pin GPIO from within the Raspberry i Desktop OS. If however, you don'thave a spare Zero, its not a problem as there's stil plenty you can do with Raspbian ona PC. 8 A Slice of Raspberry Pi Debian Stretch with Raspberry Pi Desktop 10 THINGS TO DO WITH X86 RASPBIAN ‘You can do just as much wit ths version of Raspbian as with the dedicated Pi version and to demonstrate here's ten great projects to do with Debian Stretch with Raspberry Pi Desktop. PEST eM) This version ofRaspbian apes the Full Desktop version forthe Raspberry Pi, meaning it comes wit all the necessary programming languages out ofthe box. Learn Python, C+, Use the HAT emulator and even learn JAVA. Ital there under the Programming menu option. Hook up a Pi Zero without an SD installed, select (GPIO Expansion Board from the options and you willbe able to tak to the Zero's 40-pn GPIO va the likes oF Python ot Scratch. By doing so, yout have allthe benefits ofa Raspberry Pi, with the power of your laptop. PYM stared 85 the x86 version oFRaspbian follows the Full Desktop Pi version there's an entire office suite preinstalled allowing you to use that old laptop or PC as fully functional desktop replacement for Windows or macOS. LibreOice is ‘also Microsoft Office compatible. TST ent tay As with most modem operating systems, youcan browse the Internet exactly as you would with Windows 10, the latest macOS or similar and because ths, ica Linux-based OS, there's an added element of security, as it won't be affected by Windowstargeted viruses. 50a Eee Hy Debian Stretch with Raspberry Pi Desktop 8 LINUX X86-BASED SOFTWARE Jiabao version of Linux youcan naturally install ary ofthe tens of milion of Linux x66 based sofware ‘currently avaiable Remember though only software that has both an [ARM and an x6 version wil work on both the Pi version and this version of Raspbian. RECOMMENDED SOFTWARE MSA avafable wth his verson of Raspbian This tol alowayou to plckand ‘hose which the Psfvoured sftae you aor remove Sin vekthe box next tote name ofthe app, soo a8 By {t's easy to use SSH From within the Raspberry Pi Configuration tool Select the Enabled option and then use a en, such as PUTTY, to SSH into the OS. Here we've enabled SSH and ‘eonnected From another Windows PC, using PUTTY asthe SSH dient. "Neither the Raspberry Pi or the Pi3 Model B+ are the most powerful computing devices available. Your older laptop is probably significantly more powerful buteven so, you wil be able to play games ike Minecraft without too much trouble at all retro gamingis more toyour tse, then GU DEMONS Debian has a huge number of retro erltersavalable covering both consoles and ore computers You wince legal ROMs however to ay the games, ut these are widely aval om repuablestes | CAMING Of course, there's an equally large selection of modern ‘gaming available For Debian; most oF which wil run perfectiy well under Raspbian in an x86 envionment. Youwillneedto Google what's available and try outa Few examples. thelist issimply too big to mention Ws A Slice of Raspberry Pi Debian Stretch — Virtual Desktop Dor't have a spare PC handy for Debian Stretch with the Pi Desktop? Then consider a virtual CMCC MEM n Manatee Mae euch iat Mog et aged noe GOING VIRTUAL You'l need a copy of VirtualBox to download and instal, which you can Find at https//wwwuvirtualbox.org/wiki/Downloads. Windows users dick on Windows Hosts, macOS click OS X Hosts. EEa Install the downloaded VirtualBox for your system by following the on-screen instructions Next, download the Raspberry i Desktop SO from hetpsy//wwwraspberrypiorg/ downloads /raspberry-pi-desktop/ Start VirtualBox and from the ‘menu, click Machine ~ New Ele the Type to Linux, version to Debian (64bi, and name it Raspbian. Click Next ad Follow the default options. EEE ‘When asked “Install the GRYB boot loader to the master boot record?" Select Yes, and choose /dev/sda; ‘after brief time select yes to insaling a GRUB boot loader Followed by the sda drive identification (nat the Manual option). Once installed, lick Continue to reboot and youl se the Raspbian desktop load up. Name and operating system TE eae cheese 3 descrpave rare and destraten elder fr he new tu iecine wn eect te tps of perong sytem yout ntl on ‘Tae nan yu coor il bees rough ton deny tae eel Machine Folder: | | | ¢:\sers\daviditwaBox VMs ¥] oy i@ Dp io Tei ili tar agtitap ‘oo SE oe ED meow sudo apt install build-essential module~assistant dims sudo ma prepare ‘Answer yest install packages. Click on Devices in VirtualBox, followed by insert Guest Additions CD. n the Terminal enter sudo sh /media/edrom/VBoxLinuxidditions .run ‘Star the newiy created machine andthen locate the ‘downloaded Raspberry Pi Desktop ISO. Inthe menu titles ‘Debian GNU/Linuxinstaller Boot Menu’ use the arrow keys and select Graphical Install Press Enter and Follow the on-screen installation instructions Use the Guided - Entire Disk option when asked, then Write Changesto Disk sudo reboot ‘You can now adjust resolution via Menu > Preferences > ‘Screen Configuration, Discovering Raspbian INDEX Discovering Raspbian The Raspbian operating system is a Linux distribution that comes fel c-meFelol CoML Elna! collection of programs and apps to help you get the most from your Pi. Raspbian enables the Raspberry Pi to become a fully functioning desktop computer and with it, you can code in the latest version of Python, Scratch and more. 3 Discovering Raspbian Take a Tour of PIXEL Rue Maes Moca m meee Tei ssaa koa OMe ee nue h ie ci Sur tone sa Wececel ies NAPs scan teas Phen Ontnus es mane ure emcee tact irc PIXEL PIXEL stands for “Pi Improved Xwindow Environment, Lightweight”. I’ a lightning fast and energy saving desktop that looks good too. contains almost everything youl ever need to work with the Pi 4 ‘The PIXEL interface is a module thatsinstalled ‘ontop ofthe core OS. thas seen some Improvements over the years, and withthe release ofthe Pi4 and Raspblan Buster, it now looks like this. Preferences > Main Menu Editar, then add or remove ticks next to programs and sections you want to inlude\exclude. Use ‘Move Up and Move Down to rearrange items inthe Menu. CUSTOMISE THE DESKTOP [ Take a Tour of PIXEL EI {t's important that you switch off your Raspberry Pisafely. When you refinished with your Raspberry Pisession click Menu > Shutdown, Three options appear: ‘Shutdown, Reboot, and Logout. Click Shutdown, Always wat For the ‘screen to go blank before removing the USB power. ‘Aswith any other operating system desktop, youre ableto customise the Raspberry Ps PIXEL interface, making it more personaland more you. TSTTISTa aly Choose Menu > Preferences > Appearance Settings to open the Appearance Settings window. There are four sections: Desktop, Menu Bar, System, and Defaults. You can use these to adjust the various options For your system, such as colours layout, and so on. MenuBar Sytem | Defauts Fisceenwanimage Guenpiees . PSR) eres ores tesa PEE eANL a the desktop wallpaper, or desktop background. The defaced Temple; however by citing on ‘temple inthe Picture section ofthe Appearance Settings, you have other images avallable. Naturally, you can opt For your wn. stots ge (2102 The secondtabinthe Appearance Stings window ete allows you to adjust the menu bar that runs along thetop ofthe desktop. Youcan change Rs sie, colour andevenits lacation rm he opto the bottom ofthe screen ena tar Spm | Deets Ew “The System tab in the Appearance Settings window will tenable yout change the core system Font, as wellas the ‘mouse cursor sie. There are numerous Fontsto choose from and, IF ‘you want, you can even install your own. www bdmpubliatonscom 33 8 Discovering Raspbian Exploring the Command Line USING TERMINAL Despite its graphical PIXEL interface, Raspbian sa Linux operating system and this means: \Uspend alot oftime working with text ‘commands. Using the command ine is an important part of learning to use a Raspberry Pi computer. EEa By default the Raspberry Pi boots directly into the PIXEL interface. Here you use a visual metaphor Files, buttons and soon, to make changesto your computer. The command lines where you control a computer by entering text commands. lick Terminalinthe Menu bar to view the console % O0R+ 0 Bean Bez ‘You can enter commands into the Terminal to make changes tothe computer. This works alongside the PIXEL InterFace. Enter: and press return. Notice a new Folder appears below the Trash on the desktop, Drag it to trash to get rid oft. You can use the Terminal and PDXEL, ‘environments alongside each other. 34 wu bdmpubleationscom ("pi by default) and password ("raspberry” by default) cn toeach one inthe First instance but ean then jump back and forth between them. Raspbian GMU/Linux @ raspberrypi tty6 ee eo Exploring the Comman Line & Ea Press ControlAltF1 to return to the PIXEL interface, Bea ‘Some users prefer to use just the command line, One thing to realise i that PIXELisjust a program Open Menu > Preferences > Raspberry Pi running ontop ofthe thy! session Open Terminal and enter: configuration and choose To CL! and click OK and Yes. The ‘Ouch, there goes your desktop. Dont wory, enter: Raspberry P will now boat into the command line interface. Enter: to get t back again. Most ofthe time you just enter to get back to PIXEL, open Raspberry Pi Configuration and commands into the Terminal window on top ofthe PIXELenvironment. choose To Desktop to go back to normal, 5 ODEs 0m uw © OE & © Ere 6 OES + @ Ee 3 OOS 0 Es 5 OE + 6 Ee wunbémpubleatonscom 35 8 Discovering Raspbian Setting Up a Static IP Address DHCP RESERVATION Now that you've set up your Raspberry Pi and connected itto the network, you should take time to Fixits IP address. This will makeit alot ‘easier For youto connect to the Raspberry Pi froma Mac or Windows computer and share files EE ‘When you connect your Raspberry Pitoa network, the router (or ‘modem/router assignsita ‘number known asits IP (internet Protocol address Thisisa block of four digits and the fist three are usually 192.168.0. After thatisa digitfor each electronic device Bez The router typically takes the First address, so itis usually Found at 192.168.0.1. That numbers reserved For the router. Often youl Find this number on your outer marked ‘web address". The router then assigns similar IP address numbersto the other devices you own a they ae added tothe network, so 192.168.0.2 might be your computer, 192.168.03 your smartphone and 36 wwbdmpubleationscom EEE To find out what number your Raspberry Pils using lick on the Terminal icon and enter: fonts and press Return. You should ind t next to net add”. The challenge is thatthe router assigns this number using DHCP (Oynamic Host Configuration Protocol). When the Raspberry Piis unplugged it reuses the number and your Raspberry Pimay get a different number, next time. 308 6 © Emisons EE {ts better all-round if you can get the Raspberry Pi to use the same Paderess everytime you connect itto the network. You do this using DHCP Reservation. Thisis where you tellyour router to remember the Raspberry Pi address, and only use that address From now on. tart by opening the Chromium Browser ‘and entering 192.168.0.1 to connect to your router's web interface. Ea ‘We're using a Virgin Broadband router but the processis similar on most routers. Google thename ‘of your router and “DHCP Reservation” tofind the router you're Looking For. Enter your admin password (our default password was, listed on the back ofthe router). Click Advanced Settings > DHCP Reservation. the DHCP Settings section you wil find allof the devices connected to your network. Scroll down and ind the one with the same IP Address listed in Step 3. MANAGING YOUR DHCP DEVICES Setting Up a Static IP Address 8 Bea Select the device using the check box on the right and scroll down tothe Add Reservation section. It should have filledin the Device Name, MAC Address and IP Address Fields. IF the Device name's “unknown” change ito "raspberry". Click Add Reservation to ensure italways uses that IP Address. lick Apply to enforce the changes. Now that you have set up a DHCP Reservation, you need to understand how to manage the different devices that may need to useitand connect to the IP EE ‘Now that you have set up your Raspberry Pi with a DHCP Reservation it ill aways connectto the router using that IP Address. You can check this at any ime by entering contig into terminal. The router always knows that itis your Raspberry Piby checking its MAC address. Thisis the set oF si hexadecimal numbers next to HWaddr"in ifconfig. 5 OCs 0 sma EE Ifyou decide to free up that IP Address so other devices can use you can remove it from the router ‘Open the router web interface (192,178.01) and click Advanced Settings > DHCP Reservation, Scroll down tothe IP Lease Table to find the Raspberry Pi Selec the check-box next to itand click Apply and es, poe cor Ea ‘Your Raspberry Pi will till have the same IP Address butitisrt quaranteedtokeep it Restart your Raspberry Piby entering: sudo shistdawn ~r now intoa Terminal window. When it has restarted enter: ¢config and youll find you til use the same IP Address. Overtime the router will use other slots For new devices untilitreachesits maximum (255 by default). Then wll, recycle disconnected devices Bou ‘Setting up DHCP Reservation is good practice because itensures you Raspberry Piis always going to use the same IP Address. I's also a good ide to write it down or usea label printer to create alabel forthe Raspberry Pi. You will need this ‘number to connect tothe Raspberry Pivia SSH, VPN or FPT (techniques we will use throughout this book) wunbémpubleatonscom 37 8 Discovering Raspbian | Connecting to the Pi Remotely REMOTE CONTROL ‘The Raspberry Ps easy to set up and use in projects around the home and, surprisingly, many of these projects don't need a keyboard, ‘mouse or @ monitor these are known as Headless devices, VNC lets you control a Headless Pi rom another computer, EE ‘Youwil first need to ensure that your Ps connected toakeyboard, mouse and monitor, andis connected toyour WEF router, before you attempt to connect tot remotely. ‘Star by clicking onthe Raspberry Pimenu, then scroll down to Preferences > Raspberry Pi Configuration. moo \With the Raspberry Pi Configuration window open, click onthe Interfaces tab, and ensurethat the VNC ‘option is Enabled. lick on the rio button nextto Enabled to activate, then click on the OK button to close the window. 38 wwbdmpubleationscom EEE Inthe upper right comer of the menu bar you'l notice aVNCicon (next to the Bluetooth cor. This isthe builtin VNC server cick the icon inthe menu bar once to open the \VNC Server window. poe cet Make a note ofthe IP Address ofthe Raspberry Plas FED istnscitanisctnarverhcione window our example s 192.168.1244, Now click onthe three horizontal ines inthe top right ofthe VNC Server window. From the submenu that appeas,clickon the Options entry. Ths willopen a new window popup. ‘ith the Security option highlighted on the left, ‘ensure that the Encryption option tothe right, set ‘to Prefer On, and that Authentication is VNC Password, This may ask you to enter a password, which you wil use when connecting femotely rom another computer. Enter a password youll remember REMOTE VIEWING [ Connecting to the Pi Remotely 8 EE ‘While still in the Options window, click on CConnectionsin the left hand pane. Inthe right hand pane, ensure that the Allow Direct VNC Connections Over TCPis ticked, and thatthe Portis et to 5900. usually i, but sometimes it canbe untickedif an update to software has been applied ‘The Piside of things has now been set up. Just remember the P's IP address, and get to your PC or Mac for this next part. EE Reboot the Pi then disconnect the keyboard, mouse ‘and monitor, butkeep the power connected. From your PCor Mac, open a browser and navigate to: hetps//wwwrealvne. ‘com/en/connect/download/viewer). Choose your operating system ‘and click the Download VNC Viewer app. EE Follow the on-screen instruction to install VNC Viewer ‘onyour system, when it finished, launch the app and choose whether you want to send anonymous data. nthe main VNC ‘Viewer window, enter the IP Address ofthe Raspberry Pours was. 192.168.1.244, Hit Enter when you've typed in the IP address. 8 a Inthe new popup window, enter the passwordyou uerS eated through the Raspberry Pi's VNC Server options page. You can choaeto Remember Password if you wan but ithe computer you unas shared youcanaays opto leave the option uticked ck OK when ead a ] sens anesin0 cP) Erte Seren (ee NOryour Rea scoue det) oo e temente pamers rh Catcnpace Lape pin Vena Ges speech ee Signtine SATS THe O4sS Eazy ‘You may be asked to confirm connection to aremote computer cick Continue to make the connection. You are now connected remotely to your Raspberry i. As ong asthe Pris. powered up, and has acess to the Wii signal ofthe router, then you can place t anywhere and get access without using 2 mouse, keyboard, or monitor. 8 Discovering Raspbian Using APT to Install and Remove Programs ADVANCED PACKAGING TOOL ‘Add / Remove Software is great For Finding and installing software but alled APT (Advanced Packaging Tool using the apt command, Beam ‘To manage the apps on your Raspberry Pi youll need EEzw ‘The command used to add new software to your touseatool included with Raspbian called APT Raspberry Piis ap followed by thename (Advanced Packaging Too). APT isacommand ine toolso youneed to ofthe package you want. However, because apt adds (or removes) of the time: manage apps on a Raspberry Piusing a program either tart your Raspberry Pinthe command ine or dickonthe _fles outside af yourhome directory you need to preface apt wth the Terminalicon. word suc, Almost all ofthe time you wil need to type Te when using thistool UW * OCs 6 Bam Bez ‘The command used to control packages in Raspbian is ister | Beginning a command with “sudo” runs the command apt Type apt into the terminal and press Retuin to a superuser, "super" meaning the one above you ‘get a description oF what the app does. The instructions tellus that _Piaccount, rather than one with superhero properties. However, Ft the "most Frequently used commands are update and install”. You may also hear about “apt-get” whichisan older version ofthe same tol. it youtype: followed by the name of the app ‘works in much the same way, youwant. 5 OSE + 0 Bem © OOM + 0 Bean helpsyouto think ot that way that's Fine. Soto installa new program 40 sbdpu Using APT to Install and Remove Programs 8 Bea You're going to installa chess game called Bea You can use apt-cache to search For apps you can Dreamchess. Enter: sudo a install and remove, Enter: p= eames to njchess and press Return, Descriptive text wil un up the screen. view llthe packages avaiable. Typing apt~ceche pk ‘You maysee "Do you want to continue (A Enter: and press 33 enables youto view apage atime (press ay key to srl) Return to installthe application. You Find itby choosing ‘You can use apache earch to ind packages, eter: ap Menu > Games > Dreamchess. sich pong to view alist of Pong games youcan install . 40 Econ | 5 ES + © Eicaa— MORE APT COMMANDS The apt command salso used to list, and delete, any apps you have installed EE ‘Sometimes you will ry to install an app only to get an Ec Packages are uninstalled from your Raspberry Pi exror that the file cannot be Found. In this ease you Using the remove command. Enter need to update apt so it has the latest Unks, Enter sudo. 3p tostart deleting the chess game that you ace. This dest update the aps you've installed, kjust gets installed, Analertsaying“Do you want to continue [/ appears newer sting of apps. To update your appsto the latest versions enter: enter: and press Return to delete the program. sudo apt upgrade. Youoten Find both commandsraedito o 3% 0 eames s EE To view the packages you've installed you use 2 Eau ‘Uninstalled packages using apt doesn’t remove all different command called dpkg, Enter: dc ofthe files. Some are leftin case you decide to :

=/Desktop/packages.txt tosavethelistasa can also use sudo ap nto tidy up your packages and free textile on your desktop. up some drive space 90584 0ReaaD 0 OS +0 Bema wubémpubleatonscom 41 8 Discovering Raspbian Get More from the Terminal App CUSTOM TERMINAL The Terminal Bea ‘Start Terminal by clicking the Terminal icon in the Application Launch Bar. You can also star Terminal by pressing Control Alt or choosing Menu > Accessories > Terminal. Terminal emulates the old style video terminals from before desktop interfaces; so by default it displays bright (mostly ‘green) ona black background. Bez ‘The first thing most people overlook is the ability to,run multiple terminals at once in different tabs. Choose File > New Tab (Shift-Control-) to create anew tab. Navigating multiple drectaries simultaneously can be a challenge in Terminal and tabs makes it that much easier. 42 wuddmpubleationscom command tne, sa powerful environment For accessing the system. Careful here be dragons EEzw ‘Naming tabs makes them much easier to recognise. Choose Tabs > Name Tab and enter a name for the tab suchas "Home” or "Downloads. Click OK to set the name. You can {uickly switch between tabs using ControtPage Up and Control Page Down and rearrange them using the Tabs Move Tab Left / Move Tab Right options. EEzw ‘Choose Edit > Preferences to personalise the look and Feel ofLxTerminal One ofthe best trcksis to click Background and drag the Opacity slider tothe half-way point. This ‘enables you to view through the terminal backaround and see the \windows below. You can also personals the colour ofthe background, Bea ‘While still in Preferences click the Display tab. Here you can adjust the Tab panel positions, placing them on the Left makes them mare prominent. You canalso adjust the scollback line count. This the number oF lines you cn scrol up with using the ‘mouse, not the history accessed bythe Up and Down arrows J CONNECT USING SSH Useadifferent computer to control your Raspberry Pi IF you have your Raspberry Pion the same network ‘3S a Macor Linux-based computer, you can contro it using the Terminal program on that computer. We'e going to use ‘Terminal in macOS here but the process s the same on a Linux machine. Open the Terminal app on your computer. EE Enter: fg into the Terminal app on your Raspberry Pi. This will let you know which IP address itisusing. Look forthe Four blocks of digits Following “inet addr: They should begin with 192.168.0 followed by a three-digit number. Oursis 192.168.0179, Youneed to use that number in Terminal on yur Mac to connect. Get More from the Terminal App 8 Bea \F you prefer a more minimalist approach try moving the Tabsto the bottom and selecting the Hide scrollbar, Hide menu bar and Hide Close button options. When combined with low opacity background ths makes Fora subte terminal window. You cansstillaccess menu settings using aright dick onthe mouse. Ec ‘Swittch back to Terminal on your Mac or Linux machine and enter: ach pi 0.178 (using your own P address). The “pi bit is the name of the default user account, of you have changed that it needs to match your user account on the Raspberry Fi Youll be asked for a password. This isthe password that you use to lag in to the Raspberry Pi (nat your Mac or Linux computer) Eau You are now logged in to your Raspberry Pi and can enter commands directly into the Terminal on ‘your Mac or Linux computer, Unlike remote networking you don't see the commands being entered on the screen of the Raspberry Pi, you are accessing the computer from behind the scenes, Many people prefer to set up the Raspberry Piso they can controlit From a more powerful computer. Enter: exit to close the connection. wunbémpubleatonscom — 43 3 Discovering Raspbian Using the File Manager Crete ec ce ue Cos ements he anus the file system than you would on other computers. One vital tool to become familiar with is Pe ee mee a Rau uch tcc cutee VIEWING AND MOVING FILES You can move, manage and delete files using the Command Line but lke all modern operating systems Raspbian has a program to help you ‘manage your files. Discover how to usethe File Manager app. Een Raspbian includes a great file management program EE Inthe leftchand part of the File Manager sits the Side called “Fle Manager PCManF¥M' or jst “File Manager” Pane. By default this displays the Directory Tree, for shor. Click on the FleManager PCManFMicon in the Launch Bar or whichis another way oF navigating the Folders on your harddrive. choose Menu > Accessories File Manager ‘Alternatively click the Side Pane menu and choose Places. Now the Sasol ‘Side Pane displays common locations such as Home Folder, Desktop, 7 Rubbish Bin (alo known as the Wastebasket), Applications and your TP s0card ee 2 OO oS 7 658° ——_ Flenange ions teceinyurtoneeer PERRI voucn exe ane rnb creation by Gosmdirathyerscoe Side!) ELELMD oor resCexenens rose oes defeutyoushoudhave Desttop,Docaments Oownleads Mig, SfeControl. Enters name forthe eer and cick OK lesan Fratures Publ python. games Sah and older: Doblecik any folerscan be crggedon top of one anther to move hem around folder topenitand view ts contents. Cickthe Parent Fler conor Youcanao rages tothe flersinthe Sd Pane vhs anes) press Al-Up Aout head back wey tormovethemback up the flere, on © 2 oo & on © © (| Ea] = Eeaaqg = Gag = = faa Double-click a file in File Manager to open it with the default ap. You can also rightclick ile to view compatible applications in Raspbian. Pick an application From the list provided to openit. Clk Properties and use the Open with menu to ‘2utomatically pen that type of file with that app in Future. Using File the Manager 8 EE Drag items you no longer want to the Wastebasket todelete them or rightclick and choose Move to ‘Trash, To empty the wastebasket and permanently delete the ‘unwanted files double click Wastebasket to open, Now ight-c the black space in File Manager and choose Empty Rubbish Bin. Click Yes inthe alert window and the Files willbe removed, wunbémpubleatonscom 45 8 Discovering Raspbian Edit Images with GIMP GET TO KNOW GIMP Your Raspberry Pi can display im ages with ts builtin Image View app but for any image editing youl need GIMP (GNU Image Manipulation Program). GIMP sa powerful software package for photo editing and is a great tool to install on your Raspberry Pi EExm Openterminalandenter: sudo apt install gimp to.download and install the GIMP package. An alert will appear saying: “after this operation, 117 MB oF additional dik space willbe used, Do you want to continue [/n" Enter: y and press Return, GIMP will now be installed in Raspbian, GIMP lot larger than most programs you'lLinstall so the installation takes longer r, EE ‘When the installation has completed you will Find (GIMP under Menu > Graphics > GNU Image [Manipulation Program. Ithas a more detailed interface than many Linux programs with two boxes, Tool Options and Brushes offering 3 range of image editing options. Users of software like Adobe Photoshop wil eel sight at home and it's ideal For image editing vOomFO 46 wubdmpubleationscom EE Images can be opened in GIMP using File > Open or by tightticking on Files in Fle Manager and choosing ‘GNU Image Manipulation Program. You can open multiple images at ‘once in GIMP but each opens inside a different window. Choose ‘Window > Single Window Mode to gather them together. Click onthe tabs atthe top ofthe sereen to snitch from one image to another ot ae Ezz ‘You can perform powerful edits in GIMP but we don't have space to go over them all Probably the most useful youll Find is Colours > Levels. Tis window enables you toadjust the tonal range and colour balance ofan image. Drag the left and right handles in slightly and slide the centre handle to the right to improve the contrast of an image. voDmEsas = “ * * Suga Te soon ings ieee Tad Sareiaaoinnn Gees naoe Sue Tosdecento enor napa ee tases ge anes Se ops ase ritinetsinorsheeetasctb EXPORTING IMAGES ‘Save your images For use in a website. Trereahse ge cine eases Jrocansttoge wigs wren ‘we have room to cover here. Try Filters > Artistic > Cartoon to give ‘your image a black outline or Filters > Artistic> Olly to simulate a painted artwork. Take a look at ww. gitip.org/tutorials for creative inspiration, (Cocco ras Tous Sister IF you want to save Files For use in projets, suchas. websites, use File > Export. lick the FileType option _and choose filetype; typically you will use JPEG for web images. Choose a Name and location and click Export. Tignes Pcs aia Tulsi usyromesond cy seajoopeted ticrwasrn ome ay ‘ensure that your web page loads much more quickly. You can typically peti hte sarcomeres Right-click a JPEG image in the File Manager and choose Open With. Expand internet and choose Chromium Web Browser and OK. Ths enables youto see howit will ‘appear when you add itto your website. You can also view images ‘more quickly by right clicking and choosing Image Viewer. You can use ‘Save File As in mage Viewer to quickly change the image format. Edit Images with GIMP 8 8 Discovering Raspbian More Apps ADD/REMOVE You can use the Add/Remove Software feature both on the Pi version of Raspbian as wellas the Raspberry Pi Desktop version - whether it's installed ona PCorina virtual machine. EEx Begin by powering up Raspbian and getting to the desktop. From the menu, select Preferences > Add/ Remove Software. This will open anew window with various categories down the side ofthe screen ma EE ‘These categories down the side of the Add/ Remove Software window denote the type of software package through which you want to search. For example, lick on the Games category, then scroll down the list of available packages and tick the box next to ‘Side-scrlling game named ‘Abe's Amazing Adventure’ 48 wwbdmpubleationscom EE "Now click on the OK button, located to the bottom fight ofthe Add/Remove Software window. Ths wll besin the installation of the selected package note it also ‘auto-select any other required packages in order to make the software work, EE Once the packages have been installed, you can find the software within the Pi Menu items. n this case, ‘Abe's Amazing Adventure iin the Games section of the menu. Click ‘on the icon forthe game, and itl load. To remove the newly installed software, simply re-open Add/Remove Software, untick the box and click OK again Learning Linux Ue eth Ce Rete (aaa OS works, how the filesystem is built, and how you can list, move, create and delete files and folders. To truly be able to hack and master the Raspberry Pi, you will need to be familiar with the OS and its inner workings. is Learning Linux What is Linux? Beene iat eri acura o iMac ecu Man exactly is Linux? Where did it come from and what does it do? In a world where Windows Senet cucominuet cs Mem Raa a a eae our crn tg Panag Linuxis a surprisingly powerful, fast, secure and capable ‘operating system. I's used as the OS of choice for the Raspberry Pi in the Form of Raspbian OS, as well as in some ‘of the most unlikely places. Despite only enjoying a 1.96% share (according to rnetmarketshare.com) ofthe total desktop operating system market, Linux has a dedicated following of enthusiasts, users and contributors. twas created in 1991 by University ‘of Helsinki student, Linus Torvalds, who had become Frustrated with the limitations and licensing of the popular ‘educational system Minix, a miniature version of the Unix ‘operating system, in use at the time. Unix itself was released in the early ‘70s, asa multi-tasking, modular-designed operating system originally developed For programmers who needed a stable platform to code ‘on. However, its performance, power and portability meant BOOTLOADER ‘The bootloader isthe software that initialises and boots up your computer. It loads up the various modules the OS Uses to begin to access the hardware inthe system, KERNEL ‘The kernels the core of the system and the single ‘element that is actually called Linux. The Linux kernel manages the computer processor, memory, storage and. ‘any peripherals you have attached to your computer. DAEMONS Daemons are background services that start asthe ‘operating system is booting, These can enable printing, ssound, networking and so on, GRAPHICAL SERVER ‘Thisisa module within Linux that provides a graphical ‘output to your monitor. Its referred toas the X server or simply X. that it soon became the system of choice For companies and universities where high-end computing tasks ‘were needed. Torvalds needed a system that could mirror Unix’ performance and Features, without the licensing cost. Thus ‘was born Linux, the Unix-like operating system which used Freely available code From the GNU project. This enabled Users around the world to utilise the power of the Unix-like system, completely free of charge, an ethos that still holds today: Linuxis Free to download, install and use. Linux is much like any other operating system, such as \Windows or macOS in that it manages the computer hardware, provides an interface fr the user to access. that hardware and comes with programs for productivity, communications, gaming, science, education and more. Linux canbe broken up into a number of significant elements: SHELL ‘The Linux shell is a command line interface environment, ‘which a Linux user can use to enter commands to the OS that directly affect it. Within the shell you can add new users, reboot the system, create and delete files and folders plus much more. BASH (Bourne-Again Shell) is the most popular shell used in Linux, although others are available. The shellis also known as the Terminal and it's ‘where we're going to work from through this section of the book. DESKTOP ENVIRONMENT ‘The Desktop Environment, or DE, isthe main Graphical User interface (GUI) that users interact with. Its the desktop and includes internet browsers, productivity, games and whatever program or app you're using, There are countless DEs avalable, however Raspbian uses PIXEL. PROGRAMS/APPLICATIONS As Linuxis free, open source operating system, it ‘also makes good use of the tens of thousands of Freely available applications. The likes of LibreOffice, GIMP and Python are just the tip ofthe iceberg, What is Linux? Preece” perenne Linuxis used throughout the world, in a number of basic and uite unique uses. While it may look radically different from one environment to the next, the actual Linux kernel, can be Found inmodern smart TVs, in-car entertainment systems and GPS, ‘supercomputers, loT devices and the Raspberry Pi. It's used by 'NASA, both in the command centre and on-board the ISS. Linux servers power the backbone of the Internet, along with most (of the websites you visit daily. Android utilises components of the Linux kernel, as do set top boxes, games consoles and ‘even your fridge, Freezer, oven and washing machine. Linux isn't just a free to use operating system. It’s stable, powerful and fast, easily customised and requires very little maintenance. However, it's (EEE ‘more than just performance stats; Linux means freedom from the walled «garden approach of other operating systems. It's a lively community of like-minded individuals who want more from their computers without the shackles of price or conformity, Linux means choice. 8 Learning Linux Using the Filesystem GETTING AROUND To drop into the Terminal, click on the Fourth icon from the left along the top ofthe Raspberry Pi desktop, the one with aright Facing arrow and an underscore. Thisis the shell, oF Terminal Een First, you're going to look at directories and the directory path. A directory isthe same thing asa folder, however in Linuxit’s always called a directory. These are placed inside each other using a“ character. So when you see / hhome/p it means the i directory is inside the home directory Enter: cleat and press return to clean the screen. Now enter i ‘This stands for Print Working Directory and displays home/p Bez ‘When you log in to your Raspberry Pi, you don't start at the base of the hard drive, known asthe ‘root(also known as the topmost directory). Instead you begin inside your user directory, which isnamed ‘by default and is itself in a directory called ‘home: Directories are indicated by the symbol. So, “/home/pi™ tells you that inthe root i a directory called home, and the next "/” says that inside "home" isa directory called "pi". That's where you start. Enter: sto view the contents ofthe curent Now you'r going to move from the pidirectory into the Documents directory. Enter: Note the capital", Linux case sensitive, which means you have to enter the exact name including correct capitalisation. The cd ‘command stands fr change directory, Now enter: ia again to view the directory path. twill display /home/pi/ Documents. Enter: 1s to view the Files inside the Documents directory. Bea How do you get back up to the pi directory? By using command "cd. In Linux two dots means the directory above also known asthe parent directory. Incidentally, single dot is used forthe same directory. You never use "ed." to switch to the same directory but It's worth knowing because some commands need you to specify the curent directory ABSOLUTE VS RELATIVE PATHS Using the Filesystem 8 Bea The "Is" and “cd” commands can also be used with ‘more complex paths. Ente to view the contents oF a Pictures directory inside your Documents directory You can switch to this directory using ea tomove back uptwo parent directories. Itis important to know the difference between the working directory, root directory and home. There are also two types of path: Absolute and Relative, These are easier to understand than they sound. Lets take a look. EE By default, commands like “Is” use the working directory. Tisis the current directory that youre looking at andis set to your home directory by default (users/pi) Using "pwd" (Print Working Directory) lets you know what the working diectory's, and using "cd" changes the working directory. EE ‘The root directory is always Entering: 1s / lists the contents of root, and entering: ed / switches to the root directory. Thsis important because there sa difference between is Documents/Pictures’ and "Is /Documents/Pictures’. The Fst command lsts the contents of the Pictures director in Documents inside the working directory (which ifyou arein the home directory, will wor. Eee ‘The second command ("ls /Documents/Pictures”) attempts to lit the cantent of Pictures ina directory called Documentsinside the rot directory (because the path started with 7, which is rot). There is typically no Documents directoryin Foot, so you will get a"No such ile or directory" errr. Starting a path with’f is known as an “absolute path’ while stating without the is known asa relative path” because ts relative to your working directory. Bea There is also an absolute path shortcut to your user

You might also like