Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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
✗ Incorrect
The SD library is required to communicate with the SD card module over SPI.
2fill in blank
mediumComplete 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'
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
✗ Incorrect
Pin 10 is commonly used as the chip select pin for SD card modules on Arduino Uno.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using openFile which does not exist
Using openNextFile which is for directory iteration
Using open with wrong capitalization
✗ Incorrect
The correct function to open a file on the SD card is SD.open().
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using write() which writes bytes, not strings
Using flush() instead of close()
Forgetting to close the file
✗ Incorrect
Use print() to write text and close() to close the file properly.
5fill in blank
hardFill 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'
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
✗ Incorrect
Use available() to check if data remains, read() to get a character, and print() to output it.
