FEATHER-M0-MicroPython-REPL

De MCHobby - Wiki
Sauter à la navigation Sauter à la recherche


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.

Introduction

CircuitPython sends the output of the .py files it runs to the connected computer over USB serial. So, to view the output of your code from print statements and any errors that occur you'll need to connect to the serial console.

Also, because CircuitPython is a variant of Python, it too has a read-evaluate-print-loop or  'REPL' for short. The REPL lets you run individual commands and load up code interactively and is therefore great for testing a new idea. However, the code typed into the REPL isn't saved anywhere so make sure and save it elsewhere (like code.py for example.)

Windows

Serial Drivers (for Windows 7)

If you are using Windows 7 you will need to install drivers. Click below to download the driver package and install it! This is not necessary for Mac, Linux or Windows 10+.

Download-icon.pngTélécharger les pilotes Adafruit pour Windows

Vous pouvez également retrouver le lien de téléchargement directement depuis cette page du tutoriel Adafruit

Determine Your Serial Port

Next you must determine the name of the serial port for your board.  It's easiest to look at the serial ports with the board disconnected (on Windows check Device Manager under the Ports (COM/LPT) node

It will be named something like Adafruit Circuit Playground, Adafruit Gemma M0, Adafruit Trinket M0 or Adafruit Feather M0

{{{2}}}
Crédit: AdaFruit Industries www.adafruit.com

Install Serial Port Terminal Software

On Windows you'll want to use a tool like PuTTY to connect to the serial port.  Download and run PuTTY, then configure it to use a serial connection to the board's COM port at 115200 baud similar to as shown below:

{{{2}}}
Crédit: AdaFruit Industries www.adafruit.com

After clicking Open you should see a new window pop up with the current output from the running code. If no code is running, it may be blank so hit Ctrl - C to get to the REPL prompt.

FEATHER-M0-MicroPython-REPL-03.png
Crédit: AdaFruit Industries www.adafruit.com

Mac OSX and Linux

Connecting to the serial terminal on is more straightforward than on Windows. Neither OS requires additional drivers.

First open a terminal program. On Mac OSX, Terminal comes installed and iTerm2 can be downloaded. On Linux there are a variety available such as gnome-terminal (called Terminal) and Konsole on KDE.

Now before plugging in the board, type ls /dev/tty.* to view existing serial connections.

FEATHER-M0-MicroPython-REPL-04.png
Crédit: AdaFruit Industries www.adafruit.com

Next, plug in the board. There should be one new serial connection that is for your board. Typically on Mac OSX its something like /dev/tty.usbmodem* and on Linux its /dev/ttyACM*.

FEATHER-M0-MicroPython-REPL-05.png
Crédit: AdaFruit Industries www.adafruit.com

Now that we know the device name, the screen command can be used to connect to the serial port. Its installed on Mac OSX by default but Linux users may need to install it using their package manager. Run the following command to connect at 115200 baud:

screen /dev/tty.board_name 115200


Where /dev/tty.board_name is the name of the board's serial port.

When you're done using screen most versions of it allow you to exit by pressing Ctrl-a then k then y or pressing Ctrl-a then typing :quit and pressing enter.

FEATHER-M0-MicroPython-REPL-06.png
Crédit: AdaFruit Industries www.adafruit.com

Using the REPL

After you're connected to the serial REPL try pressing enter to confirm you see the >>> prompt.  You can also type help() and press enter on most boards to see basic usage information.

FEATHER-M0-MicroPython-REPL-07.png
Crédit: AdaFruit Industries www.adafruit.com

If you can't get a >>> prompt to appear try pressing Ctrl-c a couple times to interrupt any running program on the board.

You might get a Traceback and KeyboardInterrupt that lets you know the current Python program has stopped, and you'll get a prompt:

FEATHER-M0-MicroPython-REPL-08.png
Crédit: AdaFruit Industries www.adafruit.com

That's all there is to connecting to the board's serial REPL, you're ready to start typing in and running CircuitPython code!



Source: Adafruit Feather M0 Basic Proto créé par LadyAda pour AdaFruit Industries. Crédit [www.adafruit.com AdaFruit Industries]

Traduit par Meurisse D. pour MCHobby.be

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

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.