One of the great uses for the Raspberry Pi has always been as a learning tool. The Raspberry Pi 2 continues this tradition and makes a great platform to learn how to program. Python has been one of the most popular programming languages for the Raspberry Pi, with a huge amount of content available on the Web to show you how to get started.
Figure 1 shows the options available in the basic NOOBS distribution under Programming. Both Python 2 and Python 3 come with Scratch, which is a visual programming tool. You can find a full tutorial for getting started with Scratch on the Raspberry Pi learning page. Sonic Pi is another programming environment based on the process of creating new sounds. It also has a series of tutorial pages on the Raspberry Pi learning site.
Figure 1: Available Pi options
Mathematica and the Wolfram Language come from Wolfram Research and have been used at the university level to teach mathematical principals for over 25 years. The version for the Raspberry Pi was created to make the tool available to a wide audience as a learning resource. Although you probably wouldn’t want to do any really complex mathematical computation on a Raspberry Pi, you can learn the basic concepts and programming syntax behind Mathematica.
Python is a great first language for anyone looking to learn how to program. It has many features found in most modern programming languages and is used by many universities to teach introductory computer science courses. One potential point of confusion is the inclusion of Python 2 and 3 with the NOOBS distribution. Even though much of the Python language is the same between the two versions, there are differences that make the two potentially incompatible. Many Linux utilities were written using Python 2.x, meaning you must have a Python 2 version available for these programs to run.
The current version of NOOBS comes with Python 2.7.3 and 3.2.3. Both use IDLE as their user interface. You’ll probably want to do a little customizing of your environment to suit your personal preferences. The default font size for the Python IDLE editor is 10, so you might want to make that larger depending on your monitor. To change this setting, click the Options item in the menu bar and choose Configure IDLE. This will bring up the dialog box, as shown in Figure 2.
Figure 2: Resizing text in Configure IDLE
When you launch either version of Python you’ll be presented with a ‘>>>’ prompt that accepts any valid Python command. This makes it possible to use an interactive method of learning where you type something and the interpreter processes the command and gives you feedback. This same approach to an interactive interpreter is what made the original versions of BASIC popular as a teaching tool.
For longer programs, it makes sense to use the editor window to enter your code and then save it. To open a new window, simply choose New Window from the File menu. You also can open previously saved files from the same File menu. Figure 3 shows a second window with a single line of code to print Hello World. This code was saved with the filename helloworld.py. Notice that this window has a Run menu item that will launch the Python interpreter and send the code for execution. You will be prompted if you haven’t saved your code before running.
Figure 3: Entering code
Now you have the basics for getting started programming with the Raspberry Pi 2. In our next addition, we’ll take these concepts and develop a working example to use some of the other features of the Raspberry Pi 2.