Become a fan of h2g2
Software | Hardware | Peripherals You'll Need | Getting Started
This Entry will look at some of the operating systems and programs that the Raspberry Pi uses, and introduces the concept of programming languages.
Every computer needs some form of operating system (OS) to direct its hardware, provide a user interface and allow software to be run. As it is open-source, making it free to use, Linux would seem the ideal OS for the job:
In the 1980s a type of operating system known as UNIX was too expensive for most people to use, and so the GNU Project was formed in 1986 to produce a free version. The project struggled until Linus Torvalds kindly wrote the central code required to make it all work. Thus, in 1994, the GNU/Linux operating system was born. Since then, many companies have taken this free code and created numerous 'distributions' of Linux, which are continuously being updated and improved.
The Raspberry Pi is fully compatible with several distributions of Linux, including Debian, Fedora and ArchLinux. Some of these will be available from the Raspberry Pi Foundation preloaded onto an SD card.
There is software for Linux to do more or less anything that a Windows PC might need to do. This includes text editors, presentation editors, web browsers, drawing programs, photo manipulators, calculators, printer drivers, and many penguin-related games. Better still, most of these are free under the same GNU General Public License (GPL) that covers Linux. As the Raspberry Pi has a memory card reader rather than a built-in Hard Disk Drive, you'll need to either buy a memory card with a Linux distribution pre-loaded, or buy a blank card and download an operating system onto it using another computer. Each distribution of Linux comes with its own collection of software, and as it is known that Debian, Fedora and ArchLinux are supported, we will look briefly at each.
Debian is a popular Linux distribution, including the GNOME GUI and a range of programs that fulfill most of the basic requirements of a home computer. This includes Iceweasel, a spin-off of the Firefox web browser1. It also includes an office program, typically OpenOffice.org, which can handle text documents, presentations, spreadsheets and the like. A similar package, koffice, is found in those distributions of Linux that run KDE in preference to GNOME, but can also be bundled with other distributions.
Fedora Linux is a Linux distribution popular with some power users. It is notable for continuous support of the ARM processor architecture that the Raspberry Pi uses. It has a short update cycle of 6 months, meaning that a given version of the operating system will initially be bleeding-edge but will be obsolete within just over a year. Fedora also uses GNOME, but comes bundled with LibreOffice and Firefox.
ArchLinux is a somewhat minimalist distribution of Linux aimed at speed, bug-free code and simplicity. It is possible to install only the absolute minimum required to run a computer, making it useful for users who have a specific task in mind. This distribution is therefore aimed at the more experienced Linux user, though it is still possible to install the X Desktop GUI and other software.
Some readers might recall MS-DOS, the text-only operating system that came before Microsoft started to use the Graphical User Interfaces (GUIs2) seen in Windows. MS-DOS was keyboard- and text-based, using typed commands to move files, run programs, print text and so forth – this was once the only way to interact with a computer. A similar text-only interface can still be found in Windows by opening the Command Prompt (the little black window with a blinking cursor).
Linux also comes with a text-based Command Line Interface (CLI), and any GUI you might run simply acts as an alternative to typing each command yourself. The difference between a Linux CLI and the old MS-DOS is that Linux is much, much better. After all, it was written largely by enthusiasts. You can open a CLI from your GUI's desktop, or switch to one and not have a GUI running at all. When you do so, a program known as a 'shell' starts running, and will convert any commands you type into something your computer will understand. This is usually the bash shell; however, there are plenty of CLIs that you might use to communicate with the bash shell, such as konsole, x-term or gnome-terminal.
Having brought up a CLI and thus connected to the bash shell, you'll be able to type all manner of commands. A few useful ones to start off with are:
|This calls on the in-built help command to tell you about itself.|
|In a similar manner, displays the instruction manual entry about the manual command. The output is sent through |
|Print Working Directory, which will tell you which folder you're currently in.|
|List Contents, which will list all the files and folders in the folder you're looking at.|
|List Contents, modified by |
|Change Directory, which allows you to change directory. Entering |
|Looks for the executable file fredsprogram in the current folder and runs it.|
One thing to note before doing anything drastic is the text and symbol that appears in your command line. If the line shows something like
fred@fredscomputer: ~$ then you're logged in as a user. However, if it reads
root@fredscomputer: ~# then you're logged in as 'root'. An ordinary user can only do so much damage when using the command line, whereas someone logged in as root can delete the entire system with a single command. If you are logged in as root, don't do anything – learn how to log in as an ordinary user instead.
The Raspberry Pi is aimed at encouraging a greater understanding of Computer Science, and would hardly be complete without supporting several programming languages. These are forms of code used to tell a computer what to do, and are what software and games industry coders spend a lot of time playing with. The Linux CLI mentioned above uses but one example of a programming language; others include C, C++, C#, Java, Python, BASIC, Perl, Haskell, Forth, COBOL, Fortran, MATLAB and many, many more. For an idea of what different programming languages look like, see 'Hello World!'
You'll probably be wondering, 'so which one of these does my computer speak?' The answer is none of them – your computer's processor understands a language called machine code. To us humans, a command in machine code can look something like this:
However, computer processors really talk in binary (zeroes and ones) and each of the letters and numbers above represents four zeroes or ones:
0 D 5 B A 7 2 1
0000 1101 0101 1011 1010 0111 0010 0001
These ones and zeroes are the high and low voltages of electrical current passing between parts of your computer's processor. When you enter a command into a Command Line Interface (CLI), the bash shell turns your command into a bunch of zeroes and ones which are fed into the processor and tell it what to do.
Interpreted or Compiled?
In order to run a program you've written, you'll always need to convert it from Python, C or whatever else into machine code. Languages like Python are interpreted, which means each command you type is changed directly into machine code by an interpreter program. Interpreted languages are good because you can run them while you are still writing in order to test your program. The Linux bash shell is an interpreter, as it takes commands and turns them into machine code straight away.
Other programming languages need to be compiled, whereby a compiler program takes the finished program and forms a binary file which your processor can understand. The difference is that while an interpreter translates and runs what you've written line by line, a compiler takes the whole thing and fiddles around with it before producing a complete program. While this makes it harder to experiment, compiled languages are good because they are faster to run.
Both interpreters and compilers need sources of information telling them what particular commands do, how other things mentioned in your code should behave, and so on. These are known as libraries, and every interpreter and compiler program comes with a standard set. This standard set can be expanded in order to allow specialist uses of the programming language.
It's also worth mentioning here that different processor types have different structures, and use different flavours of machine code. This is why your operating system should support the Raspberry Pi's ARM processor, and any programming software must be suitable for your operating system.
High-level or low-level?
Programming languages differ in how easy they are to us. Low-level code is great for the computer but rather difficult for a person to understand, whereas high-level code uses human patterns of thinking and therefore translates a little clumsily into machine code. As a result, a high-level language such as Python will produce a slower program than the equivalent in a more low-level language like C++. However, as a beginner it is easier to learn Python.
One final attribute worth mentioning is whether a programming language is Turing-complete. In 1937, Alan Turing described a theoretical computer he called the Turing Machine. Given enough time, it could solve any mathematical problem it was given (save for those that were mathematically impossible to solve). Thus, a programming language that can tell a computer how to solve any mathematical problem is described as being Turing-complete. A programming language that isn't Turing-complete may not be able to do everything you want. Fortunately, most commonly-used languages are complete ones.
Choosing a Programming Language