Author Topic: Using the SD card on the TFT screen  (Read 168 times)

digi_guy

  • Jr. Member
  • **
  • Posts: 79
Using the SD card on the TFT screen
« on: January 09, 2017, 12:47:56 pm »
I recently purchased the Oak TFT Shield Kit and it's been running great. Now I'd like to play around with the SD card reader, but I'm a little unsure how to wire it up. Do I just put some headers on it and connect the four pins directly to the Oak's SPI pins? The wiki page says, "connect the corresponding pins on the LCD to the PCB."

On closer inspection I see a set of four pins on the shield-PCB that obviously match up, but what about power?

And is the screen supposed to be plugged in at the same time? I assume that's where the power is connected, so can I use the screen at the SD card at the same time?

Thanks

exeng

  • Sr. Member
  • ****
  • Posts: 397
Re: Using the SD card on the TFT screen
« Reply #1 on: January 09, 2017, 02:28:48 pm »
I've not used both TFT and SD but suspect that can be done. Looking at the TFT board it seems that you simply put a 4 pin header on the board for the SD connection and connect it to the corresponding header on the shield. Remember this is a 3.3v device. Do not connect 5v to it.

On my TFT shield display combo I opted to put male headers on the shield and use female to female cables to make the connections. That way I can use the TFT without the shield on other 3.3v devices.

Let us know how it works out.

PeterF

  • Hero Member
  • *****
  • Posts: 680
Re: Using the SD card on the TFT screen
« Reply #2 on: January 09, 2017, 04:34:43 pm »
The SD card socket gets it's power from the VCC and GND of the LCD TFT block of connections, so yes, it would appear the TFT display needs to be 'plugged in' to work / it doesn't require separate power connections. I'll probably be trying it soon also, as I have a TFT display showing temperature data pushed from another Oak via Particle, and I might as well use the SD card to actually log the data. as this display Oak probably will become a dedicated display unit.

My only concern here is that the SD card pins *appear* to be reusing connections used for the TFT display, but then again, I suppose you wouldn't be able to update the TFT whilst the SD card is being used anyway, so as long as they can co-exist it may not be an issue. I'll also be interested in hearing progress... especially if you beat me to it! ;)

digi_guy

  • Jr. Member
  • **
  • Posts: 79
Re: Using the SD card on the TFT screen
« Reply #3 on: January 09, 2017, 06:53:15 pm »
So far it works great!

The screen is plugged into shield, and I simply ran 4 wires from the SD section of the screen over to the four special pins on the shield. It easily reads data off the card and prints it to the screen, using pin 4 as the CS.

Now I'm curious if I can store large html files and host larger webpages.

Thanks for the help!

digi_guy

  • Jr. Member
  • **
  • Posts: 79
Re: Using the SD card on the TFT screen
« Reply #4 on: January 09, 2017, 08:37:44 pm »
Success!

I put a simple webpage on the SD card and labeled the file index.txt. Then set up a simple loop to send it to the client when requested:

Code: [Select]
  File webpage;
  webpage = SD.open("index.txt");

  tft.println("Page size: ");
  tft.println(webpage.available());

  while (webpage.available()) {
    String msg=webpage.readStringUntil('\n');
    client.println(msg.length()+2,HEX);
    client.println(msg);
    client.println();
  }

Which it seems people were doing back with the original Ethernet shields that had an sd card slot built in.  The nice thing is that I can simply cut and paste a webpage of any size or complexity, right onto the sd card without worrying about all the little issues I kept running into.



exeng

  • Sr. Member
  • ****
  • Posts: 397
Re: Using the SD card on the TFT screen
« Reply #5 on: January 09, 2017, 08:43:00 pm »
Awesome. Thanks for sharing the results.

PeterF

  • Hero Member
  • *****
  • Posts: 680
Re: Using the SD card on the TFT screen
« Reply #6 on: January 09, 2017, 11:18:20 pm »
Brilliant! Yup, you beat me to it! Now I know I can certainly move forward with the datalogging aspect of the project now... and you've given me some new ideas now about an Oak that serves a webpage/site with a built-in display... drats, drats, drats... another half-completed project could be about to commence!  :P

digi_guy

  • Jr. Member
  • **
  • Posts: 79
Re: Using the SD card on the TFT screen
« Reply #7 on: January 10, 2017, 10:14:17 pm »
If you end up logging data to an SD card, making it all web accessible could be a lot of fun.

I managed to put together a little function that will create links to all the files on SD card
Code: [Select]
void sendFiles() {
  int numTabs = 0;

 
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println("Connection: close");
  client.println();
  client.println("<!DOCTYPE html><html><body><h3>Printing files on SD card</h3>");
 
 
  // send web page
  webFile = SD.open("/");
  while (true) {
    File entry =  webFile.openNextFile();
    if (! entry) {
      // no more files
      break;
    }
    for (uint8_t i = 0; i < numTabs; i++) {
//      tft.print('\t');  left over from something else
    }

    client.print("<p><a href=\"");
    client.print(entry.name());
    client.print("\">");
    client.print(entry.name());
    client.print("</a></p><br>");
    if (entry.isDirectory()) {
      tft.println("/");
//      printDirectory(entry, numTabs + 1);
    } else {
      // files have sizes, directories do not
//      tft.print("\t\t");
 //     tft.println(entry.size(), DEC);
    }
    entry.close();
  }
  client.println("</body></html>");
   client.println();
}

Excuse the left over junk, I was debugging with the tft. But basically this will create a webpage that both displays all the files currently on your sd card, and also hotlinks those files. So if you have a file called "index.txt" your browser will send "GET /INDEX.TXT"


PeterF

  • Hero Member
  • *****
  • Posts: 680
Re: Using the SD card on the TFT screen
« Reply #8 on: January 11, 2017, 12:47:13 am »
Indeed it would! :D Many thanks for that... is basically what I had in mind... if I'm datalogging with the Oak, might as well make it available over the wifi! Means I can add some more meaningful long term stats on the display also... currently shows things like minimum and maximum temperatures, but that is only for this session... it resets when power is lost. Being able to store that sort of stuff on the SD would make it much better... and pulling in the NTP stuff for time then allows for timestamping of it also! ;) Won't take long before the Oak is out of memory!