ArduinoArduino UnoExact chip

Data logger (SD card)

The SD library writes the knob’s reading to LOG.CSV every half second; the inspector lists the file.

Data logger (SD card) in Argynix Lab

The code

sketch.inoC++
// A data logger: every half second, the time and the knob's reading go on a line of
// LOG.CSV on the SD card. Select the card while it runs to see the file grow.
#include <SPI.h>
#include <SD.h>

const int CARD_CS = 10;

void setup() {
  Serial.begin(9600);
  if (!SD.begin(CARD_CS)) {
    Serial.println("No card found: check CS, SCK, DI and DO.");
    while (true) {
    }
  }
  File log = SD.open("LOG.CSV", FILE_WRITE);
  log.println("ms,reading");
  log.close();
  Serial.println("Logging to LOG.CSV");
}

void loop() {
  int reading = analogRead(A0);
  File log = SD.open("LOG.CSV", FILE_WRITE);
  log.print(millis());
  log.print(',');
  log.println(reading);
  log.close();
  Serial.println(reading);
  delay(500);
}