SPI (Serial Peripheral Interface) is a fast and efficient communication protocol used to connect microcontrollers (like Arduino) with one or more peripheral devices such as sensors, displays, memory cards, and more.
In this tutorial, you’ll learn how to connect and control multiple SPI devices with an Arduino. We’ll explain SPI basics, show you how to wire multiple SPI devices using separate Chip Select (CS) pins, and provide simple examples.
📘 What is SPI?
SPI is a synchronous serial communication protocol that works with four main lines:
Line | Name | Direction | Description |
---|---|---|---|
MISO | Master In Slave Out | Slave → Master | Data from slave to master |
MOSI | Master Out Slave In | Master → Slave | Data from master to slave |
SCK | Serial Clock | Master → Slave | Clock signal sent by the master |
SS/CS | Slave Select / Chip Select | Master → Slave | Selects which slave to talk to |
🧠 How Does Arduino Talk to Multiple SPI Devices?
The MISO, MOSI, and SCK lines are shared between all devices.
Each SPI device gets its own unique CS (Chip Select) pin. The Arduino sets the CS pin LOW to enable communication with a specific device. All other CS pins are kept HIGH.
🧰 Components Required for Multiple SPI Devices
- 1 × Arduino Uno
- 2 × MAX6675 Thermocouple modules (SPI-based temperature sensor)
- 2 × K-type Thermocouples
- Breadboard and jumper wires
- 1 × I2C LCD Display (optional for output)
🔌 Circuit Diagram and Wiring
SPI Pins on Arduino UNO:
SPI Signal | Arduino UNO Pin |
---|---|
MOSI | D11 |
MISO | D12 |
SCK | D13 |
Let’s assume:
- CS1 for MAX6675 #1 → Pin 8
- CS2 for MAX6675 #2 → Pin 9
Also Read: Speed up your Arduino Codes – A New Approach
MAX6675 Module Wiring (for both)
MAX6675 Pin | Connect to Arduino |
---|---|
VCC | 5V |
GND | GND |
SCK | D13 |
SO | D12 |
CS1 | D8 |
CS2 | D9 |
Arduino UNO MAX6675 #1 MAX6675 #2
----------- ---------- ----------
D13 (SCK) ------> SCK SCK
D12 (MISO) ------> SO SO
5V -----> VCC VCC
GND -----> GND GND
D8 (CS1) ------> CS
D9 (CS2) ---------------------> CS
💻 Sample Arduino Code to Read Multiple SPI Devices (Two MAX6675)
#include <SPI.h>
#include "max6675.h"
// Define CS pins for two MAX6675
int thermoSO = 12;
int thermoSCK = 13;
int thermoCS1 = 8;
int thermoCS2 = 9;
// Create MAX6675 objects
MAX6675 thermocouple1(thermoSCK, thermoCS1, thermoSO);
MAX6675 thermocouple2(thermoSCK, thermoCS2, thermoSO);
void setup() {
Serial.begin(9600);
delay(500);
Serial.println("Multiple SPI Devices - Two MAX6675 Sensors");
}
void loop() {
Serial.print("Temp 1: ");
Serial.print(thermocouple1.readCelsius());
Serial.print(" °C | ");
Serial.print("Temp 2: ");
Serial.print(thermocouple2.readCelsius());
Serial.println(" °C");
delay(1000);
}
✅ Result
In the serial monitor, you’ll see both temperature readings updating every second:
Temp 1: 215.25 °C | Temp 2: 234.00 °C
Temp 1: 215.50 °C | Temp 2: 234.25 °C
🔄 What If You Add More SPI Devices?
You can add more devices as long as:
- They support the SPI protocol.
- You assign a unique CS pin to each.
- Your microcontroller has enough GPIO pins.
Example: SD card (CS = D10), MAX6675 #1 (CS = D8), MAX6675 #2 (CS = D9)
Just define each device with its own CS pin and initialize accordingly.
⚠️ Common Issues & Tips
- Always keep unused CS pins HIGH to avoid interference.
- Use logic level shifters if you’re connecting 3.3V SPI devices to 5V Arduino.
- Be cautious with SPI clock speed—some devices have limits.
- Ensure no pin conflicts if using SPI with Ethernet or SD modules.
📝 Summary
- SPI allows communication with multiple devices using shared lines and separate CS pins.
- You only need to change the CS pin to talk to different devices.
- Arduino makes it easy to manage SPI devices with libraries and direct pin control.
📦 Bonus: Add an I2C LCD to Display Temperatures
Since I2C is a different protocol, it works perfectly in parallel with SPI.
Use LiquidCrystal_I2C
to show both temperatures on the LCD without conflicts.
Let me know if you want the LCD example included too.