Getting values from sd card

Hi all,

Actually i am using ethernet shield for writing values(counter values - integer format) into sd card. Each time when the counter gets incremented, i am replacing the value in SD card file. Hence only one value present at a time. Writing works fine here.

When i try to read that value means it shows irrelevant values. i am using function here. whether read() function cant read the numbers…??

Even i also tried for string. Same error occurs. i used read function inside my lcd.print statement. Will that will be a error…??


When i store the string or number(in sd card file), always it shows some numbers in my lcd display.

Can anyone see the code?

If you want help with a problem in your code, you need to post the code that demonstrates the problem. If the sketch is large and contains a lot of code not relevant to the problem, write a minimal test sketch just to demonstrate the problem. Just the act of creating this might reveal a false assumption and help you solve the problem for yourself, but in any case it will make it easier for us to help you solve the problem.

#include <SD.h>
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins from the above pin mappings
LiquidCrystal lcd(3,9,5,6,7,8); // 

File myFile;

void setup()
  lcd.begin(16, 2);
 // Open serial communications and wait for port to open:
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only

  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin 
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output 
  // or the SD library functions will not work. 
   pinMode(10, OUTPUT);
  if (!SD.begin(10)) {
    Serial.println("initialization failed!");
    lcd.print("init fail");
  Serial.println("initialization done.");
  lcd.print("init done");


void loop() {
  lcd.print("void loop");
    // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile ="radiant.txt");
   if (myFile) {
    // read from the file until there's nothing else in it:
    while (myFile.available()) {
    // close the file:
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");

tried with both numbers as well as string. lcd displays different things than what i stored in sd card.

You're calling read twice, once to send to the LCD, once for serial. Every other character goes to Serial, the others to LCD. Get rid of one of them.

when i used only lcd.print statement, i am getting ascii values for the content. how can i convert into real values..?? Thanks in advance.

Try casting it to char: