Dumpfile stop before to read completelly the file - Arduino Yun

Hallo,

when reading out data from SD-Card the reading stops. As you see in the link below one guy found a solution:

http://forum.arduino.cc/index.php?topic=70576.msg524117#msg524117

Unfortunately this doesn't work with the Yun board. Does anybody have a solution for this? Thanks

That thread is concerning a SD card connected through the SPI interface of the AVR, shields with a SD socket often do it that way. The SD card on the Yun is connected to the linino AR9331 processor, and works entirely differently.

See http://arduino.cc/en/Reference/YunFileIOConstructor for how to access on the AVR side, on the linino side it looks like a disc mounted on /mnt/sd.

Thanks for your answer.
I tried it with the code below. Could you kindly check what is wrong or missing ?.

#include <FileIO.h>

void setup() {

  Bridge.begin();
  Serial.begin(9600);
  FileSystem.begin();

  while (!Serial);
  delay(3000);
  Serial.println("Filesystem \n");
}


void loop () {

  File myFile = FileSystem.open("/mnt/sd/data.txt");
  if (myFile) {
    while (myFile.available()){
      Serial.write(myFile.read());
    }
    myFile.close();
  }
  else {
    Serial.println("error opening data.txt");
  }
  
  delay(10000);

}

On my Yun it does exactly what I expect from reading the code.

What do you expect it to do? What does it do?

Ask yourself: What assumptions have I made? Are they correct? What happens if they are wrong? If this happens, the answer to the last question must be no!

Yes it works with for example 50 characters but it doesn't with 1000 characters. Then the board hangs up.

You may want to look through the forum for post concerning problems with large data transfers over the bridge, “long strings” should be a good search term.

An obvious workaround would be to cut the data up into smaller pieces, using seek() lets you start reading from somewhere besides the beginning of the stream.

Ardrib: Yes it works with for example 50 characters but it doesn't with 1000 characters. Then the board hangs up.

1000 characters? Reading from the SD, at once? You do realize that you have only 2.5KB of RAM total on the 32u4 side, with less than that available for your (real) sketch, don't you? :astonished:

Ralf

Hi All,
I have the same problem.

It seems that the File::doBuffer() function, for some files (?), returns wrong number of available characters.
I think it’s due to the bridge.transfer function that returns TRANSFER_TIMEOUT (0xFFFF), that is casted to an uint8_t, so it becomes 255, but BUFFER_SIZE is only 64, so we have inconsistent data: the File::Available() returns 254, and if you try to use read(), it reads outside the buffer.

I don’t knok if it depends on filesize or something else, but I tried with different files, all 101 bytes, they differs only on the \n position. in the attached file the \n is at position 21. with bigger values (f.i. if the first line is longer and the second one is shorter) I have no problem.

Ralf, we’re not reading all the file at once, we read char by char, in the while loop.

here is my code:

#include <FileIO.h>

void setup() {

  Bridge.begin();
  Serial.begin(9600);
  FileSystem.begin();

  while (!Serial);
  delay(3000);

  Serial.println("Filesystem Initialized\n");

  File myFile = FileSystem.open("/mnt/sda1/80.txt", FILE_READ);
  if (myFile) {
    while (myFile.available()){
      Serial.write(myFile.read());
    }
    myFile.close();
  }
  else {
    Serial.println("error opening 80.txt");
  }
  
}

void loop() {
}

80.txt (101 Bytes)

Vjncenzo:
Ralf, we’re not reading all the file at once, we read char by char, in the while loop.

I don’t have a spare micro-SD card to play with right now, I will see if I can pick one up today or tomorrow morning and play around with this.
I wonder if this is still a “running out of RAM” issue, by the way how the stream is handled… :~

Ralf

Vjncenzo please open an issue on github, it looks like we must fix this https://github.com/arduino/YunBridge

My 2 cents I have similar problems with my arduino mega connected to a yun (but sending from arduino to linino). I think the serial class has a problem (there is an issue for that as well on github) which manifests in both directions. I think this issue has hardly been noticed until now because 1) you only have it when the serial buffers go full 2) because the arduino ide monitor resets the arduino it solves the problem when it occurred. 3) PC's are normally so fast sending to pc's will hardly cause the problem. 4) not many people send huge amount of stuff from pc to arduino As yun is not so fast as a pc (and has a serial rate higher than most people use on pc) the problem is more likely to pop up there. Best regards Jantje

Hi Federico I opened https://github.com/arduino/YunBridge/issues/12 and it has been solved.

Thanks! Vjncenzo


the answer I had is: may you look the content of the file /usr/bin/run-bridge and check if the exec line contains the flag -u ? The whole file should look to something like:

#!/bin/sh

cd /usr/lib/python2.7/bridge

exec python -u bridge.py 2> /tmp/bridge.py-stderr.log

Vjncenzo you may want to upgrade the image (see my signature): it contains a lot of fixes including this one