0

SD Module + LCD = Issue
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

SD Module + LCD = Issue

by Ganderra on Sun Aug 04, 2019 2:34 am

Hey so I have an SD card and module (SD Card FAT32) and I have a file that is Raw text from a .txt format
text is literally just;
CS - 2.8 - 4/8

but when it prints the code onto the lcd I just get a string of numbers (67323246323247)
and on serial its a different string DUEDATES.txt; S-28-48

Code;
Code: Select all | TOGGLE FULL SIZE
if(!key2S) {

        Serial.println("Key 2 has been pressed");
        lcd.clear();


        delay(100);

        lcd.print("Due Dates");

        myFile = SD.open("DUEDATES.txt");

        if (myFile) {
          Serial.println("DUEDATES.txt;");

          lcd.setCursor(0,1);
     
          // read from the file until there's nothing else in it:
          while (myFile.available()) {
           
          lcd.print(myFile.read());
          Serial.write(myFile.read());
          }

          myFile.close();

        }

Any ideas to fix?

Could it be with the Baud I'm using
I set it to 57600 because that's what the RTC uses on my board

Ganderra
 
Posts: 9
Joined: Thu Aug 09, 2018 12:55 am

Re: SD Module + LCD = Issue

by adafruit_support_mike on Sun Aug 04, 2019 5:00 pm

The numbers are the ASCII values of the characters. Use a type cast to make Serial.write() recognize them as characters:

Code: Select all | TOGGLE FULL SIZE
    Serial.write( (char)( myFile.read() ) );

adafruit_support_mike
 
Posts: 58856
Joined: Thu Feb 11, 2010 2:51 pm

Re: SD Module + LCD = Issue

by Ganderra on Sun Aug 04, 2019 5:16 pm

Fixed It :)
Got a friend to help,
Code: Select all | TOGGLE FULL SIZE
        myFile = SD.open("DUEDATES.txt");

        if (myFile) {
          Serial.println("DUEDATES.txt;");

          lcd.setCursor(0,1);
     
          // read from the file until there's nothing else in it:
          while (myFile.available()) {

            byte nextByte = myFile.read();
           
            lcd.print((char) nextByte);
            Serial.write((char) nextByte);

          }

          myFile.close();

        }


Ganderra
 
Posts: 9
Joined: Thu Aug 09, 2018 12:55 am

Re: SD Module + LCD = Issue

by adafruit_support_mike on Mon Aug 05, 2019 11:58 am

Glad to hear it. Happy hacking!

adafruit_support_mike
 
Posts: 58856
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.