Working with UART, I2C & SPI Protocols

Introduction to Raspberry Pi 4 Physical Computing with Raspberry Pi 4
19 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€65.43
List Price:  €93.47
You save:  €28.04
£55.38
List Price:  £79.12
You save:  £23.73
CA$95.75
List Price:  CA$136.80
You save:  CA$41.04
A$107.11
List Price:  A$153.03
You save:  A$45.91
S$95.36
List Price:  S$136.24
You save:  S$40.87
HK$547.90
List Price:  HK$782.75
You save:  HK$234.85
CHF 63.27
List Price:  CHF 90.39
You save:  CHF 27.12
NOK kr772.60
List Price:  NOK kr1,103.76
You save:  NOK kr331.16
DKK kr487.88
List Price:  DKK kr697.01
You save:  DKK kr209.12
NZ$117.84
List Price:  NZ$168.36
You save:  NZ$50.51
د.إ257.06
List Price:  د.إ367.25
You save:  د.إ110.18
৳7,700.43
List Price:  ৳11,001.09
You save:  ৳3,300.65
₹5,837.33
List Price:  ₹8,339.41
You save:  ₹2,502.07
RM333.67
List Price:  RM476.70
You save:  RM143.02
₦92,489.99
List Price:  ₦132,134.22
You save:  ₦39,644.23
₨19,533.24
List Price:  ₨27,905.82
You save:  ₨8,372.58
฿2,588.46
List Price:  ฿3,697.97
You save:  ฿1,109.50
₺2,275.23
List Price:  ₺3,250.47
You save:  ₺975.23
B$358.08
List Price:  B$511.57
You save:  B$153.48
R1,314.42
List Price:  R1,877.82
You save:  R563.40
Лв127.95
List Price:  Лв182.79
You save:  Лв54.84
₩96,452.39
List Price:  ₩137,795.03
You save:  ₩41,342.64
₪267.23
List Price:  ₪381.78
You save:  ₪114.54
₱4,034.64
List Price:  ₱5,764.02
You save:  ₱1,729.38
¥11,065.06
List Price:  ¥15,807.91
You save:  ¥4,742.85
MX$1,201.03
List Price:  MX$1,715.83
You save:  MX$514.80
QR255.83
List Price:  QR365.49
You save:  QR109.65
P965.79
List Price:  P1,379.76
You save:  P413.97
KSh9,296.24
List Price:  KSh13,280.92
You save:  KSh3,984.67
E£3,349.82
List Price:  E£4,785.67
You save:  E£1,435.84
ብር4,026.64
List Price:  ብር5,752.60
You save:  ብር1,725.95
Kz58,375.85
List Price:  Kz83,397.65
You save:  Kz25,021.80
CLP$66,628.33
List Price:  CLP$95,187.41
You save:  CLP$28,559.08
CN¥507.11
List Price:  CN¥724.48
You save:  CN¥217.36
RD$4,113.13
List Price:  RD$5,876.15
You save:  RD$1,763.02
DA9,393.54
List Price:  DA13,419.92
You save:  DA4,026.38
FJ$158.35
List Price:  FJ$226.22
You save:  FJ$67.87
Q545.71
List Price:  Q779.62
You save:  Q233.91
GY$14,678.83
List Price:  GY$20,970.66
You save:  GY$6,291.82
ISK kr9,808.34
List Price:  ISK kr14,012.52
You save:  ISK kr4,204.17
DH708.72
List Price:  DH1,012.51
You save:  DH303.78
L1,243.72
List Price:  L1,776.81
You save:  L533.09
ден4,025.16
List Price:  ден5,750.48
You save:  ден1,725.31
MOP$565.76
List Price:  MOP$808.27
You save:  MOP$242.50
N$1,323.80
List Price:  N$1,891.23
You save:  N$567.42
C$2,582.07
List Price:  C$3,688.83
You save:  C$1,106.76
रु9,353.99
List Price:  रु13,363.42
You save:  रु4,009.42
S/263.57
List Price:  S/376.55
You save:  S/112.97
K270.82
List Price:  K386.91
You save:  K116.08
SAR262.49
List Price:  SAR375
You save:  SAR112.51
ZK1,859.31
List Price:  ZK2,656.27
You save:  ZK796.96
L325.94
List Price:  L465.65
You save:  L139.71
Kč1,644.39
List Price:  Kč2,349.23
You save:  Kč704.84
Ft25,663.75
List Price:  Ft36,664.08
You save:  Ft11,000.32
SEK kr762.14
List Price:  SEK kr1,088.81
You save:  SEK kr326.67
ARS$61,304.48
List Price:  ARS$87,581.58
You save:  ARS$26,277.10
Bs486.59
List Price:  Bs695.16
You save:  Bs208.56
COP$277,527.04
List Price:  COP$396,484.19
You save:  COP$118,957.15
₡35,650.64
List Price:  ₡50,931.67
You save:  ₡15,281.02
L1,732.56
List Price:  L2,475.19
You save:  L742.63
₲522,432.19
List Price:  ₲746,363.69
You save:  ₲223,931.50
$U2,704.33
List Price:  $U3,863.50
You save:  $U1,159.16
zł282.07
List Price:  zł402.98
You save:  zł120.90
Already have an account? Log In

Transcript

Radio working with UART ITC and SPI protocols. In this video, we will learn about UART I to see an SPI protocols, then we will implement you our communication between the PI NPC. Later, we will implement ITC for interfacing ITC 16 by two LCD module. And finally, we will implement SPI for interfacing the RFID sensor. communication protocols are a set of rules and regulations that allows two electronic devices to connect for exchanging data with one another. Currently, you aren't SPI and ITC are the common hardware communication protocols people use in microcontroller development and the Raspberry Pi for supports all three.

This allows for interfacing the pifo with a large array of sensors, actuators and communication devices much easier. You are also known as universal asynchronous receiver or transmitter is a serial communication protocol in which data is transferred serially. That is, bit by bit you are serial communication protocol uses a defined frame structure for the data bytes. The frame structure basically consists of three things start bit, it is a bit which indicates that serial communication has started and it is always low data bits packet data bits can be packets of five to nine bits. Normally we use eight bit data packet which is always sent after this tag bit. Stop bit.

This usually is one or two bits in length. It is sent after data bits packet to indicate the end of frame stop it is always logic hi The frame can also consist of two stop bits instead of a single bed and there can also be a parity bit after the stop bit. The parity bit is used to check the integrity of the information in the data frame. In the Raspberry Pi four, we will show you the basics of UART communication by transmitting data from the PI to your computer through a USB to serial converter. The first step is to configure the PI four to enable UART in the terminal type sudo raspy hyphen config. Then, select the interfacing options and then select serial in the configuration menu.

Then it will ask for login shell to be accessible over serial select No as shown here. At the end, it will ask for enabling hardware serial port. Select Yes finally Are you work is enabled for serial communication on our ex ante explain of Raspberry Pi four. Now, reboot the PI. The PI four uses the UART port to interface its Bluetooth module to the CPU. Another hardware you are taught is provided across the GPIO 14 and GPIO 13.

We will use this port to send the data to the laptop. Before working with the UART port. We need to know how it's mapped. Put us enter the following command in the PI's terminal LS hyphen l forward slash dev you should look for the UART mapping for serial zero, which represents the GPIO 14 and GPIO 15 UART bus. Here you can see that it's mapped to TTY as zero. Please keep this in mind.

Now let's interface the US Pay to serial converter as shown here in the circuit diagram. It is really simple, but you have got to make sure that you connect the ground pin of the converter to one of pious ground pins. Another thing to notice that the RX pin of the converter should be connected to the TX pin of the PI and the TX pin of the converter to the unexplained of the pi. Now connect the converter to the USB port of your computer, download any serial port monitor tool of your wish on your PC. We are using real term now on the Raspberry Pi. Open the uart.pi code and run it on the PC.

Open the real term application and select the correct port after checking in the device manager. Then select the bounce rate as 9600 and open the boat Now you can see that indeed, the data transmission is happening from the pie to the PC. Now let me explain the code on the pie. First, we import the inbuilt module named serial. Then we import the class sleep from the time module. Next, we need to create an instance of class serial and assign it to sell.

The serial class accepts by arguments as inputs to configure the UART communication. The first is the port name. The second is the baud rate, which determines how many bits of information will be sent per second. The receiver should also be configured to the same rate, or we can retrieve the information. Finally, we'll set it to have no parity bit, one stop bet and the data byte size to be eight bits. The rest of the code is just a counter inside an infinite loop.

With a delay of one second that is writing the following string using the right method of the CDL class. Now, let us move on to IPC protocol. transmitting and receiving information between two or more than two devices requires a communication part called a bus system. And I two c bus is a bi directional two via serial bus that is used to transfer the data between integrated circuits. The ITC stands for inter integrated circuit, it was first introduced by Philips semiconductors in 1982. The ITC bus protocol is most commonly used in master and slave communication, wherein the master is called microcontroller.

And the slave is one of the other devices such as ADC, EEPROM D, AC and similar devices in the embedded system. The ITC bus can have multiple slaves as well as masters. Each device on the bus will have a unique address. The following steps are used to communicate the master device to the slave. Step one. First, the master device issues a start condition to inform all the slave devices so that they listen on the serial data line.

Step two, the master device sends the address of the target slave device, which is compared with all the slave devices addresses as connected to the CL and SDL lines. If any one address matches, that device is selected, and all the remaining devices are disconnected from the ACL in SDA lines. Step three. The slave device with a master address received from the master responds with an acknowledgment to the master data after communication is established between Both the master and slave devices on the data bus. Step for both the master and slave receive and transmit the data, depending on whether the communication is to read or write. Step five, the slave lets the master know that the message has been received or transmitted, depending on whether the communication is to write or read.

Step six. Finally, the master device issues a stop condition to inform all the slave devices in the bus. Now as we are clear with the ITC protocol, let's have a look at the ITC 16 by two LCD display before we start interfacing, a liquid crystal display or LCD draws its definition from its name itself. It is a combination of two states of matter. The solid and the liquid. liquid crystal display is composed of several layers, which include two polarized panel filters and electrodes.

Liquid crystal display screen works on the principle of blocking light rather than emitting light. So LCDs requires a backlight, as they do not emit light by themselves. The liquid crystal can twist based on the current supplied through the electrodes. Initially, when no current is applied across the electrode, the crystal will be in a twisted state. When a current is applied between the electrodes, the crystal starts untwisting which changes the polarization characteristics of the light and allows it to shine through. Each pixel will have three such individual sub pixels with red, green and blue filters respectively.

The mixing of different intensity primary colors allows us to reproduce millions of colors if you want to know motorboat the polarization of light, please check out the links in the resources section. The type of LCD we are using here is known as a monochrome 16 by two LCD. This means that it can only produce light of one color. The 16 by two means that it can display 16 characters per line into such lines. In this LCD, each character is displayed in a five by eight pixel matrix. If you look at the pinout diagram of a 16 by two LCD, you can see that it has 16 pins.

The ITC 16 by two LCD we are using is made by using a parallel to ITC converter based on PCF 857 for a shift register, that converts the 16 pins to justify open connection. These types of modules are commonly refer to as LCD backpacks. The module has a potentiometer to control the contrast of the LCD. It also has a jumper pin, which can be removed to disable the backlight also. Now Shall we interface the display to the Raspberry Pi. Connect the GPIO to SDA pin on the pi to the SDA pin on the LCD and the GPIO three CL pin on the pi to the CL pin on the LCD.

The ground and Vcc pins will also need to be connected. Most LCDs can operate with 3.3 volts, but they are meant to be run on five volts. So connected to the five volts pen of the pi. Now let's get on with the software side of things. Like you what you need to enable the eye to see interface from the configuration tool Follow the same method as we did for UART. But this time, select the ITC option and enable it.

Please don't forget to reboot after the change. The next step is to find the ITC address of your LCD. This can be done by entering ITC detect hyphen vi one in the terminal. The address is shown here. For you it might be different. Next, we need to modify the ITC LCD driver library and add does address instead of the default address.

Go to your repository and open the eye to see underscore LCD underscore driver dot p y code in Tony ID. Now modify the address to your eye to see address and save the file. Now to work with the LCD in any code. You need to include this library file in your current working directory where the main court will be reciting Now open the Hello World LCD dot p vi code in the repository and run the code you can see the text hello world on the LCD. Please check out the resources section where I have provided different sample codes to explore different function all the LCD further like positioning the text, clearing the screen, blinking the text scrolling the text printing custom characters printing data from a sensor and so on. The Serial Peripheral Interface that is SPI is a synchronous serial communication interface protocol used for short distance communication, primarily in embedded systems.

Devices communicating via SPI. In a master slave relationship. The Master is the controlling device, usually a microcontroller while the slave usually a sensor display or memory chip takes instruction from the master. The simplest configuration of SPI is a single master single slave system, but one master can control more than one slave also, SPI uses four separate connections to communicate with a target device. These connections are the serial clock, that is a CLK master input slave output, that is miso, Master output slave input, that is mostly and chip select, that is CS. Now we'll look at the steps of SPI data transmission.

One, the master outputs the clock signal to the master switches the CS pin to a low voltage state, which activates the slave three, the master sends the data of one bit at a time to the slave along the line. The slave reads the bits as they are received. For if a response is needed, the slave returns data one bit at a time to the master along the miso line. The master reads the bits as they are received. We will practically learn about SPI by interfacing an RFID sensor called RC fy 22. RF ID is an acronym for radio frequency identification, and refers to a technology whereby digital data encoded in RFID tags or smart labels are captured by a reader via radio waves.

RF ID is similar to bar coding in that data from a tag or label are captured by a device that stores the data in a database. And RFID tag consists of an integrated circuit and an antenna. The tag is also composed of a protective material that holds the pieces together and shields them from various environmental conditions. The protective material depends on the application. For example, employee ID badges containing RFID tags are typically made from durable plastic and the tag is embedded between the layers of plastic wiring you RFID RC fi 22 to your Raspberry Pi is fairly simple with it, requiring you to connect just seven of the GPIO pins directly to the RFID reader. Connect the SDK pin to GPIO 11 sd a pin to GPIO eight mostly to GPIO 10.

Miso to G GPIO nine G and D to any ground pin rst to GPIO 25 and 3.3 volts to 3.3 volts pin on the pie. The next step is to go to the Raspberry Pi configuration tool and enable SPI inside the interfacing option. Please reboot before going further. Now make sure you install SPI supporting libraries by entering this command. Now let's download the required library and example code by typing. Now go to the new folder that is created after downloading the library and open the read.py file and run it now bring an RFID tag Near the module.

When it finds a tag, it reads the UID and displays it on the screen. The script runs in a loop and will keep waiting and displaying any detected UID s. running this script allows you to determine the UID of the tag or card that was supplied with the reader and later created to use the logic for your application. You can find a detailed explanation of the read dot p y and write dot p y code in the resources section. Summary In this video we have covered the following what is UART ITC and SPI protocols implement you art between a PC and the PI with a USB to serial converter. Implement ITC for interfacing ITC 16 by two LCD implement SPI for interfacing mF RC fy 22 have it read a section summary. In the section we have covered the following.

Getting started with physical computing on the Raspberry Pi for introduction to hardware interfacing on the Raspberry Pi for working with LEDs and buttons, working with LDR and P AR sensors, working with relays, working with ultrasonic sensor and DC motors, working with UART ITC and SPI protocols. In the next section, we will cover wireless communication in the Raspberry Pi four

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.