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
€66.35
List Price:  €94.79
You save:  €28.44
£55.27
List Price:  £78.97
You save:  £23.69
CA$97.91
List Price:  CA$139.89
You save:  CA$41.97
A$107.61
List Price:  A$153.73
You save:  A$46.12
S$94.02
List Price:  S$134.32
You save:  S$40.30
HK$544.76
List Price:  HK$778.26
You save:  HK$233.50
CHF 61.99
List Price:  CHF 88.57
You save:  CHF 26.57
NOK kr773.52
List Price:  NOK kr1,105.08
You save:  NOK kr331.55
DKK kr494.87
List Price:  DKK kr706.99
You save:  DKK kr212.12
NZ$119.04
List Price:  NZ$170.06
You save:  NZ$51.02
د.إ257.07
List Price:  د.إ367.26
You save:  د.إ110.18
৳8,334.01
List Price:  ৳11,906.24
You save:  ৳3,572.23
₹5,905.12
List Price:  ₹8,436.24
You save:  ₹2,531.12
RM312.96
List Price:  RM447.10
You save:  RM134.14
₦117,219.95
List Price:  ₦167,464.25
You save:  ₦50,244.30
₨19,380.58
List Price:  ₨27,687.73
You save:  ₨8,307.15
฿2,429.14
List Price:  ฿3,470.35
You save:  ฿1,041.21
₺2,412.08
List Price:  ₺3,445.98
You save:  ₺1,033.89
B$405.06
List Price:  B$578.68
You save:  B$173.62
R1,267.31
List Price:  R1,810.53
You save:  R543.21
Лв129.73
List Price:  Лв185.34
You save:  Лв55.60
₩97,779.80
List Price:  ₩139,691.42
You save:  ₩41,911.61
₪261.55
List Price:  ₪373.67
You save:  ₪112.11
₱4,130.77
List Price:  ₱5,901.36
You save:  ₱1,770.58
¥10,901.93
List Price:  ¥15,574.86
You save:  ¥4,672.92
MX$1,414.26
List Price:  MX$2,020.46
You save:  MX$606.19
QR254.33
List Price:  QR363.35
You save:  QR109.01
P948.83
List Price:  P1,355.53
You save:  P406.70
KSh9,063.70
List Price:  KSh12,948.70
You save:  KSh3,885
E£3,478.50
List Price:  E£4,969.50
You save:  E£1,491
ብር8,583.46
List Price:  ብር12,262.61
You save:  ብር3,679.15
Kz63,877.12
List Price:  Kz91,256.94
You save:  Kz27,379.82
CLP$67,980.58
List Price:  CLP$97,119.28
You save:  CLP$29,138.70
CN¥507.18
List Price:  CN¥724.58
You save:  CN¥217.39
RD$4,200.06
List Price:  RD$6,000.34
You save:  RD$1,800.28
DA9,338.81
List Price:  DA13,341.73
You save:  DA4,002.91
FJ$158.92
List Price:  FJ$227.04
You save:  FJ$68.12
Q538.38
List Price:  Q769.16
You save:  Q230.77
GY$14,583.53
List Price:  GY$20,834.51
You save:  GY$6,250.97
ISK kr9,640.42
List Price:  ISK kr13,772.62
You save:  ISK kr4,132.20
DH696.78
List Price:  DH995.44
You save:  DH298.66
L1,273.82
List Price:  L1,819.82
You save:  L546
ден4,077.60
List Price:  ден5,825.40
You save:  ден1,747.79
MOP$559.09
List Price:  MOP$798.74
You save:  MOP$239.64
N$1,260.89
List Price:  N$1,801.35
You save:  N$540.46
C$2,566.52
List Price:  C$3,666.61
You save:  C$1,100.09
रु9,423.16
List Price:  रु13,462.23
You save:  रु4,039.07
S/264.65
List Price:  S/378.10
You save:  S/113.44
K280.62
List Price:  K400.90
You save:  K120.28
SAR262.75
List Price:  SAR375.38
You save:  SAR112.62
ZK1,926.57
List Price:  ZK2,752.36
You save:  ZK825.79
L330.17
List Price:  L471.69
You save:  L141.52
Kč1,676.98
List Price:  Kč2,395.79
You save:  Kč718.80
Ft27,187.34
List Price:  Ft38,840.72
You save:  Ft11,653.38
SEK kr769.78
List Price:  SEK kr1,099.74
You save:  SEK kr329.95
ARS$70,112.88
List Price:  ARS$100,165.56
You save:  ARS$30,052.67
Bs483.65
List Price:  Bs690.96
You save:  Bs207.30
COP$308,470.35
List Price:  COP$440,690.82
You save:  COP$132,220.46
₡35,450.59
List Price:  ₡50,645.88
You save:  ₡15,195.28
L1,762.11
List Price:  L2,517.41
You save:  L755.29
₲543,153.02
List Price:  ₲775,966.15
You save:  ₲232,813.12
$U2,992.07
List Price:  $U4,274.58
You save:  $U1,282.50
zł287.83
List Price:  zł411.21
You save:  zł123.37
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.