Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: Using SD List Files Code

  1. #1

    Using SD List Files Code

    I'm trying to incorporate Paul's suggested SD list code (see link below) into an application using the Teensy 3.2, PJRC Audio Shield card and the ILI9341 touch screen. The SD list code works fine listing all 34 wave files so I know the hardware is good. However, when I include the ILI9341 assignments/definitions listed in my code below, I get the following serial monitor message:

    Initializing SD card...initialization done.
    No more files, last entry = 0
    No files found, done!

    I'm wondering if there is a conflict with the SPI touch screen initialization and the SD listing function during setup. Has anyone experienced this issue before? I would appreciate any suggestions you have.

    SD List Code:

    My code:

    #include <Arduino.h>
    #include <XPT2046_Touchscreen.h> 
    #include <ILI9341_t3.h>
    #include <font_ArialBold.h> // from ILI9341_t3
    #include <Audio.h> //Audio Library
    #include <Wire.h>
    #include <SPI.h> //For LCD display
    #include <SD.h> //For SD Card
    //#include <SerialFlash.h>
    File root; 
    // --------------------------  Set Up LCD Pins  ---------------------------
    //Set up ILI9341 Display
    #define TFT_DC      20 //TFT LCD data control
    #define TFT_CS      21 //TFT LCD chip select
    #define TFT_RST    255  // 255 = unused, connect to 3.3V
    #define SDCARD_CS_PIN    10 //SD card select pin
    //const int chipSelect = 10;
    #define TFT_MOSI     7 //Also used for SDCARD_MOSI
    #define TFT_SCLK    14 //Also used for SDCARD_SCK
    #define TFT_MISO    12 //TFT LCD I2S output
    //Set up XPT2046_Touch screen display interrupt
    #define CS_PIN  8 //Touch screen chip select
    #define TIRQ_PIN  3 //IRQ pin
    ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCLK, TFT_MISO);
    XPT2046_Touchscreen ts(CS_PIN, TIRQ_PIN);
    AudioControlSGTL5000     sgtl5000_1;     //Define audio card processor
    void setup() {
      pinMode(CS_PIN, OUTPUT);
      pinMode(TIRQ_PIN, INPUT_PULLUP); //IRQ for LCD
      AudioMemory(SDCARD_CS_PIN); //SD card SS pin
      // Enable the audio shield, select input, and enable output
      sgtl5000_1.volume(0.7); //Increased, was 0.5
      // Initialize the SD card/TFT LCD I2S pins
      // Open serial communications and wait for port to open:
      Serial.begin(9600); //SERIAL USB buad rate
      while (!Serial) {
        ; // wait for serial port to connect. Needed for Leonardo only
      // -------------------------- Setup SD -----------------------------
      Serial.print("Initializing SD card...");
      if (!SD.begin(SDCARD_CS_PIN)) {
        Serial.println("Unable to access the SD card");
      Serial.println("initialization done.");
      root ="/");
      printDirectory(root, 0);
    //  ts.begin(); //Begin touch screen interface after SD initialized!
    } //----------------------------- Set-up End -------------------------------
    void loop() {
      //Nothing done here to make this example simple
    void printDirectory(File dir, int numTabs) {
      while (true) {
        File entry =  dir.openNextFile();
        if (! entry) {
          // no more files
          Serial.print("No more files, last entry = "); Serial.println(numTabs);
        for (uint8_t i = 0; i < numTabs; i++) {
        if (entry.isDirectory()) {
          printDirectory(entry, numTabs + 1);
        } else {
          // files have sizes, directories do not
          Serial.println(entry.size(), DEC);
      Serial.print("No files found, ");
    Hardware: Teensy 3.2, PJRC Audio Shield, ILI9341_Touch
    Software: Arduino IDE 1.8.5 with TeensyDuino
    Wiring: Teensy stacked on Audio Shield with wiring to ILI9341 per Paul's audio workshop 3.3 example

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Did you find an answer to this? I've not done this with Audio card - that moves the SCLK from #13 to 14. The Touch code doesn't have any setting for SPI - just assumes the 'default'.

    Above the ts.begin() is commented - does it work in that case?

    Also when devices control a pin - at least in the Touch IRQ case because is also attaches the _isr() - it takes care of setting the pin so these are not needed: pinMode(TIRQ_PIN, INPUT_PULLUP); and pinMode(CS_PIN, OUTPUT);

    I see the commands to manually set the SPI - that is after AudioMemory(SDCARD_CS_PIN); ? did you have the audio card on in the working example?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts