Bird
0
0
Arduinoprogramming~10 mins

SPI with SD card module in Arduino - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to include the SD library needed for SPI communication with the SD card module.

Arduino
#include <[1]>

void setup() {
  Serial.begin(9600);
}
Drag options to blanks, or click blank then click option'
ASPI.h
BWire.h
CSD.h
DEEPROM.h
Attempts:
3 left
💡 Hint
Common Mistakes
Including SPI.h instead of SD.h
Including Wire.h which is for I2C communication
Forgetting to include any library
2fill in blank
medium

Complete the code to initialize the SD card on chip select pin 10.

Arduino
const int chipSelect = [1];

void setup() {
  Serial.begin(9600);
  if (!SD.begin(chipSelect)) {
    Serial.println("Initialization failed!");
    return;
  }
  Serial.println("Initialization done.");
}
Drag options to blanks, or click blank then click option'
A4
B7
C13
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using pin 13 which is the SPI clock pin
Using pin 4 which is sometimes used but not standard
Using pin 7 which is unrelated
3fill in blank
hard

Fix the error in the code to open a file named "test.txt" for writing.

Arduino
File dataFile = SD.[1]("test.txt", FILE_WRITE);
Drag options to blanks, or click blank then click option'
Aopen
BopenFile
CopenNextFile
Attempts:
3 left
💡 Hint
Common Mistakes
Using openFile which does not exist
Using openNextFile which is for directory iteration
Using open with wrong capitalization
4fill in blank
hard

Fill both blanks to write the string "Hello" to the file and then close it.

Arduino
File dataFile = SD.open("test.txt", FILE_WRITE);
if (dataFile) {
  dataFile.[1]("Hello");
  dataFile.[2]();
} else {
  Serial.println("Error opening file");
}
Drag options to blanks, or click blank then click option'
Aprint
Bwrite
Cclose
Dflush
Attempts:
3 left
💡 Hint
Common Mistakes
Using write() which writes bytes, not strings
Using flush() instead of close()
Forgetting to close the file
5fill in blank
hard

Fill all three blanks to read from "test.txt" and print each character to Serial until the file ends.

Arduino
File dataFile = SD.open("test.txt");
if (dataFile) {
  while (dataFile.[1]()) {
    char c = dataFile.[2]();
    Serial.[3](c);
  }
  dataFile.close();
} else {
  Serial.println("Error opening file");
}
Drag options to blanks, or click blank then click option'
Aavailable
Bread
Cprint
Dpeek
Attempts:
3 left
💡 Hint
Common Mistakes
Using peek() which only previews data
Using write() instead of print() for Serial output
Not checking if data is available before reading