Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to open the file for writing in CSV format.
Arduino
File dataFile = SD.open([1], FILE_WRITE);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using .txt extension instead of .csv
Forgetting quotes around file name
✗ Incorrect
We open the file named data.csv to write CSV data.
2fill in blank
mediumComplete the code to write a comma separator between values in CSV.
Arduino
dataFile.print(sensorValue); dataFile.print([1]); dataFile.println(temperature);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using semicolon instead of comma
Using newline instead of comma
✗ Incorrect
CSV uses commas to separate values, so we print a comma between values.
3fill in blank
hardFix the error in the code to close the file after writing data.
Arduino
dataFile.[1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using flush instead of close
Using end or stop which do not exist
✗ Incorrect
We must close the file with close() to save data properly.
4fill in blank
hardFill both blanks to write a CSV header line with columns 'Time' and 'Value'.
Arduino
dataFile.print([1]); dataFile.print([2]); dataFile.println();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping column order
Missing comma after first column
✗ Incorrect
The header line should be Time,Value with a comma separating columns.
5fill in blank
hardFill all three blanks to write sensor data with timestamp in CSV format.
Arduino
dataFile.print([1]); dataFile.print([2]); dataFile.println([3]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using analogRead directly instead of sensorValue variable
Missing comma separator
✗ Incorrect
We write the current time from millis(), then a comma, then the sensor value.