I tried to use Arduino SD Library, I was able to run Datalogger and Dumpfile sample application to verify that the bits and bytes are written perfectly in the SD card. When I tried to read from windows, everything is null. Is there an Arduino library that can write text file compatible to windows text format?

  • Add a link to the library you are using. The example sketches might be generating a file with binary data. It would look strange if displayed with as text. – Mikael Patel Sep 12 '16 at 5:15
  • I'm guessing that the way you read the file in Windows is the issue. The file encoding at the beginning of the file is probably not specified by the Arduino program. – Code Gorilla Sep 12 '16 at 8:02
  • 3
    Maybe if you showed us what isn't working we could help you see why it isn't working and how to fix it. – Majenko Sep 12 '16 at 10:15

Notepad in Windows will show the raw data in a file - in all its hideous glory. However, there are things to make sure of:

  1. Make sure that what you write to a file is ASCII characters. By that I mean do not simply write a byte or word value, convert it to a string first:

    byte value; ...

    value = Sensor.read(); // Return a value from 0-99 Card.write(value);

The above code will write a byte of 0 to 99 to the file - but you probably don't want that! The byte 32 is a space; 65 is the capital letter A; and 97 is the lower case letter a. Say what?

Every byte is represented by a different character in Notepad, so you need to convert the byte 97 into TWO bytes - first the byte (character) 9, and then the byte (character) 7. How do you do that?

One easy way is to use the following:

byte value;
char buffer[8]; // Define once for temporary use

value = Sensor.read();
sprintf(buffer, " %d", value); // Store value in buffer as chars - with a leading space

The above will write one (or more) characters into the file depending on the value you want to print. If your existing data was just a series of 0 bytes, your old code would have been nothing but NULLs. This will (at least) print 0 0 0 0 0 0 0 0 0 0

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.