Библиотека SD. Помогите с мануалом
- Войдите на сайт для отправки комментариев
Чт, 15/09/2016 - 18:06
Всем добрый день! Пытаюсь освоить работу с SD картой. Бибгиотека была встроена в IDE, называется просто SD. Пробовал примеры - всеработает без продлем. Вот только нет к библиотеке мануала. Точнее инструкция есть в виде html страниц с описанием классов, что совершенно не понятно как их использовать, каким командам они принадлежат, как их вызывать? Вообще не понятно... Народ есть ли у кого-то нормальный PDF с описанием либы и описанием команд, а то по примерам не особо понять, а имеющийся мануал только путает...
Взять хотя бы тот же пример libraries\SD\examples\CardInfo:
Последние две строчки выводят в сериал список файлов на карте, дату модификации и размер. Но где посмотреть эти команды?? А что если сериал мне не нужен, а нужно просто получить переменную с именем файла (со списком файлов)? Как это сделать?
все примеры посмотреть религия не позволила?
>>>libraries\SD\examples\listfiles.ino:
void printDirectory(File dir, int numTabs) {
Спасибо, я видел этот пример, но не в этом дело, а в нормальной справке по библиотеке. Она вообще существует или я просто зря народ тревожу?
Первая же ссылка в гугле =)
http://robocraft.ru/blog/3178.html
первая ссылка в ненашем гугле
https://www.arduino.cc/en/Reference/SD (тут вообще полное описание либы)
Многие команды отсутсвуют по приведенным ссылкам. На подобные статьи сам наталкивался, но в них описание только базовых команд (даже на том же arduino.cc)
Код из примера библиотеки libraries\SD\examples\CardInfo:
Еще пример и вопрос:
Пробую переделать примеры для вывода на дисплей, ане в сериал
libraries\SD\examples\listfiles - Работет частично (еще не понял как сделать таб и как отследить что найденное - папка а не файл):
#include <SPI.h> #include <SD.h> #include <UTFT.h> UTFT myGLCD(31, 38, 39, 40, 41); File root; int wait = 1; extern uint8_t SmallFont[]; void setup() { // Open serial communications and wait for port to open: myGLCD.InitLCD(); myGLCD.clrScr(); myGLCD.setFont(SmallFont); myGLCD.fillScr(0, 0, 0); myGLCD.setColor(0, 255, 0); myGLCD.print("Initializing SD card...", 10, 1); if (!SD.begin(10)) { myGLCD.print("initialization failed. Things to check:", 10, wait+=12); //Serial.println("initialization failed. Things to check:"); myGLCD.print("* is a card inserted?", 10, wait+=12); //Serial.println("* is a card inserted?"); myGLCD.print("* is your wiring correct?", 10, wait+=12); //Serial.println("* is your wiring correct?"); myGLCD.print("* did you change the chipSelect pin to match your shield or module?", 10, wait+=12); //Serial.println("* did you change the chipSelect pin to match your shield or module?"); return; } else { myGLCD.print("Wiring is correct and a card is present.", 10, wait+=12); //Serial.println("Wiring is correct and a card is present."); } root = SD.open("/"); printDirectory(root, 0); myGLCD.print("Done.", 10, wait+=12); } void loop() { // nothing happens after setup finishes. } void printDirectory(File dir, int numTabs) { int x = 0; myGLCD.print("-=-=-=-", 10, wait+=12); while (true) { File entry = dir.openNextFile(); if (! entry) { myGLCD.print("------", 10, wait+=12); break; } for (uint8_t i = 0; i < numTabs; i++) { x += 10;//Serial.print('\t'); } myGLCD.print(entry.name(), 10, wait+=12); //Serial.print(entry.name()); if (entry.isDirectory()) { //Serial.println("/"); //myGLCD.print(entry.isDirectory(), 10, wait+=12); //printDirectory(entry, numTabs + 1); } else { // files have sizes, directories do not //Serial.print("\t\t"); //Serial.println(entry.size(), DEC); myGLCD.printNumI(entry.size(), 114, wait); } entry.close(); } }libraries\SD\examples\CardInfo - Выводит данные о флешке, но не видит на ней ни одного файла:
// include the SD library: #include <SPI.h> #include <SD.h> #include <UTFT.h> //#include <SdFat.h> int wait = 121; extern uint8_t SmallFont[]; Sd2Card card; SdVolume volume; File root; UTFT myGLCD(31, 38, 39, 40, 41); void setup() { // Open serial communications and wait for port to open: myGLCD.InitLCD(); myGLCD.clrScr(); myGLCD.setFont(SmallFont); myGLCD.fillScr(0, 0, 0); myGLCD.setColor(0, 255, 0); myGLCD.print("Initializing SD card...", 10, 1); //Serial.print("\nInitializing SD card..."); // we'll use the initialization code from the utility libraries // since we're just testing if the card is working! if (!SD.begin(10)) { myGLCD.print("initialization failed. Things to check:", 10, 13); //Serial.println("initialization failed. Things to check:"); myGLCD.print("* is a card inserted?", 10, 25); //Serial.println("* is a card inserted?"); myGLCD.print("* is your wiring correct?", 10, 37); //Serial.println("* is your wiring correct?"); myGLCD.print("* did you change the chipSelect pin to match your shield or module?", 10, 49); //Serial.println("* did you change the chipSelect pin to match your shield or module?"); return; } else { myGLCD.print("Wiring is correct and a card is present.", 10, 13); //Serial.println("Wiring is correct and a card is present."); } // print the type of card //Serial.print("\nCard type: "); switch (card.type()) { case SD_CARD_TYPE_SD1: myGLCD.print("Card type: SD1", 10, 25); //Serial.println("SD1"); break; case SD_CARD_TYPE_SD2: myGLCD.print("Card type: SD2", 10, 25); //Serial.println("SD2"); break; case SD_CARD_TYPE_SDHC: myGLCD.print("Card type: SDHC", 10, 25); //Serial.println("SDHC"); break; default: myGLCD.print("Unknown", 10, 25); //Serial.println("Unknown"); } // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32 if (!volume.init(card)) { myGLCD.print("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card", 10, 37); //Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card"); return; } // print the type and size of the first FAT-type volume uint32_t volumesize; myGLCD.print("Volume type is FAT", 10, 49); //Serial.print("\nVolume type is FAT"); myGLCD.printNumI(volume.fatType(), 162, 49); //Serial.println(volume.fatType(), DEC); //Serial.println(); volumesize = volume.blocksPerCluster(); // clusters are collections of blocks volumesize *= volume.clusterCount(); // we'll have a lot of clusters volumesize *= 512; // SD card blocks are always 512 bytes myGLCD.print("Volume size (bytes): ", 10, 73); //Serial.print("Volume size (bytes): "); myGLCD.printNumI(volumesize, 200, 73); //Serial.println(volumesize); myGLCD.print("Volume size (Kbytes): ", 10, 85); //Serial.print("Volume size (Kbytes): "); volumesize /= 1024; myGLCD.printNumI(volumesize, 200, 85); //Serial.println(volumesize); myGLCD.print("Volume size (Mbytes): ", 10, 97); //Serial.print("Volume size (Mbytes): "); volumesize /= 1024; myGLCD.printNumI(volumesize, 200, 97); //Serial.println(volumesize); myGLCD.print("Files found on the card (name, date and size in bytes): ", 10, 109); //Serial.println("\nFiles found on the card (name, date and size in bytes): "); root = SD.open("/"); printDirectory(root, 0); //myGLCD.print(root.ls(LS_R | LS_DATE | LS_SIZE), 10, wait+=12); } void loop(void) { } void printDirectory(File dir, int numTabs) { int x = 0; myGLCD.print("-=-=-=-", 10, wait+=12); while (true) { File entry = dir.openNextFile(); if (! entry) { myGLCD.print("------", 10, wait+=12); break; } for (uint8_t i = 0; i < numTabs; i++) { x += 10;//Serial.print('\t'); } myGLCD.print(entry.name(), 10, wait+=12); //Serial.print(entry.name()); if (entry.isDirectory()) { //Serial.println("/"); //myGLCD.print(entry.isDirectory(), 10, wait+=12); //printDirectory(entry, numTabs + 1); } else { // files have sizes, directories do not //Serial.print("\t\t"); //Serial.println(entry.size(), DEC); myGLCD.printNumI(entry.size(), 10, wait+=12); } entry.close(); } }Вот и пойми что тут к чему....Полный их список с толковым описанием я нигде не нашел.
libraries\SD\examples\CardInfo - Выводит данные о флешке, но не видит на ней ни одного файла:
// include the SD library: #include <SPI.h> #include <SD.h> #include <UTFT.h> //#include <SdFat.h> int wait = 121; extern uint8_t SmallFont[]; Sd2Card card; SdVolume volume; File root; UTFT myGLCD(31, 38, 39, 40, 41); void setup() { .............................................................................. printDirectory(root, 0); //myGLCD.print(root.ls(LS_R | LS_DATE | LS_SIZE), 10, wait+=12); .............................................................................. }Удивительно что не выводит инфо на дисплей.... может строки вывода на дисплей совершенно нет?
определить папка или нет можно просто ВНИМАТЕЛЬНО глянув ваш же код, entry.isDirectory(), правда удивительный мир программирования?
ToRcH2565, вы немного не внимательны: список файлов выводится на дисплей командой myGLCD.print(entry.name(), 10, wait+=12);, она находится перед entry.isDirectory(). К тому же в обоих примерах функция
printDirectory() абсолютно одинакова, но в одном примере работает, во втором - нет.ЕвгенийП,ToRcH2565, Спасибо за наводку. Для меня это все сложно без "разжеванных" примеров и четких либ... Я только начинающий...К тому же в обоих примерах функция
printDirectory() абсолютно одинакова, но в одном примере работает, во втором - нет.Тогда есть такое подозрение что стоит попробовать переиницализировать класс карты(Мне лень читать где же она отвалится или что с классом происходит походу первого кода =))
SD.close();
SD.begin(10);
root = SD.open("/");
А, ну ладно, спасибо за уточнение.