Modifications

Sauter à la navigation Sauter à la recherche
3 819 octets ajoutés ,  28 novembre 2017 à 10:32
aucun résumé de modification
Ligne 1 : Ligne 1 :  
{{FEATHER-M0-EXPRESS-NAV}}
 
{{FEATHER-M0-EXPRESS-NAV}}
 +
 +
Let's get blinky going with CircuitPython to explore the way we can write code and confirm everything is working as expected.
 +
 +
== code.py ==
 +
After plugging in a board with CircuitPython into your computer a CIRCUITPY drive will appear. At first, the drive may be empty but you can create and edit files on it just like you would on a USB drive. On here, you can save a '''code.py''' ('''code.txt''' and '''main.py''' also work) file to run every time the board resets. This is the CircuitPython equivalent of an Arduino sketch. However, all of the compiling is done on the board itself. ''All you need to do is edit the file.''
 +
 +
{{ADFImage|FEATHER-M0-MicroPython-Blinky-01.png|640px}}
 +
 +
So, fire up your favorite text editor, such as Notepad on Windows, TextEdit on Mac or <a href="https://atom.io/">download Atom</a> (my favorite), and create a new file. In the file copy this:
 +
 +
<pre><code class="prettyprint">import digitalio
 +
import board
 +
import time
 +
 +
led = digitalio.DigitalInOut(board.D13)
 +
led.direction = digitalio.Direction.OUTPUT
 +
while True:
 +
    led.value = not led.value
 +
    time.sleep(0.5)
 +
</code>
 +
</pre>
 +
Now, save the file to the drive as <code class="prettyprint">code.py</code> (<code class="prettyprint">main.py</code> or <code class="prettyprint">code.txt</code> also works). After a brief time, the board's red LED should begin to flash every second.
 +
 +
 +
{{traduction}}
 +
No class registered in CONVERSION_CLASS for section build-alert alert-danger
 +
<nowiki>
 +
<div class="alert">
 +
<i class='fa fa-exclamation-circle'></i>
 +
Do not click the RESET button after saving your code file! It could cause the computer to not-finish writing your code to disk. Just wait a few seconds and it should automatically restart the python code for you!
 +
</nowiki>
 +
 +
== Status LED (Gemma/Trinket/Metro/Feather) ==
 +
If you have a Gemma, Trinket, Metro or Feather running CircuitPython, there's a single RGB LED on the board to help you know what's up. While '''code.py''' is running the status neopixel will be solid green. After it is finished, the neopixel will fade green on success or flash an error code on failure. Red flashes happen when data is written to the drive.
 +
 +
 +
{{ambox|text= Circuit Playground Express does not have this status LED}}
 +
 +
=== Debugging ===
 +
Did the status LED flash a bunch of colors at you? You may have an error in your code. Don't worry it happens to everyone. Python code is checked when you run it rather than before like Arduino does when it compiles. To see the CircuitPython error you'll need to connect to the serial output (like Arduino's serial monitor).
 +
 +
See <a href="https://learn.adafruit.com/micropython-basics-how-to-load-micropython-on-a-board/serial-terminal">this guide</a> for detailed instructions.
 +
 +
If you are new to Python try googling the error first, if that doesn't find an answer feel free to drop by the <a href="https://forums.adafruit.com/viewforum.php?f=60">support forum</a>.
 +
 +
== Libraries ==
 +
Using libraries with CircuitPython is also super easy. Simply drag and drop libraries onto the CIRCUITPY drive or into a <code class="prettyprint">lib</code> folder on the drive to keep it tidy.
 +
 +
Find CircuitPython libraries on GitHub using the <a href="https://github.com/search?q=topic%3Acircuitpython">topic</a> and through our <a href="https://learn.adafruit.com/category/circuitpython">tutorials</a>.
 +
 +
Make sure the libraries are for CircuitPython and not MicroPython. There are some differences that may cause it to not work as expected.
 +
 +
== More info ==
 +
 +
* <a href="https://learn.adafruit.com/category/micropython">Guides and Tutorials</a>
 +
* <a href="https://circuitpython.readthedocs.io/en/latest/">API Reference</a>
 +
* <a href="https://forums.adafruit.com/viewforum.php?f=60">Adafruit forum</a>
 +
* <a href="https://github.com/search?q=topic%3Acircuitpython">Libraries</a>
 +
    
{{FEATHER-M0-EXPRESS-TRAILER}}
 
{{FEATHER-M0-EXPRESS-TRAILER}}
29 917

modifications

Menu de navigation