By the end of this guide you will have your Arduino UNO wired for SPI communication, the Arduino IDE installed and configured, and the SPI Echo Hello sketch running on real hardware. You will be able to watch the master transmit the stringDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/manish04-mu/TheEmbeddedInsights/llms.txt
Use this file to discover all available pages before exploring further.
"SPI Demo: Hello from the Master!" byte-by-byte over the SPI bus and read the echo response in the Serial Monitor — or, if you have a logic analyzer, observe the raw SCK, CS, MOSI, and MISO waveforms live. No prior SPI experience is required.
Prerequisites
Hardware Required
- Arduino UNO (ATmega328P) — any genuine or compatible board
- USB Type-B cable — for power and sketch upload
- Breadboard + jumper wires — for connecting a slave device when you are ready
- Logic analyzer (optional but recommended) — to observe SCK, CS, MOSI, and MISO waveforms
Software Required
- Arduino IDE 2.x — download the latest release from arduino.cc/en/software
- The built-in
SPI.hlibrary ships with the IDE — no additional library installation is needed - A serial terminal (the IDE’s built-in Serial Monitor is sufficient)
Hardware Setup
Install Arduino IDE
Download and install the Arduino IDE 2.x from https://www.arduino.cc/en/software. Accept the default installation options. Once installed, connect your Arduino UNO via USB — the IDE should automatically detect the board on a COM/serial port. Confirm this under Tools → Board → Arduino AVR Boards → Arduino Uno and Tools → Port → (your COM port).
Wire the SPI pins
The Arduino UNO exposes the ATmega328P hardware SPI peripheral on four dedicated pins. Use the table below as your reference when connecting a slave device:
| SPI Signal | Arduino UNO Pin | Direction | Notes |
|---|---|---|---|
| CS | Digital 10 | Master → Slave | Pulled HIGH (inactive) by default; pulled LOW to select slave |
| MOSI | Digital 11 | Master → Slave | Master Out Slave In — data from UNO to peripheral |
| MISO | Digital 12 | Slave → Master | Master In Slave Out — data returned from peripheral |
| SCK | Digital 13 | Master → Slave | Clock generated by the master (UNO) |
For the echo test in this guide no external slave is required — the sketch runs as a standalone master and the MISO line simply floats. You will see
0x00 returned for each byte, which is expected behavior.Open a new sketch in Arduino IDE
Launch the Arduino IDE and select File → New Sketch. An empty
setup() / loop() template will open. You will replace this with the SPI Echo Hello sketch in the next step.Copy the Hello World sketch
Delete the template content and paste in the complete SPI_Echo_Hello sketch shown in the First Sketch section below. Save the file as
SPI_Echo_Hello.ino (File → Save As…).Upload and open the Serial Monitor
Click the Upload button (→ arrow icon) or press
Ctrl+U. The IDE will compile and flash the sketch. Once you see “Done uploading”, open the Serial Monitor with Tools → Serial Monitor (or Ctrl+Shift+M). Set the baud rate drop-down at the bottom of the Serial Monitor to 9600 baud. Received bytes will begin printing immediately.First Sketch
Below is the complete source ofSPI_Echo_Hello.ino exactly as it appears in the repository. Read through the comments — they document every pin assignment and logic analyzer channel mapping used throughout this guide series.
SPI_Echo_Hello.ino
What to Expect
When the sketch is running, the master transmits the null-terminated string"SPI Demo: Hello from the Master!" character by character over MOSI. The SPI.transfer() call is full-duplex — while each byte goes out on MOSI, the hardware simultaneously clocks in a byte from MISO and stores it in receivedValue.
The Serial Monitor will print output like this every second:
0x00 for every byte — this is completely normal for a standalone echo test. When a real SPI slave is wired in, those values will reflect the bytes the slave sends back.
Key configuration details from the sketch:
| Parameter | Value | Meaning |
|---|---|---|
| Clock speed | 100000 Hz | 100 kHz — conservative rate, visible on any analyzer |
| Bit order | MSBFIRST | Most-significant bit transmitted first |
| Clock mode | SPI_MODE2 | CPOL=1, CPHA=0 — clock idles HIGH, data sampled on leading edge |
| CS pin | Digital 10 | Active LOW — asserted before transfer, released after |
If you have a logic analyzer, connect it to the SPI lines using the channel mapping from the sketch comments: CH0 → SCK (pin 13), CH1 → CS (pin 10), CH2 → MOSI (pin 11), CH3 → MISO (pin 12). Set your analyzer’s protocol decoder to SPI, clock mode 2 (CPOL=1, CPHA=0), MSB first, at 100 kHz. You will see the full
"SPI Demo: Hello from the Master!" string framed by CS going LOW and HIGH — exactly matching what the Serial Monitor reports.