FeatureGET STARTED WITH <strong>RASPBERRY</strong> <strong>PI</strong>INSTALLING AND UPDATING SOFTWAREExpand and maintain Raspbian for a long-lasting Raspberry Pi experienceINSTALL NEW SOFTWAREYou’re not limited to the softwarethat’s just on Raspbian when youinstall it. Raspbian has access tothousands of different programsthat you can download and install,just as you would with smartphoneapps. Raspbian doesn’t have anapp store, though, so you need toinstall them using the terminal.This does require you to alreadyknow what the software is calledto install it in the terminal, sinceyou can’t browse the software inthe same way as on your phone. Ifyou’re not sure of the exact nameof the software you want, you mayhave to Google it. Otherwise, ifyou’re looking for a specific kind ofapp, you can use a command likethe following to search for it:When it’s installed, youcan immediately startusing your new software,no restart required$ apt-cache search ftpIt will return a list of packages andtheir details. The package nameis how you install the software; inour case, FileZilla comes back asan FTP client. Its package name is‘filezilla’. So, to install it, we use:$ sudo apt-get installfilezillaThis will download the packageand any other necessary softwareit needs to run, and installit to Raspbian.UPDATE YOURSOFTWARE AND OSThe software on Raspbian willbe periodically updated online,bringing with it bug fixes andsecurity updates. Those don’tautomatically sync with theRaspberry Pi, though, and youshould regularly check to see ifthere are any updates for yoursystem. This is handled entirelyin the terminal again, much likethe software installation.The update process consistsof two parts: first you need toupdate the repositories; thisis the list of available softwareand their versions kept on yoursystem. You do that by firstentering the command:It may look likegobbledygook, butit’s telling Raspbianwhich softwareneeds to be updatedThis will check online tosee the state of the softwarerepositories and report back tothe Raspberry Pi, saving anychanges. It will then determinewhat software can be and shouldbe updated, but you then needto tell it to perform the updatewith this command:$ sudo apt-get upgradeEvery now and then, theremay be a major update to theRaspbian operating system,bringing with it big changeslike a new interface or browser,etc. It’s very rare, but when ithappens, you can perform theupgrade with:Raspbian asks you to agree to aninstallation with a simple press of Y$ sudo apt-get update$ sudo apt dist-upgrade22 August 2015raspberrypi.org/magpi
FeatureUSE THE G<strong>PI</strong>OMake your first small project witha bit of code and the G<strong>PI</strong>O pinsThe G<strong>PI</strong>O port is one of the mostpowerful tools at the Raspberry Pi’sdisposal, allowing you to connectdirectly to an electronic circuit tocontrol it. In such a system, the Piis referred to as a microcontroller.This is what makes the RaspberryPi great for big projects, as you canuse it to program a machine orcircuit, and even have it connect tothe internet via the other RaspberryPi functions so that it can controlcontraptions with web data.Each of the G<strong>PI</strong>O pins can dosomething different and veryspecific. At the basic core, though,you can have them provide powerconsistently to part of a circuit,program a power switch to one ofthe pins, and even have it sensea change over the pins (thanksto resistance). These three basicfunctions allow you to do a lot, andcan be programmed with Python.import RPi.G<strong>PI</strong>O as G<strong>PI</strong>Oimport timeG<strong>PI</strong>O.setmode(G<strong>PI</strong>O.BOARD)G<strong>PI</strong>O.setup(7, G<strong>PI</strong>O.OUT)G<strong>PI</strong>O.output(7,True)time.sleep(1)G<strong>PI</strong>O.output(7,False)time.sleep(1)G<strong>PI</strong>O.output(7,True)time.sleep(1)G<strong>PI</strong>O.output(7,False)print “Done”G<strong>PI</strong>O.cleanup()We’re going to wire up an LEDbulb to be programmable from theRaspberry Pi, to turn it on and offagain a few times. For this, youwill need a breadboard prototypingcircuit board, an LED, a 50-ohmresistor, and some wires. Refer toour Fritzing diagram on the right,to see how it’s wired up; thenegative end of the LED goesto the ground rail on theRaspberry Pi (which is where theflow of electricity ends), and aprogrammable pin goes through the50-ohm resistor to provide powerto the LED when it’s turned on.Open up IDLE, the Pythonprogramming software, andcreate a New file. Save it as led.py,and input the code from thecode listing. What the code doesis first tell Python to use the G<strong>PI</strong>Omodule so we can connect to theG<strong>PI</strong>O pins, by importing the module.We then import the time moduleso we can create a delay betweencommands. We then tell the code totreat the G<strong>PI</strong>O pins as the numberthey are on the board, and to turnthe seventh pin into an output. Wealternate between True and False sothat it turns the pin on and off. Onceit’s cycled a few times, it will printthe message ‘Done’ into IDLE, andfinally turn off the G<strong>PI</strong>O pins.You can do a lot more with G<strong>PI</strong>Oif you want to, and this is a goodway to start before moving on tobigger projects.Wire the circuit up just like this<strong>PI</strong>N 1 <strong>PI</strong>N 2+3V3+5VG<strong>PI</strong>O2 / SDA1+5VG<strong>PI</strong>O3 / SCL1GNDG<strong>PI</strong>O4TXD0 / G<strong>PI</strong>O14GNDRDX0 / G<strong>PI</strong>O15G<strong>PI</strong>O17G<strong>PI</strong>O18G<strong>PI</strong>O27GNDG<strong>PI</strong>O22G<strong>PI</strong>O23+3V3G<strong>PI</strong>O24G<strong>PI</strong>O10 / MOSIGNDG<strong>PI</strong>O9 / MISOG<strong>PI</strong>O25G<strong>PI</strong>O11 / SCLKCE0# / G<strong>PI</strong>O8GNDCE1# / G<strong>PI</strong>O7G<strong>PI</strong>O0 / ID_SDID_SC / G<strong>PI</strong>O1G<strong>PI</strong>O5G<strong>PI</strong>O6G<strong>PI</strong>O13G<strong>PI</strong>O19 / MISOG<strong>PI</strong>O26GNDGNDG<strong>PI</strong>O12GNDCE2# / G<strong>PI</strong>O16MOSI / G<strong>PI</strong>O20SCLK / G<strong>PI</strong>O21You can connect directly to the Raspberry Pi without needing any special slots over the pins<strong>PI</strong>N 39 <strong>PI</strong>N 40raspberrypi.org/magpi August 2015 23