BeginnerProgrammingRaspberry PiTutorials

Beginners Crash Course On Raspberry Pi 3 Programming

4 Mins read

Bought a Raspberry Pi kit recently and imagined what to do next? Well, don’t worry; here in this article, I will let you how to program a Raspberry Pi.
If you are excited about your Raspberry Pi but have not written a single line of code before, don’t worry. Programming a Raspberry Pi is a piece of cake. It’s easy, simple, and interesting to code this tiny yet powerful supercomputer.

Programming Languages

Programming, languages like C, C++, Java, Scratch, Ruby, Python all come preinstalled in the Raspberry Pi editor.
Raspberry Pi Foundation recommends Python language for all the new Pi learners. Also, the “Pi” in the name “Raspberry Pi” implies Python in it. For younger kids, Scratch is the recommended language to learn.
Any language which is compatible with ARMv6 is supported in Raspberry Pi. You are not restricted to use Python.

Other languages supported in Raspberry Pi

  1. HTML
  2. Perl
  3. Javascript
  4. JQuery

How to write a program in C?

C is the preferred language when you are just entering the programming world. It is the best language to clear your logical concepts. Now, why am I talking about all this? Well, you will need a strong logical ability to write gobsmacking programs. If your core foundation is not strong, it’s difficult to write proper and clean code.

Writing your first program

This is a simple program to print “Hello World” on your screen. Pretty simple, isn’t it?

Compiling a program

Compiling the program helps computer change the program written in a human readable form to machine readable format. For compiling a C program on Windows open “Command Prompt.” After opening Cmd. Write the following command.

Example: gcc helloworld.c -o mycprogram.

When you compile the source file, it will be changed with the new name you give. Here we will take it as mycprogram.
Here helloworld.c is your program file name.

Making the program executable

For making the program executable just change the file permissions, and you are good to go. Copy and paste the following command in your cmd.

chmod +x mycprogram

Executing the program

For executing the program write the following command in your Cmd.
./mycprogram

This is all you need to do to execute your first C program.

How to write a program in Python?

Python is widely used when it comes to programming languages. Python programs are concise and easy to execute.

Features of Python

  • Interpreted Language.
  • Object-oriented.
  • Beginner’s Language.

Writing your program in Python

print “Hello, World!”
Just a single line of code will let you print “Hello World” on your computer screen. That’s the power of Python Language.

Running a Python Program

Simply open cmd and write the following command. Make sure you are in the folder directory where you stored your program.
python helloworld.py

Making the program executable

You can make a file executable by entering this at the command prompt
chmod +x file-name.py

Executing the program

For executing the program write the following command in your Cmd.
./file-name.py

This is all you need to do to execute your first Python program.

How to write a program in HTML?

HTML is the most used language in programming when it comes to the User Interface (UI). HTML is very simple to code and requires no logical abilities. Just a creative mind to code and you will master HTML pretty soon. There are many other languages like Javascript, Bootstrap, and JQuery to make your pages more attractive and user-friendly but, it all starts with the HTML code.

Writing your program in HTML

This is how simple it is to write a HTML code. If you try executing this code you can see “Hello world” message right to your screen.

Applying CSS

With CSS you can create beautiful and attractive pages. CSS is a framework for styling your HTML pages.
Here is the demo how to code in CSS

Now, it’s time to apply this code to your Pi you need to install Apache. Make sure your Raspberry Pi is connected to the Internet and in working condition.
Write following commands:

sudo apt-get update
sudo apt-get upgrade sudo apt-get install apache2
sudo apt-get install apache2

Copy all your HTML and CSS code and save it in /var/www/index.html.

You can open this file writing the following command in your terminal:

sudo leafpad /var/www/index.html

Your program will not execute unless you give permissions to read for other users. You can do this by writing the following command.

sudo chmod a+r /var/www/index.html
Type ifconfig in command prompt to find your Pi’s IP address.
Note down your Ip address. Paste this Ip address in your browser and see how your code works.
With the combo of HTML, CSS, and Python you can create wonders in Raspberry Pi.

Wrap up

As you can see programming is not a difficult job to do. It requires a little interest and skills. I hope you found this article useful and you learned something new today by reading this article.
Try experimenting with your programming skills and make something which is truly amazing.
Let me know in the comments section which language you will prefer as your primary language to code in Raspberry Pi.

My name is Mandip and I run raspberry pi starter kits. I love to tinker with the electronics circuits and create new and useful designs. Sometimes the results come awful, too! I share all my ideas, research, and knowledge on my website. I also love to travel and explore historical places whenever I get suitable time for it.

Leave a Reply

Your email address will not be published. Required fields are marked *