The book Programming the Raspberry Pi: Getting Started with Python tells you all you need to know to get you started programming you Raspberry Pi in Python. It includes chapters on graphical user interfaces with Tkinter, as well as games programming with pygame.
Three chapters of the book are devoted to using the GPIO connector and attaching electronics to the Raspberry Pi. Example projects include an LED clock and a Pi controlled robot rover.
Chapter 1. Introduction.
- What is the Raspberry Pi?
- What can you do with a Raspberry Pi?
- A Tour of the Raspberry Pi
- Setting Up
- Booting Up
Chapter 2. Getting Started.
The Raspberry Pi uses Linux as its operating system. This chapter introduces Linux and shows the reader how to use the desktop and command line.
- The Desktop
- The Internet
- Internet Resources
Chapter 3. Python Basics.
The time has come to start creating some of your own programs for the Raspberry Pi. The language that we are going to use is called Python and it has the great benefit that it is easy to learn, whilst at the same time being powerful enough to create some interesting programs, including the use of graphics and some simple games.
- What is a Programming Language?
- For Loops
- Simulating Dice
Chapter 4. Strings, Lists and Dictionaries.
This chapter could have had ‘and Functions’ added to its title but it was already long enough. In this chapter, you will first explore and play with the various ways of representing data and adding some structure to your programs in Python. You will then put it all together in the simple game Hangman.
- String Theory
- Summary of Functions
Chapter 5. Modules, Classes and Methods.
In this chapter, we will explain how to use and make our own modules such as the ‘random’ module that we used in the last chapter.
We will also explain how Python implements something called object-orientation. Object-orientation allows programs to be structured into classes, each responsible for their own behavior. This helps to keep a check on the complexity of our programs and generally makes them easier to manage.
- Defining Classes
Chapter 6. Files and Internet.
Python makes it easy for your programs to use files and connect to the. You can read data from files, write it to files and fetch content from the Internet, or even check for new mail or tweet all from your program.
Chapter 7. Graphical User Interfaces.
Everything we have done so far has been very text-based. Our Hangman game would not have looked out of place on a 1980’s home computer. This chapter will show you how to create applications with a proper graphical user interface (GUI).
- Hello World
- Temperature Converter
- Other GUI Widgets
- The Canvas
Chapter 8. Games Programming.
This chapter will introduce you to a very handy library called Pygame, and get you started using it to build a simple game.
- What is Pygame?
- Hello Pygame
- A Raspberry Game
Chapter 9. Interfacing Hardware.
In this chapter we explore the various ways of connecting the Pi to electronic devices using the GPIO, using some of the first products that have become available to help you do this.
- GPIO Pin Connections
- Direct connection to GPIO Pins
- Expansion Boards
- Prototyping Boards
- Arduino and Pi
Chapter 10. Prototyping Project (Clock).
In this chapter, we will build, what can only be seen as a grossly over-engineered LED digital clock. We will be using a Raspberry Pi, Adafruit’s Cobbler lead some breadboard and a 4 digit LED display.
- What You Need
- Hardware Assembly
- Phase Two
Chapter 11. The RaspiRobot.
In this chapter, you will learn how to use the Raspberry Pi as the brain for a simple robot rover. The Pi will take commands from a wireless USB keyboard and control the power to motors attached to a robot chassis kit. The Robot will also optionally have an ultrasonic range finder that will tell it how far away it is from obstacles and an LCD screen attached to the robot that displays information from the range finder.
- What You Need
- Phase 1. A Basic Rover
- Hardware Assembly
- Phase 2. Adding a Rangefinder and Screen
Chapter 12. What Next?
In this chapter, we provide some pointers for different ways of using your raspberry Pi and also other resources that are available for you to use, both in programming the Raspberry Pi and making use of it for interesting uses around the home.
- Linux Resources
- Python Resources
- Raspberry Pi Specific Resources
- Other Programming Languages
- Applications and Projects
Page 1. ‘Its small’ should be: it’s small – well, detail is important!
Page 36. near the bottom ‘True AND True’ should read ‘True and True’. [thanks to Brian MacKenzie]
Page 49 before the first code example. There should be some more text that says: ‘The play function uses a global variable called lives_remaining that is initialized with the code: livesRemaining = 14
Page 50 near the bottom and 51 1/3 way down the page. the references to ‘print_word’ in the discussion should be to ‘print_word_with_blanks’. [thanks to Brian MacKenzie]
Page 57 near the top. ‘Python lets you do a couple of next tricks’ should read: ‘Python lets you do a couple of neat tricks’ [thanks to Brian MacKenzie]
Page 71 3/4 of the way down the page: ‘ The method simply returns the result of multiplying the value passed in by self.scale’ should read: ‘ The method simply returns the result of multiplying the value passed in by self.factor’ [thanks to Karl Cookson]
Page 117, last paragraph – “it was been developed”, should be “it has been developed” [thanks to Karl Cookson]
Page 127 last paragraph – “need two hit”, should be “need to hit” [thanks to Karl Cookson]
I should mention somewhere that the super user and user password by default is ‘raspberry’
Although IDLE indents for you, it is worth noting that it uses 4 spaces for indentation and no tabs, so beware if you use other editors.