Modifications

Sauter à la navigation Sauter à la recherche
4 761 octets ajoutés ,  13 décembre 2017 à 20:41
aucun résumé de modification
Ligne 1 : Ligne 1 :  
{{FEATHER-M0-NAV}}
 
{{FEATHER-M0-NAV}}
 +
 +
== 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 {{fname|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>code.py</code> for example.)
 +
 +
== Windows ==
 +
<h2>
 +
<a href="#serial-drivers-for-windows-7" class="anchor-link"><span class="fa fa-link"></span></a><span id="serial-drivers-for-windows-7" class="anchor-link-target"></span>Serial Drivers (for Windows 7)</h2>
 +
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+.
 +
 +
<h2>
 +
<a href="#determine-your-serial-port" class="anchor-link"><span class="fa fa-link"></span></a><span id="determine-your-serial-port" class="anchor-link-target"></span>Determine Your Serial Port</h2>
 +
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'''
 +
 +
{{ADFImage|FEATHER-M0-MicroPython-REPL-01.png|640px}}
 +
 +
<h2>
 +
<a href="#install-serial-port-terminal-software" class="anchor-link"><span class="fa fa-link"></span></a><span id="install-serial-port-terminal-software" class="anchor-link-target"></span>Install Serial Port Terminal Software</h2>
 +
'''On Windows''' you'll want to use a tool like <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/">PuTTY</a> 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:
 +
 +
{{ADFImage|FEATHER-M0-MicroPython-REPL-02.png|640px}}
 +
 +
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.
 +
 +
{{ADFImage|FEATHER-M0-MicroPython-REPL-03.png|640px}}
 +
 +
== 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 <a href="https://www.iterm2.com/">iTerm2</a> 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 <code>ls /dev/tty.*</code> to view existing serial connections.
 +
 +
{{ADFImage|FEATHER-M0-MicroPython-REPL-04.png|640px}}
 +
 +
Next, plug in the board. There should be one new serial connection that is for your board. Typically on Mac OSX its something like <code>/dev/tty.usbmodem*</code> and on Linux its <code>/dev/ttyACM*</code>.
 +
 +
{{ADFImage|FEATHER-M0-MicroPython-REPL-05.png|640px}}
 +
 +
Now that we know the device name, the <code>screen</code> 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:
 +
 +
<syntaxhighlight lang="python">
 +
screen /dev/tty.board_name 115200</pre>
 +
</syntaxhighlight>
 +
 +
<syntaxhighlight lang="python">
 +
</syntaxhighlight>
 +
 +
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'''.
 +
 +
{{ADFImage|FEATHER-M0-MicroPython-REPL-06.png|640px}}
 +
 +
== 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.
 +
 +
{{ADFImage|FEATHER-M0-MicroPython-REPL-07.png|640px}}
 +
 +
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:
 +
 +
{{ADFImage|FEATHER-M0-MicroPython-REPL-08.png|640px}}
 +
 +
That's all there is to connecting to the board's serial REPL, you're ready to start typing in and running CircuitPython code!
 +
    
{{FEATHER-M0-TRAILER}}
 
{{FEATHER-M0-TRAILER}}
29 917

modifications

Menu de navigation