Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
G6EJD committed Jan 28, 2017
1 parent 72fe6b6 commit 891aec2
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 0 deletions.
31 changes: 31 additions & 0 deletions ESP8266_SD_Example.ino
@@ -0,0 +1,31 @@
// Example of using the Serial Data Card Filing System

#include <SD.h>;

void setup() {
Serial.begin(115200);
Serial.println("Starting...");
if (!SD.begin(D8)) Serial.println("initialization failed!");
}

void loop() {
// Assign a file name e.g. 'names.dat' or 'data.txt' or 'data.dat' try to use the 8.3 file naming convention format could be 'data.d'
char filename [] = "datalog.txt"; // Assign a filename or use the format e.g. SD.open("datalog.txt",...);

if (SD.exists(filename)) SD.remove(filename); // First in this example check to see if a file already exists, if so delete it
File myDataFile = SD.open(filename, FILE_WRITE); // Open a file for reading and writing (appending)
if (!myDataFile)Serial.println("file open failed"); // Check for errors

myDataFile.println("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); // Write some data to it (26-characters)
myDataFile.println(3.141592654);
Serial.println(myDataFile.size()); // Display the file size (26 characters + 4-byte floating point number + 6 termination bytes (2/line) = 34 bytes)
myDataFile.close(); // Close the file

myDataFile = SD.open(filename, FILE_READ); // Open the file again, this time for reading
if (!myDataFile) Serial.println("file open failed"); // Check for errors
while (myDataFile.available()) {
Serial.write(myDataFile.read()); // Read all the data from the file and display it
}
myDataFile.close(); // Close the file
delay(10000); // wait and then do it all again
}
48 changes: 48 additions & 0 deletions ESP8266_SD_SPIFFS_Example.ino
@@ -0,0 +1,48 @@
// Example of using the Serial Data Card Filing System
#define FS_NO_GLOBALS //allow spiffs to coexist with SD card, define BEFORE including FS.h
#include <FS.h> //spiff file system
#include "SD.h";
//#define SD_MODE

void setup() {
Serial.begin(115200);
Serial.println("Starting...");
#ifdef SD_MODE
if (!SD.begin(D8)) Serial.println("initialization failed!");
#else
SPIFFS.begin();
#endif
}

void loop() {
// Assign a file name e.g. 'names.dat' or 'data.txt' or 'data.dat' try to use the 8.3 file naming convention format could be 'data.d'
char filename [] = "datalog.txt"; // Assign a filename or use the format e.g. SD.open("datalog.txt",...);

#ifdef SD_MODE
if (SD.exists(filename)) SD.remove(filename); // First in this example check to see if a file already exists, if so delete it
File myDataFile = SD.open(filename, FILE_WRITE); // Open a file for reading and writing (appending)
#else
if (SPIFFS.exists(filename)) SPIFFS.remove(filename); // First in this example check to see if a file already exists, if so delete it
fs::File myDataFile = SPIFFS.open(filename, "a+"); // Open a file for reading and writing (appending)
#endif

if (!myDataFile)Serial.println("file open failed"); // Check for errors

myDataFile.println("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); // Write some data to it (26-characters)
myDataFile.println(3.141592654);
Serial.println(myDataFile.size()); // Display the file size (26 characters + 4-byte floating point number + 6 termination bytes (2/line) = 34 bytes)
myDataFile.close(); // Close the file

#ifdef SD_MODE
myDataFile = SD.open(filename, FILE_READ); // Open a file for reading and writing (appending)
#else
myDataFile = SPIFFS.open(filename, "r"); // Open a file for reading and writing (appending)
#endif
if (!myDataFile) Serial.println("file open failed"); // Check for errors
while (myDataFile.available()) {
Serial.write(myDataFile.read()); // Read all the data from the file and display it
}
myDataFile.close(); // Close the file
delay(10000); // wait and then do it all again
}

32 changes: 32 additions & 0 deletions ESP8266_SPIFFS_Example.ino
@@ -0,0 +1,32 @@
// Example of using the Serial Peripheral Interface Flash Filing System (SPIFFS) or SPI bus Flash memory Filing System

#include <FS.h> //spiff file system

void setup() {
Serial.begin(115200);
Serial.println("Starting...");
SPIFFS.begin();
}

void loop() {
// Assign a file name e.g. 'names.dat' or 'data.txt' or 'data.dat' try to use the 8.3 file naming convention format could be 'data.d'
char filename [] = "datalog.txt"; // Assign a filename or use the format e.g. SD.open("datalog.txt",...);

if (SPIFFS.exists(filename)) SPIFFS.remove(filename); // First in this example check to see if a file already exists, if so delete it

File myDataFile = SPIFFS.open(filename, "a+"); // Open a file for reading and writing (appending)
if (!myDataFile)Serial.println("file open failed"); // Check for errors

myDataFile.println("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); // Write some data to it (26-characters)
myDataFile.println(3.141592654);
Serial.println(myDataFile.size()); // Display the file size (26 characters + 4-byte floating point number + 6 termination bytes (2/line) = 34 bytes)
myDataFile.close(); // Close the file

myDataFile = SPIFFS.open(filename, "r"); // Open the file again, this time for reading
if (!myDataFile) Serial.println("file open failed"); // Check for errors
while (myDataFile.available()) {
Serial.write(myDataFile.read()); // Read all the data from the file and display it
}
myDataFile.close(); // Close the file
delay(10000); // wait and then do it all again
}

0 comments on commit 891aec2

Please sign in to comment.