Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to read from SD inside of tasks #4

Closed
sjkelleyjr opened this issue Jul 17, 2016 · 4 comments
Closed

Unable to read from SD inside of tasks #4

sjkelleyjr opened this issue Jul 17, 2016 · 4 comments
Assignees

Comments

@sjkelleyjr
Copy link

When I create a task to read from the SD card using:

File myFile = SD.open("temp.txt",FILE_READ);

The file can't be opened. I tried placing noInterrupts(); in various places with no luck, as well as increasing the stack size for the task.

I can both read and write from the same file in the setup, the issue only occurs when placing the code in a task.

@feilipu feilipu self-assigned this Jul 17, 2016
@Sailanarmo
Copy link

Sailanarmo commented Jul 19, 2016

I can confirm,

If I run the following piece of code I can write to the SD Card. If I run it in a task, it will create the text file, however it will not write anything to it.

File myBaro = SD.open("test.txt", FILE_WRITE);
baro.readBaro();
Serial.println(baro.getPressure());
myBaro.println("This should be working.");
myBaro.println(baro.getPressure());
delay(200);
myBaro.close();

Again, in setup it works 100%, but in a task for whatever reason it will not write to the SD Card.

@feilipu
Copy link
Owner

feilipu commented Jul 19, 2016

I've had a quick look at this, and the Serial() class is used for writing text to the SD card.
There is a known issue with the Serial() class library. See issue #3. This same issue is probably occurring.

  Serial.print("Sensor Value: "); \\  Correctly prints the text "Sensor Value: "
  Serial.println(sensorValue);  \\  just a blank, but newline & CR are printed.

I'm still trying to figure out what is the underlying cause of entanglement. My suspicion is that it is to do with namespace and variable declaration.

@feilipu feilipu added the bug label Jul 19, 2016
@sjkelleyjr
Copy link
Author

It looks like we got it working by opening the file in the setup and leaving it open in the task. IE, the file should already be opened by the time the task gets a hold of it.

@feilipu
Copy link
Owner

feilipu commented Jul 21, 2016

That's good to hear.

I'm certain there is a String() class issue underlying this issue though.

The only avenue I have to investigate is the potential for a variable declaration / freeing issue in the difference between the Arduino implementation, where setup() and loop() are both called by the main() function and hence may have corresponding variable space, and the FreeRTOS case where main() is never called directly. But, I haven't nailed down anything concrete yet.

I've done a bit of investigation, and it seems necessary to declare Strings as Global variables, otherwise they get allocated each time the Task for() loop is run, and then reserve() space for them, to prevent reallocation. Also, conversion of int to String seems somehow problematic.

Some working code is here, on Issue #3, for reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants