was successfully added to your cart.

Arduino SPI Lookback Test

By May 1, 2014Arduino
Loop Back test for the SPI port of the Arduino
 * LED attached from pin 6 to ground through a 1K resistor
#include <SPI.h> // including the SPI library
char outByte [20] = "TONYLABS"; // string to be send and received via SPI port
int led = 6; // variable which holds the pin number at which the LED is attached
char inByte; // variable which stores the value of the byte received from SPI bus
int i = 0;                                                         
void setup() 
  pinMode(led, OUTPUT); // setting the LED pin as output
  Serial.begin(9600);                                             // initializing the serial port at 9600 baud rate
  SPI.begin(); // initialize the SPI port as master
void loop() 
  digitalWrite(led, HIGH);          
  for(i = 0; outByte [i] != '\0'; i ++) // send and receive the bytes of the string
    inByte = SPI.transfer(outByte [i]);
  digitalWrite(led, LOW);