Limit to file.write() ?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
cooper
Posts: 23
Joined: Mon Oct 20, 2014 8:40 am

Limit to file.write() ?

Post by cooper » Tue Mar 29, 2016 1:27 pm

Hi,

Is there a limit to the amount of bytes one can write to the SD card in one go? I have been trying to log a string of about 900 bytes long, sometimes this works and most of the time I get OSError 5. Once that happens I can no longer write to the file unless I close it and open another.

I have also stuffed in a routine which split the string into 100 byte sized chunks if it detects anything bigger than 100 bytes. This seems to fix the OSError issue but is there an underlying issue which is causing this to occur? This happens for the latest (stable) release, 1.5.2 and 1.4.2

Thanks,
Cooper

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Limit to file.write() ?

Post by pythoncoder » Tue Mar 29, 2016 2:00 pm

I can't replicate this. Might there be a problem with your SD card?

Code: Select all

MicroPython v1.6-99-g42bc25b-dirty on 2016-03-02; PYBv1.0 with STM32F405RG
Type "help()" for more information.
>>> 
>>> with open('/sd/rats.txt', 'w') as f:
...     s = 'the quick brown fox jumps over the lazy dog\n'
...     f.write(s*100)
... 
4400
>>>  
/mnt/qnap2/data/Projects/MicroPython/micropython-epaper> cat /sd/rats.txt
the quick brown fox jumps over the lazy dog
the quick brown fox jumps over the lazy dog
the quick brown fox jumps over the lazy dog
[and so on, ad nauseam]
Peter Hinch
Index to my micropython libraries.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Limit to file.write() ?

Post by Roberthh » Tue Mar 29, 2016 3:06 pm

I had an OS Error 5 when reading more that 511 bytes at once after seek or read to a position which is not a multiple of 4. Transferring 511 bytes and less works. According to your description, that could be the case here too (about 900 fails, chunks of 100 pass). See https://github.com/micropython/micropython/issues/1863
As a temporary fix, I used splitting, hoping that this behavior will be fixed sometime. It's limited to PyBoard & SD card.
Regards

cooper
Posts: 23
Joined: Mon Oct 20, 2014 8:40 am

Re: Limit to file.write() ?

Post by cooper » Wed Mar 30, 2016 7:02 am

@pythoncoder my SD card is definitely ok, as this occurs with other cards.

@Roberthh thank you for the link to the bug, it does sound consistent with the issues I am having. I shall continue to use the chopping scheme until the issue has been solved.

Thank you both for your reply and assistance!

Post Reply