Différences entre versions de « FEATHER-CHARGER-FICHIER-MICROPYTHON-BOOT »

De MCHobby - Wiki
Sauter à la navigation Sauter à la recherche
Ligne 5 : Ligne 5 :
  
 
Ces fichiers contiennent du code MicroPython qui sera exécuté lorsque la carte est mise sous-tension ou réinitialisée (en pressant le bouton "reset"). Ces fichiers sont:
 
Ces fichiers contiennent du code MicroPython qui sera exécuté lorsque la carte est mise sous-tension ou réinitialisée (en pressant le bouton "reset"). Ces fichiers sont:
* {{fname|/boot.py}}: Ce fichier est le {{underline|premier}} à être exécuté lorsque la carte est mise sous-tension (ou réinitialisée). Il doit contenir du code de bas niveau qui sera exécuté pour achever la séquence de boot/démarrage de la carte. You typically don't need to modify boot.py unless you're customizing or modifying MicroPython itself. However it's interesting to look at the contents of the file to see what happens when the board boots up. Remember you can use the ampy '''get''' command to read this and any other file!
+
* {{fname|/boot.py}}: Ce fichier est le {{underline|premier}} à être exécuté lorsque la carte est mise sous-tension (ou réinitialisée). Il doit contenir du code de bas niveau qui sera exécuté pour achever la séquence de boot/démarrage de la carte. Il n'est habituellement pas nécessaire de modifier {{fname|boot.py}} à mois d'avoir besoin de personnaliser ou modifier MicroPython. Il est intéressant de prendre connaissance du contenu de ce fichier pour en apprendre plus sur la séquence de boot d'une carte. Vous pouvez utiliser la commande {{fname|get}} de ampy pour voir facilement le contenu de ce fichier!
* {{fname|/main.py}} - If this file exists it's run '''after''' boot.py and should contain any main script that you want to run when the board is powered up or reset.
+
* {{fname|/main.py}}: Si ce fichier existe, sont contenu est exécuté {{underline|après}} le fichier boot.py . Ce fichier devrait contenir votre script principal (celui à exécuter automatiquement au démarrage de la carte). Exactement comme pour un croquis Arduino qui est exécuté automatiquement lorsque la carte est mise sous tension..<br />Ecrivez un fichier {{fname|main.py}} sur une carte MicroPython et son contenu sera automatiquement exécuté à la mise sous tension.
  
The {{fname|main.py}} script is what you can use to have your own code run whenever a MicroPython board powers up.  Just like how an Arduino sketch runs whenever the Arduino board has power, writing a {{fname|main.py}} to a MicroPython board will run that code whenever the MicroPython board has power.
+
Vous pouvez éditer le contenu du fichier {{fname|main.py}} et {{fname|boot.py}} en utilisant [[FEATHER-CHARGER-FICHIER-MICROPYTHON-FILEOP|les opérations sur fichier proposés par ampy]].  
  
You can create and edit the {{fname|main.py}} on a board [[FEATHER-CHARGER-FICHIER-MICROPYTHON-FILEOP|using the file operations in ampy]].  For example create a {{fname|test.py}} on your computer and put the following Python code inside it:
+
Par exemple, nous allons créer un fichier {{fname|test.py}} sur notre ordinateur et copier le contenu suivant à l'intérieur:
  
 
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
Ligne 29 : Ligne 29 :
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Then copy the file to {{fname|/main.py}} on a connected MicroPython board with '''ampy's''' put command:
+
Nous allons ensuite copier le contenu de test.py dans le fichier {{fname|/main.py}} de notre carte MicroPython avec la commande {{fname|put}} de ampy:
  
  <nowiki>ampy --port /serial/port put test.py /main.py</nowiki>
+
  <nowiki>ampy --port /port/serie put test.py /main.py</nowiki>
  
 
Reset the board or unplug it and plug it back in, then connect to the serial REPL and notice the board is counting numbers!  The {{fname|main.py}} code started as soon as the board finished booting.
 
Reset the board or unplug it and plug it back in, then connect to the serial REPL and notice the board is counting numbers!  The {{fname|main.py}} code started as soon as the board finished booting.

Version du 13 novembre 2016 à 16:33


MCHobby investit du temps et de l'argent dans la réalisation de traduction et/ou documentation. C'est un travail long et fastidieux réalisé dans l'esprit Open-Source... donc gratuit et librement accessible.
SI vous aimez nos traductions et documentations ALORS aidez nous à en produire plus en achetant vos produits chez MCHobby.

Il y a deux fichiers important dans le système de fichier MicroPython. Ils se trouvent tout deux dans le répertoire racine du système de fichier.

Ces fichiers contiennent du code MicroPython qui sera exécuté lorsque la carte est mise sous-tension ou réinitialisée (en pressant le bouton "reset"). Ces fichiers sont:

  • /boot.py: Ce fichier est le premier à être exécuté lorsque la carte est mise sous-tension (ou réinitialisée). Il doit contenir du code de bas niveau qui sera exécuté pour achever la séquence de boot/démarrage de la carte. Il n'est habituellement pas nécessaire de modifier boot.py à mois d'avoir besoin de personnaliser ou modifier MicroPython. Il est intéressant de prendre connaissance du contenu de ce fichier pour en apprendre plus sur la séquence de boot d'une carte. Vous pouvez utiliser la commande get de ampy pour voir facilement le contenu de ce fichier!
  • /main.py: Si ce fichier existe, sont contenu est exécuté après le fichier boot.py . Ce fichier devrait contenir votre script principal (celui à exécuter automatiquement au démarrage de la carte). Exactement comme pour un croquis Arduino qui est exécuté automatiquement lorsque la carte est mise sous tension..
    Ecrivez un fichier main.py sur une carte MicroPython et son contenu sera automatiquement exécuté à la mise sous tension.

Vous pouvez éditer le contenu du fichier main.py et boot.py en utilisant les opérations sur fichier proposés par ampy.

Par exemple, nous allons créer un fichier test.py sur notre ordinateur et copier le contenu suivant à l'intérieur:

###########################################################################
# Setup code goes below, this is called once at the start of the program: #
###########################################################################
import time
print('Hello world! I can count:')
i = 1

while True:
    ###################################################################
    # Loop code goes inside the loop here, this is called repeatedly: #
    ###################################################################
    print(i)
    i += 1
    time.sleep(1.0)  # Delay for 1 second.

Nous allons ensuite copier le contenu de test.py dans le fichier /main.py de notre carte MicroPython avec la commande put de ampy:

ampy --port /port/serie put test.py /main.py

Reset the board or unplug it and plug it back in, then connect to the serial REPL and notice the board is counting numbers! The main.py code started as soon as the board finished booting.

Putting all the pieces of this guide together you can see a simple workflow for MicroPython that's similar to Arduino & Arduino sketches:

  • Write Python code on your computer using your favorite text editor. Structure the code so it puts setup code at the top and loop code inside a main loop.
  • Use the ampy run command with the --no-output option to run the script on the MicroPython board.
  • Edit and run the script as much as you need for it to work the way you expect.
  • When you want the code to automatically run on boot use the ampy put command to save the script as a /main.py file on the board.

That's all there is to loading files & running code on MicroPython boards!


Source: MicroPython Basics: Load Files & Run Code
Créé par Tony DiCola pour AdaFruit Industries.

Traduit par Meurisse D. pour MCHobby

Toute référence, mention ou extrait de cette traduction doit être explicitement accompagné du texte suivant : «  Traduction par MCHobby (www.MCHobby.be) - Vente de kit et composants » avec un lien vers la source (donc cette page) et ce quelque soit le média utilisé.

L'utilisation commercial de la traduction (texte) et/ou réalisation, même partielle, pourrait être soumis à redevance. Dans tous les cas de figures, vous devez également obtenir l'accord du(des) détenteur initial des droits. Celui de MC Hobby s'arrêtant au travail de traduction proprement dit.

Traduit avec l'autorisation d'AdaFruit Industries - Translated with the permission from Adafruit Industries - www.adafruit.com