0

I was planning on building a current logging device with an Arduino, and tried starting off with the basic SD-card write example from the Arduino IDE sketchbook.

The Serial console showed no errors, so I assumed everything worked perfectly.

However... when I inserted the card in my computer (Ubuntu 18.04) and opened it with gedit, the file was blank? Vim had the same behaviour: it was blank.

But... when I used cat on the file, it DID show the contents?!

Anyone have a clue what I did wrong here?

EDIT: in reponse to Bodo's question:

output of cat:

... TEST TEST TEST TEST TEST TEST 372,345,324 342,340,330 331,332,328 327,325,324 322,320,318 317,315,313 313,310,309 ... 

(This is what's supposed to be in there)

out put of ls -l:

total 16 -rw-r--r-- 1 myname myname 15161 Jan 1 2000 DATALOG.TXT 

output of od -c -tx1 DATALOG.TXT | head -1 :

0000000 \r \n \r \n \r \n \r \n \r \n \r \n \r \n \r \n 

This last one answerd the question to me... It shows a bunch of newlines. But really... A LOT... This explains why gedit and vim showed empty files. I have to scroll down for ages before seeing the actual data. When using cat, I only saw the trailing lines, so it showed the contents. Probably something that went wrong when saving the data to the SD-card. Thanks Bodo! You solved my problem merely by posing a question :D

5
  • 1
    Show the output of ls -l /location/of/your/sdcard. What does cat yourfile show? Or od -c -tx1 yourfile | head -10? Commented Feb 27, 2019 at 10:50
  • @Bodo: I added the outputs to the question. But... by executing those, I was able to figure it out (see edit). Thanks a lot! Commented Feb 27, 2019 at 10:56
  • 1
    @Opifex I suggest you answer the question instead of editing the question. Should be helpful to figure out for others in future. Commented Feb 27, 2019 at 11:02
  • Relevant: Can I answer my own question? Commented Feb 27, 2019 at 11:02
  • 1
    Ok, will do! Thanks @Atul and @KamilMaciorowski! Commented Feb 27, 2019 at 11:04

1 Answer 1

1

As already shown in the edit, here's the answer:

executing od -c -tx1 DATALOG.TXT | head -1

gave me this:

0000000 \r \n \r \n \r \n \r \n \r \n \r \n \r \n \r \n 

This hinted me that the file might have a bunch of newlines at the beginning, with the contents trailing. This turned out to be the case. That is why the file appeared empty in gedit and vim, but not with cat. Because I would only see the last lines of cat in terminal.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.