Skip to main content

# Section1.4Setting Up Your Raspberry Pi¶ permalink

In this section I describe how I set up my Raspberry Pi to do all the programming described in this book. Yes, I really have run all the programs on both my original Raspberry Pi 1 Model B and my new Raspberry Pi 3 Model B. You may choose to do things differently, depending on which Raspberry Pi you are using and your personal preferences.

This book is based on using the Raspbian operating system. I used NOOBS to install Raspbian. It includes most of the programming tools you will need, but there are a couple that you should add to make documentation available to you. Here are the packages that I added:

• gcc-x.y-doc, where “x.y” is the version number of gcc, provides documentation for the GNU compiler.

• binutils-doc provides documentation for the GNU assembler, as (sometimes called gas).

You can determine the version number of gcc with the apropos gcc command:

pi@rpi3:~ $apropos gcc arm-linux-gnueabihf-gcc-ar (1) - a wrapper around ar adding the - plugin option arm-linux-gnueabihf-gcc-nm (1) - a wrapper around nm adding the - plugin option arm-linux-gnueabihf-gcc-ranlib (1) - a wrapper around ranlib adding the - plugin option c89-gcc (1) - ANSI (1989) C compiler c99-gcc (1) - ANSI (1999) C compiler g++-4.9 (1) - GNU project C and C++ compiler gcc-4.9 (1) - GNU project C and C++ compiler gcc-ar (1) - a wrapper around ar adding the - plugin option gcc-ar-4.9 (1) - a wrapper around ar adding the - plugin option gcc-nm (1) - a wrapper around nm adding the - plugin option gcc-nm-4.9 (1) - a wrapper around nm adding the - plugin option gcc-ranlib (1) - a wrapper around ranlib adding the - plugin option gcc-ranlib-4.9 (1) - a wrapper around ranlib adding the - plugin option  This display clearly shows that $x.y = 4.9$ on my Raspberry Pi at this time. Yours may have a different version. To make my life a little easier, I created symbolic links to the C and C++ compilers like this: pi@rpi3:~$ which gcc-4.9
/usr/bin/gcc-4.9
pi@rpi3:~ $sudo ln -s /usr/bin/gcc-4.9 /usr/bin/gcc pi@rpi3:~$ sudo ln -s /usr/bin/g++-4.9 /usr/bin/g++

pi@rpi3:~ \$ which gcc
/usr/bin/gcc


The which command shows where the program is located.

You will also use a text editor for all your programming. Do not use a word processor. Word processors add a lot of hidden control characters to format the text. These hidden characters confuse compilers and assemblers, causing them not to work.

Raspbian comes with several simple text editors already installed. Go to www.raspberrypi.org and look under “HELP.” Click on “DOCUMENTATION” and then on “LINUX.” Then click on “Text editors” under “Usage.” I have found that many students like GNU Nano because it is easy to use.

You have probably learned how to program using an Integrated Development Environment (IDE) , which incorporates several programs within a single user interface:

Text Editor

Used to write the source code and save it in a file.

Compiler

Translates the source code into machine language that can be executed by the CPU.

Linker

Integrates all the functions in your program, including externally accessed libraries of functions, and to determine where each component will be loaded into memory when the program is executed.

Loader

Loads the machine code version of the program into memory where the CPU can execute it.

Debugger

Used to help the programmer locate errors that may have crept into the program. (Yes, none of us is perfect!)

When using an IDE you enter your source code in the text editor part, click on a “build” button to compile and link your program, then click on a “run” button to load and execute the program. There is typically a “debug” button that loads and executes the program under control of the debugger program if you need to debug it. The individual steps of program preparation are obscured by the IDE user interface.

The main problem with using an IDE on the Raspberry Pi is that they require a fair amount of computing resources. In this book we use the GNU programming environment in which each step is performed explicitly using a command line interface. Not only does this make better use of your limited computing power, it takes you “closer to the metal,” which is the whole point of this book.