Modifications

Sauter à la navigation Sauter à la recherche
2 936 octets supprimés ,  23 septembre 2018 à 19:47
Ligne 2 : Ligne 2 :     
== Forewords ==  
 
== Forewords ==  
{{traduction}}
   
One of the most exciting feature of the M0 Express board is this small FLASH chip wired on the SPI bus. That memory could be used to provide lot of services like storing files, python script and many more.
 
One of the most exciting feature of the M0 Express board is this small FLASH chip wired on the SPI bus. That memory could be used to provide lot of services like storing files, python script and many more.
   Ligne 91 : Ligne 90 :  
Just check twice that you closed the file system (otherwise you way lost data or even the complete file)!
 
Just check twice that you closed the file system (otherwise you way lost data or even the complete file)!
   −
== Lecture et affichage de fichiers ==
+
== Read and display file content ==
L'exemple '''fatfs_print_file''' ouvrira un fichier (le fichier data.csv par défaut, le fichier créé par l'exemple '''fatfs_datalogging''' présenté ci-dessus) et affiche tout son contenu dans le moniteur série. Ouvrez l'exemple '''fatfs_print_file''' et téléversez le sur votre carte Feather M0, puis ouvrez le moniteur série (à 115200 baud).
+
The example '''fatfs_print_file''' would open a file (the file {{fname|data.csv}} per default, the file created with the '''fatfs_datalogging''' example) then it displays the file content in the serial monitor. Open the '''fatfs_print_file''' sketch and upload it to the Feather M0 board before opening the serial monitor (at 115200 baud).
   −
Vous devriez voir le croquis afficher le contenu du fichier data.csv (si la mémoire flash ne contient pas de fichier data.csv alors vous pouvez ouvrir l'exemple datalogging ci-dessus pour le créer).
+
You should see the content of the data.csv file (if the Flash Memory doesn't yet have the data.csv file, then run the datalogging example to create it).
   −
Voyez le contenu de la fonction {{fname|setup()}} pour comprendre comment s'effectue la lecture du fichier:
+
Please, see the content of {{fname|setup()}} function to understant how to read a file:
    
<syntaxhighlight lang="c">
 
<syntaxhighlight lang="c">
   // Ouvrir le fichier en lecture et vérifier s'il est correctement ouvert
+
   // Open the file in read only mode (check if opens succeed).
   // Le mode FILE_READ ouvre le fichier en lecture.
+
   // The FILE_READ opens the file to read it.
 
   File dataFile = fatfs.open(FILE_NAME, FILE_READ);
 
   File dataFile = fatfs.open(FILE_NAME, FILE_READ);
 
   if (dataFile) {
 
   if (dataFile) {
     // Le fichier a été ouvert.  
+
     // The file is now open.  
     // Afficher le contenu caractère par caractère jusqu'à
+
     // Display the content char by char until the
     // la fin du fichier.
+
     // end of file.
     Serial.println("Fichier ouvert, contenu affiché ci-dessous:");
+
     Serial.println("File open, content displayed here under:");
 
     while (dataFile.available()) {
 
     while (dataFile.available()) {
       // Utilisé la fonction read() pour lire le prochain caractère.
+
       // Use the read() function to extract next char.
       // Il est également possible d'utiliser des fonctions telles
+
       // The readUntil or readString functions can also be use.
      //    que readUntil, readString, etc.
+
       // See the exemple fatfs_full_usage for more information.
       // Voyez l'exemple fatfs_full_usage pour plus de détails.
   
       char c = dataFile.read();
 
       char c = dataFile.read();
 
       Serial.print(c);
 
       Serial.print(c);
Ligne 118 : Ligne 116 :  
</syntaxhighlight>
 
</syntaxhighlight>
   −
Tout comme pour l'écriture de donnée dans l'exemple datalogging, il est nécessaire de créer un objet '''File''' en appelant la fonction '''open''' de l'objet fatfs. Cependant, cette fois, le mode utilisé est '''FILE_READ''', indiquant que l'on désire lire le système de fichier.
+
In the same way as datalogging example, you need to create a '''File''' object by calling the '''open''' method of the {{fname|fatfs}} object.  
   −
Après avoir ouvert le fichier en lecture, la fonction '''available''' permet de facilement savoir si des données sont disponibles dans le fichier. Ensuite, la fonction '''read''' permet de lire un caractère depuis le fichier. La combinaison de ces deux fonctions permet de réaliser facilement une boucle de lecture qui vérifie la disponibilité de donnée puis la lecture et l'affichage de celle-ci (un caractère à la fois).
+
This time, the mode used to access the file is '''FILE_READ''' indicating our intention to read the content of the file.
   −
Il existe également des fonctions de lecture avancées que vous pouvez voir dans l'exemple '''fatfs_full_usage''' ou soit dans la [https://www.arduino.cc/en/reference/SD documentation de la classe SD d'Arduino] (la bibliothèque Flash SPI implémente les mêmes fonctions).
+
Once the file open in read mode, the '''available''' function let you know if some data are available in the file. Then, the '''read''' function read a byte from the file. The combination of those 2 functions allow us to create a read loop which check the availability of date before reading it (on byte at the time).
   −
== Exemple complet d'utilisation de la Flash ==
+
It also exists advanced read functions like those used in the '''fatfs_full_usage''' and explained indide the [https://www.arduino.cc/en/reference/SD Arduino SD class documentation] (the Flash SPI library implements the same functions).
Vous pouvez vous référer à l'exemple '''fatfs_full_usage''' pour une démonstration complète concernant la lecture et l'écriture de fichiers. Cet exemple utilise toutes les fonction de la bibliothèque et démontre des opérations tels que le test d'existence d'un fichier, la création de répertoire, effacement de fichier, effacement de fichier, etc.
     −
Rappelez vous que la bibliothèque SPI flash est conçue pour exposer les mêmes fonctions et mêmes interfaces que la [https://www.arduino.cc/en/reference/SD la bibliothèque SD d'Arduino]. Par conséquent, les code et exemples stockant des données sur une carte SD seront très facile à adapter pour fonctionner avec la bibliothèque SPI flash. Créez simplement un objet fatfs comme dans les exemples ci-dessus et utilisez la fonction open sur cet objet (en lieu et place de la fonction globale). Une fois que vous avez obtenu une référence sur un fichier, toutes les fonctions et utilisations sont identiques entre la bibliothèque SPI flash et la bibliothèque SD d'Arduino!
+
== Full Flash example ==
 +
The '''fatfs_full_usage''' is a complete example demonstrating reading and writing operations on files. This example use all the library functions and advanced feature like file existence, folder creation, file wiping, etc.
   −
== Lire et écrire des fichiers CircuitPython ==
+
Remember that SPI Flash library is designed to expose the same interface than [https://www.arduino.cc/en/reference/SD Arduino's SD library]. So the codes and samples storing data on SD card would would be easy to adapt to the SPI Flash library. Just create a {{fname|fatfs}} object like the examples here upper. You will also have to use the {{fname|open}} method on the object (instead of the global open function). Once the reference to the file object, all the functions and usages would be identifcal between the SPI Flash and Arduino's SD library!
L'exemple '''fatfs_circuitpython''' montre comment lire et écrire des fichiers sur la mémoire flash de sorte qu'ils puissent être accéssible depuis CircuitPython/MicroPython. Cela signifie que vous pouvez exécuter un programme CircuitPython sur votre carte pour y stocker des données, puis utiliser un croquis Arduino qui utilise cette bibliothèque pour interagir avec ces mêmes données.
     −
Notez qu'avant d'utiliser l'exemple '''fatfs_circuitpython''' vous '''devez''' avoir chargé CircuitPython sur votre carte. [[FEATHER-M0-MicroPython|Voyez ce guide pour charger la dernière version de CircuitPython]] afin que le système de fichier CircuitPython soit écrit et initialisé sur la puce Flash. Une fois CircuitPython chargé sur la carte, vous pouvez exécuter le croquis '''fatfs_circuitpython'''.
+
== Read and Write CircuitPython files ==
 +
The example '''fatfs_circuitpython''' demonstrate how to read and write the files from the SPI Flash from CircuitPython file system. This means that you can execute CircuitPython script to store data in the CircuitPython file system, then use an Arduino sketch using this library to interact with those data.
   −
Pour exécuter le croquis, il faut le charger dans Arduino IDE et le téléverser sur la carte Feather M0. Ensuite, il faut ouvrir le moniteur série à 115200 baud. Vous devriez voir des messages s'afficher lorsqu'il essaye de lire et écrire des fichiers sur la mémoire Flash.
+
Note: before running the exemple '''fatfs_circuitpython''' you '''must''' have loaded the CircuitPython on the board. [https://learn.adafruit.com/adafruit-feather-m0-express-designed-for-circuit-python-circuitpython/what-is-circuitpython|Please, see the Adafruit's M0 Express guide] to initialize the CircuitPython file system in the SPI Flash. Once the CircuitPython loaded on the board, you can execute the sketch '''fatfs_circuitpython'''.
   −
Plus spécifiquement, l'exemple cherche les fichiers '''boot.py''' et '''main.py''' (puisque CircuitPython exécute ces fichiers au démarrage) et affiche leur contenu. Puis il ajoute une ligne à la fin du fichier '''data.txt''' présent sur la carte (le fichier est créé s'il n'existe pas encore). Après avoir exécuté le croquis, vous pouvez recharger CircuitPython sur la carte et charger et lire le fichier '''data.txt''' depuis CircuitPython!
+
To execute the sketch, you have to load it inside Arduino IDE then upload it to the Feather M0 board. Then, you have to open a serial monitor a 115200 baud. You should see messages displayed when the sketch tries to read and write files on the Flask memory.
   −
Voyons un peu le code du croquis pour comprendre comment lire et écrire des fichiers CircuitPython. Pour commencer une instance de la classe '''Adafruit_M0_Express_CircuitPython''' est crée en lui passant un instance de la classe SPIFlash (permettant d'accéder à la mémoire Flash):
+
Specifically, the example looks for the files '''boot.py''' and '''main.py''' (since CircuitPython execute thos file when starting the board) to display their content. After, the sketch add a line at the end of the '''data.txt''' file available in the CircuitPython file system (the file is created if not yet existing).
 +
 
 +
When done, you can reload CircuitPython on the board to load and read the  exécuté le croquis, vous pouvez recharger CircuitPython sur la carte pour lire le fichier '''data.txt''' directement depuis CircuitPython!
 +
 
 +
Let's have a loot to the sketch code to understant how to read and write files in CircuitPython. First, an instance of the '''Adafruit_M0_Express_CircuitPython''' class is created with the instance of the SPIFlash class (SPIFlash is used to access the Flash content):
    
<syntaxhighlight lang="c">
 
<syntaxhighlight lang="c">
#define FLASH_SS      SS1                    // broche SSP de la Flash
+
#define FLASH_SS      SS1                    // SSP pin from Flash
#define FLASH_SPI_PORT SPI1                  // port SPI surlequel est branché la mémoire Flash
+
#define FLASH_SPI_PORT SPI1                  // SPI port where the Flash is wired
   −
Adafruit_SPIFlash flash(FLASH_SS, &FLASH_SPI_PORT);    // Utiliser le bus SPI matériel
+
Adafruit_SPIFlash flash(FLASH_SS, &FLASH_SPI_PORT);    // Use the hardware SPI bus  
   −
// Il est possible d'utiliser d'autres broches comme bus SPI (SPI logiciel)!
+
// Other pins can also be used for the SPI bus (software SPI)!
 
//Adafruit_SPIFlash flash(SCK1, MISO1, MOSI1, FLASH_SS);
 
//Adafruit_SPIFlash flash(SCK1, MISO1, MOSI1, FLASH_SS);
   −
// Pour finir, créer un objet Adafruit_M0_Express_CircuitPython qui offre un accès
+
// Finally, create an Adafruit_M0_Express_CircuitPython object to gain access
// à une interface de type Carte SD pour interagir avec les fichiers stockés dans
+
// to a SD alike interface. The Adafruit_M0_Express_CircuitPython would allow
// le système de fichier Flash de CircuitPython.
+
// the sketch to access the CircuitPython file system stored inside the Flash.
 
Adafruit_M0_Express_CircuitPython pythonfs(flash);
 
Adafruit_M0_Express_CircuitPython pythonfs(flash);
 
</syntaxhighlight>
 
</syntaxhighlight>
   −
En utilisant la classe '''Adafruit_M0_Express_CircuitPython''' vous obtenez un objet de type ''système de fichier'' compatible avec en lecture et écriture avec le formattage de la mémoire Flash de CircuitPython. C'est très important pour l'interopérabilité entre CircuitPython et Arduino étant donné que CircuitPython dispose d'un partitionnement spécifique et d'un agencement particulier de la mémoire flash qui n'est pas compatible avec des bibliothèque plus "simple" (que vous pourriez rencontrer dans les autres exemples).
+
By using the '''Adafruit_M0_Express_CircuitPython''' class, you get a "File System" objet type compatible with read/write operations over a CircuitPython file system. This point is important for the interoperability between CirctuitPython and Arduino. CircuitPython use a particular partitioning of the Flash which is not compatible simpler library (like those mentionned in another examples).
   −
Une fois l'instance de la classe '''Adafruit_M0_Express_CircuitPython''' créée (instance appelée '''pythonfs''' dans le croquis) vous pouvez interagir avec elle comme s'il s'agissait de la [https://www.arduino.cc/en/Reference/SD bibliothèque carte SD d'Arduino]. Vous pouvez ouvrir des fichiers en lecture ou écriture, créer des répertoires, effacer des fichiers et répertoires et plus encore.
+
One the '''Adafruit_M0_Express_CircuitPython''' class instance created  (instance named '''pythonfs''' in the sketch) you can interact with the file system like [https://www.arduino.cc/en/Reference/SD an Arduino's SD library]. You can open files in read/write mode, create folder, drop files and folders (and even more).
   −
Voici un croquis qui vérifie la présence du fichier '''boot.py''' et affiche sont contenu (un caractère à la fois):
+
Here a sketch looking for the '''boot.py''' file and displaying its content on the screen (char by char):
    
<syntaxhighlight lang="c">
 
<syntaxhighlight lang="c">
   // Vérifie si le fichier boot.py existe puis affiche le contenu.
+
   // Check the boot.py file existence THEN display it on the screen
 
   if (pythonfs.exists("boot.py")) {
 
   if (pythonfs.exists("boot.py")) {
 
     File bootPy = pythonfs.open("boot.py", FILE_READ);
 
     File bootPy = pythonfs.open("boot.py", FILE_READ);
     Serial.println("Afficher boot.py...");
+
     Serial.println("Display boot.py...");
 
     while (bootPy.available()) {
 
     while (bootPy.available()) {
 
       char c = bootPy.read();
 
       char c = bootPy.read();
Ligne 173 : Ligne 175 :  
   }
 
   }
 
   else {
 
   else {
     Serial.println("Pas de fichier boot.py...");
+
     Serial.println("No boot.py file...");
 
   }
 
   }
 
</syntaxhighlight>
 
</syntaxhighlight>
   −
Notez l'appel de la fonction '''exists''' qui vérifie la présence du fichier boot.py, puis l'utilisation de la fonction '''open''' pour ouvrir celui-ci en mode lecture (''read'' en anglais''). Une fois fichier ouvert vous obtenez une référence vers un objet de la classe File  qui permet de lire et écrire dans le fichier comme s'il s'agissait d'un périphérique Serial (encore une fois, [https://www.arduino.cc/en/Reference/SD toutes les fonctions de la classe File] sont identiques à celle de la classe carte SD).
+
Le file write operation is also very simple, the following sketch will add data to the '''data.txt''' file:
 
  −
Dans ce cas, la fonction '''available''' retournera le nombre d'octets (''bytes'') restant à lire jusqu'à la fin du fichier -et- la fonction '''read''' lit un caractère à la fois (pour l'afficher sur le moniteur série).
  −
 
  −
L'écriture d'un fichier est tout aussi simple, voici comment le croquis ajoute des données dans le fichier '''data.txt''':
      
<syntaxhighlight lang="c">
 
<syntaxhighlight lang="c">
   // Créer et ajouter des données dans le fichier data.txt  
+
   // Create and add data in the file data.txt  
   // puis ajouter un retour à la ligne.
+
   // then append a carriage return.
   // Le code CircuitPython pourra, plus tard, ou consulter
+
   // Later, the CircuitPython script will be able to
   // le contenu de ce fichier!
+
   // read the file content!
 
   File data = pythonfs.open("data.txt", FILE_WRITE);
 
   File data = pythonfs.open("data.txt", FILE_WRITE);
 
   if (data) {
 
   if (data) {
     // Ajouter une nouvelle ligne de donnée:
+
     // Add a new line of data:
     data.println("Un bonjour a CircuitPython de la part d Arduino!");
+
     data.println("A great day to CircuitPython from our beloved Arduino sketch!");
 
     data.close();
 
     data.close();
     // Voir les autre exemples fatfs comme fatfs_full_usage  
+
     // See also the examples from the fatfs_full_usage  
     // et fatfs_datalogging pour plus d'exemples concernant
+
     // and fatfs_datalogging for mode information about
     // les interactions avec les fichiers.
+
     // interaction with files.
     Serial.println("Nouvelle ligne ajoutée au fichier data.txt!");
+
     Serial.println("A new line was added to the data.txt file!");
 
   }
 
   }
 
   else {
 
   else {
Ligne 203 : Ligne 201 :  
</syntaxhighlight>
 
</syntaxhighlight>
   −
Cette fois encore, la fonction '''open''' est utilisée pour ouvrir le fichier si ce n'est que cette fois, le fichier est ouvert en lecture (''write'' en anglais). Dans ce mode, le fichier est ouvert en ajout (les données sont ajoutées en fin de fichier) si ce dernier existe. A noter le mode écriture crée le fichier si celui-ci n'existe pas. Une fois le fichier ouvert, les fonctions tels que '''print''' et '''println''' peuvent être utilisées pour écrire des données dans le fichier (juste comme envoi des données vers le moniteur série). Une fois le traitement terminé, la fonction '''close''' ferme le fichier!
+
== Access to the SPI Flash ==
 +
Arduino is not able to expose himself as a storage device (a "''mass storage''" device). Instead you will have to switch to CircuitPython to expose the SPI Flash as storage device. Here is the technique to use:
 +
* Start the bootloader of the Express board. Drag and drop the last version of the '''circuitpython''' (the UF2 file).
 +
* After a while, you should see a '''CIRCUITPY''' drive containing the file '''boot_out.txt'''. Great, the Circuit Python filesystem is initialized on the SPI Flash.
 +
* Open the Arduino IDE and upload the '''fatfs_circuitpython''' sketch available in the Adafruit's SPI FLASH library. Open the serial console and start the sketch. Voila! the CircuitPython file system is properly mounted and the file '''data.txt''' created and initialized.
   −
Voilà, nous en avons terminé avec les opérations fondamentales de lecture et d'écriture. Voyez l'exemple '''fatfs_full_usage''' pour un apercu des fonctionnalités avancées tels que la création de répertoire, effacement de fichiers et répertoires, obtention de la taille d'un fichier, etc!  Rappelez vous que pour interagir avec les fichiers CircuitPython, il faudra utiliser la classe '''Adafruit_Feather_M0_CircuitPython''' comme indiqué dans l'exemple ci-dessus!
+
{{ambox|text=So, the Arduino Sketch did manipulated a file onto the SPI Flash owning the CircuitPython filesystem!}}
   −
== Accéder à la Flash SPI ==
+
{{ADFImage|FEATHER-M0-ArduinoIDE-SPI-Flash-02.png}}
Arduino n'est malheureusement pas capable d'exposer un périphérique de stockage (dit "''mass storage''" en anglais). Par conséquent, il faut utiliser CircuitPython qui, lui, est capable de faire cela pour nous. Voici la technique à utiliser.Here's the full technique:
  −
* Démarrer le bootloader de votre carte Express. Faites un glisser/déposer de la dernière version du fichier uf2 '''circuitpython'''.
  −
* Après un moment, vous devriez voir apparaître le lecteur '''CIRCUITPY''' contenant un fichier '''boot_out.txt'''. Voilà, le système de fichier est initialisé sur la Flash SPI.
  −
* Ouvrez maintenant Arduino IDE et téléversez l'exemple '''fatfs_circuitpython''' disponible dans la bibliothèque SPI d'Adafruit. Ouvrez la console série pour démarrer le croquis. Voilà, le système de fichier CircuitPython sera correctement monté et le fichier '''data.txt''' créé et initialisé.
     −
{{ADFImage|FEATHER-M0-ArduinoIDE-SPI-Flash-02.png}}
+
This time, we will open the file created by the Arduino sketch.
   −
* Revenons sur notre ordinateur, redémarrez le bootloader de la carte Express --ET-- re-glissez/re-déposez '''circuitpython.uf2''' sur le lecteur '''BOOT''' rendu accessible par le bootloader. Voilà, CircuitPython est résintallé sur la carte Express.
+
* Let plug again the board on the computer, restart the bootloader on the Express board --AND-- drag/drop  the '''circuitpython.uf2''' on the drive '''BOOT''' made accessible by the bootloader. Great, CircuitPython is now installed (again) on the board.
* Au bout d'un moment, le lecteur '''CIRCUITPY''' redevient accessible. Celui-ci expose a nouveau le système de fichier MicroPython de la Flash SPI. Vous pouvez maintenant voir le fichier '''data.txt''', l'ouvrir et en consulté le contenu!
+
* After a a while, the '''CIRCUITPY''' drive is made available by CircuitPyhton. This would expose the SPI Flash content as a Mass Storage device. You can now see the file '''data.txt''' created by our Arduino Sketch, Open it and read it's content :-) !
    
{{ADFImage|FEATHER-M0-ArduinoIDE-SPI-Flash-03.png}}
 
{{ADFImage|FEATHER-M0-ArduinoIDE-SPI-Flash-03.png}}
   −
Une fois que votre croquis de datalogging Arduino fonctionne comme attendu, vous pouvez simplifier la procédure en copiant '''CURRENT.UF2''' depuis le lecteur '''BOOT''' pour faire une copie de sauvegarde de votre programme Arduino. Vous pourrez ensuite charger CircuitPython pour accéder au système de fichier de la Flash SPI et enfin recopier votre '''CURRENT.UF2''' sur le lecteur '''BOOT''' de la carte Express pour réactiver votre croquis Arduino!
+
Once your datalogging sketch finish, you can simplify the procedure by copying the '''CURRENT.UF2''' from the '''BOOT''' drive to make "ready to use copy" of your sketch. You could now load the CircuitPython to access the CircuitPython file system and then switch back to you Arduino sketch by restoring the '''CURRENT.UF2''' on the Express Board!
    
{{ENG-CANSAT-TRAILER}}
 
{{ENG-CANSAT-TRAILER}}
29 836

modifications

Menu de navigation