National Coding Week: beginners guide to coding on the Raspberry Pi

Now we all know that Linux is an OS operating system, and therefore we don’t strictly fall into the category of coding. However, with a massive skills shortage in the tech sector it’s in all our interests to get behind National Coding Week, an event aimed at encouraging adults to get into coding.

“Our aim is to inspire people to learn coding and other digital skills during the week” National Coding Week

 

So to do our part in inspiring and encouraging people to learn coding, we’ve teamed up with Andrew Mallett, from The Urban Penguin – a professional IT instructor who is a coding pro. He’s done a great short video for a beginners level coding project on a Raspberry Pi.

Which leads us neatly back to Linux (ah ha, you knew they’d be a link!) The Raspberry Pi runs on Linux – no surprise this brilliant and cheap computer that is making technology accessible to everyone is run on an Open Source operating system.

And what better month to be using and promoting the Raspberry Pi than this one, when it celebrates its ten millionth sale! Check out this great blog post on the Raspberry Pi website, which talks about their target to sell just ten thousand of these computers when they started, and their incredible growth up until today (this is such a success story for the tech industry we believe).

Here are some introduction notes from Andrew about the video:

In this video we are going to take a look at coding in the C Language. Many of the programs that make up Linux and other Operating systems are written in C and a good foundation in C will help in any programming Language. For a beginner’s tutorial we will keep the good sparse so we can focus on the code we absolutely need to make the program happen.

Writing in C also exposes the new developer to the concept of source code. The LPI make great efforts along with the Free Software Foundation to promote the virtues of Open Source software and by creating a C program from scratch we can see what source code is. When a software author makes the source code open then anyone can read how the code is written to both learn from and further develop the code. This cooperative environment represents the fundamental principals of Linux and helps produce better code. We will develop a program to print text to the screen and we do this by first creating the source code with a text editor. This source code then is compiled into a program.

Further notes about the content of the video are supplied below, so without further ado, we’ll hand over to the Urban Penguin for (possibly) your fist C Language coding tutorial on the Raspberry Pi…

(also available on The Urban Penguin YouTube page)

Notes to accompany the video

When creating the source code we will assign an extension of .c, indicating that this is a C source file. We are creating a program to print Hello to the screen so we will name it hello.c . The video explains the detail of the code but for clarity we add the code here:

#include <stdio.h>

main () {

printf(“Hello world\n”);

}

This is compiled into a binary program using the following command:

gcc -o hello hello.c

If we want to make the program a little more interactive we can pass arguments through to the program. The code will be modifies similar to this:

#include <stdio.h>

main (int argc, char **argv) {

printf(“Hello %s\n”, argv[1]);

}

We can compile the program in the same way as previous but now when we execute the compiled code we can pass an argument to be display after the word “Hello”. For example, if we run the new compiled file as in the following:

./hello Fred

The displayed message will be “Hello Fred”.