The Complete Raspberry Pi GuideBook Ed1 2021

You might also like

Download as pdf
Download as pdf
You are on page 1of 146
The Complete GuideBook Unlock and master the power of the amazing Raspberry Pi Rate) 1a Vy em aan a RC) and C++ coding . N3QN4d mie Yat Black Dog Media Master Your Tech ) “3 a To continue learning more about your tech visit us at: www.bdmpublications.com FREE Tech ides =. SG Codd Same EXCLUSIVE Offers on [aaeitg g Coding pathon our Tech Guidebooks = ; @ Print & digital editions © Featuring the very latest updates © Step-by-step tutorials and guides © Created by BDM experts Check out our latest titles today! SPECIAL DEALS and Bonus Content Sign up to our monthly newsletter and get the latest updates, offers and news from BDM. We are here to help you Master Your Tech! bdmpublications.com/ultimate-photoshop Eta eee eu keene images for free! Simply sign up and get creative. The Complete Raspberry Pi GuideBook Unleash your imagination with the power of the Raspberry Pi... The Raspberry Pi is a remarkable little computer. You'll find that the Raspberry Pi is a superb, and cheap, desktop computer, retro gaming system, media centre, and even a TV set-top box. All these projects use the Pi and code. With code, you can create amazing things and have your Pi do what you want it to do. We've got a section on coding with Python that will take you from the core foundations through to advanced concepts and code. There's also a section on learning Linux, the operating system of the Raspberry Pi. By learning how Linux works, you'll be able to take command of the Pi and expand your project ideas. There's something for everyone in this book. From beginners to more experienced Pi users. We've got projects, code, guides and tutorials that will help you unlock the full power of your Raspberry Pi. Contents aCe) eS 7 ASlice of Raspberry Pi Cee tos dal eon oda Sam Ler eee 14 Raspbian: The Complete ere eeu) Mca Ga Rca ced aos} Ome) neers ad Peeler Es PU oun) Bice me ere aeRO ce een) eta EO OST Nee RMB Perea iT¢] isccts}e)oleelg) Pee ae Erm our nome 36_ Setting Up a Static IP Address Ee ao Poa ae Buea ca) oe coc Ce Raa Coe eI 49 Learning Linux eo Es Pao Ear Den cd Emer eae ac lac Eee ceo Com aoe) Renaming Files Cae cd me eta 66 Getting to Know Users Come ei tr eS ear Begone aac) Eiiacs Zane eas) Ty ec ones Pen Coma RS EA Eaecre nea P ys il) a oles See ed pcr hd _87 Python be tae 86 ry 90 92 oy 96 98 ee Se cr Serato Saving and Executing Your Code Een oc eer my ee Pe ea PMO an Pecos Treo Te ones nee RA RS ued cs ard 117 Pi Projects: Ideas and Code GSEs 118 Creating a Loading Screen See ki Maer) aon ear) 128 Using Text Files for Animation SO i A Cee Seas ee Ay Erercae) 184 Pi Projects: Desktop Pi Seale coeur m} 188 Pi Projects: Media Centre ioc ean gies 144 Common Raspberry Pi seus Contents S&S wn brmpubleatons com 5 8 New to Pi? Where to Buy’ New to Pi? Where to Buy? POMC RCM aM RuCl see Naame ered Ge crn eae RR Mr are four main Raspberry Pi approved resellers throughout Europe, and hundreds more internationally. Let’s look at the top four Pi sellers. Open a Browser and navigate to MEPS ‘nits release n2012 CB Forel was one ofthe orga UiLALAD thepinuccomfatectionsfaspberry-p The all reselersfthe Raspberry P.Theefore nt oly does CPC Hut one of the most popular online shops foralthings Raspbery —stockahuge amount of Prelatedgoodes, butts ako one ofthe Pyincluding the Piel, cases, HAT, kts and bundles cables, premier global online eleconis tres. rowsethe Piseton at addons and much more. Prices vary Gepending on what youre __—tpe/cpcfarnllcomé/maker-ircu-development/single-board- looking for, but they're some ofthe best around. ‘With its huge range of Raspberry Pi products, including iy Founded in 2012, and the makers of the excellent Fee ciiccreierceace ceases? GILEAD parecse iene snntsennerys addons, OKGo one ofthe top go-to stores or lltheinkeres__Pimoroniisa superb resource fr tnkerers makers and P Fans outthere,YullFind the P section ofthe shop at hetps/wrww. everywhere, Found st hetpsi/shop.pimoronicom/products/ cokdacom/product-category/raspberry-p) sohunt around and raspberrypia?sre=raspberypi, Pimoroni stocks everything yout seewhats aalable, need or your P, among other great technologies. MORE PI Naturally, you don't have to go through any ofthese recommended stores. Look around the Internet and youl Find plenty of other eet ee he ie Lt dec 6 wwbdmpubleationscom 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. ; & A Slice of Raspberry Pi 8 eeu ects Beane ah Cet ss ee eat} orecretit er ar ce eee eee ca ioe het tis emia caer PSCC nar ce ea eine eto Poe ee eee Mc ro IA Bree wu bmpubeatons com ee age eaeucrttaee pects Mae eran Le) Sree Uae ean eo ed Pern ner acco Rant esate ‘The Raspberry Piis a British built low cost computer that enables everybody to learn computing, start programming and ‘explore basic electronics. Is the size oF a 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 ‘p 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 iis 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 Raspberry Pi 4 Model B a Rate rien Say Hello to Raspberry Pi a similar though. Each models lightweight computer on asingle board that’ roughly the size ofa creditcard, Each Raspberry Pi board features a processor made by ARM, which s similar to the madels you find in mobile phone. The ARM processors Fast and lightweight butit 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 with PIXEL, which is the 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 systems 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 PDXEL {and 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 eee Peper toner eerie Ree i econ anne rotenar at Pee ee Bren teegcrees iets ah Raspberry Pils connected to a monitor viaa HDMI socket whist a keyboard 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 cable is connected from your Raspberry ito asocket on your modem router. ‘The Raspberry Pi 3has builtin wireless networking and Bluetooth, making it easy toget online. You can attach a USB WiFi » ‘Another caveat worth mentioning is that you wontthave accessto the 40;pin GPIO thatthe Raspberry Pi features, as this isn't standard piece of hardware on anormal PC Theres, however, a way around this you own a Raspberry Pi Zero (ether with or without the W), then you're able to connect the Zero toa spare USB port on the PC, va the Zro's micro USB port and the Raspberry Pi Desktop OS wil recognise the Zero as extended hardware and allow you access tothe ‘Zero’ 40-pin GPIO, which, you have to admis prety clever stuf The Raspberry Pi Desktop: What You Will Need 8 WHAT YOU WILL NEED Here'salist of tems needed ifyou want to test out the latest version ofthe Debian Stretch with Raspberry Pi Desktop OS on your PC. BSP Pay Naturally youl need the Raspberry Pi Desktop 05, just as you would with Raspbian or the Pi, Open browser ‘and download the SO file that contains the OS From: hetps//ww. raspberrypiorg/downloads/raspberry-pi-desktop/. ‘node destopPCor laptops anes (Ngo Glues candidate For running the Raspberry Pi Desktop (05. while you can easy vse the latest PCfaptop ks bi overt or isparticlar operating sytem PW Feratd The best method of transferring the 80 to aPC For installation sto use @ combination of atool suchas Rufus Found at: htps,//rofusie/en_JEhtm), whichis apiece of software that can create a bootable USB driver From an ISO ile and, at least, an 868 USB stick RASPBERRY PIZERO LUneEUEE ney spare Raspberry PiZero wil allow you toaccessthe 40;pin GPIO from within the Raspberry Pi Desktop OS. IF, however, you don'thave a spare Zero, it’s not a problemas there's stil plenty you can do with Raspbian ona PC. wbdmpublcatonscom 27 is ASlice of Raspberry Pi J Debian Stretch with Raspberry Pi Desktop None ecm ne NC eMac Mace cu coda somehow lacking and therefore a bit pointless in its use. However, theres a lot that you can CPM Unr rs eae ssi aaT eee Meroe 10 THINGS TO DO WITH X86 RASPBIAN ‘You can do just as much wit this version of Raspbian as withthe dedicated Pi version and to demonstrate here's ten great projects todo with Debian Stretch with Raspberry Pi Desktop. Festa tei) Thisversion of Raspbian apes the Full Desktop version, forthe Raspberry Pi, meaning it comes withall the necessary programming languages out ofthe box. Learn Python, C+, Use the HAT emulator and even learn JAVA. It’s there under the Programming menu option. aeeeads BITES kins Fcre vito Drain ied FERED et crcmsouctertvesnor cys Scratch. By doing so, you have allthe benefits ofa Raspberry Pi, with the power of your laptop. 28 wuwbdmpubleationscom PTWssstaretsy 5 the x86 version of Raspbianfolowsthe Full Desktop Piversion there's an entire office suite preinstalled allowing you to use that old laptop or PC as aflly functional desktop replacement for Windows or macOS. LibreOffice ‘also MicrosoFe Office compatible so Tete tay As with most modem operating systems, youcan browse the Intemet exactly as you would with Windows 10, the latest macOS or similar and because ths, ica Linuxbased 05, there's an added element of security, ast won't be affected by Windowstargeted viruses. Debian Stretch with Raspberry Pi Desktop a LINUX X86-BASED SOFTWARE Jiadaiaeh sian version of Linux you can natural install any ofthe tens ofmilions of Linux x86 based soRware currently avaiable. Remember though only software thathas both an [ARM and an x8 version wil werk on both the Piversion and this version of Raspbian RECOMMENDED SOFTWARE JBpiasdiiahoa Software optonis also _valable with this version of Raspbian. This ool allows youto pick and choose which ofthe PHavoured software you addor remove. Smply Uickthe box nex othe name ofthe app By {t's easy to use SSH From within the Raspberry Pi Configuration tool Select the Enabled option and then use a Cen, such as PUTTY, to SSH into the OS. Here weve enabled SH and ‘connected From another Windows PC using PUTTY asthe SSH client. oe oo = wu — ‘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 wl be able to play games ike Minecraft without too much trouble a all retro gaingis more to your taste then BEUSOERLNS Debian has a huge number of retro erlatrsavalable covering bath consoles and hore computers You wine eal ROMs however to pay the games, Du hese are widely aval om reputabestes = | | CAMING Of course, there's an equally large selection of modern ‘gaming available For Debian; most of which will run perfectiy well under Raspbian in an x86 envionment. You will needto Google what's available and ty outa Few examples asthe lis issimply too big to mention nn a wbdmpubleatonscom — 29 is ASlice of Raspberry Pi J Debian Stretch — Virtual Desktop yaar ES Aen ACU aR UU oo ea une eR Ct M EMER M Manu at Coe Mane econ Mg et Meee nod GOING VIRTUAL You'l need a copy of VirtualBox to download and instal, which you can Find at https//wrwwsvirtualbox.org/wiki/Downloads. Windows users click on Windows Hosts, macOS dick OS X Hosts. Een Install the downloaded VirtualBox For your system by following the on-screen instructions. Next, download the Raspberry i Desktop SO from hetps//wwwraspberrypiorg/ Preferences > ‘Screen Configuration, nt dims Discovering Raspbian INDEX Discovering Raspbian The Raspbian operating system is a Linux distribution that comes pre-packed with a fantastic 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. Ree 8 Discovering Raspbian Take a Tour of PIXEL PIXEL is the desktop environment for your Raspberry Pi. It’s built on top of Raspbian, the core OMCs rrr enn cisur tones Weenies NA rescanstes eet ec Oden ence caren cu eI PIXEL, PIXEL stands for “PI Improved Xwindow Environment, Lightweight’ tsa lightning fast and eneray saving desktop that looks good too. It contains almost everything youl ever need to work with the Pi. BITS areiay The PIXEL interface is a module that’s installed ilentng Youtnotice that within the Main menu, ‘ontop ofthe core OS. thas seen some there's acategory named Office. in here, improvements over the years and withthe elease ofthe Pi4 and _you'lfind a preinstalled suite of programs called LibreOfFice, that are Raspian Buster, it now looks like this. ‘Microsoft Office compatible there's a word processo, database, drawing, presentation and spreadsheet program. avait acaemag Theepa tne ale Ti isan Raon 0 SD rarirsrcst ccnaty ase Sumuehehacgetonnoe tetagteryMosnnthesons tsa cteteln ct plein. here otter The soe moe 32 wuwbdmpubleationscom eM iseelsy it spossibieto remove and additems to the Application Menu using the Main Menu Eilitor. Choose Menu > Preferences > Main Menu Editor, then add or remove ‘ticks next to programs and sections you want to include\exclude. Use ‘Move Up and Move Down to rearrange items inthe Menu. CUSTOMISE THE DESKTOP ‘swith anyother oper BIE 'ts important that you switch off your Raspberry Pisafely. When youare finshed with your Raspberry Pi session click Menu > Shutdown, Three options appear: ‘Shutdown, Reboot, and Logout. Click Shutdown, Always wait For the screen to go blank before removing the USB power. == = system desktop, youre able to customise the Raspberry Ps PIXEL interface, making t more personal and more you, TST 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. Desktop MenuBar| System | Deft yout Filsceen ain mage Pee Guenpiees ® Documens ¥ Wastbasiet Mounted Dike PSR) eres err tener BIER ay the desktop wallpaper, or desktop bachoround The deat caled Temple’ however by ccking on ‘temple inthe Picture section ofthe Appearance Settings, you hhave other images avaiable. Naturally, you can opt For your own, Deskop Menuar | Sytem | Deut Large (3282) The seondtabinthe Apperanc Settings window eS allows you to adjust the menu bar that runs along thetop ofthe desktop, Youcan change Rs sie, colour andevenits location rom the tpt the bottom ofthe screen eon [Mewar] Sem | Dots eae Sees 5 Ss mz : Ew “The System tab nthe Appearance Settings window will tenable yout change the core system Font as well asthe mouse cursor size. There are numerous Fonts to choose From and, F ‘you want, you can even instal your own. Dt [Menu tar) Sen | Delete wubémpubleatonscom 33 Take a Tour of PIXEL 6 & Discovering Raspbian Exploring the Command Line USING TERMINAL Despite its graphical PIXEL interface, Raspbian isa Linux operating system and this means you'll spend alot of time working with text ‘commands. Using the command line isan important part of learning to use a Raspberry Pi computer. Een By default the Raspberry Pi boots directly into the PIXEL interface Here you use a visual metaphor, files, ‘buttons and so.on, to make changes to your computer. The command lines where you control a computer by entering text commands. Click Terminalinthe Menu bar to view the console. (WOCms 6 Bs wr Eee cree const inate temnsto nate changes tothe computer This works alongside the PIXEL interface Enters sorand press return, Notice a new Folder appears below the Trash on the desktop. Drag to trash to getrid oft You can use the Terminal nd PEL erironments alongside ech other. 5 OCS s 6 Bene 34 wwbdmpubleationscom EE ‘Another way to switch to @ command line environment isto press Controle and F2,Thisgets id ofthe desktop completely and you seejusta black screen with text. Tiss known as virtual environment and you're now in ty2 (tty isa throwback to teletext writers). Youll need to enter your login name (Cpr by deFault) and password (aspberry" by default. Bez ‘There are six different virtual environments available, Press Control Alt#3 to switch to the third, and ControlAlt-Fa to goto the fourth, and so on, Yul need to log ‘on to each one in the First instance but can then jump back and forth between them. So ts et oc Cay Exploring the Command Lin 8 Bea ress ControlAltF1 to return to the PIXEL interface, Bea ‘Some users prefer to use just the command line. One thing to realise ithat PIXEL is just a program Open Menu > Preferences > Raspberry Pi running on top ofthe thy? session, Open Terminal and enter: configuration and choose To CL! and lick OK and Yes. The e ‘uch, there goes your desktop. Dont wory, enter: Raspberry P will now boot into the commandline 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 PIXEL envionment. choose To Desktop to go back to normal 5 ODEs 0 eae: 1B OTAEM & © Eleenstee & 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 FixitsIPaddress. Ths will makeitalot ‘easier For youto connect to the Raspberry Pi from a Mac or Windows computer and share Files modem/router) assigns it a Configuration Protocol). When the Raspberry Piis unplugged it. Bez ‘The router typically takes the first address, so itis EE It’s better altround f you can get the Raspberry Fito usually Found at 192.168.0.1. That umber is reserved se the same IP address every time you connectitto forthe router. Often youll ind this umber on your router marked the network. You do this using DHCP Reservation This is where you “web address. The router then assigns similar IP addressnumbers to tellyourrouterto remember the Raspberry P address, and only use the other devices you own a they are added tothe network, so that address From now on. Start by opening the Chromium Browser 192,168,022 might be your computer, 192.16803 yoursmartphone and andentering 192-1680. to connectto your router's web interface. 36 wuwbdmpubleationscom Setting Up a Static IP Address om EE ‘We're using a Virgin Broadband router but the EE Select the device using the check box on the right and processis similar on most routers. Google the name scroll downto the Add Reservation section It should ‘of your router and “DHCP Reservation” tofind the router you're have filled in the Device Name, MAC Address and IP Address Feld. IF Looking For. Enter your admin password (our default password was _the Device names "unknown" change itto"raspberry-p". lick Add listed on the back ofthe router). Click Advanced Settings > DHCP —_—Reservation to ensure it always uses that IP Address. Click Apply to Reservation. In the DHCP Settings section you wil find allo the enforce the changes. devices connected to your network. Scroll down and ind the one with the same IP Addeess listed in Step 3. MANAGING YOUR DHCP DEVICES Now that you have set up a DHCP Reservation, you need to understand how to manage the different devices that may need to use Itand connectto the IP Ex ‘Now that you have set up your Raspberry Pi with a Your Raspberry Pi will still have the same IP Address DHCP Reservation it will aways connectto the router butitisnt guaranteed to keep it. Restart your using that IP Address. You can check this at ay time by entering Raspberry Piby entering: sudo shutdown ~r now intoa Terminal 4 £config into terminal, The router always knows thattis your ‘window. When ithas restarted enter: :fcontig and youl find youstil, Raspbery Pi by checking its MAC address. Thisis the set of si se the same IP Address. ver time the router willuse other slots For hexadecimal numbers next to "HWaddr" in ifconfig. new devices untilit reaches its maximum (255 by default). Then t wll, SonmeA recycle disconnected devices. EE IF you decide to free up that IP Address so other devices can use you can remove i 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. Select the check-box next to it and click Apply number to connect tothe Raspberry Pi via SSH, VPN or FPT and Yes. (techniques we will use throughout ths book. 3 soso: Fe Setting up DHCP Reservation is good practice because it ensures you Raspberry Ps always going to use the same IP Address.’ also a good idea to wite it down or use alabet printer to create alabe forthe Raspberry Pi. You will need this Vay Ty? wbémpubcatonscom 37 8 Discovering Raspbian Connecting to the Pi Remotely NC ceo eects collar eat Cente Cm Ue LN eat mele une Sat ec Aa Coup ota kegs em REMOTE CONTROL, ‘The Raspberry Ps easy to set up and use in projects around the home and, surprisinaly, many ofthese projets don't need a keyboard, ‘mouse or a monitor, these are known as Headless devices. VNC lets you control Headless Pi From another computer. EE ‘Youwil first need to ensure that your Pls connected toa keyboard, mouse and monitor, and is connected to your WiFi router, before you attempt to connect to itremotely. ‘Start by licking on the Raspberry Pi menu, then scroll down to references > Raspberry Pi Configuration, voume® @ EE ‘With the Raspberry Pi Configuration window open, click onthe Interfaces tab, and ensurethat the VNC ‘option is Enabled. Click on the rio button nextto Enabled to activate, then click on the OK button to close the window. 38 wuwbdmpubleationscom FEI copie fener Taccapeeobetswamton thee insanesecrisceoneue mene octree Melina jstep4 | ‘Make @ note of the IP Address ofthe Raspberry Pi as. detailed inthe lefthand section ofthe VNC Server window our example s 192.168.1244, Now clk onthe three horizontal ines inthe top right oFthe VNC Server window. From the submenu that appears, clikon the Options entry. Ths willopen a ‘new window popup. Eee ‘With the Security option highlighted on the left, censure that the Encryption option, tothe right, set to Prefer On, and that Authentication is VNC Password, This may ask youto enter a password, which you wil use when connecting ‘remotely From another computer. Enter a password youll remember [ Connecting to the Pi Remotely am ‘While sili the Options window, lick on Connections inthe lefthand pane, In the right hand pane, ensure that the Allow Direct VNC Connections Over TCP is. ticked, and that the Poti set to 5900 usually i, but sometimes it can be unticked fan update to software has been applied REMOTE VIEWING ‘The Piside of thing has now been set up. Just remember the P's IP address, and get to your PC or Mac for this next part. Ea Reboot the Fi, then disconnect the keyboard, mouse ‘and monitor, but keep the power connected. From your PCor Mac, open a browser and navigate to: hetps//www.realvne. ‘com/en/connect/download/viewer). Choose your operating system ‘and click the Download VNC Viewer app. Follow the on-screen instruction to install VNC Viewer ‘onyour sytem, when its finished, launch the app and choose whether you want to send anonymous data. n the main VNC ‘Viewer window, enter the IP Address ofthe Raspberry Pours was 192.168.1.244, Hit Enter when you've typedin the IP address. Inthe new popup window, enter the passwordyou Suer created through the Raspberry Pi's VNC Server option page. Youcan choose to Remember Password you wan but the compter youre ung shared youcanavays opto leave the option uticked Ck OK when ead God fezteenauessoocc) (He NoTyeu Rea secout det) oo e emente peamerd egal Cacnpnace: Laptop apn Ven Ges speech fr Ste Se STSTH DEES ‘ound cnr cnwetontosroel Soret Counce caret are now connected remotely to your Raspberry Pi. As long as the Pi is: suesanavharsces wbeittonalttereoer he npn yc ongeocsoabe ess to rmor wubdmpubeatonscom 39 & Discovering Raspbian Using APT to Install and Remove Programs ADVANCED PACKAGING TOOL ‘Add / Remove Software is great For Finding and installing soReware but most ofthe time you manage apps on a Raspberry Pi using a program called APT (Advanced Packaging Tool using the apt command. ‘To manage the apps on your Raspberry Pi youll need touseatool included with Raspbian called APT (Advanced Packaging Too!) APT a command ne toolso you need to either start your Raspberry Pin the command line or click on the Terminalicon BOCES 6 Bem Bez ‘The command used to control packages in Raspbian is apt Type apt into the terminal and press Retutn to ‘get a description of what the app does. The instructions tell us that the "most Frequently used commands are update and install’. You may also hear about “apt-get” whichis an older version ofthe same took It ‘Works in much the same way. © OGM 0 Bean mpublicationscom EE ‘The command used to add new software to your Raspberry Plis apt: snstal followed bythe name of the package you want. However, because apt adds (or removes) files outside of your home directory you need to preface apt with the ord suis. Almost all ofthe time you will need totype sudo ant ‘when using this tool 5 ODEs 6 Biman EEzw Beginning a command with “sudo” runs the command ‘asa super user, “super” meaning the one above your Piaccount, rather than one with super hero properties. However, Fit helps youto think oft that way that's Fne. Soto installa new program youtype: sudo 1211 Followed by the name ofthe app youwant. © OM & 6 Eisen Using APT to Install and Remove Programs 8 faa ‘You're going to install a chess game called Dreamchess. Enter: sudo apt install ‘and press Return, Descriptive text willrun up the screen. ‘You may see "Do youwant to continue Yl” Enter and press Return to install the application. Youll Find it by choosing Menu > Games > Dreamchess, © ODE # © Brecon MORE APT COMMANDS EE ‘You can use apt-cache to search For apps you can install andremove. Enter apst-cache pksnanes to view athe packages available. Typing apt-cache pkonane: leas enables youto view a page at atime (press any key to scrol, Youcan use aptcache search to Find packages enter: apt=cache aiech pong to view alist of Pong games you can install, The apt command salso used to list, and delete, any apps you have installed EE Sometimes you will try to install an app only to get an terror thatthe File cannot be Found. Inthis case you need to update apt soit has the latest Inks, Enter sudo apt update. This doesnt update the apps you've installed, just gets a newer sting of apps. To update your appsto the latest versions enter: 1. Youll often find both commands rolled into one: sudo apt up. © ORE * 0 Beam ae sudo ade To view the packages you've installed you use a different command called dpkg. Enter: dpkg tions | grep stall toview all ofthe packages on your Raspberry Pi. Place | less afteritto view one page ata time. Or dpkg —a ep ~v > =/Desktop/packages.txt to save thelist asa text ile on your desktop. 8 OBE FO Bern - EE Packages are uninstalled from your Raspberry Pi using the remove command. Enter: sido apt to start deleting the chess game that you Installed, An alert saying "Do you want to continue [Y/aP| appears, enter: y and press Return to delete the program. * OGE + 6 Eie= Ezz Uninstalled packages using apt doesn’t remove all, ofthe files. Some are leftin case you decide to reinstall the program later. To completely remove a package from ‘your Raspberry Piuse the purge command, Enter: sudo. apt ai toremove ll ofthe supporting files. You canalsouse suc ‘Lean to tidy up your packages and free uupsome drive space * OGE4s46 = wnebdmpubleatonscom — 41 & Discovering Raspbian Get More from the Terminal App CUSTOM TERMINAL ‘The Terminal, or command line, isa powerful environment For accessing the system, Careful, here be dragons. Bea ‘Start Terminal by clicking the Terminal icon in the Bez ‘Naming tabs makes them much easier to recognise. ‘Application Launch Bar, You can also stat Terminal Choose Tabs > Name Tab and enter a name for the tab by pressing ControlaltT or choosing Menu Accessories > suchas "Home" or Downloads’, Click OK to set the name. You can Terminal. Terminal emulates the old style video terminals rom quickly switch between tabs using ControlPage Up and ControtPage before desktop interfaces; so by default it displays bright (mostly Down and rearrange them using the Tabs Move Tb Left/ Move Tab ‘green) ona black background. Right options. Eee Bez ‘The first thing most people overtook is the ability EEzw ‘Choose Edit > Preferences to personalise the look and torun multiple terminals at once indifferent tabs. feel of LxTerminal. One of the best tricks isto click Choose File > New Tab (Shift-Control-) to create anew tab. Background and drag the Opacity slider tothe half-way point. This Navigating multiple directories simultaneously can be a challenge enables you to view through the terminal background and see the in Terminal and tabs makes it that much easier. windows below. You can also personalise the colour ofthe background. mpublicationscom faa ‘While stillin Preferences click the Display tab, Here you canagjust the Tab panel postions placing them on the Left makes them mare prominent. You can also adjust the scrollback line count. This is the numberof ines you canscrol up with using the mouse, notte history accessed bythe Up and Down arrows w | CONNECT USING SSH sea different computer to control your Raspberry Pi IF you have your Raspberry Pion the same network using the Terminal program on that computer. We're 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: ifconfig 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 touse that number in Terminal on your Mac to connect. I Get More from the Terminal App 6 EE |F you prefer a more minimalist approach try moving the Tabsto the bottom and selecting the Hide scrol bar, Hide menu bar and Hide Close button options. When combined with a low opacity background this makes Fora subte terminal window. You cansstill access menu settings using aright-lick onthe mouse w EE ‘Switch back to Terminal on your Mac or Linux machine and enter: seh pi@i92-168.0.178 (using your own P address). The “pI” bit is the name of the default User account, so if you have changed that it needs to match your user account on the Raspberry Pl Youll be asked for a password. This isthe password that you use to lag into the Raspberry Pi (not your Mac or Linux computer) Ezy You are now logged in to your Raspberry Pi and can enter commands directly into the Terminal on yyour 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 controlt From a more powerful computer. Enter: exit to close the connection. wnbdmpubleatonscom 43 mis Discovering Raspbian } Using the File Manager Crete Ecce ce un Cos ema m rn she amu the file system than you would on other computers. One vital tool to become familiar with is Reg mee Mae aoa osu iam VIEWING AND MOVING FILES You can move, manage and delete files using the Command Line but like all modern operating systems Raspbian has a program to help you ‘manage your files. Discover how to use the File Manager app. pines ee rorgeen 5 Ser Renocerouen orca fron cc ontherieape Personen oe Sone bre toner Fehon Ses Ee File Manager displays the folders in your Home Folder (this should match your user name, PF by default. By default you should have Desktop, Documents, Downloads, Music, Pictures, Public, python_games, Scratch and folders Double-click any Folder to open it and view its contents. Clickthe Parent Folder icon or press AltUp Arrow to head back up. 44 wuddmpubleationscom jstep3 | Inthe leftchand part of the File Manager sits the Side Pane. By default ths displays the Directory Tree, which is another way of navigating the Folders on your harddrive, ‘Alternatively clckthe Side Pane menu and choose Places. Now the ‘Side Pane displays common locations such as Home Folder, Desktop, Rubbish Bin (alo known as the Wastebasket), Applications and your SD Cad. Ezy ‘You can create a new folder inthe current location by choosing File > Create New > Folder or press ‘Shif-ControlN. Enter aname For the folder and click OK. Files and folders can be dragged on top of one another to move them around. ‘You can also drag files tothe foldersin the Side Pane, whichis an easy \way to move them backup the folder tree. Eee Double-click file in File Manager to open it with the default app. You can also rightlick filet view ‘compatible applications in Raspbian. Pick an application From thelist provided to openit. Click Properties and use the Open with menusto automatically open that type o ile with that app in Future. Using File the Manager 6 EE rag 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 openit. Now right lick the black space in File Manager and choose Empty Rubbish Bin Click Yes in the aler window and the Files willbe removed, wbdmpubleatonscom — 45 & Discovering Raspbian Edit Images with GIMP GET TO KNOW GIMP ‘Your Raspberry Pican display images with ts builtin Image View app but for any image editing you'l need GIMP (GNU Image Manipulation Program). GIMP sa powerful software package for photo editing and isa great tool to install on your Raspberry Pi EE Openterminalandenter: sudo apt install gimp to.download and install the GIMP package. An alert will appear saying: “after this operation, 117 MB oF addtional disk space willbe used. Do you want to continue [\/n]" Enter: y and press Return, GIMP will now be installed in Raspbian. GIMPis alot larger than most programs youtlinstall, so the installation takes longer Pe, aS 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 feel right at home andi’ ideal For image editing, 45 wwddmpubleationscom EE Images can be opened in GIMP using File > Open or by right-licking 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 switch from one image to another voumeas . — EEzy ‘You can perform powerful edits in GIMP but we dont have space to go over themall, Probably the most useful you'l find is Colours > Levels. This 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 tothe right to improve the contrast of an image. voumeas o a ‘To crop an image click the Rectangle Select Tool and ‘drag a square on the image. Choose Image > Crop To Selection to remove the unwanted parts ofthe image. Use the Image > Scale image and image > Canvas Size options to adjust the image to specific sizes. Cropping and resizing imagesiisa vital technique to know when working on websites. wor EXPORTING IMAGES ‘Save your images For use in a website. | Edit Images with GIMP 6 Tarearehse ge inane eases Jroansaliomuge vies nrtan wefreoomis sore Ph aon ogre sorimadesuineraen acces cubresmeiaes painted artwork. Take a look at ww. giinp.org/tutorials For (Covina rpg fos Tasers rabelmtaeibopinccice ices ony Sooo IF you want to save Files For use in projects, such as ebsites, use File > Export. lick the FileType option {and choose filetype; typically you wll use JPEG For web images. Choose a Name and location and lick Export. The Exportimageas PEG window appears dplayng SUEFS a Quality slider. The Quality range is from 0 (very oor to 100 (perfect). White you might be tempted to set the quality _2€ 100, reducing tslightly wil create much smaller files. Smaller files ensure that your web page loads much more quickly. You can typically reduce the Qualtyto 80 and get a much smaller file with ttle discernible difference, & E Ian Right-click 2 JPEG image in the File Manager and ‘choose Open With. Expand Internet and choose Chromium Web Browser and OK. Ths enables youtto see howit will ‘appear when you additto your website. You can also view images ‘more quickly by ight clicking and choosing Image Viewer. Youcan use ‘Save File As in image Viewer to quickly change the image format. wubémpublcatonscom 47 mis Discovering Raspbian ) More Apps While installing apps, or rather packages, is perfectly fine through the Terminal and the Apt Co TaN Mt E-) eo AL ene SEM UPS 0 nee LLL Ua Cm RU kee Aen oe aol Le 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 i's installed on a PCorina virtual machine. EEx ‘Begin by powering up Raspbian and getting to the EEE "Now click on the OK button, located to the bottom desktop. From the menu, select Preferences > Add/ right of the Add/Remove Software window This will Remove Software. This will open anew window with various begin the installation of the selected package note, itl also categories down the side ofthe screen ‘auto-select any other required packages in order to make the | ian software work. Bez ‘These categories down the side of the Add/ EE ‘Once the packages have been installed, you can find Remove Software window denote the type of the software within the Pi Menu items. In this case, software package through which you want to search. For example, Abe's Amazing Adventures in the Games section ofthe menu. Click lick on the Games category, then scroll down the list of available on the icon For the game, and it! load. To remove the newly packages and tick the box next to Side-scrolling gamenamed —_installed software, simply reopen Add/Remove Software, untick ‘Abe's Amazing Adventure the box and click OK again 48 wwbdmpubleationscom Learning Linux INC Learning Linux RUE eth Cel Ru ele (mae OMe MOMS une s 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. eee eee | is Learning Linux ] What is Linux? Deo oda cS eCuen cos came ene ec Cun Ta exactly is Linux? Where did it come from and what does it do? In a world where Windows PRO ee mm emt Omer aa eur ccrel mand rap Cette naan Linuxis a surprisingly powerful, fas, 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 ‘ofthe 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. It was 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 atthe time. Unix itself was released in the early "70s, as a 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 intialises 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, sound, networking and so on. GRAPHICAL SERVER This isa module within Linux that provides a graphical ‘output to your monitor. It’s referred toas the X server or simply X. 50 ww.bdmpubleationscom that 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 for the user to access. that hardware and comes with programs for productivity, communications, gaming, science, education and more. Linux can be broken up into a number of significant elements: SHELL ‘The Linux shells 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 shells 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 available, however Raspbian uses PIXEL. PROGRAMS/APPLICATIONS As Linuxis 2 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,

You might also like