Go Down

Topic: Bug in SD library? File.available() issue (Read 2506 times) previous topic - next topic



Hopefully this is the right forum for this... I'm using an Arduino Uno paired with SparkFun's MP3 player shield. The File.available() function in the SD library for Arduino 022 seems to be reporting spurious information, at least for me. Originally in my loop, I had it walk through reading files off the SD card in 32 byte chunks and using available() to track how many bytes remained in the file. But after much confusion and serial output debugging, I was able to nail down that available() was not reporting accurately. It would decrement properly with each read() but it never started in the right place! For one of my files it always reported it as only 7734 bytes long before the first read() (which is a tenth of my file's size) and for the second file it consistently reported a negative number.

File.size() works just fine for me. I rewrote my code to use that function and then track how many bytes I read out of the file within my sketch. So my program is running great now (and actually playing the whole file out through audio when it should). But I figured I should report this. could this something going wrong that's unique to my SD card? (I know those can be quirky sometimes.) Or is this an actual bug in Arduino's SD library?



Sounds like its overflowing. According to the doc, it returns an int which will overflow at 32767 or 65535 depending if its signed or unsigned.
Avoid throwing electronics out as you or someone else might need them for parts or use.
Solid state rectifiers are the only REAL rectifiers.
Resistors for LEDS!


Ah. Yeah that would explain it. I wonder why it isn't coded to use long instead of int? Oh well. Like I said, size() works fine and it only takes a little bit of extra code to rely on that function instead.


Reported as issue - http://code.google.com/p/arduino/issues/detail?id=571 -

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)


Cool, thanks for logging that! I suppose I should have thought about finding and putting that in some sort of bug reporting repository. At least it looks like the fix will be easy enough for the next patch.

Go Up