* ------ [SD_04] - Read data from SD file --------
* Explanation: Turn on the SD card. Append data at the end of
* the SD file and then show how to read it.
* Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L.
* http://www.libelium.com
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
* Implementation: Yuri Carmona
// define file name: MUST be 8.3 SHORT FILE NAME
char filename[]="FILE4.TXT";
// array in order to read data
USB.println(F("SD_4 example"));
sd_answer = SD.del(filename);
USB.println(F("file deleted"));
USB.println(F("file NOT deleted"));
sd_answer = SD.create(filename);
USB.println(F("file created"));
USB.println(F("file NOT created"));
SD.appendln(filename,"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
SD.appendln(filename,"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
SD.appendln(filename,"cccccccccccccccccccccccccccccc");
SD.appendln(filename,"dddddddddddddddddddddddddddddd");
SD.appendln(filename,"eeeeeeeeeeeeeeeeeeeeeeeeeeeeee");
SD.appendln(filename,"ffffffffffffffffffffffffffffff");
SD.appendln(filename,"gggggggggggggggggggggggggggggg");
SD.appendln(filename,"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhh");
SD.appendln(filename,"iiiiiiiiiiiiiiiiiiiiiiiiiiiiii");
USB.println(F("\n-------------------"));
USB.print(F("SHOW THE FILE CONTENTS"));
// Read file bytes using different values of
// offset (first position to be read) and
// scope (number of bytes to be read)
USB.println(F("\n\n-----------------------------"));
USB.println(F("1 - Use of SD.cat function"));
USB.println(F("-----------------------------"));
USB.println(F("Read file in bytes (offset:0; scope:10):"));
USB.println(F("-----------------------------"));
USB.println(F("Read file in bytes (offset:25; scope:10):"));
SD.cat( filename, 25, 10);
USB.println( SD.buffer );
USB.println(F("-----------------------------"));
USB.println(F("Read file in bytes (offset:0; scope:1000) [256 bytes max]:"));
SD.cat( filename, 0, 1000);
USB.println(F("-----------------------------"));
// Read file hexadecimal data using different values of
// offset (first position to be read) and
// scope (number of bytes to be read)
USB.println(F("\n\n-----------------------------"));
USB.println(F("2 - Use of SD.catBin function"));
USB.println(F("-----------------------------"));
USB.println(F("Read binary data (offset:0; scope:10):"));
SD.catBin(filename,0,10);
Utils.hex2str( SD.bufferBin, output, 10);
USB.println(F("-----------------------------"));
USB.println(F("Read binary data (offset:25; scope:10):"));
SD.catBin(filename,25,10);
Utils.hex2str( SD.bufferBin, output, 10);
USB.println(F("-----------------------------"));
USB.println(F("Read binary data (offset:0; scope:50):"));
SD.catBin( filename, 0, 50);
Utils.hex2str( SD.bufferBin, output, 50);
USB.println(F("-----------------------------"));
// Read file lines using different values of
// offset (first line to be read) and
// scope (number of lines to be read)
USB.println(F("\n\n-----------------------------"));
USB.println(F("3 - Use of SD.catln function"));
USB.println(F("-----------------------------"));
USB.println(F("Read file lines (offset:0; scope:1):"));
USB.println( SD.buffer );
USB.println(F("-----------------------------"));
USB.println(F("Read file lines (offset:1; scope:1):"));
USB.println( SD.buffer );
USB.println(F("-----------------------------"));
USB.println(F("Read file lines (offset:2; scope:1):"));
USB.println( SD.buffer );
USB.println(F("-----------------------------"));
USB.println(F("Read file lines (offset:0; scope:5):"));
USB.println( SD.buffer );
USB.println(F("-----------------------------"));
USB.println(F("Read file lines (offset:0; scope:25) [256 bytes max]:"));
USB.println( SD.buffer );
USB.println(F("-----------------------------"));
USB.println(F("*****************************"));