Loading...
Pages: 1 [2] 3   Go Down
Author Topic: Sainsmart TFT touch SD shield, SD not working  (Read 3777 times)
0 Members and 2 Guests are viewing this topic.
UK
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
BUT.......If you remove these lines.......
The sketch refuses to work????? 
So, if you don't call SD.begin(), you can't then read from the SD card. And, that surprises you?

Thankyou for your intelligent reply! You clearly have NOT read the whole of my post!!
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 311
Posts: 35470
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I did read your whole post. I was impressed by your level of tenacity.

Why the code without the SD.begin() code would work with one SD card is the mystery. It should not, as I understand the SD class. But, even fat16lib, who wrote the class, says there are bugs with that class that the Arduino team does not see fit to correct.

So, stick with what works (and, I'll bet that works with the 1G card, too).
Logged

UK
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why the code without the SD.begin() code would work with one SD card is the mystery. It should not, as I understand the SD class. But, even fat16lib, who wrote the class, says there are bugs with that class that the Arduino team does not see fit to correct.

I dont fully understand what you mean?

Bugs with the SD class? 

I am using the henningkarlsen libraries, as far as I know, they do not use the SD class?

I am confused...

Regards,

Graham
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 311
Posts: 35470
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
BUT.......If you remove these lines.......

#include <SD.h>
File root;
// change this to match your SD shield or module;
//     Arduino Ethernet shield: pin 4
//     Adafruit SD shields and modules: pin 10
//     Sparkfun SD shield: pin 8
const int chipSelect = 53;

  if (!SD.begin(chipSelect)) {
    return;
  }
The code you are removing, that causes the sketch to quit working, is using the SD class. That's where SD.begin() comes from, as well as file.initFAT(). There must be some link to the SD library in one of the other classes. Else, where does the name in the call to loadBitmap() get used? Where does that file get loaded from?
Logged

UK
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

/*
   tinyFAT.h - Arduino library support FAT16 on SD cards
   Copyright (C)2010-2011 Henning Karlsen. All right reserved

   You can find the latest version of the library at
   http://www.henningkarlsen.com/electronics

   This library has been made to easily use SD card with the Arduino.

   If you make any modifications or improvements to the code, I would appreciate
   that you share the code with me so that I might include it in the next release.
   I can be contacted through http://www.henningkarlsen.com/electronics/contact.php

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, write to the Free Software
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/
#ifndef tinyFAT_h
#define tinyFAT_h

#if defined(__AVR__)
   #if defined(ARDUINO) && ARDUINO >= 100
      #include "Arduino.h"
   #else
      #include "WProgram.h"
   #endif
   #include "HW_AVR_defines.h"
#else
   #include "WProgram.h"
#endif

#define NO_ERROR               0x00
#define ERROR_NO_MORE_FILES         0x01
#define ERROR_FILE_NOT_FOUND      0x10
#define ERROR_ANOTHER_FILE_OPEN      0x11
#define   ERROR_MBR_READ_ERROR      0xF0
#define   ERROR_MBR_SIGNATURE         0xF1
#define   ERROR_MBR_INVALID_FS      0xF2
#define ERROR_BOOTSEC_READ_ERROR   0xE0
#define   ERROR_BOOTSEC_SIGNATURE      0xE1
#define ERROR_NO_FILE_OPEN         0xFFF0
#define ERROR_WRONG_FILEMODE      0xFFF1
#define FILE_IS_EMPTY            0xFFFD
#define BUFFER_OVERFLOW            0xFFFE
#define EOF                     0xFFFF

#define FILEMODE_BINARY            0x01
#define FILEMODE_TEXT_READ         0x02
#define FILEMODE_TEXT_WRITE         0x03

#define SPISPEED_LOW            0x03
#define SPISPEED_MEDIUM            0x02
#define SPISPEED_HIGH            0x01
#define SPISPEED_VERYHIGH         0x00

struct _master_boot_record
{
   byte part1Type;
   unsigned long part1Start;
   unsigned long part1Size;
};

struct _boot_sector
{
   byte sectorsPerCluster;
   uint16_t reservedSectors;
   byte fatCopies;
   uint16_t rootDirectoryEntries;
   uint32_t totalFilesystemSectors;
   uint16_t sectorsPerFAT;
   uint32_t hiddenSectors;
   uint32_t partitionSerialNum;
   uint16_t fat1Start;
   uint16_t fat2Start;
   float partitionSize;
};

struct _directory_entry
{
   char filename[9];
   char fileext[4];
   byte attributes;
   uint16_t time;
   uint16_t date;
   uint16_t startCluster;
   uint32_t fileSize;
};

struct _current_file
{
   char filename[13];
   uint16_t currentCluster;
   uint32_t fileSize;
   uint32_t currentPos;
   uint8_t fileMode;
};


class tinyFAT
{
public:
   _master_boot_record   MBR;
   _boot_sector      BS;
   _directory_entry   DE;
   unsigned long      firstDirSector;
   byte            buffer[512]; // the buffer cannot be any smaller, SD cards are read/written in blocks of 512 bytes
   
   tinyFAT();
      
   byte      initFAT(byte speed=SPISPEED_VERYHIGH);
   byte      findFirstFile(_directory_entry *tempDE);
   byte      findNextFile(_directory_entry *tempDE);
   byte      openFile(char *fn, byte mode=FILEMODE_BINARY);
   uint16_t   readBinary();
   uint16_t   readLn(char *st, int bufSize);
   uint16_t   writeLn(char *st);
   void      closeFile();
   boolean      exists(char *fn);
   boolean      rename(char *fn1, char *fn2);
   boolean      delFile(char *fn);
   boolean      create(char *fn);
   void      setSSpin(byte pin);

private:
   _current_file   currFile;
   int            DEcnt;
   boolean         _inited;

   uint16_t   findNextCluster(uint16_t cc);
   char      uCase(char c);
   boolean      validChar(char c);
   uint16_t   findFreeCluster();

};

extern tinyFAT file;

#endif





As previously stated, tinyFAT is fully self-contained....undependent on SD library?

Regards,

G
Logged

UK
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The code you are removing, that causes the sketch to quit working, is using the SD class. That's where SD.begin() comes from, as well as file.initFAT(). There must be some link to the SD library in one of the other classes. Else, where does the name in the call to loadBitmap() get used? Where does that file get loaded from?

File is an SD class..... file is a tinyFAT class?

Subtle but significant?

/*
  UTFT_tinyFAT.h - Add-on library to integrate UTFT and tinyFAT
  Copyright (C)2010-2012 Henning Karlsen. All right reserved
 
  Basic functionality of this library are based on the demo-code provided by
  ITead studio. You can find the latest version of the library at
  http://www.henningkarlsen.com/electronics

  If you make any modifications or improvements to the code, I would appreciate
  that you share the code with me so that I might include it in the next release.
  I can be contacted through http://www.henningkarlsen.com/electronics/contact.php

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#ifndef UTFT_tinyFAT_h
#define UTFT_tinyFAT_h

#if defined(__AVR__)
   #if defined(ARDUINO) && ARDUINO >= 100
      #include "Arduino.h"
   #else
      #include "WProgram.h"
   #endif
#else
   #include "WProgram.h"
#endif
#include "UTFT.h"
#include "tinyFAT.h"

class UTFTtf: public UTFT
{
   public:

      UTFTtf(byte model, int RS, int WR,int CS, int RST, int SER=0) : UTFT(model, RS, WR, CS, RST, SER) {}

      word loadBitmap(int x, int y, int sx, int sy, char *filename);
};

#endif

Regards,

G
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

GDI!!!!

I knew it! I knew it would be a library glitch of some sort. That has been my issues with the Sainsmart stuff from the beginning.

Graham,

I don't want to be a burden, but would you mind helping me sort through this now?

I am guessing to first start by re-connecting to the original pin configuration.
Will I need to get new resistors between the connections?

Also, I might not be loading images to the SD correctly. In the example sketch for UTFT_tinyFAT a commented line states "be sure images are loaded into the root folder of a properly formatted SD card"

How do I load them?
I tried loading them to the SD card from my computer, but when I still couldn't get the example sketches to work is when I stumbled upon this thread and tried this.

Thanks for any help! Please remember I am not an electrical engineer by trade, and might not fully understand what you're talking about. So, if you could keep it as simple as possible I would appreciate it.

Steve
Logged

UK
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Steve,

I have PM'd you my personal email address.

Regards,

Graham
Logged

UK
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

To conclude my input to this topic, Henning Karlson contacted me, and it turns out my SD Card is a cheap Chinese one and using his tinyFAT alone, my card fails to initialise at anything other than SPISPEED_LOW. However, if I include the previously mentioned lines of the SD library, I can then use the tinyFAT library initialised at SPISPEED_VERYHIGH, which obviously has dramatic benefits to the speed of file reading!!

Dont know if this is useful to anyone else, but the SD card that is causing me problems is an Elite Pro, 8GB SDHC class 4.

Graham
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello guys,

I am new to arduino forum. My name is Marek, I am from Poland. I live in sunny Florida for more than 13 years.
I work as a programmer. In my spare time I do ... well, programming :-).

I decided to add my problem to this topic because it is very closely related to the actual problem - a SD card issue on TFT LCD shield.

Here goes:

I have a following setup:

- Arduino Mega 2560.
- TFT LCD Mega Shield V1.2 (by JQT).
- A matching TFT touch LCD module from the same vendor with integrated SD card slot.

My TFT LCD Mega Shield had the bug described at the beginning of the topic with MOSI and SCK pins mixed. I corrected it by removing the surface mount resistors and leading wires directly from pin 36 on the Mega Shield LCD connector to pin 52 of the Arduino Mega board connector and from pin 37 on the Mega Shield LCD connector to pin 51 on Arduino Mega board connector.
This somewhat corrected the issue with SD card slot being completely useless, however I still have a problem reading the card information/initializing. More specifically, I use SD library and I copied the code from CardInfo example to my sketch. This sketch fails on:
Code:
  // 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/32 partition.", LEFT, 80);
    return;
  }

Here is the full code of my sketch:

Code:
//
// This program requires the UTFT library and SD library.
// It tests UTFT's built in SD card functionality.
//

#include <SD.h>
#include <UTFT.h>

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 53; 

// Declare which fonts we will be using
extern uint8_t SmallFont[];

// Uncomment the next line for Arduino 2009/Uno
//UTFT myGLCD(ITDB32S,19,18,17,16);   // Remember to change the model parameter to suit your display module!

// Uncomment the next line for Arduino Mega
UTFT myGLCD(ITDB32S,38,39,40,41);   // Remember to change the model parameter to suit your display module!

void setup()
{
  // Open serial communications
  Serial.begin(9600);

  myGLCD.InitLCD();
  myGLCD.clrScr();
  myGLCD.setColor(0, 255, 0);
  myGLCD.setBackColor(0, 0, 0);
  myGLCD.setFont(SmallFont); 
 
  myGLCD.print("Initializing SD card...", LEFT, 0);
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  // or the SD library functions will not work.
  pinMode(53, OUTPUT);     // change this to 53 on a mega
 
  /*
  if (!SD.begin(chipSelect))
  {
    myGLCD.print("SD initialization failed.", LEFT, 16);
    return;
  }
  */


  // we'll use the initialization code from the utility libraries
  // since we're just testing if the card is working!
  if (!card.init(SPI_QUARTER_SPEED, chipSelect)) {
    myGLCD.print("initialization failed.", LEFT, 16);
    return;
  } else {
   myGLCD.print("Wiring is correct.", LEFT, 16);
   myGLCD.print("Card is present.", LEFT, 32);
  }

  // print the type of card
  myGLCD.print("Card type: ", LEFT, 48);
  switch(card.type()) {
    case SD_CARD_TYPE_SD1:
      myGLCD.print("SD1", LEFT, 64);
      break;
    case SD_CARD_TYPE_SD2:
      myGLCD.print("SD2", LEFT, 64);
      break;
    case SD_CARD_TYPE_SDHC:
      myGLCD.print("SDHC", LEFT, 64);
      break;
    default:
      myGLCD.print("Unknown", LEFT, 64);
  }

  // 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/32 partition.", LEFT, 80);
    return;
  }

  myGLCD.print("Volume type is FAT.", LEFT, 80);
  // print the type and size of the first FAT-type volume
  uint32_t volumesize;
  Serial.print("\nVolume type is FAT");
  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
  Serial.print("Volume size (bytes): ");
  Serial.println(volumesize);
  Serial.print("Volume size (Kbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);
  Serial.print("Volume size (Mbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);

 
  Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  root.openRoot(volume);
 
  // list all files in the card with date and size
  root.ls(LS_R | LS_DATE | LS_SIZE); 

}

void loop()
{
  while(1) {};
}


I get following output on the LCD screen:


Initializing SD card...
Wiring is correct.
Card is present.
Card type:
SD1
Could not find FAT16/32 partition.


I tried multiple SD cards. These cards worked fine with CardInfo example on Arduino UNO with 2 different SD shields.
If you can spare some time and give me some advice on this topic, that'd be great.

Thanks!

Marek
Logged

Marek K.

Don't worry! We have our best people working on it.

France
Offline Offline
God Member
*****
Karma: 19
Posts: 613
Scientia potentia est.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello and welcome smiley

Try with these libraries:

http://henningkarlsen.com/electronics/library.php?id=37
http://henningkarlsen.com/electronics/library.php?id=53
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Thanks.

I was thinking about it too. I hoped there was some tricky know-how about using SD library with these shields. Could not find anything by googleing though and going through library code also did not reveal anything obvious.

I will give it a try and update the topic with my results.

Marek
Logged

Marek K.

Don't worry! We have our best people working on it.

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Thank you guix,

The tinyFAT library worked. I have successfully read a text file from the SD card and displayed its contents on the LCD screen.
I guess I will not be using SD library with this project.

Thanks again for a helpful suggestion.
Logged

Marek K.

Don't worry! We have our best people working on it.

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Re. the resistors (this seems to be unanswered on the thread) - I've done a lot of research on the Sainsmart TFT01 display and it is, indeed, a 3.3v device. The resistors are intended to drop the Arduino 5v signalling to 3.3v to protect the display.

The ElecFreaks shield, compatible with the same display, provides "actual" level convertors (a bunch of chips) to do this a bit more predictably. Those with wire links in place of the resistors run *some* risk of damaging the display and/or the arduino.

Now... if anyone can explain the ElecFreaks shield driving the LED-A pin (19) of the display by 3.3v via 10 Ohm resistor, when it's forward voltage is 3.2v @ 80mA.... time for some soldering of my own to get some much needed brightness on the display (20 Ohm to 5v... or maybe gated through a 2n3906 to allow the arduino to control the backlight).
Logged

France
Offline Offline
God Member
*****
Karma: 19
Posts: 613
Scientia potentia est.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello Doddy, you may be interested by this topic: http://forum.arduino.cc/index.php/topic,139391.0.html
Logged

Pages: 1 [2] 3   Go Up
Print
 
Jump to: