About this book

The Raspberry Pi is a small, low-cost computer invented in the U.K. by the Raspberry Pi Foundation. It provides an easy-to-use tool for learning to program in Python. The Raspberry Pi, with its companion memory card, is preloaded with all the software you need to jump into programming in Python. The Raspberry Pi is made for you to learn to code by playing with it. It includes many input and output ports to give you flexibility in how you connect it. Much like a desktop computer, you need to connect a keyboard, mouse, monitor, and power cable to get started.

This book will teach you how to set up your Raspberry Pi, to write programs in Python, and to use your Raspberry Pi and Python to complete some projects. We’ll cover the basics of Python: displaying text, gathering input, repeating commands, creating logic, as well as using the input and output pins of your Raspberry Pi for projects.

This book does not cover advanced Python topics, nor act as a comprehensive reference for Python. Since it is a book for beginners, these topics have been left out for clarity and brevity. If you’d like to learn more Python, there are links to online resources throughout the book.

This book is for kids and other beginners who would like to learn to program. It’s also for kids who have a Raspberry Pi and want to learn what they can do with it. We’ll introduce you to your Raspberry Pi and teach you Python in a natural, playful way, introducing topics and giving you activities to do using your Raspberry Pi. You don’t need to have any prior programming experience. As long as you know how to use a mouse and open up programs by clicking on icons or menu items, you’ll do great.

This book requires a Raspberry Pi, cables, and some other parts to complete the projects and activities. These items are needed throughout the book:

  • Raspberry Pi 2 Model B
  • 8 GB SD memory card, preloaded with the Raspberry Pi Foundation’s NOOBS (New Out of the Box Software)
  • USB power supply with micro USB cable (must deliver 1.2 A @ 5 V)
  • USB keyboard
  • USB mouse
  • TV or monitor
  • Cable to connect to TV or monitor (specific cables for your TV or
  • monitor are discussed in chapter 1)

To complete the projects in part 3, you’ll also need these parts:

  • Solderless breadboard
  • GPIO ribbon cable for the Raspberry Pi 2 Model B (40 pin)
  • GPIO breakout board
  • 1 dozen jumper wires, male-to-male
  • 1 red LED (light-emitting diode)
  • 1 green LED
  • 1 blue LED
  • 1 red, green, blue (RGB) LED
  • 3 push buttons
  • 3 resistors, 10K ohm
  • 3 resistors, 180 ohm (or between 100 and 300 ohms)
  • Headphones or powered computer speakers

You can typically find all these items in a Raspberry Pi starter kit or available individually through online retailers and stores that sell the Raspberry Pi, such as CanaKit, Sparkfun, or Adafruit.

Roadmap

This book is divided into three parts.

Part 1 introduces you to the Rasperry Pi, shows you how to set it up, and provides an introduction to the Python programming language:

  • Chapter 1 provides an overview of the Raspberry Pi and how to set it up for the first time.
  • Chapter 2 shows you how to write your first Python programs and introduces you to doing math and displaying text with Python.

Part 2 shows you how to build different text-based games while learning how to gather input, display information, make decisions, and repeat instructions in Python:

  • Chapter 3 teaches you how to create your first interactive Python game, the Silly Sentence Generator 3000, by asking users to type in something and then displaying funny messages to the screen.
  • Chapter 4 explores how to give your programs logic and use repeating loops as you create a Norwegian Blue Guessing Game.
  • Chapter 5 demonstrates how to build a Cave Adventure Game, give users multiple choices, check input from users, and create your own Python functions.

Part 3 involves making your Raspberry Pi interact with the world around it:

  • Chapter 6 explains setting up your Pi with an electronics breadboard, building a simple circuit, and controlling an LED (light) using your Raspberry Pi and Python.
  • Chapter 7 dives into creating an interactive guessing game that uses lights to respond to a player’s input, letting them know with different colors whether their answer is right or wrong.
  • Chapter 8 teaches you how to listen to your Pi’s input pins by making a project that combines light and sound to make your own DJ Raspi sound mixer.

Code conventions and downloads

All source code in this book is in a fixed-width font like this, which sets it apart from the surrounding text. In many listings, the code is annotated to point out key concepts. I have tried to format the code so that it fits within the available page space in the book by adding line breaks and using indentation carefully.

The code accompanying this book is hosted at the GitHub repository: https://github.com/rheitz/hello-raspberry-pi. It is also available for download as a zip file from the publisher’s website at www.manning.com/books/hello-raspberry-pi.

Author Online

Purchase of Hello Raspberry Pi! includes free access to a private web forum run by Manning Publications where you can make comments about the book, ask technical questions, and receive help from the author and other users. To access the forum and subscribe to it, point your web browser to www.manning.com/books/hello-raspberry-pi. This Author Online (AO) page provides information on how to get on the forum once you’re registered, what kind of help is available, and the rules of conduct on the forum.

Manning’s commitment to our readers is to provide a venue where a meaningful dialog among individual readers and between readers and the author can take place. It’s not a commitment to any specific amount of participation on the part of the author, whose contribution to the AO remains voluntary (and unpaid). We suggest you try asking the author some challenging questions, lest his interest stray!

The AO forum and the archives of previous discussions will be accessible from the publisher’s website as long as the book is in print.

About the author

Ryan Heitz is a teacher, programmer, maker, father, and big kid. He is the cofounder of Ideaventions, a Science Center for kids, and Ideaventions Academy for Mathematics and Science, a private school focused on science and technology. He specializes in teaching kids how to experience computer science in a fun and engaging way. As a programmer, Ryan has developed software for everything from NASA data collection systems to web mapping applications.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.120.133