In this particular project the Arduino pro-mini board is used since it is very small and bread board compatible. It occupies only small area of a breadboard and any kind of connectors can be soldered into the periphery of the board to connect it with the breadboard. The Arduino pro-mini board has digital pins marked as 2, 3, 4 up to 13. Among the digital pins four pins namely 10, 11, 12 and 13 can be configured as SS, MOSI, MISO and SCK. The image of the Arduino pro-mini board and the Arduino IDE version 1.0.3 for windows used in this project is shown in the following image;
Since the arduino pro-mini board has no circuitary for interfacing it with the serial port or the USB port of the PC, an external USB to TTL converter board is required to connect it with the PC. This hardware helps in programming the arduino board and also helps in the serial communication with the PC through the USB port of the PC.
It is assumed that the reader has gone through the project how to get started with the arduino and done all the things discussed in it.The code written for this project uses functions from the library <SPI.h> for initializing the SPI module and sending and receiving data using it. The functions namely SPI.begin() is used to initialize the SPI module and the function SPI.transfer() used to transfer a byte of data and receive a byte of data at the same time.
This function initializes the SPI module of the Arduino board and configures the corresponding digital I/O pins as SPI pins. The function always initializes the Arduino as SPI master device with the pin number 10 as SS, pin number 11 as MOSI, pin number 12 as MISO, and pin number 13 as SCK pin. The function has no parameters and it returns nothing.
The function SPI.transfer() is used to transfer a byte of data to the slave device and to receive a byte of data from the slave device at the same time. The function takes a parameter which is the byte of data to be transmitted and the return from the function is a byte which is the data byte received from the slave device. Whenever only data transfer is required the return value can be ignored and whenever there is data to be read from the slave only the parameter passed to the function can be any arbitrary value.
There is no slave device used in this project but the pin number 11 and 12 which are MOSI and MISO are shorted together so that whatever data send will be received at the same time. The function SPI.begin() is used to initialize the SPI module and the function SPI.transfer() is used to transfer bytes of a particular string and receive the same bytes which are then displayed in the Serial monitor using the serial communication functions.