0

I am trying to load some variables from an SD card on the start up of my arduino Uno. I have been given some advice but am unable to communicate at the same hours. Using this advice, I have the following edited code, but it doesn't work and I believe that it's my implementation that is the problem. All help would be greatly appreciated.

myFile = SD.open("test.txt", FILE_READ);
    if (myFile) {
        while (myFile.available()) {
            myFile.read();

            km = myFile.parseInt();
            kmTemp = myFile.parseFloat();
            kmrevs = myFile.parseInt();
            miles = myFile.parseInt();
            milesTemp = myFile.parseFloat();
            milesrevs = myFile.parseInt();

            }
        myFile.close();
        }
    else {
        Serial.println("Read Error");
    }
  • 1
    How is it not working? Describe further. And what is actually written in the file you want to read? – chrisl May 6 '18 at 13:55
  • The program gathers/calculates 6 pieces of data which is then saved to a text file on an SD card. The text file displays the 6 pieces of data in a vertical list. On power up of the arduino, I am trying to make the program read these 6 bits of data, assigning the values to 6 different variables before the program hits the loop (this script is within setup() if that eliminates a question). – user4163554 May 6 '18 at 14:08
  • When ran and then restarted the data output is at the programs defaults of '0' & '0.000000' where floats apply....not the data that is saved on the disk. – user4163554 May 6 '18 at 14:09
  • You still have not listed the file from your SDCard. Make sure you are using a plain text editor for this. For example, Microsoft Word or Adobe Framemaker would add an unbelievable amount of overhead that would confuse the parsing library. – st2000 May 6 '18 at 15:43
  • what is actually written in the file you want to read? please answer this question. – Gerben May 6 '18 at 15:44
1

in you previous question, where I answered, you had no commas or new-lines in the example file content. the parseInt and parseFloat ignores only spaces by default.

remove the commas or read them or ignore them with parseInt parameter SKIP_ALL

km = myFile.parseInt(SKIP_ALL);
  • Hi there is no commas, it's just in the comments section, whenever I press enter it posts the message instead of starts a new line....so I used commas to seperate the different data. – user4163554 May 6 '18 at 21:47
  • Hi Juraj. I have to admit, I have never analysed anything as much as your two answers. I feel that my bank holiday was no longer wasted as I have finally worked out what you meant. All is rolling amazingly now and it's just what I wanted. Thank you. – user4163554 May 8 '18 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.