2019-04-16 19:40:16 -04:00
|
|
|
CircuitPython
|
|
|
|
=============
|
2018-02-20 20:34:59 -05:00
|
|
|
|
2019-04-16 19:40:16 -04:00
|
|
|
.. image:: https://s3.amazonaws.com/adafruit-circuit-python/CircuitPython_Repo_header_logo.png
|
2018-12-28 14:43:14 -05:00
|
|
|
|
|
|
|
|Build Status| |Doc Status| |License| |Discord|
|
2018-02-20 20:34:59 -05:00
|
|
|
|
2019-05-04 16:14:43 -04:00
|
|
|
`circuitpython.org <https://circuitpython.org>`__ \| `Get CircuitPython <#get-circuitpython>`__ \|
|
2019-04-16 19:40:16 -04:00
|
|
|
`Documentation <#documentation>`__ \| `Contributing <#contributing>`__ \|
|
|
|
|
`Branding <#branding>`__ \| `Differences from Micropython <#differences-from-micropython>`__ \|
|
|
|
|
`Project Structure <#project-structure>`__
|
2018-02-20 20:34:59 -05:00
|
|
|
|
2019-04-17 13:48:11 -04:00
|
|
|
**CircuitPython** is a *beginner friendly*, open source version of Python for tiny, inexpensive
|
2019-04-16 19:40:16 -04:00
|
|
|
computers called microcontrollers. Microcontrollers are the brains of many electronics including a
|
|
|
|
wide variety of development boards used to build hobby projects and prototypes. CircuitPython in
|
|
|
|
electronics is one of the best ways to learn to code because it connects code to reality. Simply
|
|
|
|
install CircuitPython on a supported board via drag and drop and then edit a ``code.py`` file on
|
|
|
|
the CIRCUITPY drive. The code will automatically reload. No software installs are needed besides a
|
|
|
|
text editor (we recommend `Mu <https://codewith.mu/>`_ for beginners.)
|
2018-02-20 20:34:59 -05:00
|
|
|
|
2019-04-16 19:40:16 -04:00
|
|
|
CircuitPython features unified Python core APIs and a growing list of 150+ device libraries and
|
|
|
|
drivers that work with it. These libraries also work on single board computers with regular
|
|
|
|
Python via the `Adafruit Blinka Library <https://github.com/adafruit/Adafruit_Blinka>`_.
|
2018-02-20 20:34:59 -05:00
|
|
|
|
2019-04-17 13:48:11 -04:00
|
|
|
CircuitPython is based on `MicroPython <https://micropython.org>`_. See
|
|
|
|
`below <#differences-from-micropython>`_ for differences. CircuitPython development is sponsored by
|
|
|
|
`Adafruit <https://adafruit.com>`_ and is available on their educational development boards. Please
|
|
|
|
support both MicroPython and Adafruit.
|
2018-02-20 20:34:59 -05:00
|
|
|
|
2019-04-16 19:40:16 -04:00
|
|
|
Get CircuitPython
|
|
|
|
------------------
|
2018-02-20 20:34:59 -05:00
|
|
|
|
2019-04-16 19:40:16 -04:00
|
|
|
Official binaries for all supported boards are available through
|
2019-04-16 20:33:13 -04:00
|
|
|
`circuitpython.org/downloads <https://circuitpython.org/downloads>`_. The site includes stable, unstable and
|
|
|
|
continuous builds. Full release notes and assets are available through
|
2019-04-16 19:40:16 -04:00
|
|
|
`GitHub releases <https://github.com/adafruit/circuitpython/releases>`_ as well.
|
2018-02-20 20:34:59 -05:00
|
|
|
|
|
|
|
Documentation
|
|
|
|
-------------
|
|
|
|
|
|
|
|
Guides and videos are available through the `Adafruit Learning
|
|
|
|
System <https://learn.adafruit.com/>`__ under the `CircuitPython
|
2019-04-16 19:40:16 -04:00
|
|
|
category <https://learn.adafruit.com/category/circuitpython>`__. An API
|
2018-05-14 13:50:06 -04:00
|
|
|
reference is also available on `Read the Docs
|
|
|
|
<http://circuitpython.readthedocs.io/en/latest/?>`__. A collection of awesome
|
|
|
|
resources can be found at `Awesome CircuitPython <https://github.com/adafruit/awesome-circuitpython>`__.
|
|
|
|
|
|
|
|
Specifically useful documentation when starting out:
|
|
|
|
|
|
|
|
- `Welcome to CircuitPython <https://learn.adafruit.com/welcome-to-circuitpython>`__
|
|
|
|
- `CircuitPython Essentials <https://learn.adafruit.com/circuitpython-essentials>`__
|
|
|
|
- `Example Code <https://github.com/adafruit/Adafruit_Learning_System_Guides/tree/master/CircuitPython_Essentials>`__
|
2018-02-20 20:34:59 -05:00
|
|
|
|
|
|
|
Contributing
|
|
|
|
------------
|
|
|
|
|
|
|
|
See
|
|
|
|
`CONTRIBUTING.md <https://github.com/adafruit/circuitpython/blob/master/CONTRIBUTING.md>`__
|
|
|
|
for full guidelines but please be aware that by contributing to this
|
|
|
|
project you are agreeing to the `Code of
|
|
|
|
Conduct <https://github.com/adafruit/circuitpython/blob/master/CODE_OF_CONDUCT.md>`__.
|
|
|
|
Contributors who follow the `Code of
|
|
|
|
Conduct <https://github.com/adafruit/circuitpython/blob/master/CODE_OF_CONDUCT.md>`__
|
|
|
|
are welcome to submit pull requests and they will be promptly reviewed
|
2018-03-21 22:11:24 -04:00
|
|
|
by project admins. Please join the
|
2019-05-09 12:53:31 -04:00
|
|
|
`Discord <https://adafru.it/discord>`__ too.
|
2018-02-20 20:34:59 -05:00
|
|
|
|
2019-04-16 19:40:16 -04:00
|
|
|
Branding
|
|
|
|
------------
|
|
|
|
|
|
|
|
While we are happy to see CircuitPython forked and modified, we'd appreciate it if forked releases
|
|
|
|
not use the name "CircuitPython" or the Blinka logo. "CircuitPython" means something special to
|
|
|
|
us and those who learn about it. As a result, we'd like to make sure products referring to it meet a
|
|
|
|
common set of requirements.
|
|
|
|
|
|
|
|
If you'd like to use the term "CircuitPython" and Blinka for your product here is what we ask:
|
|
|
|
|
|
|
|
* Your product is supported by the primary
|
|
|
|
`"adafruit/circuitpython" <https://github.com/adafruit/circuitpython>`_ repo. This way we can
|
|
|
|
update any custom code as we update the CircuitPython internals.
|
2019-04-16 20:33:13 -04:00
|
|
|
* Your product is listed on `circuitpython.org <https:/circuitpython.org>`__ (source
|
|
|
|
`here <https://github.com/adafruit/circuitpython-org/>`_). This is to ensure that a user of your
|
|
|
|
product can always download the latest version of CircuitPython from the standard place.
|
2019-04-16 19:40:16 -04:00
|
|
|
* Your product has a user accessible USB plug which appears as a CIRCUITPY drive when plugged in.
|
|
|
|
|
|
|
|
If you choose not to meet these requirements, then we ask you call your version of CircuitPython
|
|
|
|
something else (for example, SuperDuperPython) and not use the Blinka logo. You can say it is
|
|
|
|
"CircuitPython-compatible" if most CircuitPython drivers will work with it.
|
|
|
|
|
2018-02-20 20:34:59 -05:00
|
|
|
--------------
|
|
|
|
|
|
|
|
Differences from `MicroPython <https://github.com/micropython/micropython>`__
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
CircuitPython:
|
|
|
|
|
2019-04-16 19:40:16 -04:00
|
|
|
- includes ports for MicroChip SAMD21 (Commonly known as M0 in Adafruit
|
2018-06-07 15:15:15 -04:00
|
|
|
product names) and SAMD51 (M4).
|
2019-04-16 19:40:16 -04:00
|
|
|
- supports only SAMD21, SAMD51, and nRF52840 ports.
|
2018-02-20 20:34:59 -05:00
|
|
|
- tracks MicroPython's releases (not master).
|
2019-04-16 19:40:16 -04:00
|
|
|
- floats (aka decimals) are enabled for all builds.
|
|
|
|
- error messages are translated into 10+ languages.
|
2019-04-16 20:33:13 -04:00
|
|
|
- does not support concurrency within Python (including interrupts and threading). Some concurrency
|
|
|
|
is achieved with native modules for tasks that require it such as audio file playback.
|
2018-02-20 20:34:59 -05:00
|
|
|
|
|
|
|
Behavior
|
|
|
|
~~~~~~~~
|
|
|
|
|
|
|
|
- The order that files are run and the state that is shared between
|
|
|
|
them. CircuitPython's goal is to clarify the role of each file and
|
|
|
|
make each file independent from each other.
|
|
|
|
- ``boot.py`` (or ``settings.py``) runs only once on start up before
|
|
|
|
USB is initialized. This lays the ground work for configuring USB at
|
|
|
|
startup rather than it being fixed. Since serial is not available,
|
|
|
|
output is written to ``boot_out.txt``.
|
|
|
|
- ``code.py`` (or ``main.py``) is run after every reload until it
|
|
|
|
finishes or is interrupted. After it is done running, the vm and
|
|
|
|
hardware is reinitialized. **This means you cannot read state from
|
|
|
|
``code.py`` in the REPL anymore.** CircuitPython's goal for this
|
|
|
|
change includes reduce confusion about pins and memory being used.
|
|
|
|
- After ``code.py`` the REPL can be entered by pressing any key. It no
|
|
|
|
longer shares state with ``code.py`` so it is a fresh vm.
|
|
|
|
- Autoreload state will be maintained across reload.
|
|
|
|
- Adds a safe mode that does not run user code after a hard crash or
|
|
|
|
brown out. The hope is that this will make it easier to fix code that
|
|
|
|
causes nasty crashes by making it available through mass storage
|
|
|
|
after the crash. A reset (the button) is needed after its fixed to
|
|
|
|
get back into normal mode.
|
2019-04-16 20:33:13 -04:00
|
|
|
- RGB status LED indicating CircuitPython state, and errors through a sequence of colored flashes.
|
2019-04-17 13:48:11 -04:00
|
|
|
- Re-runs ``code.py`` or other main file after file system writes over USB mass storage. (Disable with
|
2019-04-16 19:40:16 -04:00
|
|
|
``samd.disable_autoreload()``)
|
2019-04-16 20:33:13 -04:00
|
|
|
- Entering the REPL after the main code is finished requires a key press which enters the REPL and
|
|
|
|
disables autoreload.
|
2019-05-15 21:22:40 -04:00
|
|
|
- Main is one of these: ``code.txt``, ``code.py``, ``main.py``,
|
2019-04-16 19:40:16 -04:00
|
|
|
``main.txt``
|
2019-05-15 21:22:40 -04:00
|
|
|
- Boot is one of these: ``settings.txt``, ``settings.py``, ``boot.py``,
|
2019-04-16 19:40:16 -04:00
|
|
|
``boot.txt``
|
2018-02-20 20:34:59 -05:00
|
|
|
|
|
|
|
API
|
|
|
|
~~~
|
|
|
|
|
2019-04-16 20:33:13 -04:00
|
|
|
- Unified hardware APIs. Documented
|
|
|
|
`on ReadTheDocs <https://circuitpython.readthedocs.io/en/latest/shared-bindings/index.html>`_.
|
2019-04-16 19:40:16 -04:00
|
|
|
- API docs are rST within the C files in ``shared-bindings``.
|
|
|
|
- No ``machine`` API.
|
2018-02-20 20:34:59 -05:00
|
|
|
|
|
|
|
Modules
|
|
|
|
~~~~~~~
|
|
|
|
|
|
|
|
- No module aliasing. (``uos`` and ``utime`` are not available as
|
|
|
|
``os`` and ``time`` respectively.) Instead ``os``, ``time``, and
|
|
|
|
``random`` are CPython compatible.
|
|
|
|
- New ``storage`` module which manages file system mounts.
|
|
|
|
(Functionality from ``uos`` in MicroPython.)
|
|
|
|
- Modules with a CPython counterpart, such as ``time``, ``os`` and
|
|
|
|
``random``, are strict
|
|
|
|
`subsets <https://circuitpython.readthedocs.io/en/latest/shared-bindings/time/__init__.html>`__
|
|
|
|
of their `CPython
|
|
|
|
version <https://docs.python.org/3.4/library/time.html?highlight=time#module-time>`__.
|
|
|
|
Therefore, code from CircuitPython is runnable on CPython but not
|
|
|
|
necessarily the reverse.
|
|
|
|
- tick count is available as
|
2018-02-20 21:06:42 -05:00
|
|
|
`time.monotonic() <https://circuitpython.readthedocs.io/en/latest/shared-bindings/time/__init__.html#time.monotonic>`__
|
2018-02-20 20:34:59 -05:00
|
|
|
|
|
|
|
--------------
|
|
|
|
|
|
|
|
Project Structure
|
|
|
|
-----------------
|
|
|
|
|
|
|
|
Here is an overview of the top-level source code directories.
|
|
|
|
|
|
|
|
Core
|
|
|
|
~~~~
|
|
|
|
|
|
|
|
The core code of
|
|
|
|
`MicroPython <https://github.com/micropython/micropython>`__ is shared
|
|
|
|
amongst ports including CircuitPython:
|
|
|
|
|
|
|
|
- ``docs`` High level user documentation in Sphinx reStructuredText
|
|
|
|
format.
|
|
|
|
- ``drivers`` External device drivers written in Python.
|
|
|
|
- ``examples`` A few example Python scripts.
|
|
|
|
- ``extmod`` Shared C code used in multiple ports' modules.
|
|
|
|
- ``lib`` Shared core C code including externally developed libraries
|
|
|
|
such as FATFS.
|
2018-12-12 08:51:16 -05:00
|
|
|
- ``logo`` The CircuitPython logo.
|
2018-02-20 20:34:59 -05:00
|
|
|
- ``mpy-cross`` A cross compiler that converts Python files to byte
|
|
|
|
code prior to being run in MicroPython. Useful for reducing library
|
|
|
|
size.
|
|
|
|
- ``py`` Core Python implementation, including compiler, runtime, and
|
|
|
|
core library.
|
|
|
|
- ``shared-bindings`` Shared definition of Python modules, their docs
|
|
|
|
and backing C APIs. Ports must implement the C API to support the
|
|
|
|
corresponding module.
|
|
|
|
- ``shared-module`` Shared implementation of Python modules that may be
|
|
|
|
based on ``common-hal``.
|
|
|
|
- ``tests`` Test framework and test scripts.
|
|
|
|
- ``tools`` Various tools, including the pyboard.py module.
|
|
|
|
|
|
|
|
Ports
|
|
|
|
~~~~~
|
|
|
|
|
|
|
|
Ports include the code unique to a microcontroller line and also
|
|
|
|
variations based on the board.
|
|
|
|
|
2019-04-16 19:40:16 -04:00
|
|
|
- ``atmel-samd`` Support for SAMD21 and SAMD51 based boards.
|
|
|
|
- ``nrf`` Support for the nRF52840 based boards.
|
|
|
|
- ``unix`` Support for UNIX. Only used for automated testing.
|
|
|
|
|
2019-04-16 20:33:13 -04:00
|
|
|
The remaining port directories not listed above are in the repo to maintain compatibility with the
|
2019-04-16 19:40:16 -04:00
|
|
|
`MicroPython <https://github.com/micropython/micropython>`__ parent project.
|
2018-02-20 20:34:59 -05:00
|
|
|
|
2019-04-16 20:33:13 -04:00
|
|
|
`back to top <#circuitpython>`__
|
2018-02-20 20:34:59 -05:00
|
|
|
|
2018-12-12 11:58:46 -05:00
|
|
|
.. |Build Status| image:: https://travis-ci.com/adafruit/circuitpython.svg?branch=master
|
2018-02-20 20:34:59 -05:00
|
|
|
:target: https://travis-ci.org/adafruit/circuitpython
|
|
|
|
.. |Doc Status| image:: https://readthedocs.org/projects/circuitpython/badge/?version=latest
|
|
|
|
:target: http://circuitpython.readthedocs.io/
|
|
|
|
.. |Discord| image:: https://img.shields.io/discord/327254708534116352.svg
|
2019-01-31 22:03:13 -05:00
|
|
|
:target: https://adafru.it/discord
|
2019-04-16 19:40:16 -04:00
|
|
|
.. |License| image:: https://img.shields.io/badge/License-MIT-brightgreen.svg
|
|
|
|
:target: https://choosealicense.com/licenses/mit/
|