 SPI is a very simple multi-device communication protocol. It supports fast 10 megabits per second transfer speeds and it's very, very cheap to implement into your projects. SPI stands for Serial Peripheral Interface and as the name suggests, it's commonly used by microcontrollers to send and receive information from small peripherals such as SD cards, shift registers and sensors. Just like I2C, SPI supports masters and slaves. The masters are typically microcontrollers such as Arduino's or Raspberry Pi's and slaves are usually peripherals such as, you know, like the SD card sensors or shift registers in this case. Unlike I2C, however, SPI only supports one master. SPI also uses separate clock and data lines to facilitate with communication and it also has a slave select line for the device like a microcontroller to decide which slave or peripheral it wants to communicate with. Next, let's actually understand how SPI communication works. There are three to four wires in each communication loop. The three core wires are the clock cable, the master in slave out and the master out slave in. The fourth one is the slave select. Now if you're using more than one slave, this slave select cable is necessary for each separate slave but if you have only one slave device or one peripheral then you don't need this. Now that we've understood how SPI is wired, let's actually understand how the signal propagates within the SPI communication loop. Step number one, a common clock is set between all the peripherals by the single master device. Now this is set over the SCK wire and the four modes of setting up the clock as you can see here. Now the compatible modes for SPI devices can be found in the datasheet and if you want to learn more about the different modes of clock, you can learn about them in the tutorial I've linked in the description below. Step number two, if you have multiple slave devices, the master will pick which slave device it wants to communicate to and it will enable communication with that slave device by pulling the slave select line down to a lower voltage. Step number three, here's where the actual data communication happens. The master will actually transmit information to the slave with the master out slave in line that we talked about earlier. Now the master can send the information with the most significant bit first or the least significant bit first. This depends on the slave specification. Step number four, next the master can actually request a slave to send information back to it. This is especially useful if your slave is a device like a sensor. So after step three is actually completed which is the master sending information to the slave, the master can actually send a reply bit back to the slave and then the slave will send its reply over the other cable which is the master in slave out cable and that's how signals are sent over SPI. Now moving on, let's actually understand the two ways of wiring up multiple slaves in SPI. First we have the multiple slave select option. This method is very similar to how multiple electronics might be wired up in a parallel manner. Now this option allows you to have individual slave select lines for each of your slave peripherals. This is especially useful if you want to individually address each of your slaves but this comes at the cost of having additional IO for each of your slaves. That means you need an additional pin for each slave. This can become a hassle when you have multiple slaves and you don't have enough input or output devices on your microcontroller. Now an alternative to this is the daisy chaining approach as you can see here. Now like I mentioned the last approach was sort of similar to how electronics are wired up in parallel. In this case the daisy chaining approach is sort of similar to how electronics might be wired up in series. This method allows us to address all the SPI slaves with just one slave select line but you must send enough data for all the SPI slaves. What actually happens to the data is it goes to the first slave and then overflows to each of the subsequent slaves till it reaches the last slave. This method is very commonly used with LED clusters. Next let's actually compare SPI to its alternatives such as I2C and C0. Now one of the reasons that SPI is so popular is that you can use a simple shift register for your receiving hardware. A shift register is very simple to use and incredibly cheap. Next SPI can stream its data continuously because it doesn't use a start and an end bit like I2C does. Next SPI doesn't need to use a complicated slave addressing system like I2C because SPI just addresses each of its slaves using a dedicated slave select line. Furthermore because SPI has a dedicated data in and data outlined to the master we can actually stream data continuously in both directions and this is one of the reasons why SPI is a lot faster than I2C. But now we come to the downsides. The first one is the slave select system. While it's convenient for a few slave devices if you have multiple slave devices and you're not using a daisy chaining setup this can require a lot of additional input and output pins. Furthermore I2C only uses two wires while SPI even if you do use a daisy chaining setup will have at least four wires. Next SPI only supports one master device while I2C actually supports multiple master devices. Next SPI doesn't have error correction like you are or it doesn't have acknowledged bits like I2C. You also have a lot of configurable things in SPI such as if you want to send least important of most important bit first the multiple clock modes or the different ways of wiring up multiple slaves. Now this is great if you're advanced and you want to have more configurability in your projects but it can also be a downside for big nodes who might find all this confusing and want to just get started on their projects. So lastly before we end this video, let's talk about how we can integrate SPI into our Arduino or Raspberry Pi powered projects. First let's talk about the Raspberry Pi implementation. For the Raspberry Pi you have to go into raspy-config and into interfacing options and then enable SPI. These are the SPI compatible pins on your Raspberry Pi. Lastly before you can use SPI you have to make sure that you have imported the rpi.gpi package into your Python code and that's it. You're ready to use SPI on your Raspberry Pi. For the Arduino it's even simpler. Each Arduino has its own SPI compatible pins. On the Arduino Uno for example it's pin 10, 11, 12, 13. And lastly to actually use SPI in your code you have to import the SPI.h library into your project. And that's it for this tutorial. Now throughout the tutorial I talked about i2c and also serial. Now I have dedicated tutorial videos for that. If you enjoyed this tutorial you can give me a like or you can ask your questions down in the comment section below and also stay tuned for more future tutorials like this by subscribing down below. Thanks for watching.