Learn to program with a Raspberry Pi in 4 easy steps

Ad Code

Learn to program with a Raspberry Pi in 4 easy steps

 


Ever wanted to learn to program with a Raspberry Pi? Single-board computers are great because not only are they extremely useful, they also allow coding fans large and small to easily enter the fascinating world of programming. I think it's an idea. We'll show you how in four easy steps. The Raspberry Pi course is also highly recommended if you are looking for like-minded people. Let's start with the Raspberry Pi.

Table of Contents

  1. What is the Raspberry Pi?
  2. Learn to program with the Raspberry Pi in 4 easy steps
  3. FAQs – Programming with Raspberry Pi

What is Raspberry Pi?

If you want to learn how to program with a Raspberry Pi, you're not new. Then, of course, a brief and concise introduction. The Raspi is an inexpensive single-board computer about the size of a deck of cards. Developed by his Raspberry Pi Foundation in the UK to get young people interested in computers and programming. done!

Due to the freely accessible inputs and outputs (they have many metal pins on the side), they are also very popular in the electronics field. When it comes to controlling, measuring and adjusting, the Pi isn't too far off. The performance of the last generation (Raspberry Pi 4) is gradually approaching PCs, so computers with standard connections like Ethernet, USB and HDMI can also be used as desktop replacements.

IMPORTANT: Raspberry Pi does not exist like an Arduino project. This is the whole family. Other members are called, for example, Zero, Zero W, Pico, and so on. However, I'm using a standard Raspberry Pi here, preferably version 4 (see image below).



Learn to program with the Raspberry Pi in 4 easy steps


Want to quickly learn how to program with a Raspberry Pi? Maybe you don't even know how to get started. Not bad at all, but after all, we do many things for the first time every day. That's why the tutorial provides step-by-step instructions on how to get started with Raspberry Pi.

1. Flash SD card


Raspberry Pi is a full-fledged computer with its own Raspberry Pi OS operating system. Unlike a PC or Mac, it is not stored on a hard drive or SSD but on a microSD card of at least 16 GB. Since the speed of the card affects the speed of the Pi, it should be as fast as possible.

To save (flash) maps, you need a PC or Mac with a card reader, either built into the computer or connected as a separate device via USB. There you install this software, available for Windows, macOS and Ubuntu-Linux.

The following screenshot shows the Imager, i.e. software, after it starts:


At the top of the list is the Raspberry Pi operating system, which can still be found in many web posts under the old name Raspbian. The Pi's default operating system is based on the Debian Linux distribution. In the Raspberry Pi OS (other) section you will find variants for special cases. There are also other operating systems from other vendors in the Other General Purpose Operating System. In the following, we assume that you are using the first option. However, you can try other operating systems later. By changing or refreshing the card, you can switch operating systems very quickly.

Besides the operating system, the photographer must also define his or her operating target, i.e. the SD card. The card will then be written and verified, which takes a few minutes. When done, the card can be removed from the reader.

2. Connection of the Raspberry Pi

The SD card is then pushed into the slot specified at the bottom of the Pi. The contacts should face towards the PCB. You also need a mouse and keyboard to get started, simply connected via USB. Connecting the monitor is a bit tricky. The Pi 4 only has a micro HDMI socket. You may need an adapter that you can purchase from a professional dealer. The computer is best powered via the official 3.0 A / 5.1 V power supply.

There is no switch because when you plug the power source into the outlet, the Pi starts directly. Then you can recognize it by the flashing LEDs on the circuit board. When you first start, you still have to make settings like language or WLAN, but don't worry, a wizard will assist you. You're one step closer to programming with your Raspberry Pi!

3. Select Python in the terminal

The Raspberry Pi is now ready to go and we are slowly getting started with programming. Now the question is what programming language do you want to program in. Because the Pi is a full-fledged computer, you can use any programming language you want. Well-known languages ​​like C, C++, Java, Python, JavaScript or Scratch come pre-installed or can be easily upgraded.

We are using Python in this tutorial. This language is relatively easy to learn and is widely used to program with Raspberry Pi. Python is already pre-installed in version 3 currently on the Raspberry Pi operating system. You can try this by entering the python command in the Raspberry Pi terminal window:


Three consecutive greater than (>>>) indicates the Python shell. A shell is a command interpreter, and in this case the commands entered are Python commands, as you'd expect. Try it by entering the following command:

>>> print ("Hello world!")
Hello world!

Programming this way is of course a bit cumbersome. It would be better to wrap your program in a text file and then call it with the interpreter from the terminal. So it's like this:

python name_of_text_file.py

4. Working with Thonny

Since we want to work with Python here, we will use Thonny in what follows. This is an IDE specifically for Python beginners and also comes with Raspberry Pi. You can find Thonny in the menu under Development. The following image shows the IDE after launch:


To try Thonny, type the following code in Notepad (the text box at the top of the window):
       i =  1
       while  i <=  12 :
       print(i)
       i = i +  1

As you enter the code, you may notice that Thonny marks the ingredients in different colors. This feature is called syntax highlighting and helps you quickly navigate through your program code. The program can be started by the green play arrow in the toolbar.

But Thonny can do more than that. For example, you can double click to the left of the code (where the line numbers are) and thus create a breakpoint. If you now start the program using the Debug toolbar button, execution will stop at the breakpoint and can be resumed line by line. In the right view of the code, the values ​​of the variables (in this case i) are output. good right?

You have now learned the essential steps to start programming Raspberry Pi. But the Pi offers a multitude of possibilities and a full range of programming languages. And of course databases like MySQL, PostgreSQL or MongoDB and the famous web servers Apache and NGINX can also run on Raspi. Only for resource-intensive IDEs like Eclipse or IntelliJ, dwarf computing is still not suitable, but hey - Raspberry Pi 5 is already in the planning stage.



Close Menu