Différences entre versions de « ENG-CANSAT-PICO-LOG »
Ligne 33 : | Ligne 33 : | ||
[[Fichier:ENG-CANSAT-PICO-LOG-10.png|480px]] | [[Fichier:ENG-CANSAT-PICO-LOG-10.png|480px]] | ||
+ | |||
+ | === Writing and data lost === | ||
+ | xxxx | ||
+ | |||
{{ENG-CANSAT-PICO-TRAILER}} | {{ENG-CANSAT-PICO-TRAILER}} |
Version du 7 mars 2022 à 00:32
MicroPython File System
MicroPython board does fits an internal file system. This means that Python language on a MicroPython board can also manage files!
On a MicroPython board, you can manage files and directories. Creating them, deleting them, adding data to them, etc.
As any good implementation of Python, MicroPython can manage text files and binary files.
MicroPython file system (~100Kio) is not as large as a computer file system (10+ Gigabytes). Do not manipulate/write large amount of data on a MicroPython file-system. |
Data Logging on MicroPython
Doing data logging with MicroPython is quite easy. You just open a file and write data into it like you will do with any Python code.
Writing data to text file
The following example adds lines to the 'file.txt'. The with statement will automatically close the file when the code gets out of the with scope.
with open( 'file.txt', 'a' ) as _file:
_file.write( "Hey, it is MicroPython\r\n" )
Notes:
- The 'a' parameter in the open() call stand for "append". So executing several times the code will append the same text again and again to the file.
- IF the file doesn't exists yet THEN it will be automatically created.
- Use the 'w' parameter (instead of 'a') to overwrite the file content.
- As the write() just writes bytes then the the carriage return and line feed (\r\n) must also be written.
The following screen capture do show the 'file.txt' on the pico file system (do not hesitate to refresh the file list) and the file content is displayed on the file pane.
Writing and data lost
xxxx
Written by Meurisse D. for MCHobby