0% found this document useful (0 votes)
325 views100 pages

Raspberry Pi For Beginners Oct 2023

raspberry

Uploaded by

Nenad Petrovic
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
325 views100 pages

Raspberry Pi For Beginners Oct 2023

raspberry

Uploaded by

Nenad Petrovic
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 100
Raspberry Pi Jargon-free Tips & Advice www. pclpublications.com Step-by-step Clear Full Tutorials Colour Guides Raspberry Pi 4 Model B Raspberry Pi Pico Raspberry Pi 400 Papercut 100% INDEPENDENT Want to master your Code? Then don't miss our NEW Programming & Coding magazine on 5 Readily now! Bau) ING THE SMART THINKING Pi Tea day he Future Is Code Coding Mastering eG p Windows The “S&S Ultimate Expert Pi Guide! oueH Insider = Tips & Tricks Sf On This Epic Coding Device Click our handy link to read now: https://bit.ly/30cL1zx Raspberry Pi For Beginners G Raspberry Pi For Beginners is the first and only choice if you want to learn everything about the Pi from the ground up - where the only limitation is your imagination. Learn how to build some amazing projects from a retro gaming console to a home entertainment system. The possibilities of the Raspberry Pi are endless and the best place to start is right here. Papercut www.pclpublications.com Contents 6 Raspberry Pi is Good For You! CS Mielke sse aa EY Caran ksi da ne! tere oy ee} The Pi 400 = Up Close eet ete euler ic a occ aM Sahai Neco Pee ny Microcomputer eae eerste 36 ET co cya cry 50 Explore Raspbian Ee Rial Te eS eck 7) foring the Command Line NICS 58_Connecting to the Pi Remotely Ce eosin Bate Pte ee Other SBCs to Use eoaream ete cs Ceres cul Rie aoe Raspberry Pi in Numbers PRCT eeu ra) Set it Up ace sagan) eis Sie oa Ey Rieoiae) Michio nage ariel MALL) PES ISC aT earn Terminal App Contents 68 Python on the Pi 70 Starting Python for the Fitst Time Pa PMS son ke scene Ne Comm Ue ei) Lea oee iss Ester Epon Nemes aaa meine Sore ere es ae ean Caer oa “Thanks to the Raspberry Pi’s unique setup, operating system and amazing community of imagineers, this little computer has become one ofthe most important pieces of educational technology in the world. It's helped people learn how computers, coding and electronics work, as well as helping science and engineering, astronauts and technicians, young and old, teachers and students. You will learn and discover how the Pi works, what you\can do with it and where to take your Pi adventures.” ee an Fi [ Raspberry Pi is Good For You! 5 Raspberry Pi is Good For You! Your journey with this amazing little computer begins here. Say hello to the Raspberry Pi; learn how it works, what kind of operating system it has, what you need to get it up and running and much more. This is your first step into the world of the Pets e a Tee ee Un Ree OCC CoR Ute am such a fabulous little computer and project board. There are in-depth guides to the hardware, operating system, what you'll ohne MU RMR UCR COR Okie BiB el me Tees Lo) a ol ETRE} rer Cm Roki 8 Raspberry Pi is Good For You! See eee ey Been ec eM cian any atts ee etn Peete Gaeeenrstt) Pieroni teu med ence ree Tat ad ea orate meter ata Revert ncne en enen rae ta ner a eee Oe Sena prea eerie kone eee Re ae comers een Perera nn icon caret an here his ert perros tt oreo board we recommend you buy. “The Raspberry Pis a British built Low cost computer that enables everybody to learn computing, start programming and explore basicelectronics. It’s the size of acredit card but capable of running afulloperating system and doing everything a desktop does. More importantly, with the Raspberry Pi you install your own operating system, connectall ‘your devices and create your own programs Using languages like Scratch and Python, ‘There's no case so you can hookup electronic circuits to the pins and control them to get inputand output, so you can hack together electronic projects at home. Setting up a Raspberry Piis pretty simple, ‘and throughout this book welltake youstep- bysstep From unboxing your Raspberry Pito. setting itup and getting started. “There are mary different models oF Raspberry Pi available and each has slightly different Features (see opposite) ‘The fundamentals of each Raspberry Pare similar though. Each modelis alightweight ere arts Say Hello to Raspberry Pi 8 computerona single board thet’sroughly the ize ofa credit card. Each Raspberry Pi board Features processor made by ARM, whichis similar the models you ind ina motile phone. The ARM processoris fast and lightweight butitrunsa different set of software than you might be used to. There ate many diferent operating systems (05) avaiable, but For most ofthis book well focus on one called Raspberry PiOS, which isthe 05 recommended by the Raspbery Pi Foundation. ‘There'sno hard drive on the Raspberry Pi, instead the operating system is installed ‘on an SD Card (the cards typically used in ‘cameras). The operating system s installed ‘onto the SD Card by copying the files to the ‘SD Card using a computer. Well show you hhow to set up the Raspberry PiOS using a ‘Macor Windows computer. ‘Once you have an OS installed on the SD (Card you can set up your Raspberry Pi. The Raspberry Piis connected to a monitor viaa HDMsocket whilst a keyboard and mouseis. attached to the USB socket. Asmaller Micro USB connectionis used to provide power to the device, Most Raspberry Pi models feature ‘anEthemet connection, and an Ethernet ‘ableis connected from your RaspberryPito socket on your modem router. Both the Raspberry Pi3 and 4 models have built in wireless networking and Bluetooth, ‘making iteasy to get online. You can attach ‘a USB WiFi dongle or Ethemet adaptor to colder models. Firstitwillhelp to know which Raspberry Plyou are using. This can be trickyas there have been several distinct models sor. The layouts opposite will help you determine \hich Raspberry Piyou have. This book covers allthe different models, and they offer largely similar Features although ‘newer models offer additional extras. Once you know which Raspberry Pi you own, you ‘angett up and running, Rei e ence et) Perea hony ferent memory size versions: 2GB, 4b, and 868. Obviously, the version i the most powerful OF the three, and th erin eee he eto “There's also an improved CPU, duat-monitor support inthe Form of Pegi eer ecE Sct mesa es ao ea eos Sie otc moray Brean eee esate a iow amount of power (Micro USB) making it ideal for smell power Serena en Peeve ‘3 mlero-USB adaptor to Connect devices A fourport USB Hub end Exhernet adaptor will come in handy too 8 Raspberry Pi is Good For You! 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 what powers the fantastic Pi 3. | Get to Know the Raspberry Pi 8 8 Raspberry Pi is Good For You! Up Close with the Raspberry Pi 4 Model B FASTER AND CONNECTED ‘There'sa lt to lke about the Raspberry 4: Up to 8GB of on-board memory, a Faster quad-core CPU, support for dual 4k displays Via apair of micro-HDM ports, and more, Lets take a look at the Pi 4, and see whatit’s got underthe-hood. PRICING BU ‘versions within therew mode t stands treason thatthe ee ee a eo ear tee Re ee ee er ee cement etry bbackin the region oF £54, Together with the cost ofthe P ea ee een Cee ee ene ee at eas two monitors), each costing roughly €Splus. Up Close with the Raspberry Pi 4 Model B 8 USE 3.0 Cetera etn Cie Petey ore eens ER ee ee arr rt Reece icy riueaest See preci Connectivity Ethernet port, the Pi 4 is certainly welt connected. Pena) feces Prone Peet the Pi ee) BS 22spber0y Piis Good For You! The Pi 400 - Up Close The Raspberry Pi 400 is an all-in-one keyboard Pi that was released in November 2020, offering the user a different approach to their Pi lifestyle. This compact and powerful Pi is the flagship of anew kind of Pi and one we'll hope to see more of this in the future. Inside the P| 400s a modified Raspberry Pi4 k's longer, spanning the width of the keyboard, witha large heatsink to disipate enough heat for the overclocked processor. The Pi4's communication portsare spaced along the back ofthe Pi 400 keyboard, minus asecond USB 20 port anda 3.5mm audiojack. microSD Card Slot ‘The microSD Card Slot is where you'll insert the card that contains the Raspberry Pi OS~ or eee enero eet et ees Sanne) other devices as you would a Peet micro-HDMI Ports Pen ard al device, you're Peet et eect erga COO ce Te Ete See rues) Sens Prete | The Pi 400-Up close SE Bie B16) See ae oe arate ee ie reer) fede ee Re tal Pete eter ts ee eee eeu latest Raspberry Pi OS. Sree ee Reais Deon LEI cere Doerr Incase you're RC aE aed Detects ea) Gigabit Ethernet ce cn Pores other USB 2.0 port is Cea ences PCC ene connection for the Pi 400 to your home Penner ribbon connected to, DOSE ete Pit wering, the Pi 400's keyboard. _ 8 Raspberry Pi is Good For You! J Pi 400: Return of the 80s Home Computer De eee cea ues cea Ta components were small enough to fit inside the living room of a house, and versatile Proteome ure eS ee nee M on cM ucee insur hacia Foundation has kept that feeling alive with the Pi 400 Released in November 2020, and while the UK and most ofthe world was stil in lockdown, the Raspberry Pi 400 came at atime when we were beginning to Fel lke there was no end to the pandemic and the restrictions it brought. Initial thoughts were that the Pi 400 wasa new small-board computer, ina similar vein to the Pi 4 and its predecessors. However, we were quite wrong. ‘The Pi 400is.a very different beast to that ois siblings. Rather than the naked board we've seen inthe past, the Pi 400 came asa complete keyboard package, wich the P's Familiar ports ined up along the backplate of the keyboard. ‘This in itself was remarkably reminiscent of the home microcomputers ofthe 80s, the prime examples being the ZX Spectrum and the Commodore 64, Indeed, the nostalgia was strong with this one, and itbrought a smile to more than one retro Fan's Face, THE REINVENTION OF THE oer MICROCOMPUTER ‘space of the keyboard. This, and thanks to a couple of air vents It’s more than sheer aesthetics that makes the Pi 400 hark back to on the bottom of the keyboard, are what allows the Pi 400 to be a simpler age of computing. Inside the keyboard is a Raspberry Pi overclocked to the default 1.8GHz. in Fact, we even took the Pi 400 albeit one that’shada facelift and some hardware alterations. he to.an impressive 2.2GHz, andit remained stable and cool enough id's ports, which are the twin microHDMland USB 3.0 ports,USB For continual operation, 20, Gigabit Ethemet and microSD card sot, take up the rear ofthe keyboard together witha port that connects directly tothe 40.GPIO pins ~and resembling an older style communications pot from the rear of an xT or earlier machine. ‘The heat dissipation From the large heatsinkisa great idea—and one that was previously sen in the Commadore 64 There'salso a thermal sticky pad on the top ofthe heatsink, that'sattachedlte the Pi 400 processor and helps tlift as much heat as possible From the CPU. IF Interms of hardware the Pi4inside the Pi 400 has beenexpandedto you get inside, youll also see why the Pi 400s missing a USB 2.0 port Fitmost ofthe width ofthe keyboard. The processoristhesame ARM sinceit only featuresa single2.0 port overthe Pi4's dual USB 20 ports ‘¥BCortex-A72 asfoundinthe bare Raspberry Piboard,butin this ne ofthe Pi 400's USB 2.0 ports has been used asa hard-wired ribbon instances been overclocked to 1.8GHz; 300Mhzfasterthanthe bare connector ta the keyboard section ofthe unit. Again, those oFyou board, There's also 4G8 of LPDDR¢ RAM installed, butsadlyno sian oF familiar with the internals ofan 80s home computer willrecall ribbons an 868 version which the Pi 4 bare model has on offer. being ateached to keyboard membranes. ‘The keyboarditcelFs availabe in different language layouts: UK, US, Germany, France Italy and Spain Essentially, i's the same keyboard that the PiFoundation hasbeen selling for some time, except this time there's anactual Raspberry Piinside of tas opposed tot simply being multi-port USB hub. P1400 DESKTOP COMPUTING ‘One ofthe prime benefits of having the Pi 400 keyboard ‘setups the Fact thatt can be quickly plugged into a monitor and working from the moment you hit the power key. The Pi ‘bare board, for example, requires a separate keyboard and mouse, and, let's be honest here, not many Folk want tosee bare circuit board on their desk. True, there are some great ‘design Pi4 cases around these days, but the Pi 400 already comesin aneat package. ‘The extra overclock brings a decent amount of oomph to the 1 400, and as such it’s perfectly reasonable to use the Pi 400 asastandard desktop computer. However, there comes with itsome negatives in this respect. While agreat device the Pi 400i. litte too smal for comfort, specifically atypical working day's use. 'sroughly the same size asa laptop keyboard, but the keys dont feel ‘as good ~a bit too squishy For our tastes. But, s with most things, welll probably get used toit overtime. ‘Another caveat that's worth mentioning, that the Pi 400 lecks.a3.5mm audio port. Where the Pi4 model had one, this, doesn't, instead opting to output sound via the HOM ports) While this isn'ta deat-breaker for mos, it does mean that for personal istening you'll need to hook up a set oF headphones toyourmonitor,or find another solution. The builtin Bluetooth will connect to headphones with that technology, Pi 400: Return of the 80s 8 but fyou'e limited to wired models, then you could be looking to buy upgrades. However, withallthatin mind the Pi 400 is another step closer to becoming the only computer youll ever need THE ZX PI 64 ‘There's good feeling of nostalgia when plugging ina Pi 400 to _amonitor or TV t's tke you're backto being 10 years ld again {and plugging in the Spectrum or the C6 for aspot of gaming or homework, before having to unplugit all when your Mum calls through that dinners ready. ‘Thankfully, these days, ts easy to save where you were-and the ‘entire thing doesn't crash when the kette is switched on! ‘Overall, the Pi 400s great addition to the Foundation’s stable, ‘and one thet we're sure youtcome to love and use dally. edpublatonscom 17 _ 8 Raspberry Pi is Good For You! Ten Pi 400 Projects and Ideas SMU UConn eee Toner Mell Recker ae Ce however that's not the case. Indeed, you won't be able to utilise the Pi 400 in quite the sam way asa standard Pi 4, but there's a lot you can get to grips with EVERYONE LOVES PI We've put together ten possible projects thet you could use your Pi 400 with; that will entertain and keep you busy while helping you learn ‘more about coding, the Pi and computing, ‘With the Pi400 being very similarto Ga Sd ‘that of the great home computers oF the 80s, we thoughe we'd start these ideas witha simple retrothemed project Fuse sa ZX Spectrum emulator that's avalabe forthe Raspberry i. Instat, and you can enjoy some of the greatest games ever created. I's possible to stream any game installed on your powerful gaming PC toa Raspberry Pi. All you needs to ensure that your home network is upto scratchuse Ethernet connections between the two iFyau can and to install Parsec From https,//parsecapp/downioads xe: PIT Faa] Since we've mentionedthe 2x Spectrum, its onl fair that weinclude the other great -bit home computer From the 80s, the Commodore 64. The uses a program called 64+a5pi or C64 emulation, and canbe installed via https// cé4emulator.11 mb defindex php?site=pp_ raspiBlang=enBgroup=c6s. Ee Peery While we're onthe subject of streaming ‘games if you own.a Google Stacia, then you're able to stream games to the Piva the Chromium browser. You" need a good network connection, and some games may wellbe abit laggy, but ts worth a try ‘ec Ten Pi 400 Projects and Ideas 8 PVentetolet ted Te P2005 1.8GH: processoris adequate FPESVarsfadste] Since lockdown started in 2020, folk have been For most tasks, but thanks tothe large, ‘coming up with novel ways in which they can metal heatsink inside the keyboard, ts possible toget that clock work and educate at home on a budget. The arrival of the Pi 400 speed even higher. There's a great YouTube tutorial on how to vasa great boost for home working, and it makes Fora great ‘overclock the Pi 400 to 2.2GH2 a httns/Awww youtube.com) desktop PC. Just add a mouse, dual monitors and you can even use watehv=0qZ99MGDSRO, Teams via Chromium, —_ <—$_ PONTITSR Yes posible oun aversion of FRESNO Te cefauitResbeny Pio ent Windows 10 onthe i 400. Tere are the only operating system sping tobe some iitationsthere's no sound, WeFior Bluetooth, but avaiable forthe Raspbery Fi Weve already seen Retry ut theres is afin project that’s definitely going places Checkout theinstall_alsoa verson oF Ubuntu, an entertainment OS called Lire video courtesy of Lepspuideo at https/wwuyoutube.comy RISCOS,the orginal ARM OS and many more to discover watehv=xbRBovkmZVUSt=05, Ba estninc) Te Pi400 makes fora great underthe TV MNS NUED nea cene Youdort specfcaly need ‘megia-cenric operating system, the Raspberry Pi OS wil suffice. With ityou can watch network-stored movies, browse the Internet, watch YouTube content and much more. | P0001 Peeled The Pi 4 made For a great platform on which to learn how to code, but thanks to the neater approach of the Pi 400, it's now an even better base on Which to code. You can learn how to code with Python, MicroPython, C and C++ and many more languages. Check out ‘our coding guides at httpsi//bdmpublications.com. _ 8 Raspberry Pi is Good For You! The Pi Pico — Up Close aaa The Pi Pico isn't your normal Raspberry Pi. Instead, this is a tiny microcontroller, designed to help enthusiasts control and utilise connected appliances and electronics projects. From displaying an LCD to controlling LEDs, using MicroPython and C++. The Pi Pico may be small, tit packs a decent punch. witht youcan ‘expand your electronics projects, and incorporate a whole new Level ‘of functionality that you werer't able to before with the traditional ¢ Raspberry Piurits micro-USB Port ‘The Pi Pico's micro-USB provides both power, as Pere Teeter) Reece ce to upload programs and projects on to your Pico. Erefeee SeeaTT Prosetti enabling you Beers Perea ince PE Fs re reer The Pi Pico - Up Close 8 Sere ec) Fees ers acs ieee eee cn eh ere eerste ee Ce aia mer core ARM Cortex-MO+ processor, with a flexible clock speed up of to 133MHz. Settee ay Perec) Perea et arate es foray of Pa Mee cee rtd rns ees) 8 Raspberry Pi is Good For You! Pico Power: The Tiny Microcontroller ‘The Picois something entirely different from the Raspberry Pi Foundation's usual releases. Whereas the Raspberry Pi, now on version 4, is small computer, and even the Compute Module and the Pi 400 are stil ust computers, the Picois actually amicrocontroler. Amicrocontrollerisa processing unit thats designed to work with programmable peripherals, and has input and output modules alongside small amount of memory and storage capabilities. The processors are often scaled down, compared to the processor on a Raspberry Pi, oF leven inside your desktop computer, but powerful enough to complete basic tasks. Examples ofa microcontroller inaction can be Found inside a washing ‘machine, or traffic lights. Awashing machine has no need for aquad-core processor, 368 of memory, and the ability to output toa 4K monitor. Instead, has a set of microcontrollers, that ae connected to various parts (of the washing machine ~such as the pump, or motor. When asignal is sent ton input on the washing machine's microcontroler,itknows~ through some clever programming stored inits limited memory that itneedsto send asignal output t the valvesto allow ina certain amount of water, thenactivate the motor forthe drum and so on. “The same can be apliedin the traffic light example. A powerful computer isn't necessary, soa microcontroller willactivate the red, amber and green lights in sequence or switch to red to stop traffic when someone presses the Walk button, While would probably be interesting to have a powerful computer inside ‘your washing machine t's overkl, A microcontroller takes up less space, uses ess eneray, andisnt prone to the kind of crashes orinneed ofthe frequent updates that a traditional computer requires. They simply it there, act on inputs that come their way, process that data, and output whatever is required depending on the inputactions Power useis the main reason why rmicrocontrollersare in ation everywhere we look There's often limited supply to devices, or situations. Amicrocontroller can work effectively with the limited amount of eneray drawn From small sola cell-evenin the most overcast ‘of nother climes. For example, on-board the Intemational Space Station, there are thousands cof microcontrollrsin action: monitoring ar quality, monitoring radation levels, distributing ower and keeping trackon the crew. each of these units were a more powerful computing device, the power draw on the ISS would be immense; so microcontrollers are the way Forward atleast untilwe work outhow to build a warp corevith near unlimited energy, thats Pico Power: The Tiny Microcontroller 8 a PROGRAMMABLE PICO ‘The main difference between the microcontrollers inside your ‘everyday appliances and the Pico is that where the microcontrollers within your washing machine are pre-programmed with their instructions, the Pico isn't and can be programmed by you ‘This means that you can use the Pic's USB port to connect toa ‘computer, write some codetto control something, upload the cade to the Pico's RP2040 microcontroller, and watch asit does what you've asked it do. ‘The 26 multifunction GPIO pins located down the ong sides ofthe. Pico, canbe used to solder electronics projects to. And with some lever coding, you're able to contro the input and output of devices ‘depending on thelr state via the Pico microcontroller. Each ofthe Pico'sGPIO pins have specific uses, as you can see from the pinout chart. This means that certain electronic components. soldered to the pins, can be programmed using the co's primary microcontroller language, MicroPython (or C+) REMEMBER, IT'S NOTA PI és worth mentioning thatthe Raspberry Pico ist designed the ‘same as or can replace, a Raspberry Pi. This isa different type (of device altogether. Where you'luse your Pito browse the Internet, playa game, do some coding and so on the Pico can't do that. It's designed for use with physical components and project, such 2s lighting LEDs or responding toa button push, controlling motors and the like. |Fyou want more versatility For your projects, then the Raspberry Pisstillthe perfect device to use. you've got something speaificin mind, and you want to expand into electronics and microcontrollers, chen the Pico will i the bill. But, you' also ‘need a computer, or Raspberry Pi, in order to program the Pico to begin with. ee} _ 8 Raspberry Pi is Good For You! | The Pico and MicroPython The beauty of the Pico is that it's a blank microcontroller, meaning that it's free from any pre- installed code or routines. This allows you to program the Pico to whatever tasks or projects Meme hem ates e en hecho eatin ‘The Pico uses MicroPython or C/C++ code in order to communicate with the devicesit willbe attached to. The code will, when uploaded to the Pico, run a specific set of instructions depending onthe electrones that are soldered tothe Pico. For example, in ‘MicroPython, with an LED attached to the Pico, you would nitialise andimport the Pin and Timer modules tel the Pico which GPIO the LED is attached to, then setup a routine that wil use the Timer Function to send a signalto the LED lets say every couple of seconds The end result would bea blinking LED, which goes on and off every two seconds Naturally, the more complex the electronics attached t the Pico are, then the more complex the MicroPython code wil beto make thern workin the way you want. \MicroPython is probably the best language to begin with when it ‘comes to programming the Pico. Like Python, ts abit easierto get ‘your head around when compared to Cor C++ -andit’s probably slightly easier to get up and running. There's also the added advantage of there being more examples of it online, so you can dip ino the various sites around the Internet and take the code snippets ‘youneed to make certain devices and peripherals work. ations a s MICROPYTHON MicroPython sa Python 3-based coding language that's designed to be executed on the RP2040 microcontroller the one that's powering the Pi Pico. It’s. highly efficient language, and thanks tothe co's larger than average memory and capacity -for a microcontroller 'sthe ideal language to start learning, Ifyou already have some ‘experience with Python3, then MicroPython should be relatively ‘easy to follow; since they e essentially the same. Ifyou've never used Python before, then we'd recommend you take a look atone of our coding ites at, https//bdmpublcations.com, Before you can use MicroPython, though, you'lneed to flash the Pico with the latest version of MicroPython. This means downloading the latest version of MicroPython and uploading t onto the Pico. The processis remarkably easy, however. ‘Start by connecting one end of a USB cable to the Pico. Then press {and hold the BOOTSEL button on the Pico, while atthe same time plugging the other end of the USB cable into your computer, ora Raspberry Pi Count to Five, then et go ofthe BOOTSEL button. ‘within afew seconds the computer, or Raspberry Pi, wll display 3 notification that an external, or removable, drive has been attached the same feshion as when you plug na USB Flash drive. IF you open your File Manager or Explorer window, and navigate to the newly installed Pico storage, you'll see two files present: INDEX. HTMand INFO_UF2.TXT. ‘The INFO_UF2.TXT file contains information regarding your Pico, {and the INDEX.HTM isa web-based page that contains allthe information youl need to get the Pico connected and installed with -MicroPython | The Pico and MicroPython 8 ‘Alternatively, ou can open a browser and navigate to https//www raspberrypi.ora/documentation/pico/aettina started. Scroll down untilyou get to the Getting started with MicroPython section, and follow the on-screen instructions. lick on the Download UF2 ile button ~at the bottom ofthe Getting Started info box. ‘Once the UF? ile has been downloaded, locate tin the Downloads folder on your computor, and click and drag t into the Pico storage >>".Now, enter the following: print (Hello, world!) Users of Python wil undoubtedly recognise the syntax, butif you've never coded with Python before, then lets explain what's going anin thissimpletine ‘The prt command, as you probably assume, is used to print, oF display, something tothe screen forthe user to read. Fyouwant to say something tothe use, then you'lineed to enclose your text inside a pair of brackets and quotation marks. In this example, we're displaying the words Bel16, world¥. When the MicroPython interpreter reads the Print command it will naturally assume that somethings being csplayed, and look fora number of acceptable ‘outcomes. The First bracket and opening quotation mark means there's going tobe some text, so the interpreter will look Fora closing set of quotation marks nd bracket Press Enter, and the words Hel16, WoELaY will appear inthe Shel section of Thonry, \What you've just done s communicate directly with the Pico, and through MicroPython on the Pico, i's recognised the command you've centered and acted onit. Just for Fun, enter the command again, but this time intentionally miss out the last bracket. Youll notice that the Shell doesn’t want to continue without the bracket, so therefore it'san error. While using MicroPython, or most other programming languages, you'l need tobe careful what you type. The: dire consequences to your code ~or, more than kel itfrom working. Forthe next example, clidcthe upper partof Thonny, where the number “Tis, Now enter the Hell, world code again. When youhit Enter this time, youl natice that instead of running the code through the Pico, ‘Thonny has created a second line ands waiting for more input. ‘While using the Shells great, isnot so good For creating multHine ‘code. This is where the upper section comes in, To execute the code in the upper section youl need to dothe followings Clickthe Run button; this opens anew window asking Fora save location (This computer or the Raspberry Pi Picc). This is because any code thats been entered, in the upper section of Thonny needstobe saved first, 2s.py ile, beforeit canbe executed, Select the Pico asthe save location, then when asked, createa name for the py fle—inthis case callit HelloWorld.py and click the OK button, ‘As soon as you've saved the file, will automatically rn and youllsee the output from the code displayed in the Shel box. ‘Alternatively, you can open.a browser and navigate to https://wwww raspberrypiorg/documentation/pico/getting started. Scroll down Lntilyou get to the Getting started with MicroPython section, and follow the on-screen instructions. Click on the Download UFZfile button ~at the bottom ofthe Getting Started info box. ‘Once the UF2 file has been downloaded, locate tin the Downloads Folder on your computer, and click and drag it into the Pico storage dive; as you would drag and drop afile From your computer toa standard USB Flash drive. ‘AftoraFow seconds, the Pico storage drive will isappear- you may ‘got a warning stating thatthe device wasnt unplugged correctly, but ignore that. This process has now ‘lashed! the Pico with the MicroPython Firmware. The Pico disappearing from the File Manager means thatithas rebooted and is now in MicroPython mode. Thisis ‘essentially allyou need todo For the moment. The Picoisnow ready tostart coding on to using MicroPython. BEOQOS®9® aeO088 \ Pico Examples and How To 8 BLINKING LEDS! ‘MicroPython, as with Python, uses modules to enhance the code you're writing. A modules simply Further code, but when called ‘upon by your code it will operate to specific parameters. For ‘example, there are modules available that are designed to handle ‘raphics, while others handle complex mathematical operations. Using these modules saves you from having to invent the code and place it among the mary tines you'r typing in. All youneed dois cal ‘upthe madule, and pass ary varlables and parameters through the ‘module to get the result you want In MicroPython, and in the Pico's case, there are modules that can bbe called upon that handle the physical hardware side of things. The Pico-specfic modules will handle input and output through the GPIO ports, or utilise some of the Pico's inherent sensors. For example, here's some code that wlllght up the builtin LED on the Pico: ‘from machine import Pin Jed = Pin(25, Pin.ovr) ed.on() “Type into the upper section of Thonny,saveit as LED.py (for example) andrunthe code. The LED wilight up. But, ets explain Whats going on here, To begin wth we have, from machine import Pin. This means thatthe code is going to open the bultn module called Machine, of which a certain cass within itis called Pn, This particular set of external code isdesigned to talk’ to and handle the input and output of the Pico's PIO pins. ‘Thenext tine, Yea'= Pin (25, Pin-OUT) . What we've done heres, create a variable called Led, which we've told to hold the information regarding the Pin class, in particular the number 25, as an Output. The PIO pin on the Pico is hardwired tothe LED, so essentially we've told MicroPython that Pin 25 is going to have Outout data sent tot, and i's going to be called led “The finalline,1ea.on (is a trigger that sets Pin 25 Outputto ahigh value -in this case, On. The resuleis thatthe LED on the Pico willbe turned on. Try and alter the code, so the last ine reads: ea.orf() ‘Ae you would expect, this ture the LED off. Now try: ed. toggle () ee _ 8 Raspberry Pi is Good For You! What toggled) does is every time the code's executed, fthe LED ison Teil switch off and it’s off et switch on ineeresting stuf isnt. Let's expand our LED code further and include aloop with another - re] >) kind of module: New ‘from machine import Pin [LeDpyl ‘from utine import sleep from wachine inport Pin aS Lea'= Pin(25, Pin.OUT) : 5 tee. togater if for 4 4n range(5): ‘ed. toggle sleep (1) ‘ed. toggle () sleep (1) \When you execute this new code it will lnk the LED five times ~ based on whether the LED was previously on or off using the led. togale() syntax we looked at amoment ago. Let's take a moment to break down the new elements ofthe code, though, ‘Fron time import sleep, as ou probably suspect, thisis using ‘anew module called utime, from which we want to use the sleep class. Utime holds code that canbe used For timing, and the sleep class enables the code to pause for a specficnumber of seconds. For 4 in range(5), is anew lie which sthe beginning of aloop. Basically, we've asked MicroPython to count to5, and anything after the colonis repeated ve tines. Providing what code weve enteredin fl |Shet tthe loop Is okay, itl do it Five times before stopping, Note: The indent ceil Ahnu afterthe colon. This meansthat the code inthe indents directly 2 controled by the Fo loop néensn Python areas important 2s ies speling and geting the correct characters in order sos “The final new element is sLeep(1), which pauses the code forthe ed count of one, or one second, Feel Free to mess araund withthe code ae {you've created, Extend the numberof seconds, use led.on and led.off instead of toggle, and extend the For loop to more than Five, ° 4 + 4 ies toontet) jot TEMPERATURE READINGS ‘The Pico also comes with a builtin temperature sensor, andis ‘connected to one ofthe Pico's analogue pins. The analogue pins on the Pico are actually called ADC's or Analogue to Digital Converter whereas the GPIOs are digital. The difference is that a digital pin reads only two states: High or Low (or One and OFF), and an analogue pin can read a range of values from zero 65535 (through the use ‘of MieroPython, the Pic's ADC really reads From zero to 4096), ‘This meansthat anything that’s read through the analogue pins canbe from Oto the value of 65536, which makesit perfect Fora temperature sensor. ‘The temperature on the Pico is hardwired into ADC4~ or analogue pin 4. Sowe can extract the data from the temperature sensor using the following code: ‘from machine import ADC tempsensor = ADC(4) temperature = tempsensor.read 1164) ‘print (temperature) ‘There'sallt going on here, and the dsplayed number that appears in the Shel! probably won't make much sense, solet's havea look at the code. First we're using the machine module and from it the ADC clas. ‘Then we've created atempsensor variable which wil pullthe data from ADC pin 4whichs the Picos temperature sensor. The third line ofthe code creates a temperature variable, which stores the value oF ADC4 and applies 16-bit data range tot so we can havea value from Oto 65535. And finally, we're printing the currently held value oF temperature inthe Shel Nowhere'sthe part that will make your head hurt. ‘The Picos microcontroller runs at 3:3 volts. So when there's full 33V being applied, the ADC wil read a value oF 65535, and when there's no voltage it will read zero. The temperature sensor on ‘ADC4 works by sending voltage to ADCS thats proportional to the ‘environmental temperature. othe environment the Picoisin is 27 degree Celsius the Pico sends voltage of 0.706V.So, using the 33V maximum at the value of 65535 and the operational specifications (0F 27 degrees Celsiusas being a voltage of 0.706V, we can work ‘out code that will convert te original value you got from the temperature variable into degrees Celsius Before our brains dribble out, here's the rest ofthe code ‘from machine import apc ‘tempsensor = anc(4) ‘temperature = tempsensor.read u16() volts = 3.3 / 65535 ‘temperature = temperature * volte calsius = 27 = (tomparature = 0.706) / 0.001721 print (celsius) Let's run through the code. We've created a volts variable which takes the maximum 3.3V and divides t by 65535, then we've taken | The Pico and MicroPython 8 the already read temperature variable and multiplied that by the volts value. We've then created a Celsius variable, which we've used the above numbersto store the value of 27, minus the temperature value, minus 0.706 and divided by 0.001721. This wil give usa reasonably accurate conversion of volts to Celsius, which the code will then print ino the Shell section of Thonny. ‘Asyoucansee fromthe screenshot, the room we ran this code in wasa balmy 2049 degrees Celsius. When we looked a the temperature on the digital thermostatin the same room, it read21 degree Celsius, so only half degree out, Which sn to0 bad, THE WORLD OF THE PICO AWAITS... ‘Thisis only a small example ofthe type of projects and coding that ‘canbe achieved withthe Pico and MicroPython, There are numerous. ‘extras, such as motors, sensors, LEDS and even LED screens that can be attached to the Pico's GPIO ports with some neat soldering and the use ofa handy electronics kit ‘What we've looked at here is taster and the Foundations on how to ‘allup the Pico's GPIO pins and howto use MicroPython in Thonny. Fromhere, we'd recommend you learn more about how the Raspberry Pi functions as well as some more Python coding, which will give youa better insight into how the Pico and MicroPython will work. Have fun, and let us know what Pico projects you've created. ee) 8 Raspberry Pi is Good For You! Pico Projects & Ideas PICO POWER! Here are ten ideas and projects that you could look into achieving with your Raspberry Pi Pico. You may need to enhance your electronics skis, but there's plenty of help online if you hunt around For it Perle] CanvouceateaPicopoweredmicocontrolleto FWSRSISEY Inaddition tothe robotics idea, aPico canbe used to work aiferent aspects ofa robot” You could se the control motors. Again, depending on the input to the Pico to drive the robot, or control an element onit depending on Pico, the output can spin up a motor and move an object, stop i, oF ‘where itisin your home. ‘even power something else EES Peristrnoccesertse MESPTMERETY wv rotonkunsane core cs an tis 3 built-in ADC to convert analogue to use the Pico microcontroller asa set of igital signals. talso has abun temperature sensor soit’s possible trafficights. You can even incorporate a button, that when pushed toutilise the Pcoas a temperature gauge. willact. asa Walk button and stop the trafic for pedestrians. Pico Projects and Ideas 8 NED oscceryurommoscnsccion WAAMMASNMMEESISAED (ton tenho sensor whichmeansyoucan creates burglar am orinddeleth Plo together ith phototansstor sensor, and telescope, could therebodea to allow ome orm atonory, be used createa scope tht can tack the pe:sage ofthe Moon through the night sky. Treen Tater feria) Usina buttons and LEDs you can NATURE PHOTO CAPTURE [uukiiaaclnecal create a simple button push reaction sensor,you could attach the ‘game, for multiple players Pechaps you could attach buzzer thet Pico toan outdoor camera~or camera withina weather-xrooF signifies the winner or loser. container—to activate when something passes the sensor; capturing i & v 0 0, PETE lany Mosthome automation tasks are PRUNRSRPNINESNINY There are a number of Pico-built RGB run through microcontrollers, so LED displays available ontine. You can the Pico is suitably placed for those who have setup some advanced use one to display messages, create some form of interactive home automation devices. Elements such as turing the heating or game, or display data that's coming from one of the input GPIOs lights on, or opening the garage door, for instance. attached to a sensor. 8 Raspberry Pi is Good For You! Other SBCs to Use ‘An S&C, or Single-Board Computer, is a complete computer system that's buit ona single piace of circult board; consisting of memory, storage and input and output ports. The Raspberry Pisa prime example of modern SBC, and the one that has easily become the most popular However, there are a numberof other SBCs available that vary in size, capacity, performance, price and expandability. Some of them are 86-based, which means they e basically very small PCs on which you can install Windows 10; others utilise different makes of processor or ‘microprocessors and offer a varied number of operating systems that will work on them, such as Android or Linux While the Raspberry Plis the SBC that offers some of the best opportunities in terms of project work, and flexibility, i's certainly not the only ‘one of ts kind. Weve listed some of our favourite boards, that you may consider taking alookat ifthe Raspberry P isn't Fulfiling your goals “The Udoo brand has been active since 2013, when it aunchedits First SBC via Kickstarter. hese daysthe company sat the forefront of developing some of the most powerful SCs onthe market; in particular, the Udoo Balt “The Udoo Bolt measures 120mm x 120mm and features an ultra-powerful AMD RRyzen V1605B, quad-core/eight thread CPU, running at a maximum oF 3.6GHz. ‘The builtin GPUis the AMD Radeon VEGA 8, and there's support fortwo dua channel SO-DIMM DDR4 memory units toa maximum of 3268. “There's alsoa 32GB EMMC 5.0 Flash module installed, but witha pair oF M2 sockets For M2 SSDs. Interms of connectivity, there's a gigabit Ethernet port, with Bluetooth and Wi, wo US® 3.0 ports, two USB-C ports, a single USB 3.1 port, two fullsized HOM ports and power input via USe-PO. Line - ‘The V0 for projectsis Arduino Leonardo ‘compatible, with 12 analogue ports, up to23 digital ports, anda single UART, 12C and SPL ies remarkably impressive board, that can run Windows or Linux. But all that power and lOcomesataprce. Te Bava.theboawe mentioned above, comes inat $418, roughly +€300. Whichis pretty expensive compared to the Raspberry Fi; but this tiny board is more powerful than most desktop computers. BANANA PI Launched in 2014, the Banana Pisa Raspberry Picompatble board thathas seen mary releases since itsintial conception. These are ‘ARiV-based SBCs developed in China and sold via anumber of international distributors. ‘The latest version of the Banana Pi the BPLMS, looks remarkably similar tothe Raspberry P36. Itfeatures an AmlogicS905X quad-core CCortex-ASS CPU running ata decent 2GHz, together with a MaliG31 (GPU. There's 4G8 of LPDDR4 memory, 16GB of eMC Flash storage on- board and MicroSD slot with support for upto 25668 cards. Connectivity comesin the form oF asigabit Ethernet port, Full sized HOM, 35mm aucio jack, four USB 3.0 ports anda USB-C port for power input. The VO mimics the Raspberry P's 40-pn GPIO, but there's ‘noextra connectivity For cameras and such; as Found onthe Raspberry Pi. ROCK PI Developed by Rada the Rock Pihas been a direct competitor to the Raspberry Pifor some years now; and t's certainly not looking Uke t’s slowing down any time soon. ‘The latest version i the Rock Pi4 Model C, which sports ahexs- core CPUwith a dual-core Cortex-A72 at 1.8GHz and a quad core CCortex-AS3 at 1.4GHz together with a Mall T860MPa GPU. Models. ‘Aand 8 feature 1GB,2GB and 4GB memory options; ut the Model ‘Ccomes with only 4GB oF LPDDR4 memory. There's an eMMC Flash module available, in 868, 16GB, 32GB, 64G8 and 128GB options, as ‘wells a MicroSD card slot with support For 12868 cards, and an M2 connector For M2 SDs. ‘As For connectivity there's HDMI, gigabit Ethernet, two USB 3.0 ports, two USB 2.0 ports, 3.5mm audio jack, USB-C For power, and Bluetooth and WiFi. For project work, there's 40-pin GPIO, as wells. MIPICCSI slot For ‘cameraaattachments, t's also interesting tonote that the Ethernet. port supports Power-over-Ethernet (with an additional HAT). Not bad fora board that measures 85mm x 54mm, ‘The Rock Pi Model Ccosts $59 or £42, and while alittle more ‘expensive than the Raspberry Pi, it outperforms the Pin nearly ‘every benchmark. [ other SBCs to Use 8 “The Banana Pi MSis atad more powerfulthan the Raspberry Pi4, and the 4GB memory option copies the more common Pi available. ‘Although you wil have extra RAM if you were Lucky enough to get hold ofthe 868 memory You can install both Linux or Android on the MS, andit’s even Raspberry i OS compatible. Itcosts$53~at the time of writing - which equates to around £38; 50 not too far fromthe cast ofa Raspberry i. ARE THEY WORTH IT? The question of whether to use a diferent board other than the Raspberry Pls purely up to you asan individual and what you're planning on using the SBC for. For most Folk, who buy a Raspberry Pi For emulation or asa media server - which are the two most popular projects used by users then they'd probably get more mileage out ofthe aforementioned boards. rue, the expense is considerable in the case of the Udoo, but tll do. far better job of processing than the Raspberry Pi willever do. The realargument comes down to cost. Fyou'e willing to paya little ‘more forthe extra performance, then the alternative SBCs wil suit, you Fine. But when you compare them tothe Raspberry Fi, the Pi does seem to come on top in terms of cost-versus-performance. Needless to ay there are countless more SBCs available. Some are smaller, even more powerful than the Pand cost does vary wildly From one product to the next. For most users, though ~ and especially for the beginner the best bets to stick to the Raspberry i. Whenyourskillsimprove, and you have more specific projects inmind, then look to the other boards or the specifications and Features youneed. eee} _ 8 Raspberry Pi is Good For You! | Raspbian: The Complete Operating System DS ce occu es iam etree COe Na Eee enced ee aac ance cosets icone cec Result POWERING THE PI ‘The Raspbian OS has been powering the Raspberry Pisince its release backin2013.Atits cre, Rspbianisa Linux operating system, based on the hugely popular Debian Flavour of Linux. Mike Thompson and Peter Green created Raspbian in 2012, to werk on 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 mode Pi, the Raspberry 2; ulising the 3.18 Linux kernel while stillhaving Debian 7 (codenamed Wheezy) as the base. ‘Mid-way through 2015,Raspbianstartedusing Debian 8 Jesse) asthe base, withkemels 4.1, 44, and 49, Kernel 49 was alo 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 essentially the same core operating system, those available now are a Lite, Minimal and Full desktop set of images. ‘One ofthe primary reasons forthe three- way spit is due to the overall size of the continually improving Raspbian. ints early years, the Raspbian desktop image size ‘was a litle under 1GB. This image contained everything the Pi user ofthe time needed to get their projects up and running, 2s well as enjoying third-party applications such as LibreOffice. Slowly, a the Pi itself evolved, the Rasphian image increased. These days the image weighs in at around 1.868 and it's ely to continue to.expand over the coming years as new software is improved on and added, alongside changing hardware. However, the three-way spt addresses the issue ofan ever-expanding OS image, while still enabling the userto get the most from their Raspberry Pi. “The Lite version image comes in at roughly 350MB in size. While I may seem like a logical choice to opt forthe Lite version, i's not recommended for every user. The Lite version basically installs without anyof the software you expect From the previous versions of Respbian; it doesnt even come with the graphical desktop. This makes it an incredibly streamlined and efficient version ofthe OS that's ideal for those who run headless Pi servers (aPiwithout a monitor, keyboard or ‘mouse attached, thatthe 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, so For most beginners it's not a ‘g00d place to start. The more advanced users wil, however, be able to setup thelr Pi projects without the unnecessary baggage of all the ‘other applications clogging up the P's precious system resources. t's worth noting that the Lite edition can be made upto a fully funcional

You might also like