Using SD List Files Code

Status
Not open for further replies.

jshooks

Well-known member
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:
https://github.com/PaulStoffregen/S...67c3b7b20c6be1/examples/CardInfo/CardInfo.ino

My code:

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.enable();
  sgtl5000_1.volume(0.7); //Increased, was 0.5
  // Initialize the SD card/TFT LCD I2S pins
  SPI.setMOSI(TFT_MOSI);
  SPI.setSCK(TFT_SCLK);

  // 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");
    return;
  }

  Serial.println("initialization done.");
  root = SD.open("/");
  printDirectory(root, 0);
  Serial.println("done!");
//  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);
      break;
    }
    for (uint8_t i = 0; i < numTabs; i++) {
      Serial.print('\t');
    }
    Serial.print(entry.name());
    if (entry.isDirectory()) {
      Serial.println("/");
      printDirectory(entry, numTabs + 1);
    } else {
      // files have sizes, directories do not
      Serial.print("\t\t");
      Serial.println(entry.size(), DEC);
    }
    entry.close();
  }
  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
 
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?
 
Status
Not open for further replies.
Back
Top