Sams Teach Yourself Python Programming for Raspberry Pi in 24 Hours, Second EditionCopyright © 2016 by Pearson Education, Inc.. The official programming language of the Raspberry Pi is P
Trang 2EPUB is an open, industry-standard format for e-books However, support for EPUBand its many features varies across reading devices and applications Use your device orapp settings to customize the presentation to your liking Settings that you can customizeoften include font, font size, single or double column, landscape or portrait mode, andfigures that you can click or tap to enlarge For additional information about the settingsand features on your reading device or app, visit the device manufacturer’s Web site.Many titles include programming code or configuration examples To optimize thepresentation of these elements, view the e-book in single-column, landscape mode andadjust the font size to the smallest setting In addition to presenting code and
configurations in the reflowable text format, we have included images of the code thatmimic the presentation found in the print book; therefore, where the reflowable formatmay compromise the presentation of the code listing, you will see a “Click here to viewcode image” link Click the link to view the print-fidelity code image To return to theprevious page viewed, click the Back button on your device or app
Trang 3Programming for Raspberry Pi in 24
Hours SECOND EDITION Richard Blum and Christine Bresnahan
800 East 96th Street, Indianapolis, Indiana, 46240 USA
Trang 4Sams Teach Yourself Python Programming for Raspberry Pi in 24 Hours, Second Edition
Copyright © 2016 by Pearson Education, Inc
All rights reserved No part of this book shall be reproduced, stored in a retrieval system,
or transmitted by any means, electronic, mechanical, photocopying, recording, or
otherwise, without written permission from the publisher No patent liability is assumedwith respect to the use of the information contained herein Although every precaution hasbeen taken in the preparation of this book, the publisher and author assume no
responsibility for errors or omissions Nor is any liability assumed for damages resultingfrom the use of the information contained herein
Trang 5Trademarks
All terms mentioned in this book that are known to be trademarks or service marks havebeen appropriately capitalized Sams Publishing cannot attest to the accuracy of this
information Use of a term in this book should not be regarded as affecting the validity ofany trademark or service mark
Warning and Disclaimer
Every effort has been made to make this book as complete and as accurate as possible, but
no warranty or fitness is implied The information provided is on an “as is” basis Theauthors and the publisher shall have neither liability nor responsibility to any person orentity with respect to any loss or damages arising from the information contained in thisbook or from the use of programs accompanying it
Special Sales
For information about buying this title in bulk quantities, or for special sales opportunities(which may include electronic versions; custom cover designs; and content particular toyour business, training goals, marketing focus, or branding interests), please contact ourcorporate sales department at corpsales@pearsoned.com or (800) 382-3419
For government sales inquiries, please contact governmentsales@pearsoned.com
For questions about sales outside the U.S., please contact international@pearsoned.com
Trang 9Learning About the Python Development EnvironmentCreating and Running Python Scripts
Trang 13Exploring the tkinter WidgetsSummary
Q&A
Workshop
HOUR 19: Game Programming
Understanding Game ProgrammingLearning About Game Tools
Setting Up the PyGame LibraryUsing PyGame
Trang 16Richard Blum has worked in the IT industry for more than 30 years as a network and
systems administrator, managing Microsoft, Unix, Linux, and Novell servers for a
network with more than 3,500 users He has developed and teaches programming andLinux courses via the Internet to colleges and universities worldwide Rich has a master’sdegree in management information systems from Purdue University and is the author of
administration, and Linux security classes Christine produces Unix/Linux educational
material and is the author of Linux Bible, Eighth Edition (coauthored with Christopher Negus) and Linux Command Line and Shell Scripting Bible (coauthored with Richard
Blum) She has been an enthusiastic owner of a Raspberry Pi since 2012
Trang 18First, all glory and praise go to God, who through His Son, Jesus Christ, makes all thingspossible and gives us the gift of eternal life
Many thanks go to the fantastic team of people at Sams Publishing for their outstandingwork on this project Thanks to Rick Kughen, the executive editor, for offering us theopportunity to work on this book and keeping things on track We are grateful to
development editor Mark Renfrow, who provided diligence in making our work morepresentable Thanks to the production editor, Seth Kerney, for making sure the book wasproduced Many thanks to the copy editor, Megan Wade-Taxter, for her endless patienceand diligence in making our work readable Also, we are indebted to our technical editor,Kevin E Ryan, who put in many long hours double-checking all our work and keeping thebook technically accurate
Thanks to Tonya of Tonya Wittig Photography, who created incredible pictures of ourRaspberry Pis and was very patient in taking all the photos we wanted for the book, and tothe talented Daniel Anez (theanez.com) for his illustration work We would also like tothank Carole Jelen at Waterside Productions, Inc., for arranging this opportunity for us andfor helping us out in our writing careers
Christine would also like to thank her student, Paul Bohall, for introducing her to the
Raspberry Pi, and her husband, Timothy, for his encouragement to pursue the “geekystuff” students introduce her to
Trang 19As the reader of this book, you are our most important critic and commentator We valueyour opinion and want to know what we’re doing right, what we could do better, whatareas you’d like to see us publish in, and any other words of wisdom you’re willing topass our way
We welcome your comments You can email or write to let us know what you did or didn’tlike about this book—as well as what we can do to make our books better
Please note that we cannot help you with technical problems related to the topic of this
book
When you write, please be sure to include this book’s title and author as well as your nameand email address We will carefully review your comments and share them with the
Trang 20Visit our website and register this book at informit.com/register for convenient access toany updates, downloads, or errata that might be available for this book
Trang 21Officially launched in February 2012, the Raspberry Pi personal computer took the world
by storm, selling out the 10,000 available units immediately It is an inexpensive creditcard–sized exposed circuit board, a fully programmable PC running the free open-sourceLinux operating system The Raspberry Pi can connect to the Internet, can be plugged into
a TV, and—with the latest version 2—runs on a fast ARM processor, rivaling the
performance of many tablet devices, all for around $35
Originally created to spark schoolchildren’s interest in computers, the Raspberry Pi hascaught the attention of home hobbyists, entrepreneurs, and educators worldwide
Estimates put the sales figures around 6 million units as of June 2015
The official programming language of the Raspberry Pi is Python Python is a flexibleprogramming language that runs on almost any platform Thus, a program can be created
on a Windows PC or Mac and run on the Raspberry Pi, and vice versa Python is an
elegant, reliable, powerful, and very popular programming language Making Python theofficial programming language of the popular Raspberry Pi was genius
Programming with Python
The goal of this book is to help guide both students and hobbyists through using the
Python programming language on a Raspberry Pi You don’t need to have any
programming experience to benefit from this book; we walk through all the necessarysteps in getting your Python programs up and running!
Part I, “Python Programming on the Raspberry Pi,” walks through the core Raspberry Pisystem and how to use the Python environment that’s already installed in it Hour 1,
“Setting Up the Raspberry Pi,” demonstrates how to set up a Raspberry Pi system, andthen in Hour 2, “Understanding the Raspbian Linux Distribution,” we take a closer look atRaspbian—the Linux distribution designed specifically for the Raspberry Pi Hour 3,
“Setting Up a Programming Environment,” examines the various ways you can run yourPython programs on the Raspberry Pi, and it goes through some tips on how to build yourprograms
Part II, “Python Fundamentals,” focuses on the Python 3 programming language Pythonv3 is the newest version of Python and is fully supported in the Raspberry Pi Hours 4–7take you through the basics of Python programming, from simple assignment statements(Hour 4, “Understanding Python Basics”), arithmetic (Hour 5, “Using Arithmetic in YourPrograms”), and structured commands (Hour 6, “Controlling Your Program”), to complexstructured commands (Hour 7, “Learning About Loops”)
Hour 8, “Using Lists and Tuples,” and Hour 9, “Dictionaries and Sets,” kick off Part III,
“Advanced Python,” showing how to use some of the fancier data structures supported byPython—lists, tuples, dictionaries, and sets You’ll use these a lot in your Python
programs, so it helps to know all about them!
In Hour 10, “Working with Strings,” we take a little extra time to go over how Pythonhandles text strings String manipulation is a hallmark of the Python programming
Trang 22After that primer, we walk through some more complex concepts in Python: using files(Hour 11, “Using Files”), creating your own functions (Hour 12, “Creating Functions”),creating your own modules (Hour 13, “Working with Modules”), object-oriented Pythonprogramming (Hour 14, “Exploring the World of Object-Oriented Programming”),
inheritance (Hour 15, “Employing Inheritance”), regular expressions (Hour 16, “RegularExpressions”), and working with exceptions (Hour 17, “Exception Handling”)
Part IV, “Graphical Programming,” is devoted to using Python to create real-world
applications Hour 18, “GUI Programming,” discusses GUI programming so you can
create your own windows applications Hour 19, “Game Programming,” introduces you tothe world of Python game programming
Part V, “Business Programming,” takes a look at some business-oriented applications youcan create In Hour 20, “Using the Network,” we look at how to incorporate network
functions such as email and retrieving data from webpages into your Python programs.Hour 21, “Using Databases in Your Programming,” shows how to interact with popularLinux database servers, and Hour 22, “Web Programming,” demonstrates how to writePython programs you can access from across the Web
Part VI, “Raspberry Pi Python Projects,” walks through Python projects that focus
specifically on features found on the Raspberry Pi Hour 23, “Creating Basic Pi/PythonProjects,” shows how to use the Raspberry Pi video and sound capabilities to create
multimedia projects Hour 24, “Working with Advanced Pi/Python Projects,” exploresconnecting your Raspberry Pi with electronic circuits using the General Purpose
If you are reading this book, you are not necessarily new to programming, but you might
be new to using Python programming, or at least Python programming in the Raspberry Pienvironment This book will prove to be a good resource for quickly finding Python
features and modules that you can use for all types of programs
Conventions Used in This Book
To make your life easier, this book includes various features and conventions that help youget the most out of this book and out of your Raspberry Pi:
Trang 23By the Way
By the Way boxes present asides that give you more information about the currenttopic These tidbits provide extra insights that offer better understanding of the task
Did You Know?
Did You Know boxes call your attention to suggestions, solutions, or shortcuts thatare often hidden, undocumented, or just extra useful
Watch Out!
Watch Out! boxes provide cautions or warnings about actions or mistakes that bringabout data loss or other serious consequences
Trang 24Raspberry Pi
Trang 25A Raspberry Pi is a very inexpensive, fully programmable computer that is small enough
to fit into the palm of your hand (see Figure 1.1) Although the Raspberry Pi is small insize, it is mighty in potential You can use it like a regular desktop computer or create asuper-cool project with it For example, you could use a Raspberry Pi to set up your veryown home-based cloud storage server
Figure 1.1 The Raspberry Pi 2 Model B Note the paperclip for scale.
Trang 26The Raspberry Pi is still a fairly young device It was created in the United Kingdom byEben Upton and a few colleagues The first commercial version, Raspberry Pi 1 Model A,was officially offered for sale in early 2012 at the low price of $25
By the Way: Different Raspberry Pi Names
People use a few different names for the Raspberry Pi You also will see it called
names such as RPi and just Pi.
Upton created the Raspberry Pi to address a concern that he and others in his field shared:Too few young people were getting involved in computer science Offering a cheap,
flexible, and small computing device seemed like a good way to trigger more interest.Upton formed the Raspberry Pi Foundation, with expected sales around 10,000 units.When the Raspberry Pi went on sale in February 2012, it sold out immediately An
upgraded model, Model B, was offered during late summer 2012, and sales continued toskyrocket
Since that time, more Raspberry Pi models have been created, such as the Raspberry Pi 2Model B shown in Figure 1.1 In addition, various add-on modules are now available,such as the Camera module for taking high-definition pictures or video with a RaspberryPi
Even though the Pi was originally created to spark young people’s interest in computers, italso has caught the attention of home hobbyists, entrepreneurs, and educators worldwide
In just one year, the Raspberry Pi Foundation sold approximately 1 million Raspberry Picomputers Since the Pi’s beginning, more than 6 million have been sold!
Did You Know?: Supporting the Raspberry Pi Foundation
The Raspberry Pi Foundation is a charitable organization It asks that you help
support its cause of sparking young people’s interest in computers by purchasing aRaspberry Pi (raspberrypi.org)
Raspberry Pi owners have used their devices in a variety of creative projects People
around the world have used Pi to create fun projects, like voice-controlled garage dooropeners, weather stations, pinball machines, touch interfaces for car dashboards, and
motion-activated cameras (as shown in Figure 1.2)
Trang 27programming Though Python can be considered “educational” because it is easy to learn,
by no means is Python wimpy
Armed with Python and Pi, your creative projects can take off You can write games inPython and run them on gaming consoles controlled by your Raspberry Pi You also canwrite programs to control robots attached to your Raspberry Pi Some Raspberry Pi
enthusiasts have sent their computers high into the air to take high-definition photos of theearth With a Raspberry Pi and Python, the sky is no longer the limit on your creativity
By the Way: Raspberry Pi Already Up and Running?
If you are currently a Pi owner and have your Raspberry Pi up and running, you canskip the rest of this hour
Trang 28Figure 1.3 Diagram of the Raspberry Pi 2 Model B.
Did You Know?: What Is an SoC?
A system on a chip (SoC) is a single microchip or integrated circuit (IC) that
contains all the components needed for a system SoCs are typically found on cellphones and embedded devices For the Raspberry Pi, the SoC contains an ARM
processor for application processing, a graphics processing unit (GPU) for video
processing, a USB controller, and so on
Trang 29Models Synopsis,” offers an in-depth comparison between these models Although themodels have similarities, you might want to review their different features to help youpick the best model for you
The focus in this tutorial is on Raspberry Pi 2 Model B However, any of the current orprevious models will work fine for learning the Python programming language
By the Way: Why Stop at One?
If you cannot decide between two models, why not buy both? You will allow
yourself additional flexibility for projects; most peripherals will work with the
various current models; and you are supporting the Raspberry Pi Foundation withyour purchases!
Where can you buy a Raspberry Pi? When the Raspberry Pi first came out, there wereonly a few places to buy them Now the following are just a few of the many businessesthat sell the Raspberry Pi:
necessary peripherals separately A prepackaged kit will save you time but cost you moremoney Buying everything separately may save you money but cost you time It’s best tolook at both options before making your decision
Watch Out!: Purchasing Peripherals
Be sure to read the rest of the hour before you purchase a Raspberry Pi and
peripherals There are several important facts you need to know to avoid wastingtime and money
Trang 30The microSD Card
The Raspberry Pi comes with no internal storage device and no preloaded operating
system The microSD card is used to provide the operating system to the Pi for it to run.You must have a microSD card to boot your Raspberry Pi
Buy a supported microSD card and load the necessary software onto it yourself
Trang 31Buy a microSD card that has the necessary software already on it
elinux.org/RPi_Easy_SD_Card_Setup lists companies that sell these preloadedmicroSD cards
Watch Out!: Getting the Correct microSD Card
Spend some time making sure you are purchasing the right microSD card for yourRaspberry Pi as discussed in the following paragraphs The right microSD card canmake your Raspberry Pi experience wonderful, and the wrong microSD card can
cause you lots of heartache and pain
If you decide to get your own microSD card and load on the installation software yourself,you can’t just run out to the store and buy any old microSD card You must get one thatworks with a Raspberry Pi So, how do you find out which card to buy? Fortunately, thegood people at the Raspberry Pi wiki page are here to help On their RPi SD card page atelinux.org/RPi_SD_cards, various Raspberry Pi enthusiasts have listed which microSDcards will work and which ones won’t Generally speaking, you need an SDHC card with
recommendations for the Raspberry Pi:
5 volts
700mA–1200mA (1.2A)
The 5 volts is firm, but you can go over the 1200mA In fact, it is better to have morepower because the more peripherals you add, such as a USB mouse, the more power thatwill be needed
You have several options here Read on to learn more
Trang 32When finding a cable for your Raspberry Pi, keep in mind that the longer the cable,the more flexibility you will have If you use a short cable to connect your Pi to
power, then you will have some limitations on where your Pi can move and be setdown In general, longer cables equal greater flexibility
If you happen to live in an apartment or home which has USB A port wall sockets, youcan power your Raspberry Pi through those ports You will need to purchase a cable with aUSB A male connector on one end and a micro B male connector on the other end If youdon’t already have these wall sockets, you can have an electrician replace one of yourregular wall sockets with USB A port sockets or you can use adapters
More Expensive Power Supply Options
If you do not want to share a charger with your phone or ebook reader, you can buy yourRaspberry Pi its own power peripherals In this case, you will need a USB power plug thatplugs into a wall outlet with a USB A port Also, you will need a cable that has a USB Amale connector on one end and a USB micro B male connector on the other
The power plug will allow you to plug into any wall socket for power And you can usethe USB power plug to power other USB-compatible devices If you plan on sticking theRaspberry Pi in a backpack or case for travel, consider getting a USB power plug that hasthe ability to fold up its power prongs This will make the power plug into a nice smallcube that is compact and easy to carry
Even better is a power cord that has both an AC power plug on one end and a USB micro
B male connector on the other end You can typically find highly rated power supply cords
in this category that provide better power stability for your Raspberry Pi projects Figure1.5 shows an example of this power supply type
Trang 33Output Display
For a very small device, the Raspberry Pi has the ability to display incredible images Itsports an HDMI port for output and enables Blu-ray-quality playback The Raspberry Pialso provides composite output, allowing you the flexibility of using older equipment foroutput display Once again, you get a choice of what you use to get your Raspberry Pifunctional
Trang 34If you have access to an old analog television, you possibly can display your RaspberryPi’s output to it All you need is an Audio/Video (A/V) composite cable with a 3.5mmconnector jack on one end and three RCA connectors on the other end The three RCAconnectors are typically color-coded yellow (video), white, and red (stereo audio)
On the Raspberry Pi 2 Model B, the A/V composite output port is located between theCamera Serial Interface (CSI) and the network port An analog television often has threeRCA A/V ports They are typically colored yellow, white, and red to match the compositecable’s three color-coded RCA connectors
Watch Out!: No VGA Support
VGA output converter Be sure you read any buyer reviews on such a converter
The Raspberry Pi does not provide VGA support You can use an HDMI input-to-before purchasing one—many do not work with a Raspberry Pi Also, you might
have to make some configuration file changes to get such a converter to work withyour Pi’s HDMI output
You also can hook up a computer monitor with a DVI port on it In this case, you need anadapter to go from HDMI to DVI output Also, like a composite video cable, DVI does notcarry an audio signal Thus, if you also need sound, you might need a converter that willsplit the HDMI’s video and audio signal output and enable you to hook up a separate
audio cable to speakers
Working with Up-to-Date Display Equipment
Using up-to-date display equipment is the easiest and best way to capture a Raspberry Pi’svideo and audio output HDMI handles both video and audio signals, so you need to
purchase only an HDMI male-to-male cable Plug one end into your Raspberry Pi’s HDMIoutput port and the other end into either the HDMI input port on a computer monitor ortelevision Of course, you should be sure you purchase an HDMI cable that is long enough
Raspberry Pi kits do not include a USB keyboard and a USB mouse, but you probablyalready have a few lying around
Trang 35A USB keyboard and mouse can consume from your Raspberry Pi somewhere
between 100mA and 1000mA, depending on their power requirements Check theirpower ratings and determine whether your selected power supply can support them
Using a Network Cable or Wi-Fi Adapter
Although it’s not always necessary, having your Raspberry Pi connected to the Internetand/or your local network is very handy The Raspberry Pi comes with an RJ45 port for awired Ethernet connection Depending on how your local network is configured,
connecting to the network can be as simple as plugging an Ethernet patch cable into theRaspberry Pi’s network port and into the back of your router In this case, all you need topurchase is an Ethernet patch cable with two RJ45 connectors
By the Way: Start with a Wired Network Connection
If it is possible, it is best to start with a wired Ethernet connection when setting upyour Raspberry Pi With a wired connection, you have increased network
transmission speed and typically fewer network connection issues
You also can set up your Raspberry Pi to connect via a wireless network In this case, youneed a USB wireless network adapter, which often comes with the prepackaged Raspberry
Pi kits The downside of this method is that you need to use one of your Pi’s USB ports.But with a wireless setup, you have much more flexibility
Nice Additional Peripherals
Now that you know which peripherals you absolutely must have to run your Raspberry Pi,you can think about a few additional peripherals that will make your life with the
on the side that allow access to the various ports
Trang 36Figure 1.7 A professional case for the Raspberry Pi 1 Model B.
You need to decide which kind of case meets your needs You easily can switch your
Trang 37or above (depending on your power needs) More expensive portable power chargers can
be powered by multiple sources, such as your car’s 12-volt power port as well as wallsockets
You will still need to purchase a cable that has a USB A male connector on one end and aUSB micro B male connector on the other end to connect the Pi to the portable powercharger The nice thing about this is that you can charge your portable power at the sametime you are powering your Raspberry Pi at home Just don’t forget to unplug your
portable power charger when you remove or insert peripherals on your Pi!
Looking at a Self-Powered USB Hub
If you want to connect a USB keyboard, a USB mouse, a Wi-Fi adapter, a USB externalstorage device, and another USB peripheral, you’ll run out of USB ports! No worries Justpurchase a self-powered USB hub, which gets its power by being plugged into an
electrical outlet
Watch Out!: Bus-Powered USB Hubs
Make sure you do not get a bus-powered USB hub A bus-powered USB hub drawsthe power it needs from the computer to which it is connected Therefore, it wouldtry to draw power from your Raspberry Pi
Typically, a self-powered USB hub can supply up to 500mA to each device connected to
it It has a USB A cable that lets you connect it to your Raspberry Pi via a USB port Thus,you can turn one of the Raspberry Pi’s USB ports into many!
Deciding How to Purchase Peripherals
Now that you have seen what the Raspberry Pi needs in the way of peripherals, you candecide which ones will be best for you You can either buy the Raspberry Pi with its
necessary peripherals in a prepackaged kit or purchase the Raspberry Pi and its necessaryperipherals separately
Trang 38You will spend more money on this option than if you buy the Raspberry Pi andperipherals separately
Kits vary, so be sure to buy a kit that has the peripherals you want or be prepared tobuy any that don’t come with the kit Typically, the kits do not include a USB mouseand keyboard
Many kits have the necessary software to install an operating system preloaded onthe microSD card If you get such a kit, you can skip downloading the software andloading it onto your card section of this hour
Getting Your Raspberry Pi Working
After you have made your purchase decisions and received your Raspberry Pi and itsnecessary peripherals, you can begin to really have some fun The first time your
Raspberry Pi boots up and you realize what a powerful little machine you now own, you’llreally be amazed The following sections describe what you need to do to prepare your Pifor booting
Doing Your Research
As with many other things in life, if you plan ahead and do your research, getting yourRaspberry Pi up and running should go smoothly and quickly This up-front time andeffort are very worthwhile And many excellent resources can help For example, the book
Raspberry Pi User Guide by Eben Upton and Gareth Halfacree will really help you have a
pleasant Pi experience Books like this one help you get your Raspberry Pi working andtroubleshoot problems
Also, there are many sources on the Internet that can assist you in your Raspberry Pi
research One of the best comes from the Raspberry Pi Foundation It maintains a website(raspberrypi.org) filled with wonderful tidbits of information, including frequently askedquestions (FAQs), help forums, and other various resources At this site, you can also findsoftware downloads and the latest news concerning the Raspberry Pi Foundation and the
Pi itself You should start your Raspberry Pi investigation at this resource
Exploring the Installation Software
After you have completed your initial research, the next step is to download the
installation software The Raspberry Pi Foundation’s website, raspberrypi.org, offers NewOut Of Box Software (NOOBS), which handles:
Trang 39If you need more details on downloading and moving NOOBS to a microSD card,see Appendix A, “Loading the Raspberry Operating System onto an SD Card.” Thisappendix will take you step-by-step through process and provides a more in-depthexplanation than given here
After choosing a machine, download the NOOBS installation software from
raspberrypi.org/downloads/ You have two NOOBS choices on the website: Offline andnetwork install or Network install only The Network install only option is typically faster
The Raspberry Pi Foundation provides the correct SHA-1 checksum number on their
Downloads page near the NOOBS software download choices Windows, OS X, and
Linux each handle producing a checksum differently Check Appendix A if you need
additional help with verifying the checksum
Trang 40Moving NOOBS
Before moving the NOOBS files and directories to your microSD card, you need to fullyformat and flash the card back to its factory state The SD association, sdcard.org,
provides a free SD card formatter that can be used on Windows and OS X For Linux, youcan use the GNOME Partition Editor utility, gparted See Appendix A if you need moredetails
If your machine has only an SD card reader and not a microSD card reader, you will need
to insert the microSD card into an SD card adapter before loading it If you do not have an
SD card reader at all, you can get a USB flash drive adapter for the SD card, which willwork just fine here
Watch Out!: Properly Preparing a microSD Card
You cannot just delete files from the microSD card or use a quick-format If you do,the NOOBS software might not work properly and your Raspberry Pi might not
boot, or other problems could arise Be sure you use SD card formatter software tofully format and flash the microSD card back to its factory state
The next step is to move the NOOBS directories and files to the microSD card Unlikemoving an operating system, you can just copy the files to the microSD card—no imagewriter program or utility is needed to move them