How to connect multiple SPI sensors/devices with Arduino?
I want to connect two, three or more SPI devices to Arduino (as slave), How can I do it?
You can connect not only two SPI devices but also three or more SPI devices to Arduino.
If you takes a look to SPI reference, you will know that SPI requires four pins: MOSI, MISO, SCK, and SS . Among them:
- Three pins (MOSI, MISO, SCK) must be shared between SPI devices. It means all devices connects to the same these Arduino's pins.
- The SS pin MUST be different among SPI devices.
If we use only one SPI slave device, we usually use the default SS pin (ex pin 10 on Arduino Uno). When we use multipe SPI slave devices we need to do the following.
Assign any digital pin as SS pin to connect to each devices. Each selected pins should be used for only one deivces and not used for other purposes. Avoid using pin 0 and pin 1 because these pins are used for Serial communication.
Look at to the library or example code of each slave device. Find the way to set SS pin according to the assigned SS pin. For example RC522 RFID/NFC Module, we will see below code:
We can change SS pin to the new SS pin. For example, using pin 4 as SS pin.
|1 × Arduino UNO Buy on Amazon|
|1 × USB 2.0 cable type A/B Buy on Amazon|