Need Help, stuck on code!!!

Sorry for the dull title, didn’t know what else to write. I’m making a robot da doese quizes. It shows an .txt file from the sd card with questions and awnsers and depending on the awsner you give via 4x4 keypad, it shows a line of text on the 2.4’’ Tft MCufrined display. All this is done via the arduino due.

I’ve writen all of the code and thought it would work, but it only get’s to one point. It goes fine until the ‘for’ line, I’m gonna upload the code as an atachment.

It would be great if someone could look at the code. I ran out ideas.

Thank you!

Code.ino (17.8 KB)

    File myFile = SD.open("1. Pitanje");

Is that a valid filename ? Does the SD library actually work with a Due ?

Yes that's the name of the .txt file on the sd. The Module Works with the due, i checked with the example cardinfo.

And my code passes the initialization part succsefuly.

Maybe you should consult the SD library reference to see what it says about filenames.

Yes that's the name of the .txt file on the sd.

Yes, but is it a valid filename for the SD library ?

This maybe a stupid question but where can i check the SD library reference, and where can I see witch names are valid?

I thought all names are fine.

http://www.arduino.cc/en/Reference/SD

You can also run the file list example that ships with the library. It will display all the file names, as the library sees them.

I saw that the files have to be named using the 8.3 filename system (P01.TXT) and I renamed them according to them. It still doesen’t work.

Here is that part of the code

Serial.begin(9600);

 Serial.print("Initializing SD card...");
   pinMode(SS, OUTPUT);
   
  if (!SD.begin(chipSelect)) {
    Serial.println("initialization failed!");
    return;
  }
 Serial.println("initialization done.");
 show_tft();


  
for (int x = 1; x<16; x++) { 
  if (x == 1){ 
    File myFile = SD.open("P01.TXT");
   if (myFile){
  while (myFile.available()) {
    tft.println(myFile);
    char keypressed = key.getKey();
    Serial.println(keypressed);
  }
  
}

I tried the example and showed me the list of files without any problems.

Can i directly read a file from my sd module and display it on the tft shield. Maybe i have to convert it to a string or something?

You're expecting the tft software to act like a terminal display, which it isn't. So you have to write that yourself. The simplest terminal would understand things like cursor positioning , line wrap and so on.

Yeah, I missed it, you're where right, there is a '~' but, before I changed the file name, the screen would load the text i have before the initialization part, and then the screen would go white. Now after i changed the names to 'P01TXT~2.txt' as it said in the FileName example, the screen just shows the text before the initialization part and it just stays like that.

I tried to add 'tft.reset()' before the reading of the file, but with that the screen just goes blank. It seems like it still doesent read the file, or something.

I'm afraid I don't understund. The tft screen understands at least cursor positioning, i have that in my code and it Works.

How do i write my own terminal?

Broda: Yeah, I missed it, you're where right, there is a '~' but, before I changed the file name, the screen would load the text i have before the initialization part, and then the screen would go white. Now after i changed the names to 'P01TXT~2.txt' as it said in the FileName example, the screen just shows the text before the initialization part and it just stays like that.

I tried to add 'tft.reset()' before the reading of the file, but with that the screen just goes blank. It seems like it still doesent read the file, or something.

Well, if you are writing off the edge of the screen, it might be crashing the display library. The print function of the library is only designed for strings that fit on the screen.

Broda:
I’m afraid I don’t understund. The tft screen understands at least cursor positioning, i have that in my code and it Works.

How do i write my own terminal?

The way all software is written. By thinking about what something does, breaking it down into functional pieces, and then coding the pieces.

What does a terminal have to do? For example, what should happen when a character is sent to it? :slight_smile:

Yeah you are right, I adjusted the cursor and now it opens the file, but it only shows the first letter. The file beings with '1. Text' but it only writes 1 with no end. Is it becaus of the '.' ?

Broda: Yeah you are right, I adjusted the cursor and now it opens the file, but it only shows the first letter. The file beings with '1. Text' but it only writes 1 with no end. Is it becaus of the '.' ?

It would behoove you to rename all the files on your SD card to the 8.3 standard. Then you wouldn't be plagued with these doubts.

Yeah I am new to programing, I know Pascal and Delphi thats what we did in school to master the logic of codes.

The file that I am trying to display looks like this

' 1. Ovde ide tekst prvog pitanja:

a) Nije tacan odgovor b) Tacan odgovor c) Nije tacan odgovor d) Nije tacan odgovor '

It's in serbian it's not important. But i guesse I need to set a 'while' to to read the file, but until when? Am I at least on rigt track? :D

aarg: It would behoove you to rename all the files on your SD card to the 8.3 standard. Then you wouldn't be plagued with these doubts.

I did rename them all to the 8.3. Standard.

What happens when you run the example sketch that dumps the contents of a file? Make sure the file has only plain text in it, not the junk that a word processor often puts in there.

It Works fine when i show it on the serial, and i modified it to work on the display, now i just have to try it in my code! :D Thank you.

One more question, is there a way to rotate the display?

Solving one problem at a time, solved the SD modul, and the TFT, hope there will be no problem with the 4x4 keypad! :D

I know that I can insert 'delay()' but is there a way to make the text staj on the display until button click on keypad?