Go Down

Topic: navigate files on sd card (arduino meg+sdcard+lcd 12C) (Read 59 times) previous topic - next topic

elentirmo

hi,
   i have a project for my school and i'm kinda stuck. i will describe what it is suppose to do:

-on sd card i have .csv files
-i have to list them on lcd
-i have to navigate using buttons
-choose 1 file from there and open it pressing a button
-sent it via serial1

what i managed to do is to config the lcd and read the sdcard, and list the files on serial. i need some help from you guys, maybe you have some ideeas how to solve this.

here is my code so far.

Code: [Select]
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
//-------------------
Sd2Card card;
SdVolume volume;
SdFile root;
const int chipSelect = 53;
//-------------------
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address
//-------------------
/*
The circuit:
  * SD card attached to SPI bus as follows:
 ** 50-MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila
 ** 51-MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila
 ** 52-CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila
 ** 53-CS - depends on your SD card shield or module.
 
 SPI Uno Mega
SS 10 53
MOSI 11 51
MISO 12 50
SCK 13 52
Pin 4 used here for consistency with other Arduino examples
 */

void setup() {
  Serial.begin(9600);
  lcd.begin(20,4);
  lcd.setCursor(4,0);
  lcd.print("Programator D");
  delay(2000);
  lcd.setCursor(0,2);
  lcd.print("Initializing SD...");
  pinMode(53, OUTPUT);
 
  if (!card.init(SPI_HALF_SPEED, chipSelect)) {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("init failed. Check:");
    delay(1000);
    lcd.setCursor(0,1);
    lcd.print("* card in ?");
    delay(1000);
    lcd.setCursor(0,2);
    lcd.print("* wiring ?");
    delay(1000);
    lcd.setCursor(0,3);
    lcd.print("* chipSelect pin ");
    delay(3000);
    return;
  } else {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Wiring is correct");
    lcd.setCursor(0,2);
    lcd.print("a card is present.");
    delay(2000);
  }
 
   // print the type of card
   lcd.clear();
   lcd.setCursor(0,0);
  lcd.print("\nCard type: ");
  switch (card.type()) {
    case SD_CARD_TYPE_SD1:
      lcd.println("SD1");
      break;
    case SD_CARD_TYPE_SD2:
      lcd.println("SD2");
      break;
    case SD_CARD_TYPE_SDHC:
      lcd.println("SDHC");
      break;
    default:
      lcd.println("Unknown");
  }
  delay(2000);
  lcd.clear();
  lcd.setCursor(0,0);
  // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  if (!volume.init(card)) {
    lcd.print("No FAT16/32 part.");
    lcd.setCursor(0,1);
    lcd.print("format the card");
    delay(3000);
    return;
  }
  // print the type and size of the first FAT-type volume
  uint32_t volumesize;
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(" Volume is FAT");
  lcd.print(volume.fatType(), DEC);
  delay(1000);
  //lcd.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
  lcd.setCursor(0,1);
  lcd.print("Volume size (Mb): ");
  lcd.setCursor(0,2);
  volumesize /= 1024;
  lcd.print(volumesize);
  delay(2000);
  lcd.setCursor(0,3);
  lcd.print(" Files found : ");
  root.openRoot(volume);
  // list all files in the card with date and size
  root.ls(LS_R | LS_DATE | LS_SIZE);
  delay(3000);
 
}

void loop() {
  //lcd.clear();
 

}


thank you

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy