Ligne 1 : |
Ligne 1 : |
| {{MicroPython-Hack-Prepare-NAV}} | | {{MicroPython-Hack-Prepare-NAV}} |
− |
| |
− | {{traduction}}
| |
| | | |
| == Utiliser la carte PyBoard == | | == Utiliser la carte PyBoard == |
− | {{bloc-etroit|text=When plugged into a USB port of a computer, the pyboard appears as a disk. You can edit the main.py file on this disk, then eject it, and press the RST button on the pyboard to reboot it and execute main.py. | + | {{bloc-etroit|text=Lorsque nous branchons le Pyboard sur un port USB de notre ordinateur, la carte apparaît comme un disque. Vous pouvez éditer le fichier {{fname|main.py}} sur le disque, puis éjecter le disque, et finalement presser le bouton RST (''Reset'') pour réinitialiser la carte afin d'exécuter {{fname|main.py}}. |
| | | |
− | However, there is a more interactive way of playing with the pyboard which has a REPL (Read-Eval-Print Loop). For this, you need to connect to the /dev/ttyACM0 (Linux) or /dev/tty.usbmodemXXXX (MacOS) using a serial communication program. The Unix screen command works fine, but I prefer to use [https://www.archlinux.org/packages/community/i686/minicom/ minicom].}}
| + | Il existe cependant des façon plus interactive d'utiliser la pyboard comme le mode REPL (Read-Eval-Print Loop, boucle lecture-evaluation-affichage). Pour l'utiliser un programme de communication série (un ''Terminal'') pour vous connecter sur le périphérique /dev/ttyACM0 (sur Linux) ou /dev/tty.usbmodemXXXX (MacOS). Le programme ''screen'' sous Unix fonctionne bien mais l'auteur de ce tuto préfère utiliser [https://www.archlinux.org/packages/community/i686/minicom/ minicom] (lien ArchLinux, existe aussi sur de nombreuses distribution Linux).}} |
| | | |
| == pyterm.py == | | == pyterm.py == |
− | {{bloc-etroit|text=The following script, which I use to call {{fname|pyterm.py}}, will connect to a plugged pyboard using minicom: }} | + | {{bloc-etroit|text=Le script suivant s’appelle {{fname|pyterm.py}}, il se connecter sur la PyBoard en utilisant le programme minicom: }} |
| | | |
| <nowiki>#!/usr/bin/python | | <nowiki>#!/usr/bin/python |
Ligne 17 : |
Ligne 15 : |
| | | |
| """ | | """ |
− | Usage: pyterm [device]
| + | Utilisation: pyterm [péripherique] |
− | Calls minicom on "device". If device is not given, looks for /dev/ttyACM* devices
| + | Appelle minicom sur le "périphérique". Si le périphérique n'est pas mentionné, il |
− | (the name of the pyboard under Linux) or /dev/tty.usbmodem* devices (name of the | + | recherche les pérhophériques /dev/ttyACM* (le nom de la pyboard sous Linux) |
− | pyboard under MacOS). | + | ou les périphériques /dev/tty.usbmodem* (nom de la pyboard sous MacOS). |
| """ | | """ |
| def main(): | | def main(): |
Ligne 40 : |
Ligne 38 : |
| Avec le script {{fname|pyterm.py}}, vous pouvez démarrer une session avec la commande {{fname|./pyterm.py /dev/ttyACM1}} ou /dev/ttyACM1 est le périphérique correspondant à votre pyboard. | | Avec le script {{fname|pyterm.py}}, vous pouvez démarrer une session avec la commande {{fname|./pyterm.py /dev/ttyACM1}} ou /dev/ttyACM1 est le périphérique correspondant à votre pyboard. |
| | | |
− | Once connected, you can type Python commands and discover many possibilities of the pyboard. For instance:
| + | Une fois connecté, vous pouvez saisir des commande et découvrir de nombreuses possibilités de la PyBoard. Par exemple: |
| | | |
| <nowiki>led = pyb.LED(1) | | <nowiki>led = pyb.LED(1) |
| led.on()</nowiki> | | led.on()</nowiki> |
| | | |
− | will turn on the red LED on the pyboard.
| + | qui allumera la led rouge sur la pyboard. |
| | | |
| <nowiki>led = pyb.LED(1) | | <nowiki>led = pyb.LED(1) |
Ligne 52 : |
Ligne 50 : |
| tim = pyb.Timer(4, freq=2, callback=blink)</nowiki> | | tim = pyb.Timer(4, freq=2, callback=blink)</nowiki> |
| | | |
− | will make the red LED blink at 1Hz (it is toggled on/off at 2Hz).
| + | Fera clignoter la LED rouge a 1Hz (la LED change d'état allumé/éteind à 2Hz). |
| | | |
| == Charger du code sur le PyBoard == | | == Charger du code sur le PyBoard == |
− | For writing more complex code, there are two possibilities:
| + | Pour l'écriture de code plus complexe, il y a deux possibilités: |
| | | |
− | # edit the files on the pyboard, and load them into the REPL using import | + | # Editer le fichier sur la PyBoard puis le charger en mode REPL en utilisant la commande {{fname|import}} |
− | # edit the files on your computer, and paste them into the REPL | + | # Editer les fichiers sur votre ordinateur puis faire un copier/coller en mode REPL |
| | | |
− | The first solution works fine and is the only way to work with code that is split into different modules.
| + | La première solution fonctionne bien, c'est la seule façon de de travailler si vous avez un code réparti dans différents modules. |
| | | |
− | The second solution is perhaps easier, but you cannot paste too much text in the REPL without getting errors. You have to switch to the raw REPL by hitting Ctrl-A, pasting your code, and hitting Ctrl-D to finish the transfer. Your code will be running on the pyboard. Hit Ctrl-C to kill it if it does note terminate by itself, then hit Ctrl-B to exit the raw REPL and switch back to the friendly REPL. You can perform a soft reset of the pyboard by hitting Ctrl-D.
| + | La seconde solution est peut être la plus simple mais vous ne pouvez pas envoyer trop de texte/code dans le mode REPL sans erreur. Vous aurrez besoin de passer en mode ''raw REPL'' (REPL brute) en pressant Ctrl-A, puis coller votre code, et finaliser le transfert en pressant Ctrl-D. Votre code sera exécuté sur la PyBoard. S'il ne se termine pas par lui même, vous pouvez stopper votre code en pressant Ctrl-C, puis pressez Ctrl-B pour sortir du mode ''raw REPL'' (afin de revenir au mode REPL utilisateur). Vous pouvez effectuer une réinitialisation logiciel de votre PyBoard en pressant Ctrl-D. |
| | | |
− | Note than when using minicom, you have to hit Ctrl-A twice to send a Ctrl-A to the REPL because Ctrl-A is by default the escape key of minicom. You can use the paste file command in minicom to send a file to the REPL. For this:
| |
| | | |
− | # hit Ctrl-A twice to enter the raw REPL
| + | {{underline|Note pour les utilisateurs de minicom:}} vous aurez besoin de presser Ctrl-A deux fois pour envoyer un Ctrl-A au REPL parce que, par défaut, Ctrl-A est aussi la touche d'échappement de minicom. Vous pouvez utiliser la commande "paste file" dans minicom pour envoyer un fichier vers REPL. Pour réaliser cela avec Minicom: |
− | # hit Ctrl-A Y to execute the paste file minicom command
| |
− | # navigate to your file in the file selection screen that appears and select it
| |
− | # hit Ctrl-D to finish the transfer
| |
| | | |
− | Your file is then loaded. If it contains just definitions, hit Ctrl-B to exit the rawREPL and use the definitions in the regular REPL.
| + | # Presser Ctrl-A deux fois pour entrer en mode ''raw REPL'' |
| + | # Presser Ctrl-A Y tpour exécuter la commande "paste file" dans minicom |
| + | # Naviguer dans vos fichier apparaissant à l'écran et sélectionner le fichier à envoyer |
| + | # Presser Ctrl-D pour terminer le transfert |
| + | |
| + | Votre fichier est alors chargé. S'il ne contient que des définitions, pressez Ctrl-B pour sortir du mode ''raw REPL'' et utiliser les différentes définitions dans le mode REPL standard. |
| | | |
| == pyboard.py == | | == pyboard.py == |
| | | |
− | Another way of executing code on the pyboard is to use the {{fname|pyboard.py}} script available in the tools directory of the MicroPython git repository. Exit minicom with Ctrl-A X, then load your file onto the pyboard with pyboard.py file_to_load.py. You can connect to the REPL by launching minicom again.
| + | {{ambox|text=Une fois maîtrisé, PyBoard.py est un outil plus que pratique. Vivement recommandé par MCHobby.}} |
| | | |
− | You can modify the pyboard.py script to find the pyboard device automatically by changing the beginning of the main function as follows:
| + | Une autre façon d’exécuter du code sur votre pyboard est d'utiliser le script {{fname|pyboard.py}} disponible dans le répertoire ''tools'' du dépôt GIT MicroPython. |
| + | |
| + | Plutôt que d'utiliser minicom pour transférer le contenu un fichier sur la PyBoard, vous pouvez utiliser directement le script {{fname|pyboard.py}}. Rien ne vous empêche, par la suite, de réutiliser un programme terminal (comme minicom) pour vous reconnecter à nouveau en mode REPL. |
| + | |
| + | Vous pouvez modifier le script {{fname|pyboard.py}} pour rechercher automatiquement le périphérique "pyboard" en modifiant la fonction {{fname|main()}} comme suit: |
| | | |
| <nowiki>def main(): | | <nowiki>def main(): |
Ligne 92 : |
Ligne 95 : |
| cmd_parser.add_argument('--device', default='/dev/' + ttymodems[0], help='the serial device of the pyboard')</nowiki> | | cmd_parser.add_argument('--device', default='/dev/' + ttymodems[0], help='the serial device of the pyboard')</nowiki> |
| | | |
− | An already patched version (may not be up to date with respect to the git repository) [http://wdi.supelec.fr/boulanger/downloads/MicroPython/pyboard.py is available].
| + | Si vous désirez utiliser le script original du script {{fname|pyboard.py}}, la commande à utiliser pour charger votre fichier "mon_fichier.py" sur ma pyboard est {{fname|1=./pyboard --device=/dev/ttyACM1 mon_fichier.py}} . /dev/ttyACM1 correspond à la connexion série associée à votre PyBoard. |
| | | |
− | Si vous desirez utiliser le script original du script, la commande à utiliser pour charger votre fichier mon_fichier.py sur ma pyboard est {{fname|./pyboard --device=/dev/ttyACM1 mon_fichier.py}} . /dev/ttyACM1 correspond à la connexion série associée à votre PyBoard.
| + | == Ampy == |
| + | Ampy est un outil développé par Adafruit industrie alors que Tony Dicola produisait de la documentation pour le Feather ESP8266 Huzza. |
| + | |
| + | Il permet de réaliser les différentes opérations décrites ci-dessus mais également {{underline|le transfert de fichier vers et depuis une carte MicroPython}} par l'intermédiaire '''d'une connexion série'''. |
| + | |
| + | Il s'agit d'un outil pratique car il vous permet de conduire vos développements sur PC avec votre éditeur de texte favoris; puis transférer vos fichiers sur la carte MicroPython avant de les exécuter via une session REPL. |
| + | |
| + | {{ttuto-begin}} |
| + | |
| + | {{ttuto |
| + | |label=Téléverser & Exécuter |
| + | |descr=Téléverser des fichiers et exécuter du code avec '''Ampy'''. Un flux simple de développement. |
| + | |img=tlogo-feather-load-file.jpg |
| + | |link=FEATHER-CHARGER-FICHIER-MICROPYTHON |
| + | }} |
| + | |
| + | {{ttuto-end}} |
| + | |
| + | == RShell == |
| + | Si [[FEATHER-CHARGER-FICHIER-MICROPYTHON|Ampy]] d'Adafruit est un outil pratique et simple, '''RShell''' est un outil nettement plus puissant. |
| + | |
| + | Tout comme Ampy, '''RShell''' permet de transférer des fichiers vers (et depuis) une carte MicroPython par l'intermédiaire d'une simple connexion série. C'est donc un outil puissant et pratique. |
| + | |
| + | Par contre, RShell, ne se présente pas comme une série de commande Linux mais comme {{underline|un vrai shell dédié à MicroPython}}. Il est par ailleurs capable de supporter plusieurs cartes MicroPython connectées en même temps. |
| + | |
| + | Chez MCHobby nous avons un faible un RSheel mais il faut bien reconnaître qu'il nécessite un peu plus d'investissement que [[FEATHER-CHARGER-FICHIER-MICROPYTHON|Ampy]] mais le jeu en faut largement la chandelle. |
| + | |
| + | {{ttuto-begin}} |
| + | |
| + | {{ttuto |
| + | |label=RSHell |
| + | |descr=Transférez des fichiers et contrôlez votre carte depuis une simple connexion série. ESP8266 compatible. |
| + | |img=tlogo-micropython-Debugger.jpg |
| + | |link=MicroPython-Hack-RShell |
| + | }} |
| + | |
| + | {{ttuto-end}} |
| | | |
| == Element Fritzing == | | == Element Fritzing == |
− | I use [http://fritzing.org/ Fritzing] to draw my sketches. I have made a [http://wdi.supelec.fr/boulanger/downloads/MicroPython/pyboard.fzpz Fritzing part for the pyboard]. You can also get the SVG pictures I made for the [http://wdi.supelec.fr/boulanger/downloads/MicroPython/pyboard_PCB.svg PCB], the [http://wdi.supelec.fr/boulanger/downloads/MicroPython/pyboard_schem.svg schematics] and the [http://wdi.supelec.fr/boulanger/downloads/MicroPython/pyboard.svg icon].
| + | Mr Boulanger utilise [http://fritzing.org/ Fritzing] pour dessiner ces montage. A cette fin, il a réalisé [http://wdi.supelec.fr/boulanger/downloads/MicroPython/pyboard.fzpz un composant PyBoard pour Fritzing]. Vous pouvez également obtenir le dessin SVG pour [http://wdi.supelec.fr/boulanger/downloads/MicroPython/pyboard_PCB.svg la carte], le [http://wdi.supelec.fr/boulanger/downloads/MicroPython/pyboard_schem.svg schéma] et l' [http://wdi.supelec.fr/boulanger/downloads/MicroPython/pyboard.svg icon]. |
| | | |
− | You can see how it looks on the example below:
| + | Vous pouvez voir le résultat dans l'exemple Fritzing ci-dessous: |
| | | |
| [[Fichier:MicroPython-Hack-Outil-01.png|320px]]<small><br />Source: [http://wdi.supelec.fr/boulanger/MicroPython/ Supelec.fr]</small> | | [[Fichier:MicroPython-Hack-Outil-01.png|320px]]<small><br />Source: [http://wdi.supelec.fr/boulanger/MicroPython/ Supelec.fr]</small> |
| + | |
| + | == Codes d'exemples == |
| + | L'article de Mr Boulanger contient également quelques codes d'exemples, vous pourrez les [http://wdi.supelec.fr/boulanger/MicroPython/#Code trouver ici]. |
| | | |
| == Source et autorisation de traduction == | | == Source et autorisation de traduction == |