O
O
oc1tane2017-12-10 01:31:20
Arduino
oc1tane, 2017-12-10 01:31:20

Arduino. How to write data to an array from an SD card?

The bottom line is this, it turns out to write data to a memory card for temporary storage:

File dataFile = SD.open("datalog.txt", FILE_WRITE);

  if (dataFile) {
    dataFile.println(dataString);
    dataFile.close(); }

With a slight change, we get a file that contains an array of the following form:
6, 233, 453, 323, 676, 213, 673

Unfortunately, I can’t figure out how to properly get data from the sd card into a variable. I created an array
int mass[РАЗМЕР ПОЛУЧАЕТСЯ СЧИТЫВАЕМ ПЕРВОГО ЭЛЕМЕНТА МАССИВА С КАРТЫ];

but then I can’t write the array values ​​​​from the memory card element by element, this example does not suit me:
myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    myFile.close();

As I understand it, reading from the port goes by bytes and you need to somehow implement the parsing of commas and the length of the array value, because it can be one character (5) or maybe three (246). Please tell me how to implement it so that it is possible to output data from the sd card to an array without mistakenly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vanyamba-electronics, 2017-12-10
@vanyamba-electronics

You can use   sscanf() . Read a string from the port, then parse it into numbers.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question