Raspberry Pi first Programming and Basic commands–This project is a tutorial for beginners that explains how to write your first Raspberry Pi python program and what are the most frequently used commands any beginner should know about.This tutorial will help you understand the python programming environment quickly and, in addition, the commands I will share with you are almost used in any Raspberry Pi programming. Although there are many commands for Raspberry Pi, for now you should only practice the commands I will share with you.
But you will need to set up your Raspberry Pi properly before you start programming in python so you can access your raspberry. This is my second tutorial about how to use the most simple Raspberry Pi commands and then how to write your first Raspberry Pi python script.
In my previous tutorial, I explained how you can setup your SSH network using Putty software so that you can wirelessly access your raspberry pi, and can write your Raspberry Pi first Programming using your laptop keyboard and mouse. In this tutorial, we will cover
- How to create a directory
- How can files and directories be viewed
- How to create a file within a directory
- How to write a python idle basic hello world program
- How to run a program
- How to modify a program
Let’s start without any further delay!!!
The Amazon Purchase links are given below:
Arduino Uno: https://amzn.to/39aq6ZT
Mega 2560: https://amzn.to/2SszMsI
lm7805 Voltage Regulator: https://amzn.to/2ERYoTJ
330-ohm resistors pack: https://amzn.to/2Qj1Igg
female DC power jack socket: https://amzn.to/377Pg9M
470uf capacitors: https://amzn.to/2MrN3xR
5×7 cm Vero board: https://amzn.to/37b7KWO
female headers: https://amzn.to/350w6RE
connection wires: https://amzn.to/2MvOJXd
Super Starter kit for Beginners: https://amzn.to/398dliF
Jumper Wires: https://amzn.to/2SrnBwo
Bread Board: https://amzn.to/2MxV5FM
12v Adaptor: https://amzn.to/2MuOlZk
PCB plate: https://amzn.to/2MuwNMB
Variable Supply: https://amzn.to/39d0KdP
Digital Multimeter: https://amzn.to/34WbVoa
Vero Board / stripboard: https://amzn.to/39nL9Zg
Soldering iron kit: “best” You guys should definitely purchase this: https://amzn.to/2PVwexF
Solder wire: https://amzn.to/2QlOvTS
Wire Stripper: https://amzn.to/353tYJa
PCB small portable drill machine: https://amzn.to/2MvQqnx
Please Note: these are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!
Once you write a script, first of all, there is no need for a keyboard and mouse to power up your raspberry pi, as we will use the keyboard and mouse of our laptop. If you don’t use the SSH network, you’ll need to attach your keyboard and mouse and you’ll need an LCD as well. But since I’ve already set up the SSH network, I’m going to use the keyboard and mouse of my laptop.
As you can see, no input or output devices are actually attached to the GPIO pins, because we do not use any sensors in this tutorial. Only charging up the Raspberry Pi is the only thing we need to do.
Let’s open the putty program now, enter your raspberry pi’s IP address, if you don’t know about the IP address, look at my previous tutorial. Then open press.
You will be asked to enter your user name and password after clicking on the Open key. Only enter the name of the account as “pi” and the password is “raspberry.”
If the login name and password have been entered correctly, you will be logged in.
We’re signed in as you can see.
The following are Raspberry Pi’s most commonly used commands.
Raspberry pi display files and folders:
Let’s begin with the ls command, which is one of the most commonly used commands, the ls command used to display all the list of folders write ls and press enter.
As you can see all the directories and files in the list.
Raspberry Pi clear screen command:
Another commonly used command is the clear command, which was used to clear the Write clear screen and press enter
Everything on the screen will vanish after you press the enter key on your keyboard.
How to change the directory in Raspberry?
Now let’s use the ls command to show the folders and files again.
Now let’s say this time we want the test directory to be opened. We just write a cd check and press in. The command used to search the inside of the folder.
As you can see, foo.txt and temp.py are two files. Simply write cd and press enter if you want to exit this file.
How to make a Director in Raspberry Pi?
Another command that is most frequently used is mkdir. Which folder is used to create. Write mkdir with the name of the folder. First, let’s clear the screen using the clear command before we use this command. Now let’s say we want the name youtube to create another folder. We simply write and click enter mkdir youtube. This command creates a folder called youtube. Write the ls command to test whether or not the folder has been created.
As you can see it has been created. Now, just write cd youtube and press enter to open this folder. If I use the ls command now, you can see that it doesn’t have any files or folders.
YouTube is our current working directory now.
How to Write and Run a Python Program on the Raspberry Pi terminal?
Let’s build our first.py extension python program directory. Just write first.py sudo nano and press enter as you can see in the above picture. You can choose any name, but make sure you add the.py extension.
Open the editor, that’s where you can write your script. Let’s write a very easy hello program for the world.
We don’t need any semicolons at the start, unlike Arduino’s programming. Click control o to save this file on your keyboard and simply press enter as we’ve already produced a file, then press + x to exit the editor.
Now if we’re writing the ls, you can see the first.py file in the youtube directory.
Just type python first.py and press enter to run this program.
You can see the hello world message. now let’s say you want to edit this program.
How to edit the Python programming for Raspberry Pi?
It’s unwritable because you can see file first.py. To exit, press control x.
Now write and enter sudo nano first.py.
Now write something you’d like to print.
Press ctrl+ o to save the file and click x to exit the editor at the end. To run this script, write python first.py.
How to delete/remove a file in Raspberry Pi?
Now let’s say we’ve got two files and we want to delete one file, we’ve got a rm simple write sudo rm command, then enter the file name and press enter.
The folder is deleted as you can see. So for now, that’s all. These were Raspberry Pi’s most simple commands. Such commands should be followed.