Raspberry Pi - introduction

Written by Lenvin Gonsalves.
on April 21, 2021

Hi guys, it's my first blog. I'm still learning a lot of stuff and this blog is to keep track of what I'm learning and also to spread whatever I know to the community .

Introduction

Raspberry Pi is a SOC (System on Chip) with immense potential, although it serves as the base for commercial projects, it is discarded in production.

System on chip means that the entire components like the processor,memory,GPU is combined on a single chip, unlike traditional desktops in which components are spread apart so as to provide flexibility and upgradability (I don't think it's a word).

It includes a processor, a graphics chip, some RAM, a few USB ports, an HDMI output, an Ethernet port, and (in the latest version) integrated wifi and Bluetooth.

It is more similar to mobile phones in terms of overall deign and architecture than traditional desktops, since it has an ARM based processor and VideoCore -IV graphics. So i.e. normal OSes meant for the x86 based machines wouldn't run on this.

We have Raspbian, Windows 10 IoT core (stripped down free version for Raspberry Pi) and other freely available OSes for the SoC. There's no storage on the board to store the OS (although there is storage on which is not capable and not meant for storing the OS).The OSes are stored on the SD card

The following web pages can be of help to install the OS on your pi board.

To be noted, a SD card of size of at least 8 GB would be required

Various sensors and components can be added to the board via the breadboard.The pins on the board serve their own purpose

Lenvin's stunning image should have been here

Connecting the modules to the board

  • The GND pin is connected to the GND pin of the board
  • The VCC pin of the sensor is connected to the desired power supply (5V/5V/3V)
  • The DO pin of the sensor to the GPIO(Input/Output) of the Raspberry pi, all data communication is done via this

WARNING: GPIO pins use a 3V3 logic level and are not tolerant of 5V levels. Check whether the digital output (DO) value is 3.3V, otherwise, you may permanently damage your Raspberry PI

Lenvin's stunning image should have been here

Sample program to light a LED

import RPi.GPIO as GPIO
importtime
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18,GPIO.OUT)
print "LED on"
GPIO.output(18,GPIO.HIGH)
time.sleep(1)
print "LED off"
GPIO.output(18,GPIO.LOW)

Differences between the pi models

Lenvin's stunning image should have been here

Raspberry Pins in detail

1

First let's get familiar with the numbering/ labeling system of the pins on the board. There are two numbering conventions, one is as per the Broadcom SOC (called bcm here and everywhere else) and one as per the numbering printed on the board (simply called board).

The numbers in big bold towards the extremes of the diagram refer to the bcm naming convention , which is usually preferred since it remains the same throughout the various models. The numbering next to the colorful circles(i.e. the pins) are the number printed on the board.

You might argue why two different conventions, it is because the bcm refers to the internal(logical?) of the SoC while the board represents it's physical location .

Let us first understand the various data/bit transferring protocol before we talk about the individual pins.

I2C

This protocol was found by Philips electronics and is popular for the reason that only two pins are required to connect to a device. It is the cousin of the SPI protocol. The addresses of the module is sent in a 7 bit hex format to the module and once it matches communication takes place.t is also well supported by user-made libraries. There are many components designed to be used with I2C on Raspberry Pi. While it is slower than SPI, it still works fast enough for most day to day uses.

Much like SPI, the protocol has a master device, such as the Pi, and a slave device, such as a screen, shift register, or motor driver.

The first connection between the devices is the SCL (Serial Clock) which is set by the master to synchronize the transfer of data. The second line is the SDA (Serial Data) which transfers the data back and forth between all devices on the I2C bus.

The master device begins communication with a start bit, and a seven-bit hex address. This must match the slave device in order for them to communicate. This is how so many devices can be used with only two wires.

The master device then specifies whether it wants to read or write (R/W) the slave, before receiving an acknowledgment or ACK back.

SPI

SPI (or Serial Peripheral Interface) allows a microcontroller such as the Pi to communicate with over 100 peripheral components at once. The microcontroller acts as a “master” to all of the “slave” components, and can communicate with them at a high speed. This diagram outlines a simple SPI connection:

2

SCLK is the clock speed set by the master which determines the speed that information is shared between the devices.At each cycle (or “tick”) of the clock, both master and slave send and receive one bit of information. This is what the MOSI (Master Out Slave In) and MISO (Master In Slave Out) pins are for.

The SS or Slave Select pin (marked CE0 or CE1 on the Pi) is used to tell a slave device to communicate with the master—or not—at any given time. In most cases, each slave device requires its own SS pin, but can share the SCLK, MOSI and MISO pins.

Some devices can be “daisy chained” to share an SS pin, keeping the total pins used down to four, plus two for power and ground. SPI is known for being incredibly fast and is commonly used in shift registers or ADCs (Analogue to Digital converters) to pass data between devices. Read more...

UART

UART stands for Universal Asynchronous Receiver/Transmitter. It’s not a communication protocol like SPI and I2C, but a physical circuit in a microcontroller, or a stand-alone IC. A UART’s main purpose is to transmit and receive serial data.

In UART communication, two UARTs communicate directly with each other. The transmitting UART converts parallel data from a controlling device like a CPU into serial form, transmits it in serial to the receiving UART, which then converts the serial data back into parallel data for the receiving device. Only two wires are needed to transmit data between two UARTs. Data flows from the Tx pin of the transmitting UART to the Rx pin of the receiving UART:

3

UART is used to connect the bluetooth module or in scenarios where the board is supposed to be used in a header-less way(i.e. without the display).

UARTs transmit data asynchronously, which means there is no clock signal to synchronize the output of bits from the transmitting UART to the sampling of bits by the receiving UART. Instead of a clock signal, the transmitting UART adds start and stop bits to the data packet being transferred. These bits define the beginning and end of the data packet so the receiving UART knows when to start reading the bits. UART is used to connect the bluetooth module or in scenarios where the board is supposed to be used in a header-less way(i.e. without the display). The kernel of the board can be directly accessed via this port. Read more...

PCM

PCM (Pulse-code Modulation) is a digital representation of sampled analog. On the Raspberry Pi it's a form of digital audio output which can be understood by a DAC for high quality sound.

It consists of FS which groups the bits into frames, CLK for synchronization and DIN/DOUT for input and output.

PWM

PWM stands for ‘Pulse Width Modulation’. PWM is a method used for getting variable voltage out of constant power supply. used for connection motors and blinking leds.

It is not compulsory that the pins function as per the diagram above, they can be set to the alternative usage as shown below

4 5

There is one more resource i would like to share if you would like to know more about the pins (from Broadcom's perspective)