Learn Raspberry Pi| Pi How To use Raspberry Pi (Part 1)

In this article we learn about Raspberry Pi. We learn raspberry pi by some tutorials. Raspberry Pi is most popular SBC (Single Board Computer). The Raspberry Pi is a low cost, credit-card sized computer that plugs into a computer monitor or TV, and uses a standard keyboard and mouse. It is a capable little device that enables people of all ages to explore computing, and to learn how to program in languages like Scratch and Python. It’s capable of doing everything you’d expect a desktop computer to do, from browsing the internet and playing high-definition video, to making spreadsheets, word-processing, and playing games.

What’s more, the Raspberry Pi has the ability to interact with the outside world, and has been used in a wide array of digital maker projects, from music machines and parent detectors to weather stations and tweeting birdhouses with infra-red cameras. We want to see the Raspberry Pi being used by kids all over the world to learn to program and understand how computers work.

Raspberry Pi  For Internet of things (IoT)

Yes RPi can used in IoT. Because RPi is a SoB- System on Board. RPi support various Operating System. Mostly RPi used as Iot Gateway. The internet of things (IoT) is the rapidly growing network of devices(things) connected to the Internet. the does not just mean more and more computers using browsers, but appliances and wearable and portable technology. This includes all sorts of homes automation from smart appliances and lighting, to security systems and even Internet-operated pet feeders, as well as lots of less practicals and fun projects.

You can program hardware on the RPi?

You can, via the row of pins at the top edge of the board (of the 40, 26 are GPIO pins). By attaching hardware like LEDs, sensors and motors to these pins you are able to interact with them using the Pi. Writing simple programs will allow you to send signals via the pins to control the attached hardware–for example making an LED flash– or to read a signal sent from the attached hardware via the pins–for example to take a measurement from a sensor.

Raspberry Pi 4

Raspberry Pi 4 is a latest version. The Raspberry Pi 4 comes with up to 4GB RAM, which is four times than that of its predecessors. The RAM now comes in LPDDR4, unlike LPDDR2 used in the previous version. Apart from this, the device comes with Broadcom BCM2711, Quad-core Cortex-A72 (ARM v8) 64-bit processor at 1.5GHz.

The Raspberry Pi 4 comes with dual-band WiFi comprising of 2.4 GHz and 5.0 GHz IEEE 802.11ac. It also has Bluetooth 5.0 and Gigabit Ethernet. Apart from this, there is also a couple of USB 3.0 ports and two USB 2.0 ports. There are two micro-HDMI ports, which can plug two 4K display screens at 60 frames per second. It has many more features you can visit official website for more information.

Getting Started with Raspberry Pi 4

For using Raspberry pi we need a operating system, memory card, Monitor, keyboard and mouse. Officially RPi recommended Raspbian OS for Raspberry Pi. Raspbian is a free operating system based on Debian optimized for the Raspberry Pi hardware.

Install Raspbian OS image on an SD card

You will need another computer with an SD card reader to install the image. You will need to use an image writing tool to install the image you have downloaded on your SD card. Etcher is a graphical SD card writing tool that works on Mac OS, Linux and Windows, and is the easiest option for most users. Etcher also supports writing images directly from the zip file, without any unzipping required. To write your image with Etcher:

  • Download Etcher and install it.
  • Connect an SD card reader with the SD card inside.
  • Open Etcher and select from your hard drive the Raspberry Pi .img or .zip file you wish to write to the SD card.
  • Select the SD card you wish to write your image to.
  • Review your selections and click ‘Flash!’ to begin writing data to the SD card.

Now insert SD card into Raspberry Pi and connect a keyboard, mouse and Monitor with raspberry Pi. Now you can use Raspberry Pi. Default username is Pi and Password is Raspberry.

How To Use Raspberry pi in a headless mode

If you want use Raspberry Pi in headless mode, please follow these steps are given below:

Download Raspbian and Flash it on SD Card– Download Raspbian from Raspberrypi.org ‘s download section: https://www.raspberrypi.org/downloads/raspbian/

You need to flash this downloaded image to the micro SD card. Assuming your laptop has a SD card slot, you need a flashing software like etcher. Go ahead and download from: https://etcher.io/

WiFi Configureation – Its easier to make two devices talk to each other if they are in the same network. So we are going to add a file to the SD card so that the Pi boots with a wifi pre-configured.

The SD card mounts as two volumes boot and rootfs . Open the boot volume and create a file named wpa_supplicant.conf On booting the RPi, this file will be copied to /etc/wpa_supplicant directory in /rootfs partition. The copied file tells the Pi the WiFi setup information. This would overwrite any existing wifi configuration, so if you had already configured wifi on the pi, then that will be overwritten.

A typical wpa_supplicant.conf file is as follows

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=«your_ISO-3166-1_two-letter_country_code»

network={
    ssid="«your_SSID»"
    psk="«your_PSK»"
    key_mgmt=WPA-PSK
}

Your SSID is your wifi’s name. To find out SSID on ubuntu, you can use theiwgetid command. The psk is the wifi password and your country code can be found here: https://www.wikiwand.com/en/ISO_3166-1_alpha-2#/Officially_assigned_code_elements

So replace all the «item» fields in the above text

Enable SSH and Find Pi’s IP address – We can access Pi via secured shell (SSH), SSH is disabled by default in raspbian. To enable SSH, create a file named ssh in the boot partition. If you are on linux, use the touch command to do that. Now we need findout IP address so we need to findout the existing devices connected to the network. Make sure your laptop is connected to the same wifi network as the one you configured on pi above.

Run the command hostname -I to find out your laptops’ ipaddress. Say it is 192.168.1.8 then when connected your pi’s ip would be 192.168.1.x

Run the command nmap -sn 192.168.1.0/24 to findout existing devices in the network in range 0 to 24 for the last portion of ipaddress. I get

Starting Nmap 7.01 ( https://nmap.org ) at 2019-10-03 18:39 IST
Nmap scan report for 192.168.1.1
Host is up (0.0020s latency).
Nmap scan report for 192.168.1.8
Host is up (0.000097s latency).
Nmap done: 256 IP addresses (5 hosts up) scanned in 2.58 seconds

Remove the micro SD card from your laptop and insert it into Pi. Power it up using a power source (5v regular android charger) and try nmap -sn 192.168.1.0/24 again, to see which ip address newly appears

Starting Nmap 7.01 ( https://nmap.org ) at  2019-10-03 18:39 IST
Nmap scan report for 192.168.1.1
Host is up (0.0020s latency).
Nmap scan report for 192.168.1.2
Host is up (0.040s latency).
Nmap scan report for 192.168.1.8
Host is up (0.000097s latency).
Nmap done: 256 IP addresses (5 hosts up) scanned in 2.58 seconds

so 192.168.1.2 should be the ip address of the pi.

SSH into the Pi – To create a secured shell connection, in linux we can use the ssh command. If you are on windows, try downloading PuttY from https://www.putty.org/  or Xshell from https://www.netsarang.com/en/xshell/

To connect to Pi you need the default username and password of the device. On first boot, the username and password would be as follows.

username : pi
password: raspberry

now you can do

ssh [email protected]

Type in y when asked if you sure to continue connecting with the device. Then when asked for password, type in the pass.

Its a good practice to change the password to something else.

[email protected]:~ $ passwd
Changing password for pi.
(current) UNIX password: raspberry
Enter new UNIX password: yournew passowrd
Retype new UNIX password: yournew passowrd
passwd: password updated successfully

 See the screen – Sometimes it doesn’t feel right if we can’t use the mouse. For that we need to look into the Raspbian desktop.

We need to setup VNC (Virtual Network Connection) to see and control Pi graphically. Let’s do that.

sudo apt-get update
sudo apt-get install -y realvnc-vnc-server realvnc-vnc-viewer

These commands would update Pi’s softwares and install realvnc which will be used to setup remote sessions.

Access Pi remotely – On the raspberry pi’s ssh prompt, type in vncserver to start the service. This will print an ipaddress where you can access the desktop remotely, note that down. Mine says

New desktop is raspberrypi:1 (192.168.1.2:1)

To access the remote desktop, you need a vncviewer (client) for your laptop. Fortunately RealVNC is available for a lot of OSes, pick one for your OS from https://www.realvnc.com/en/connect/download/viewer/

If you are on debian/ubuntu, you might have to do some additional step after downloading the executable.

cd ~/Downloads

Here we are changing the file mode of the downloaded executable to make it installable. We are also moving the executable from the downloads folder to the home folder.

Once RealVNC viewer is installed, add the raspberry pi device to the connections (File > New connection). Enter the pi’s desktop identifier (192.168.1.2:1 ), give it a friendly name, click Ok. Enter pi’s username and password when prompted. That’s it, you should now see the desktop. Give me a five!

Alternative option – sometimes vncserver does not work, So you can use tightvncserver

Install TightVNC on your Pi

sudo apt-get update

sudo apt-get install tightvncserver

That takes care of the installation. Now we need to start the vnc server…

tightvncserver

Raspberry Pi GPIO Connector

Raspberry Pi GPIO connector allows you to connect all sorts of interesting electronics to your RPi. Raspberry Pi 4 has 40 GPIO pins.

Keeping Raspberry Pi Safe when using the GPIO Connector

Raspberry Pi is little fragile when it comes to adding external electronics. Today, Latest Models are little more robust but still quite easy to break. So follow some precaution given below:

  • Do not put more than 3.3V on any GPIO pin being used as an input.
  • Do not draw more than 16mA per output and keep the total for all outputs below 50mA in total for Revison 1 layout and below 100mA on a revison 2 (40 Pins).
  • Do not power the RPi with more than 5V.
  • Do not draw more than a total of 250mA from the 5V supply Pin.
  • Do not poke at the GPIO connector with a screwdriver or any metal object when the Pi is powered up.
  • When using LEDs, 3mA is enough to light a red LED reasonably brightly with a 470ohm series resistor.

I hope you like this article “Learn Raspberry Pi”. This was Part 1 of learn Raspberry Pi. In Next article “Learn Raspberry Pi Part 2” we learn Controlling LED with Raspberry Pi and some other tutorials.

Do you have any questions? Leave a comment down below! and Subscribe for Latest updates.


You may like also: IoT OS and RTOS for Internet of Things Devices

Harshvardhan Mishra

Hi, I'm Harshvardhan Mishra. I am a tech blogger and an IoT Enthusiast. I am eager to learn and explore tech related stuff! also, I wanted to deliver you the same as much as the simpler way with more informative content. I generally appreciate learning by doing, rather than only learning. Thank you for reading my blog! Happy learning! Follow and send tweets me on @harshvardhanrvm. If you want to help support me on my journey, consider sharing my articles, or Buy me a Coffee!

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this:
satta king tw