Skip to content

Instantly share code, notes, and snippets.

@daz
Last active February 28, 2017 08:16
Show Gist options
  • Save daz/d8def596f6e513ce118f79fa8f1ad2a7 to your computer and use it in GitHub Desktop.
Save daz/d8def596f6e513ce118f79fa8f1ad2a7 to your computer and use it in GitHub Desktop.
Arduino UNO Data Logger Shield example
// This isn't needed with official Arduino app
#include <SPI.h>
#include <SD.h>
File file;
void setup() {
Serial.begin(9600);
delay(50);
pinMode(4, OUTPUT);
if (!SD.begin()) {
Serial.println("Initialization failed");
return;
}
// Write to SD card
file = SD.open("test2.txt", FILE_WRITE);
if (file) {
file.println("Hello Test 3!");
file.close();
} else {
Serial.println("Error opening test.txt");
}
// Read from SD card
file = SD.open("test2.txt");
if (file) {
while (file.available()) {
Serial.write(file.read());
}
file.close();
} else {
Serial.println("Error opening test.txt");
}
}
void loop() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment