raspberry pi

Raspberry Pi:

Very useful tool to learning microcontrollers and building projects. This is preferred over all other microcontrollers, as it can support Linux OS, so you can write programs in any programming language, and be able to control pins. It works just like working on a desktop or laptop with Linux installed. The advantage that Raspberry Board provides is that it behaves as a microcontroller, so it has pins available that you can use to drive any output or to receive any input which allows you to connect various devices to it's pins and make cool projects. A regular microprocessor doesn't provide you these general purpose pins (known as GPIO), so we can't use processors from Intel/AMD to make these projects.

official website: https://www.raspberrypi.org

Generations of Raspberry pi:

A summary of Raspberry pi journey is on wiki here: https://en.wikipedia.org/wiki/Raspberry_Pi

More and more powerful raspberry pi are coming on market. What started as 1st generation Raspberry pi 1 in 2012, soon expanded to Raspberry Pi 2, Pi Zero, Pi 3 and now Pi 4 as of 2020. All Raspberry Pi have Broadcom SOC which have ARM microprocessor. Here are the details:

Pi 1:  It came out with Model B in 2012, then a cheaper Model A. Then improved pi Models B+ and A+ were released. Broadcom BCM2835 SOC was used in these 1st gen Pi, which had 700MHz ARM 11 Processor. Models A/B had 256MB memory, while A+/B+ had 512MB memory. The ARM11 is the same CPU used in the original iPhone although at a higher clock rate and mated with a much faster GPU. So, you can imagine the power of Pi 1, and this is the lowest performing 1st gen Pi !!

Pi 2: These were released in 2015. They initially had BCM2836 SOC which featured a 900 MHz 32-bit quad-core ARM Cortex-A7 processor with 1 GB RAM. Later versions had BCM2837 SOC which featured a 1.2 GHz 64 bit quad-core ARM Cortex-A53 processor.

Pi Zero and Pi Zero W: These were cheapest pi and smaller in size. Pi Zero was released in Nov, 2015 for $5. In 2017, Pi Zero W was released, which was similar as Pi Zero but with wifi and bluetooth capabilities (the term W implied Wireless). This sold for $10. Both used the same Broadcom BCM2835 SoC as the first generation Raspberry Pi, although now running at 1 GHz CPU clock speed. They both had 512MB memory. With wireless capabilities added, Pi Zero W was the first real all purpose microcontroller. With a rock bottom price of $10, and working as a desktop, there was nothing on market that could compete with it. I myself bought couple of Pi Zero W for $3.14. They work extremely well, although slow for any browser viewing.

Pi 3: There were 3 versions: B, A+ and B+. All used BCM2837 SOC. Model B was released in 2016 with BCM2837 SOC which featured a 1.2 GHz 64-bit quad-core ARM Cortex-A53 processor (same as Pi 2). B/B+ had 1GB memory, while A+ had 512MB memory. Model B+ and A+ had higher CPU speed of 1.4GHz. However, now all Pi had wireless capabilities, That was the only meaningful addition over Pi 2.

Pi 4: The only model released here as of 2020 is Model B which was released in 2019. It used BCM2711 with a 1.5 GHz 64-bit quad-core  ARM Cortex-A72 processor. More details in next section.

For the 1st time, Pi supported ARM virtualisation capabilities. It came in 4 flavors, with RAM of 1GB, 2GB, 4GB and 8GB.  It added USB type C port for powering the board. It had 2 micro HDMI ports for connecting 2 4K monitors. It also has 2 USB 2.0 ports and 2 USB 3.0 ports.  There was significant upgrade in RAM, comparable to low end PC, for the first time. Pi 4 with 8GB RAM became a full desktop capable processor, which can perform on same level as Intel or AMD machines.

Where to Buy:

Raspberry Pi is sold at bunch of places (the website lists such places), but the prices vary a lot. You can usually buy raspberry pi at discount during sale. In USA, Microcenter is the best place to buy, as they frequently have lowest performing Raspberry Pi Zero W for $3.14 (i.e value of pi). BestBuy also has sales some of the times. Best website to look for such deals is slickdeals.net, and search for raspberry.

Which Raspberry Pi to Buy:

I would suggest sticking to Raspberry Pi Zero W, or Raspberry Pi 4. All other Raspberry Pi are basically just variations of these 2. My next sections will only deal with these 2 flavors of Pi. Pi Zero W is the cheapest Raspberry Pi, and could be had for $3. Raspberry Pi 4 with 4GB memory could be had for $40. It is so powerful that it can serve as a full desktop replacement. I've a 2GB version, and though it works well, it lags in browsing. 8GB is where all programs can fit in memory well, even with multiple tabs open on browser. So, 8GB would be ideal, though 4GB will serve well for 99% of tasks.

You don't need to buy any accessories bundled with Pi, since they are a lot cheaper to buy separately. You will need to buy below accesories, before you can use Pi. However, I don't suggest buying Keyboard/Mouse and Monitor, as we'll use vnc to connect to raspberry pi. That way we can use our laptop's keyboard and monitor to work on raspberry pi.

- memory SD card => Get a SD card of 64GB or 128GB as these are very cheap and go for $10 or less. Large size is good, incase you need to install a lot of stuff on raspberry pi later.

- USB cable => You may order some cheap USB cables from ebay

- Keyboard/Mouse => You don't need to buy this.

- Monitor => You don't need to buy this.

Raspebrry Pi: Getting started

Steps to get a raspberry project going. I'm listing general steps irrespective of which raspberry Pi you use. My preferred raspberry Pi are Pi Zero W (since it's the cheapest one), and Pi 4 (since it's the most powerful one).

A. Burn Raspberry Pi OS on SD card: I'm doing this on a Laptop which has Linux Mint installed on it. The below steps are all done on the laptop, and NOT on raspberry board.

1. download he raspberry pi OS:

https://www.raspberrypi.org/downloads/raspbian/

Download the "Raspbian Buster with desktop and recommended software". Download the zip file, and extract it. It gets extracted as "2020-02-13-raspbian-buster-full.img".

2. get a SD memory card with atleast 8GB space as raspbian OS after extraction needs atleast 8GB. On a terminal, type the lsblk cmd to check what what devices it shows connected (After inserting the SD card)

$ lsblk -p
NAME             MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
/dev/sda           8:0    0 931.5G  0 disk
├─/dev/sda1        8:1    0   260M  0 part /boot/efi
├─/dev/sda2        8:2    0    16M  0 part
├─/dev/sda3        8:3    0 246.7G  0 part
├─/dev/sda4        8:4    0   980M  0 part
├─/dev/sda5        8:5    0   7.5G  0 part [SWAP]
└─/dev/sda6        8:6    0 676.1G  0 part /
/dev/sr0          11:0    1  1024M  0 rom  
/dev/mmcblk0     179:0    0  29.7G  0 disk
└─/dev/mmcblk0p1 179:1    0  29.7G  0 part /media/ash/6636-6330

Above o/p of lsblk cmd shows our SD memory card as mmcblk0. It has 1 partition mmcblk0p1 which is mounted on /media/ash/6636-6330. We need to unmount the device by typing below cmd.

$ umount /dev/mmcblk0p1 => NOTE: we unmount the partition in SD card, and not the SD card device itself (i.e unmount mmcblk0p1 and NOT mmcblk0)

3. Now copy the raspbian image on to SD memory card using Linux dd cmd below:

$ sudo dd bs=4M if=2020-02-13-raspbian-buster-full.img of=/dev/mmcblk0 status=progress conv=fsync => block size is set to 4MB to speed up copy time, while status is set so that copy progress can be seen
[sudo] password for anvay:
7319060480 bytes (7.3 GB, 6.8 GiB) copied, 222 s, 33.0 MB/s
1746+0 records in
1746+0 records out
7323254784 bytes (7.3 GB, 6.8 GiB) copied, 249.04 s, 29.4 MB/s

4. Now once the image is copied on SD card, eject the SD card, and it's time to insert that card in Raspberry pi motherboard.

B. Power up Raspberry Pi: Now, get your Raspeberry Pi Board out, and perform all below steps on it:

1. Insert The memory card into the card slot on Raspberry pi board.

2. Get the accessroies needed for raspberry Pi. At the least you need a usb Type A or Type C cable for powering the raspberry pi. For initial setup, you will also need a monitor and a keyboard and mouse.

3. There is no turn on/off button on any raspberry pi. They start powering up, as soon as the usb cable is connected to a power supply. You will see a raspberry logo, and then the screen should appear. You should connect it to your wireless network, by clicking on wireless icon on top right. That wireless network name and password will be stored, so you don't need to enter it ever again.

At this stage you are done with basic setup, and can start using your Pi to browse, write scripts, play games or do nothing.

Other Utilities:

There are few other things that we can install on raspberry pi, that will be useful.

C. ssh: To connect to raspberry pi terminal, you could use ssh. Look into "openssh" section of "software tools". First we need to install ssh on raspberry pi. NOTE: client ssh is always installed by default. It's the sshd daemon or server ssh that is not installed (or not activated) by default, as it's not needed that often.  ssh is already installed on raspberry pi, it just needs to be enabled. This link shows how: https://www.raspberrypi.org/documentation/remote-access/ssh/

Our laptop from which we are trying to connect to raspberry pi only needs the client ssh, and NOT the server ssh. Since client ssh is slways installed by default, we don't need to install server ssh (i.e sshd), but it's always good to install it on the laptop too, as that way we can connect to our laptop from raspberry pi too (the use case is rare though).

Once all that is done, we need to find the ip address of raspberry pi. You can also use the name of "raspberry pi". By default, name of your raspberry pi is "raspberrypi" and it's private ip address is of form 192.168.1.xx. You could run cmd ifconfig and get the ip address of your ethernet i/f or wireless i/f. But in our case, it's not needed. We know the name of our device, and that will suffice. Next, we also need to know he username on raspberry pi. By default, username is "pi". So, to connect to raspberry pi, we need to go to our laptop from where we want to connect to raspberry pi. Assuming it's a Linux laptop, open a terminal and type ssh cmd as below:

ssh pi@raspberrypi => This will ask for your password on raspberry pi for user "pi". On successful connection, it will show raspberry pi terminal. The terminal prompt will change to that of raspberry pi prompt. By default, the new prompt will show as "pi@raspberrypi".

Now you can access any file, open apps , etc. NOTE: not all application will open from this terminal due to Xdisplay not setup. Look in Xwindows section on how to do it.

D. scp: If you want to copu any file from raspberry pi to your laptop or from your laptop to raspberry pi, you use this cmd. Usage is provided on "openssh" section. From your local computer, type this cmd to transfer files back and forth. NOTE: in both examples below, we ssh into raspberry pi, that's why we need server ssh (sshd) running on raspberry pi.

ex: scp test1.py pi@raspberrypi:/home/ramesh/. => copies test1.py from local computer to raspberry pi

ex: scp pi@raspberrypi:test3.txt project/tmp/tmp.txt => copies test3.txt from raspberry pi to our local computer in current dir subdir as tmp.txt

 E. Setup VNC:   Now we'll connect VNC. This is the last thing that will allow us to use our raspberry pi as a local desktop without requiring monitors, mouse, etc. VNC steps are detailed in vnc section. Once you have vnc installed on raspberry pi, connect to it using any laptop running windows or Linux. There in nothing special or different for raspberry pi. You need to have vnc server installed on raspberry pi, and vnc client installed on your laptop from which you are going to connect to raspberry pi.