I have an ILI9488 3.95” touch screen with an onboard SD card reader.
The SD reader on the TFT screen is very intermittent so I bought a separate SD card (ADA254 unit).
It works fine on nano, UNO and the Mega using the SD example “list files”.
I have added a breakout board to the mega and connected the SD reader to the screwed terminals and it works fine.
As soon as I plug the TFT screen into the breakout board, the SD card reader stops working.
I have changed the CS/SS port to various pin terminals (also changed the PIN numbers in software) and I still have the same problem. (BTW I have used these various pin terminals without the TFT screen attached and they all work).
Any clues on how I can get the new SD card reader to work with the TFT screen attached?
Please post a link to the actual "ILI9488 3.95” touch screen with an onboard SD card reader."
Likewise the "ADA254 unit"
Googling "ADA254" gets https://www.amazon.com/Adafruit-MicroSD-Breakout-Board-ADA254/dp/B00NAY2NAI
Googling "ILI9488" gives many different items. Which one would you like us to guess?
Why should readers have to Google when the OP could just provide the actual links?
David.
The links are as follows.
SD board
8 bit 3.95” ILI9488 TFT screen
https://www.aliexpress.com/i/4000035671218.html
Please note that the TFT screen says “no longer available”. Also, it’s 8 bit so pins 22 to 29 show NC on the board even though the link image shows them connected.
I have posted about the ILI9488 screen before but I’ll post another photo here so you don’t have to search.
Thanks for the links. I would never have guessed that you had that particular Shield.
I would expect the microSD to be 100% reliable. Just make sure that the XPT2046 is not selected i.e. TP_CS = OUTPUT HIGH. e.g.
pinMode(53, OUTPUT); //TP_CS
digitalWrite(53, HIGH);
bool success = SD.begin(48); //SD_CS
If you really want to use an external breakout board you will need to say:
pinMode(53, OUTPUT); //TP_CS
digitalWrite(53, HIGH);
pinMode(48, OUTPUT); //SD_CS
digitalWrite(48, HIGH);
bool success = SD.begin(xxx); //BREAKOUT_CS
Some of the older Mega2560 Shields just used 10k resistor packs to "level shift". The TFT "works" but the SD would be "unreliable".
I would expect your Shield to be 100%.
David.
Thanks for the reply.
I am only running the SD example file "listfiles" with no touch pad or TFT screen input/output.
The code, with your suggestions, is as follows; but it still fails to initialise the card when using the SD reader on the TFT board.
Have I failed to follow your suggestions correctly in the code below?
Also, using your suggestions for the add-on SD reader also fails.
/*
Listfiles
This example shows how print out the files in a
directory on a SD card
The circuit:
SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN)
created Nov 2010
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
modified 2 Feb 2014
by Scott Fitzgerald
This example code is in the public domain.
*/
#include <SPI.h>
#include <SD.h>
File root;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
pinMode(53, OUTPUT);
digitalWrite(53, HIGH);
bool success = SD.begin(48);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
if (!SD.begin(48)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
root = SD.open("/");
printDirectory(root, 0);
Serial.println("done!");
}
void loop() {
// nothing happens after setup finishes.
}
void printDirectory(File dir, int numTabs) {
while (true) {
File entry = dir.openNextFile();
if (! entry) {
// no more files
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();
}
}
I don't have your Shield. But I do have an earlier version with 8-bit bus on D22-D29. i.e. XPT2046 + 3 HC245A chips.
It looks as if your pcb was a "mistake". i.e. they have XPT2046 + 4 HC245A chips but don't use the full 16-bit bus.
The TFT and XPT2046 Touch should work ok.
I guess that the SD Card will be exactly the same on all versions of this Shield
- 8-bit D22-D29
- 8-bit D30-D37
- 8/16-bit D22-D37
I tried the first microSD card with your program. It worked fine.
I presume you have a sensible microSD card e.g. 128MB - 8GB
Does your card work in the breakout without the TFT?
If you are worried about pcb "mistakes" just trace the SD Card connections to U5 from D48-D53 with a DMM. Note the R1-R5 values.
Post a proper table. i.e. U5 pin numbers, Dnn numbers, Rn numbers, SD holder pin numbers.
David.
Thanks again. Card formatted to FAT32. As I said in my original post, all works fine with the separate SD card reader attached to the Mega as long as the TFT is NOT plugged in. As soon as I plug the TFT screen in, the message is card not initiated.
I’ll do some tracing tomorrow and report back.
The TFT and touch screen work great - it’s the same display we talked about some months ago and you helped with the 8 bit MCFRIEND_special.h to suit the 8 bit board.
Edit - just uploaded the sketch again ( after running a screen and touch sketch) and ran it with the SD card in the SD reader on the TFT board and it works now?
I’ll see if I can get the other attached SD card reader working.
I added the Adafruit SD external card reader to the Mega screw terminal shield and followed your advice re programing.
/*
Listfiles
This example shows how print out the files in a
directory on a SD card
The circuit:
SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN)
created Nov 2010
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
modified 2 Feb 2014
by Scott Fitzgerald
This example code is in the public domain.
*/
#include <SPI.h>
#include <SD.h>
File root;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
pinMode(53, OUTPUT);
digitalWrite(53, HIGH);
pinMode(48, OUTPUT);
digitalWrite(48, HIGH);
pinMode(40, OUTPUT);
digitalWrite(40, HIGH);
bool success = SD.begin(10);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
if (!SD.begin(10)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
root = SD.open("/");
printDirectory(root, 0);
Serial.println("done!");
}
void loop() {
// nothing happens after setup finishes.
}
void printDirectory(File dir, int numTabs) {
while (true) {
File entry = dir.openNextFile();
if (! entry) {
// no more files
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();
}
}
Without the TFT screen fitted to the shield, the SD card is read and files on it listed so all OK.
As soon as the TFT board is fitted to the screw terminal shield, and I try to access the SD card on the external SD reader, I get the Card initialisation fail message.
I decided to investigate which pins between the TFT and the Mega were stopping the external SD Reader from working with the TFT connected.
I ran cables between the two and disconnected one at a time, testing with the Read/Write example.
When both the 5V wire connections were disconnected it worked. With the 5V connections back on, the connection that was stopping it from working was the connection from Mega Pin 50 (MISO) and the TFT board. With that disconnected and all other wires connected, the READ/WRITE example, the Listfiles example all worked as expected. With the MISO wire reconnected, I got the Card initialisation fail message.
Why would anyone connect a Shield via Dupont wires ?
I am not familiar with your screw adapter. I guess that all the Shield connections are "straight-through" and you can access the pins via screw terminals.
If the SD works on the Shield why do you want an external SD ?
I would expect TP_CS, SD_CS and your EXTERNAL_SD_CS to select the SPI bus as required. (via 3.3V level shifters)
I would expect XPT2046 chip DOUT, card SD_DAT0 and EXTERNAL_SD_DAT0 pins to all go directly to D50 (MISO)
All of these Slave "Data-Out" pins should work ok. i.e. one pin active when the respective CS is selected.
It is not difficult for you to follow copper traces on a pcb with a DMM.
“Why would anyone connect a Shield via Dupont wires ?”
So I could disconnect one wire at a time to see which connection was causing the problem, Besides that, I had them available
“I am not familiar with your screw adapter. I guess that all the Shield connections are "straight-through" and you can access the pins via screw terminals.”
Exactly - see photo.
“If the SD works on the Shield why do you want an external SD ?”
It’s all going into an enclosure with just the screen visible. This would make it extremely difficult to use an SD card under these circumstances
“I would expect TP_CS, SD_CS and your EXTERNAL_SD_CS to select the SPI bus as required. (via 3.3V level shifters)”
As would I.
“I would expect XPT2046 chip DOUT, card SD_DAT0 and EXTERNAL_SD_DAT0 pins to all go directly to D50 (MISO)”
D50 goes to U5, not Pin12 on the XPT2046 chip, EXTERNAL_SD_DAT0 goes to D50. Unfortunately I can’t get a trace on the on SD_DAT0 at the moment.
“All of these Slave "Data-Out" pins should work ok. i.e. one pin active when the respective CS is selected.”
One would think so.
“It is not difficult for you to follow copper traces on a pcb with a DMM.”
I know - only having a problem with identifying pins in the onboard SD.
I guess that you have 4 HC245A chips. And U5 is the HC245A that handles SD_CS, TP_CS, SCK, MOSI, ... i.e. shifts the 2560 weird 5V logic to a regular 3.3V for the electronics.
The D50 MISO pin connects directly to the 3.3V Data_Out signals from XPT2046, SD, External_SD.
The 2560 can read 3.3V data reliably. All three SPI Slaves handle their Data_Out signals correctly i.e. 3-state when not selected.
If someone has chosen to "shift" the 3.3V Data_Out signal to 5V life becomes difficult. Each Data_Out "shift" must go via 3-state i.e. separate /CE pin for each shifter signal.
HC245A can /CE all 8 channels in one go. Not individually.
Go on. SD pins are numbered 1-9. Google finds the pinout.
Google finds HC245A pinout, XPT2046 pinout.
You might even find the schematic via the LCDWIKI docs.
When I said identifying the pins on the onboard SD, I actually meant getting to them to follow with a DMM as I left my needle probes at work.
I have downloaded the schematic via Altium.
They are LVC245A ICs
The MISO pin on the header DOES NOT directly connect to the Data_Out pin on the XPT2046. It connects to U5 as I stated earlier. It is indirectly connected via U5 to the Data_out pin on XPT2046 ( pin 12) as shown in the schematic.
Lots of posts talk about MISO problems and adding additional SD card readers (and even problems with the onboard SD card readers as well) so I have decided to use the onboard SD reader and add an extension to it so it could be accessed once its all in its enclosure.
I now have the SD card in the reader on the TFT board itself, for trial, as its not in its enclosure yet so accessible.
I have now encountered a problem, that others have spoken about, re once the SD reader is accessed, it locks out the Touch pad.
The following sketch shows this. I have removed the display going to the TFT screen and left it for display on the Serial screen.
I have also taken some screen shots. I can select menu items and go back and forth with the toucj serial data showing valid co-ordinates - all's fine.
However, access and SD card reader and the touch serial data reports either -1, -1 or 0,316 or a combination so you can no longer choose menu items. If i reset the board via the reset pin or close and open the serial display, it all goes back to normality until you select the file read menu item,
Sketch to follow
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
#include <URTouch.h>
#include <Fonts/FreeSansBold24pt7b.h>
#include <SD.h>
File root;
MCUFRIEND_kbv tft;
#define BLACK 0x0000
#define NAVY 0x000F
#define DARKGREEN 0x03E0
#define DARKCYAN 0x03EF
#define MAROON 0x7800
#define PURPLE 0x780F
#define OLIVE 0x7BE0
#define LIGHTGREY 0xC618
#define DARKGREY 0x7BEF
#define BLUE 0x001F
#define GREEN 0x07E0
#define CYAN 0x07FF
#define RED 0xF800
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define ORANGE 0xFD20
#define GREENYELLOW 0xAFE5
#define PINK 0xF81F
float Zsteprate = 1;
float XYsteprate = 10;
int Feedrate = 100;
float tp; //touchpad thickness
float retract; //Z retract after touch
float dt; // distance to move down before reporting an error
int resetPin = 10;
URTouch myTouch( 52, 53, 51, 50, 44); //(for hardware SPI)
String symbol[4][4] = {
{ "7", "8", "9", "UP" },
{ "4", "5", "6", "ST" },
{ "1", "2", "3", "DN" },
{ "C", "0", "=", "." }
};
int x, y;
void setup() {
//following recommended to add by David Prentice
pinMode(40, OUTPUT);
digitalWrite(40, HIGH);
pinMode(48, OUTPUT);
digitalWrite(48, HIGH);
pinMode(53, OUTPUT);
digitalWrite(53, HIGH);
//
Serial.begin(115200); //Use serial monitor for debugging
tft.reset();
tft.begin(0x9488);
myTouch.InitTouch(1);//0 = portrait 1= landscape
myTouch.setPrecision(PREC_MEDIUM);
tft.setRotation(1); //0 Landscape
tft.fillScreen(BLACK);
startmenu();
}
void loop() {
}
void startmenu() {
tft.fillScreen(BLACK);
tft.fillRoundRect(5, 50, 190, 50, 5, WHITE);
tft.fillRoundRect(5, 120, 190, 50, 5, WHITE);
tft.setCursor(100, 5);
tft.setTextSize(3);
tft.setTextColor(WHITE);
tft.print ("MAIN MENU");
tft.setTextColor(BLACK);
tft.setTextSize(2);
tft.setCursor(25, 65);
tft.println("Second Screen");
tft.setCursor(15, 135);
tft.println("Read File List");
tft.setCursor(18, 205);
while (true)
{
if (myTouch.dataAvailable())
{
delay(100);
myTouch.read();
x = myTouch.getX();
y = myTouch.getY();
Serial.print(x); Serial.print(','); Serial.println(y);
if (x < 170 && x > 17)
{
if (y > 230 && y < 250)
{
secondscreen();
delay(100);
}
if (y > 155 && y < 185)
{
readfiles();
}
}
}
}
}
void secondscreen()
{
tft.fillScreen(BLACK);
tft.setCursor(10, 10);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.print("Second Screen");
tft.setCursor(380, 280);
tft.print("Exit");
while (true)
{
if (myTouch.dataAvailable())
{
delay(100);
myTouch.read();
x = myTouch.getX();
y = myTouch.getY();
Serial.print(x); Serial.print(','); Serial.println(y);
if (x < 460 && x > 340)
{
if ( y > 10 && y < 50)
{
startmenu();
delay(500);
}
}
}
}
}
void readfiles()
{
// bool success = SD.begin(48); //don't need???
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
if (!SD.begin(48)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
root = SD.open("/");
printDirectory(root, 0);
Serial.println("done!"); //tft.println
// the following is foir use if displaying on tft screen
// tft.setCursor (380, 280);
// tft.print("Exit");
while (true)
{
if (myTouch.dataAvailable())
{
delay(100);
myTouch.read();
x = myTouch.getX();
y = myTouch.getY();
Serial.print(x); Serial.print(','); Serial.println(y);
if (x < 2 && x > -2)
{
if ( y > -2 && y < 2)
{
delay (500);
// pinMode(resetPin, OUTPUT); //reset board so it will reinitialise the touch pad
startmenu();
}
if ( y > -2 && y < 360)
{
delay (500);
// pinMode(resetPin, OUTPUT); //reset board so it will reinitialise the touch pad
startmenu();
}
}
}
}
}
void printDirectory(File dir, int numTabs) {
//use the following if printing o the TFT screen
// tft.fillScreen(BLACK);
// tft.setCursor(10, 5);
// tft.setTextColor(WHITE);
while (true) {
File entry = dir.openNextFile();
if (! entry) {
// no more files
break;
}
for (uint8_t i = 0; i < numTabs; i++) {
Serial.print('\t'); //tft.print
}
Serial.print(entry.name()); //tft.print
if (entry.isDirectory()) {
Serial.println("/"); // tft.println
printDirectory(entry, numTabs + 1);
} else {
// files have sizes, directories do not
Serial.print("\t\t\t\t"); //tft.print
Serial.println(entry.size(), DEC); //tft.println
}
entry.close();
}
}
I have got various ZIP files for MAR3953, MAR3954, ... shields.
There is PDF for the schematic. Only a SCHDOC file for Altium.
If you possess a PDF or can link to a human readable schematic I would be grateful.
Meanwhile I tried your sketch. Are you crazy?
There is no way to use URTouch.h with hardware SD.h
I will try it with XPT2046_Touchscreen.h later.
I really don't see the SD access problem. An 8GB SD card will contain as many pictures as you will ever want to use on your Arduino.
You write all the files to the SD via your PC. Insert the SD once.
Assemble the Shield into its case. Run Arduino.
I attempted to view SCHDOC via an Altium online viewer but it did not work.
David.
First of all, if you read my post correctly, there is no problem with access to the SD card with that sketch. It reads the SD and lists the files, as it should, on the Serial display.
The problem is that after it reads the files the Touch pad? malfunctions - it reads -1,-1 or 0,316 or a combination of the both - not the true coordinates.
You have to reset the board to get the touch to starting reading correctly.
Secondly - you refer to be being crazy for using URTouch.h and hardware SD.h together but you don’t say why? URTouch is using the hardware SPI, not software SPI.
I use URTouch because I’m comfortable using it and I’ve never had problems before using it. It controls CNC machines, router tables etc and has never caused a problem.
Thirdly - how would you like the Schematic? I can post it here or send you a copy. Let me know.
Edit. The SD card is to be used to upload GCode to machinery, rather than having a PC connected in a very dusty environment, So, for different jobs, the card will need to be removed and fitted on multiple occasions as I design jobs then send them to machinery.
URTouch has no concept of hardware SPI. And it does some bad things to the Arduino pins.
If you want to use multiple SPI slaves on the hardware SPI bus you need to use hardware SPI libraries for each item.
Would you be happy if the bus driver changed the engine while you are traveling on the bus?
Your program use random x, y values to detect a Touch but it makes life complicated too. My head hurts less when the Touch returns the correct pixel position.
I have not tried an external SD card. If you have a schematic for the Shield I would like to read that first.
Please try this. Note that Serial is 9600 baud.
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
#include <XPT2046_Touchscreen.h> //.kbv
#include <Fonts/FreeSansBold24pt7b.h>
#include <SD.h>
File root;
MCUFRIEND_kbv tft;
#define BLACK 0x0000
#define NAVY 0x000F
#define DARKGREEN 0x03E0
#define DARKCYAN 0x03EF
#define MAROON 0x7800
#define PURPLE 0x780F
#define OLIVE 0x7BE0
#define LIGHTGREY 0xC618
#define DARKGREY 0x7BEF
#define BLUE 0x001F
#define GREEN 0x07E0
#define CYAN 0x07FF
#define RED 0xF800
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define ORANGE 0xFD20
#define GREENYELLOW 0xAFE5
#define PINK 0xF81F
float Zsteprate = 1;
float XYsteprate = 10;
int Feedrate = 100;
float tp; //touchpad thickness
float retract; //Z retract after touch
float dt; // distance to move down before reporting an error
int resetPin = 10;
//.kbv XPT_Touchscreen is much better
XPT2046_Touchscreen ts(53, 255);
const int TS_LANDSCAPE = 1; //XPT2046_TouchScreen.h
const int TS_LEFT = 338, TS_RT = 3879, TS_TOP = 3767, TS_BOT = 237; //Red ST7796 Shield (landscape)
int pixel_x, pixel_y; //Touch_getXY() updates global vars
bool Touch_getXY(void)
{
bool pressed = ts.touched();
if (pressed) {
TS_Point p = ts.getPoint();
if (TS_LANDSCAPE) mapxy(p.y, p.x);
else mapxy(p.x, p.y);
extern int x, y; //to suit your global variables
x = pixel_x;
y = pixel_y;
}
return pressed;
}
void mapxy(int x, int y)
{
int aspect = tft.getRotation(); //LANDSCAPE
int tft_width = tft.width();
int tft_height = tft.height();
switch (aspect & 3) {
case 0: //PORTRAIT
pixel_x = map(x, TS_LEFT, TS_RT, 0, tft_width);
pixel_y = map(y, TS_TOP, TS_BOT, 0, tft_height);
break;
case 1: //LANDSCAPE
pixel_x = map(y, TS_TOP, TS_BOT, 0, tft_width);
pixel_y = map(x, TS_RT, TS_LEFT, 0, tft_height);
break;
case 2: //PORTRAIT REV
pixel_x = map(x, TS_RT, TS_LEFT, 0, tft_width);
pixel_y = map(y, TS_BOT, TS_TOP, 0, tft_height);
break;
case 3: //LANDSCAPE REV
pixel_x = map(y, TS_BOT, TS_TOP, 0, tft_width);
pixel_y = map(x, TS_LEFT, TS_RT, 0, tft_height);
break;
}
}
String symbol[4][4] = {
{ "7", "8", "9", "UP" },
{ "4", "5", "6", "ST" },
{ "1", "2", "3", "DN" },
{ "C", "0", "=", "." }
};
int x, y;
void setup() {
//following recommended to add by David Prentice
pinMode(40, OUTPUT); //.kbv WHY
digitalWrite(40, HIGH); //.kbv WHY
pinMode(48, OUTPUT);
digitalWrite(48, HIGH);
pinMode(53, OUTPUT);
digitalWrite(53, HIGH);
//
Serial.begin(9600); //Use serial monitor for debugging .kbv 9600 is easier
tft.reset();
//tft.begin(0x7796); //.kbv my screen is ST7796
tft.begin(0x9488);
ts.begin(); //.kbv XPT2046
tft.setRotation(1); //0 Landscape
tft.fillScreen(BLACK);
startmenu();
}
void loop() {
}
void startmenu() {
tft.fillScreen(BLACK);
tft.fillRoundRect(5, 50, 190, 50, 5, WHITE);
tft.fillRoundRect(5, 120, 190, 50, 5, WHITE);
tft.setCursor(100, 5);
tft.setTextSize(3);
tft.setTextColor(WHITE);
tft.print ("MAIN MENU");
tft.setTextColor(BLACK);
tft.setTextSize(2);
tft.setCursor(25, 65);
tft.println("Second Screen");
tft.setCursor(15, 135);
tft.println("Read File List");
tft.setCursor(18, 205);
while (true)
{
if (Touch_getXY()) //.kbv call a single functio
{
Serial.print(x); Serial.print(','); Serial.println(y);
if (x > 5 && x < 5+190) //your RoundRect positions
{
if (y > 50 && y < 50+50)
{
secondscreen();
delay(100);
}
if (y > 120 && y < 120+50)
{
readfiles();
}
}
}
}
}
void secondscreen()
{
tft.fillScreen(BLACK);
tft.setCursor(10, 10);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.print("Second Screen");
tft.setCursor(380, 280);
tft.print("Exit");
while (true)
{
if (Touch_getXY())
{
Serial.print(x); Serial.print(','); Serial.println(y);
if (x > 340 && x < 480) //your EXIT pixel positions
{
if ( y > 270 && y < 320)
{
startmenu();
delay(500);
}
}
}
}
}
void readfiles()
{
// bool success = SD.begin(48); //don't need???
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
if (!SD.begin(48)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
root = SD.open("/");
printDirectory(root, 0);
Serial.println("done!"); //tft.println
// the following is foir use if displaying on tft screen
tft.setTextColor(RED);
tft.setCursor (380, 280);
tft.print("Exit");
while (true)
{
if (Touch_getXY())
{
Serial.print(x); Serial.print(','); Serial.println(y);
if (x > 340 && x < 480) //your MENU pixel positions
{
if ( y > 270 && y < 320)
{
startmenu();
delay(500);
}
}
}
}
}
void printDirectory(File dir, int numTabs) {
while (true) {
File entry = dir.openNextFile();
if (! entry) {
// no more files
break;
}
for (uint8_t i = 0; i < numTabs; i++) {
Serial.print('\t'); //tft.print
}
Serial.print(entry.name()); //tft.print
if (entry.isDirectory()) {
Serial.println("/"); // tft.println
printDirectory(entry, numTabs + 1);
} else {
// files have sizes, directories do not
Serial.print("\t\t\t\t"); //tft.print
Serial.println(entry.size(), DEC); //tft.println
}
entry.close();
}
}
Thanks for the work.
You said I used random x,y value to detect Touch. The values I used from the main menu to second screen and second screen exit back to main menu and main memo to read files list perfectly match the coordinates on my screen so they weren’t random values. Touch coords 0,0 are at the bottom left of the screen while tft coords 0,0 are at the top LH corner.
The only weird ones were the -2,-2 and -2,360 ones which I had to use to get back to the main menu because -1,-1 and 0,316 were the only ones reported when the screen was touched after the SD was read. I stated those readings in a previous post and stated they were the only ones reported after the SD was accessed. Please read my posts more carefully.
Your changing engines on a bus analogy is somewhat strange. I had URTouch.h for touch SPI, I has SD.h for the SD reader SPI and MCFRIEND_kbv.h for the TFT. All specific libraries.
II’ll try the XPT_Touchscreen sketch you supplied tomorrow.
How do you want me to give you the schematic for the tft board? Do you want one for the external SD card as well.
When you say shield, are you talking about the TFT/TOUCH shield or the Screw terminal shield?
https://www.ebay.com.au/itm/393408113952?hash=item5b98f36d20:g:gD8AAOSw--hg1Ica
Thanks again
If you have a PDF or a link to something human readable for your specific TFT Shield.
I have ZIP files for MAR3953V1.0, MAR3953V1.1, MAR3954V1.0, ...
Only MAR3953V1.1 has a SCHDOC file. The others all have SCHLIB files.
I have managed to view the MAR3953V1.1 SCHDOC file. Sure enough it "wastes" a whole 245A chip (U5) in shifting 3.3V data_out to 5V
And the 245A buffers are wired completely wrong. e.g. DIR, /OE permanently enabled.
Hey-Ho. These Shields "work" as write-only. And yes, the MISO signal on D50 will kill your external SD card. You need to connect your external SD_MISO signal to U5.2.
You can't mix HW SPI and SW SPI on the same pins. It is like changing the Diesel engine on your bus to bicycle pedals half-way through a journey.
Regarding Touch positions. If you draw a "button" at (5, 50) it seems only sensible to have Touch respond to (5, 50)
Likewise, you have a "debug" X,Y printed on Serial. Surely you want X, Y to report the actual pixel positions.
Simple answer is:
- external SPI devices will only work if you make a hardware mod to the TFT Shield.
- I can make URTouch.h perform the roadside engine-change if you are desperate for poor performance.
David.
I assumed that using URTouch with the hardware pin connections, it was a hardware connection, not software, so there you go - never assume.
"You need to connect your external SD_MISO signal to U5.2" - is that U5 pin 2?
Having screen orientation and touch orientation the same does make it easier .
I ran your sketch - works fine - thanks. I will now have to rewrite my large CNC controller sketch to incorporate the XPT changes but it will keep me off the streets
I did try connecting the external SD reader, but it couldn't access it - error message re card initialisation.
I have attached the schematic PDF - hope its readable. If there's a problem I'll work something else out.
Thanks for all your help.
tft pcb.pdf (133.2 KB)
Thanks for the PDF. It is exactly the same as the SCHDOC that I have.
The schematic shows U3 connected to D22-D29
The schematic shows R5=0R and R4=nc
Your photo in #3 shows copper traces from U3 to D22-D29
Your photo in #3 shows R5=nc and R4=0R
Your photo in #3 says D22-D29 are NC
The SPI behaviour revolves around U5, U4 wiring. I suspect that the Chinese designer has exactly the same U5, U4 "features" in all three versions of this Red Shield. i.e. USE_MEGA_8BIT_SHIELD, USE_MEGA_8BIT_PORTC_SHIELD, USE_MEGA_16BIT_SHIELD