Setting up Raspberry Pi

After sudo apt update and upgrade and all the necessary install, you can create an SSH connection:

1) Crtl+ Alt+T to open Terminal

2) ifconfig -a command in a Pi Terminal window will show details related to active network interfaces on the device

3)To install the OpenSSH server, open a Terminal window and enter the following installation command (don’t enter the $ symbol, as that is simply illustrating the prompt indicator shown in the Pi’s Terminal window):
$ sudo raspi-config

raspi-config is Raspberry Pi OS’s built-in hardware and software configurator. Rather than manually editing boot configuration files, raspi-config allows you to easily activate hardware ports and software like OpenSSH. We’ll revisit other raspi-config settings like camera and I2C interface access, but for now we’ll enable SSH on the Pi by selecting Interface Options from the main screen.
On the next screen, select the P2 SSH option to Enable/disable remote command line access using SSH. In addition to enabling SSH access via the Terminal, this service will also allow you to transfer files to and from the Pi securely.
Once activated, you should be able to SSH into your Pi from another
computer on your network that has the SSH client installed. If you’re using a Mac or Windows 10 computer, an SSH client is included with those operating systems. To test your SSH access to your Pi, open a Command or PowerShell window on Windows or launch the Terminal app on macOS and enter the following command at the respective window’s command prompt (substitute the IP_ADDRESS label with the IP Address of the Pi on your network):
$ ssh pi@IP_ADDRESS
As an example, my Pi has has an IP address assignment of
Therefore, to log in to my Pi from my Windows 10 computer, I open a PowerShell window and type this in:
$ ssh pi@
You’ll then be prompted to type in your password that you created for your Pi during the initial OS setup procedure. When you SSH from another computer, you’ll need to enter this password each time until you’ve set up digital keys for your SSH access. We’ll do that shortly.

Now that you’re connected to the Pi via SSH, you can access the file system, perform commands, and execute programs as if you were typing into the keyboard locally connected to your Pi. For example, typing the command ls at the Pi’s command prompt will display a listing of the visible files and folders in your user’s home directory on the Pi. If you’re not familiar with Linux-centric command-line statements and utilities, check out the website for a number of well-written beginner tutorials.

Cheking Python

$ python3 –version

The most popular Python package management and distribution system used today is called Pip. Pip is a recursive acronym for “Pip installs packages” and makes Python package installation a breeze.
install command:
$ sudo apt install python3-pip
$ pip3 –version
pip 18.1 from /usr/lib/python3/dist-packages/pip (python 3.7)
$ pip –version
pip 18.1 from /usr/lib/python2.7/dist-packages/pip (python 2.7)

Installing a Virtual Environment for python like Pipenv is easy. To do so for all users, simply sudo the pip3 commandin the Terminal.
$ sudo pip3 install pipenv
Once Pipenv is installed, I encourage you to review the variety of options this powerful, easy-to-use Python virtual environment manager has to offer.
By virtualizing your Python development environment, you can create discretely quarantined Python instances that have their own set of packages. You can even create virtual environments running different versions of the Python interpreter. This can come in handy when you want to test your Python code on different versions of Python without having to uninstall and reinstall those versions each time you want to run a test.

sudo apt install python3-gpiozero



Pinout of Raspberry Pi 4

import RPi.GPIO as GPIO

You need to add this line to the top of your Python script. This will import the RPi.GPIO module with the local name GPIO,

Pin Scheme Declaration

After importing the module, you need to select a pin-numbering scheme among the two alternatives: If you are using T-cobbler breakout, use the BCM scheme because there is BCM labeling on the breakout board. But if you are using simple jumper wires, go with the board scheme. To specify the pin number scheme, you use the GPIO.setmode() function, along with the pin scheme as an argument (GPIO.BCM for the BCM scheme and GPIO.BOARD for the board scheme). For example,


Here, GPIO is the local name of the module, declared when it’s imported. The import and setmode lines of code are both important and you should add them to the top of your program if you want to use Python to access the GPIO.

Pin Mode Declaration

If you have used the Arduino board, you are familiar with the pinMode function to set the GPIO as input or output. Similarly, you have to declare the GPIO pin as input or output in the Python program. To set the pin mode, use GPIO.setup([pin],[GPIO.IN, GPIO.OUT]). For example, if you want to use GPIO 14 as input, you would declare it as follows:



To make the GPIO state high or low, use GPIO.output([pin] or [GPIO.LOW, GPIO.HIGH]). For example, if you want to set the GPIO 14 as high,then you would write:


This will set 3.3V at GPIO 14. If you provided GPIO.LOW, it will drive it to 0V. You can also give 0 or False for GPIO.LOW and 1 or True in place of GPIO.HIGH.

You can also generate PWM signals but sadly there are only two PWM pins—GPIO18 and GPIO19. To initialize PWM, use the GPIO.PWM([pin],[frequency]) function. Then use the pwm.start([duty cycle]) function to set the initial duty cycle. For example, if you want to set the PWM with a 1000Hz frequency and 75% duty cycle at GPIO18, you would write as follows:



You can change the duty cycle later in the program, by using pwm.

ChangeDutyCycle([duty cycle]).

To stop PWM on that GPIO, use the pwm.stop() function.