1

I want to read the data from the text file and want to show it on the Arduino Serial Monitor. SO Below is the code which I extracted from

Code extracted from!

#include<SD.h> 
File myfile;
void setup(){

Serial.begin(9600);

Serial.print("Initializing card...");

// declare default CS pin as OUTPUT
pinMode(53, OUTPUT);

if (!SD.begin(4)) {
  Serial.println("initialization of the SD card failed!");
  return;
}
Serial.println("initialization of the SDcard is done.");

// open the text file for reading:
myfile = SD.open("help2.txt");
if (myfile){
     Serial.println("help2.txt:");

     // read all the text written on the file
     while (myfile.available()){
         Serial.println(myfile.read());
     }
     // close the file:
     myfile.close();
} 
else {
    // if the file didn't open, report an error:
    Serial.println("error opening the text file!");
}
}

void loop(){
}

But when the code is compiled and uploaded on the Arduino, only "Initializing card..." is printing on the serial monitor. I want to get whole data which is present in the text file on the serial monitor.

lokesh
  • 108
  • 3
  • 17
  • You're going to have to debug your code. Which if statement is entered? Is the while loop entered? Is the file in place? Is it being found? – Kevin Workman Jun 08 '16 at 12:48
  • @lokesh From what you describe it sounds like the initialization success or failure prints aren't reached. Try to add another test println just after ```pinMode(53,OUTPUT);```. This of course assuming the circuit and pins are correctly configured – George Profenza Jun 08 '16 at 13:00
  • @GeorgeProfenza I add the println after pinMode, now it goes inside the if condition and also prints "initialization of the SD card failed!". While I want to get the data from file. – lokesh Jun 08 '16 at 13:48
  • @Kevin I tried a lot but I am not able to solve the problem that's why I posted it on stack overflow. I am not asking you for the code, what I want is just a little help. – lokesh Jun 08 '16 at 13:50
  • @lokesh I am trying to help you. The best way I can help you is getting you to answer those questions. You need to understand exactly **what** your code is doing before we can understand **why** your code is doing that. – Kevin Workman Jun 08 '16 at 13:53
  • @lokesh You're making progress debugging the issue. Double your circuit and your SD card before retrying: e.g. make sure you're got the wires connected to the pin numbers you expect, make sure the sd card is formatted to a supported file system (I remember using SD cards on Arduino many years ago and I had to format cards to FAT16 as FAT32 was not supported), etc.) – George Profenza Jun 08 '16 at 13:55
  • @Kevin Thanks but if you can tell my flaw then it will be a great help – lokesh Jun 08 '16 at 13:57
  • @GeorgeProfenza I am using Arduino Uno(1.6.9) where I want to get a file from my computer and process it in arduino to get the desired output – lokesh Jun 08 '16 at 14:06
  • @lokesh We can't really tell you where your flaw is without you trying to narrow down exactly which line isn't behaving how you expect. That's why I'm trying to get you to answer those questions. But George knows this stuff much better than I do, so I'll stop stepping on his toes now! :p – Kevin Workman Jun 08 '16 at 14:21
  • @lokesh The text file goes from your computer to the SD card, correct ? If so, please check if the SD Card is formatted using FAT16 filesystem. What are you using to connect the SD Card to your Arduino ? Kevin, don't worry mate, you're not stepping on any toes. Narrowing down the exact issue is what everyone with a code issue should do – George Profenza Jun 08 '16 at 15:40
  • @lokesh Are you able to share an image of your circuit ? That might help – George Profenza Jun 08 '16 at 16:00
  • @ George thing is that I had connected the Arduino board model uno from desktop via cable and running it on Arduino 1.6.9 which is an open source software. I want to display the data of a text file that is stored in my harddisk(computer) on the Arduino 1.6.9 software's Serial monitor screen. I hope you got my point – lokesh Jun 08 '16 at 16:32
  • @lokesh Sorry, it's not making a lot of sense right now. If you want to send data from text file on your computer to Arduino, one line at time you can simply use [Serial.write()](https://www.arduino.cc/en/Serial/Write). You can't store too much data on the Arduino though because it doesn't have a lot of memory. The more important question is what do you do with data your receive from your computer ? Also, based on your code above I assumed you wanted to copy a text file from your hard drive to an SD card, use an SD reader shield for Arduino and read the text data from the text file on SD card. – George Profenza Jun 08 '16 at 18:27

0 Answers0