# SD-card read problem

**URL:** <https://forum.xod.io/t/sd-card-read-problem/4261>\
**Category:** XOD Programming Questions\
**Created:** [July 23, 2020, 6:12pm UTC](https://forum.xod.io/t/sd-card-read-problem/4261 "2020-07-23T18:12:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lucianobonfil](https://avatars.discourse-cdn.com/v4/letter/l/3ab097/32.png) [@lucianobonfil](https://forum.xod.io/u/lucianobonfil)\
**Post date:** [July 23, 2020, 6:12pm UTC](https://forum.xod.io/t/sd-card-read-problem/4261/1 "2020-07-23T18:12:07Z")

</div>

Hello. I have a few month programing with XOD. I´m not c++ programer, but i have a general idea. I´m trying to make a node to read from a .txt file into de SD-card. I´v succes making a “file erase” node. But when i store information into the file with sd-log, then i read with the new node, it´s shows only one digit and it seems that it´s on hexadecimal format. I mean that into the file is the number 21 saved, but the node only reads the first digit “2”, and shows it like in byte format plus 30. For example: 32, but then output in decimal: 50. Simplyfing: i saved 2, but reads 32, and shows me 50. I post the code here. It´s based on the sd-log. The “while (myFile.available())” doesn´t work, so y hide from the code with dash //. I´v edited the node with a byte output that displays the 32 i mean. Also i linked the table of conversion by refference. Thanks alot.

#pragma XOD evaluate\_on\_pin disable  
#pragma XOD evaluate\_on\_pin enable input\_W  
#pragma XOD error\_raise enable

{{#global}}  
#include \<SPI.h\>  
#include \<SD.h\>  
{{/global}}

struct State {  
bool begun;  
};

{{ GENERATED\_CODE }}

void evaluate(Context ctx) {  
auto state = getState(ctx);  
if (!isInputDirty\<input\_W\>(ctx))  
return;

```
if (!state->begun) {
    // First time use, initialize
    auto csPin = getValue<input_CS>(ctx);
    state->begun = SD.begin(csPin);
}
if (!state->begun) {
    raiseError(ctx);
    return;
}

```

char filename[16] = { 0 };  
dump(getValue\<input\_FILE\>(ctx), filename);  
// re-open the file for reading:  
File myFile = SD.open(filename, O\_READ);  
if (myFile) {  
// while (myFile.available()){  
emitValue\<output\_OUT\>(ctx, myFile.read());  
// }  
} else {  
state-\>begun = false;  
raiseError(ctx); // Can’t open file  
return;  
}  
// close the file:  
myFile.close();  
emitValue\<output\_DONE\>(ctx, 1);

}

 ![XOD_SD-READ-LOG](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/4/430cfcf7aeafd3192b5595e41c70002417595d24.jpeg)

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [July 23, 2020, 8:34pm UTC](https://forum.xod.io/t/sd-card-read-problem/4261/2 "2020-07-23T20:34:09Z")

</div>

My guess would be that your logging converts number to string. Reading the first byte returns the “letter” 2, which in ASCII is hex 32 or decimal 50. You will either need to change logging to write the number to SD (which could be done in many different formats) or read in the string and convert it to a number instead of just casting (the programming equivalent of assuming) it as a number.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/1X/eb7348baa04192c2ef932d1db54d44f09f8a7888.png) [@system](https://forum.xod.io/u/system)\
**Post date:** [August 22, 2020, 8:34pm UTC](https://forum.xod.io/t/sd-card-read-problem/4261/3 "2020-08-22T20:34:19Z")

</div>

Closed on August 22, 2020, 8:34pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
