What Next - Programming the Raspberry Pi: Getting Started with Python (2013)

Programming the Raspberry Pi: Getting Started with Python (2013)

12. What Next

The Raspberry Pi is a phenomenally flexible device that you can use in all sorts of situations—as a desktop computer replacement, a media center, or an embedded computer to be used as a control system.

This chapter provides some pointers for different ways of using your Raspberry Pi and details some resources available to you for programming the Raspberry Pi and making use of it in interesting ways around the home.

image

Linux Resources

The Raspberry Pi is, of course, one of many computers that runs Linux. You will find useful information in most books on Linux; in particular, look for books that relate to the distribution you are using, which for Raspbian will be Debian.

Aside from the File Manager and applications that require further explanation, you’ll want to know more about using the Terminal and configuring Linux. A useful book in this area is The Linux Command Line: A Complete Introduction, by William E. Shotts, Jr. Many good resources for learning more about Linux can be found on the Internet, so let your search engine be your friend.

image

Python Resources

Python is not specific to the Raspberry Pi, and you can find many books and Internet resources devoted to it. For a gentle introduction to Python, you might want to pick up Python: Visual QuickStart Guide, by Toby Donaldson. It’s similar to this book in style, but provides a different perspective. Also, it’s written in a friendly, reassuring manner. If you want something a bit more meaty, but still essentially a beginner’s text, consider Python Programming: An Introduction to Computer Science, by John Zelle.

When it comes to learning more about Pygame, you’ll find Beginning Game Development with Python and Pygame, by Will McGugan, to be quite helpful.

Finally, here are some good web resources for Python you’ll probably want to add to your browser’s favorites list:

http://docs.python.org/py3k/ The official Python site, complete with useful tutorials and reference material.

www.pythonware.com/library/tkinter/introduction/ A useful reference for Tkinter.

http://zetcode.com/gui/tkinter/layout/ This tutorial sheds some much needed light on laying out widgets in Tkinter.

www.pygame.org The official Pygame site. It contains news, tutorials, reference material, and sample code.

image

Raspberry Pi Resources

The official website of the Raspberry Pi Foundation is www.raspberrypi.org. This website contains a wealth of useful information, and it’s the place to find announcements relating to happenings in the world of Raspberry Pi.

The forums are particularly useful when you are looking for the answer to some knotty problem. You can search the forum for information from others who have already tried to do what you are trying to do, you can post questions, or you can just show off what you’ve done to the community. When you’re looking to update your Raspberry Pi distribution image, this is probably the best place to turn. The downloads page lists the distributions currently in vogue.

The Raspberry Pi even has its own online magazine, wittily named The MagPi. This is a free PDF download (www.themagpi.com) and contains a good mixture of features and “how-to” articles that will inspire you to do great things with your Pi.

For more information about the hardware side of using the Raspberry Pi, the following links are useful:

http://elinux.org/RPi_VerifiedPeripherals A list of peripherals verified as working with the Raspberry Pi.

http://elinux.org/RPi_Low-level_peripherals A list of peripherals for interfacing with the GPIO connector.

www.element14.com/community/docs/DOC-43016/ A datasheet for the Broadcom chip at the heart of the Raspberry Pi. (This is not for the faint of heart!)

If you are interested in buying hardware add-ons and components for your Raspberry Pi, Adafruit has a whole section devoted to the Raspberry Pi. SparkFun also sells Raspberry Pi add-on boards and modules.

image

Other Programming Languages

In this book, we have looked exclusively at programming the Raspberry Pi in Python, and with some justification: Python is a popular language that provides a good compromise between ease of use and power. However, Python is by no means the only choice when it comes to programming the Raspberry Pi. The Raspbian Wheezy distribution includes several other languages.

Scratch

Scratch is a visual programming language developed by MIT. It has become popular in education circles as a way of encouraging youngsters to learn programming. Scratch includes its own development environment, like IDLE for Python, but programming is carried out by dragging and dropping programming structures rather than simply typing text.

Figure 12-1 shows a section of one of the sample programs provided with Scratch for the game Pong, where a ball is bounced on a paddle.

image

Figure 12-1 Editing a program in Scratch

C

The C programming language is the language used to implement Linux, and the GNU C compiler is included as part of the Raspbian Wheezy distribution. To try out a little “Hello World”’ type of program in C, use IDLE to create a file with the following contents:

image

Save the file, giving it the name hello.c. Then, from the same directory as that file, type the following command in the terminal:

image

This will run the C compiler (gcc), converting hello.c into an executable program called just hello. You can run it from the command line by typing the following:

image

The IDLE editor window and command line are shown in Figure 12-2, where you can also see the output produced. Notice that the \n characters create blank lines around the message.

image

Figure 12-2 Compiling a C program

image

Applications and Projects

Any new piece of technology such as the Raspberry Pi is bound to attract a community of innovative enthusiasts determined to find interesting uses for the Raspberry Pi. At the time of writing, a few interesting projects were in progress, as detailed next.

Media Center (Raspbmc)

Raspbmc is a distribution for the Raspberry Pi that turns it into a media center you can use to play movies and audio stored on USB media attached to the Pi, or you can stream audio and video from other devices such as iPads that are connected to your home network. Raspbmc is based on the successful XBMC project, which started life as a project to use Microsoft Xboxes as media centers. However, it’s available on a wide range of platforms.

With the low price of the Raspberry Pi, it seems likely that a lot of them will find their way into little boxes next to the TV—especially now that many TVs have a USB port that can supply the Pi with power.

You can find out more about Raspbmc at www.raspbmc.com/about/, you can learn about the XBMC project at www.xbmc.org. All the software is, of course, open source.

Home Automation

Many small-scale projects are in progress that use the Raspberry Pi for home automation, or domotics as it is also known. The ease with which sensors and actuators can be attached to it, either directly or via an Arduino, make the Pi eminently suitable as a control center.

Most approaches have the Raspberry Pi hosting a web server on the local network so that a browser anywhere on the network can be used to control various functions in the home, such as turning lights on and off or controlling the thermostat.

image

Summary

The Raspberry Pi is a very flexible and low-cost device that will assuredly find many ways of being useful to us. Even as just a simple home computer for web browsing on the TV, it is perfectly adequate (and much cheaper than most other methods). You’ll probably find yourself buying more Raspberry Pi units as you start to embed them in projects around your home.

Finally, don’t forget to make use of this book’s website (www.raspberrypibook.com), where you can find software downloads, ways of contacting the author, as well as errata for the book.