Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • add_menu_vibration
  • blinkisync-as-preload
  • ch3/api-speed-eval2
  • ch3/dual-core
  • ch3/genapi-refactor
  • ch3/leds-api
  • ch3/splashscreen
  • dualcore
  • dx/flatten-config-module
  • dx/meh-bdf-to-stm
  • freertos-btle
  • genofire/ble-follow-py
  • koalo/bhi160-works-but-dirty
  • koalo/factory-reset
  • koalo/wip/i2c-for-python
  • master
  • msgctl/faultscreen
  • msgctl/textbuffer_api
  • plaetzchen/ios-workaround
  • rahix/bhi
  • rahix/bluetooth-app-favorite
  • rahix/bma
  • rahix/user-space-ctx
  • renze/hatchery_apps
  • renze/safe_mode
  • schleicher-test
  • schneider/212-reset-hardware-when-entering-repl
  • schneider/ancs
  • schneider/ble-buffers
  • schneider/ble-central
  • schneider/ble-ecg-stream-visu
  • schneider/ble-fixes-2020-3
  • schneider/ble-mini-demo
  • schneider/ble-stability
  • schneider/ble-stability-new-phy
  • schneider/bonding
  • schneider/bonding-fail-if-full
  • schneider/bootloader-update-9a0d158
  • schneider/deepsleep
  • schneider/deepsleep2
  • schneider/deepsleep4
  • schneider/default-main
  • schneider/freertos-list-debug
  • schneider/fundamental-test
  • schneider/iaq-python
  • schneider/ir
  • schneider/max30001
  • schneider/max30001-epicaridum
  • schneider/max30001-pycardium
  • schneider/maxim-sdk-update
  • schneider/mp-exception-print
  • schneider/mp-for-old-bl
  • schneider/png
  • schneider/schleicher-test
  • schneider/sdk-0.2.1-11
  • schneider/sdk-0.2.1-7
  • schneider/sleep-display
  • schneider/spo2-playground
  • schneider/stream-locks
  • schneider/v1.17-changelog
  • bootloader-v1
  • release-1
  • v0.0
  • v1.0
  • v1.1
  • v1.10
  • v1.11
  • v1.12
  • v1.13
  • v1.14
  • v1.15
  • v1.16
  • v1.17
  • v1.18
  • v1.2
  • v1.3
  • v1.4
  • v1.5
  • v1.6
  • v1.7
  • v1.8
  • v1.9
82 results

Target

Select target project
  • card10/firmware
  • annejan/firmware
  • astro/firmware
  • fpletz/firmware
  • gerd/firmware
  • fleur/firmware
  • swym/firmware
  • l/firmware
  • uberardy/firmware
  • wink/firmware
  • madonius/firmware
  • mot/firmware
  • filid/firmware
  • q3k/firmware
  • hauke/firmware
  • Woazboat/firmware
  • pink/firmware
  • mossmann/firmware
  • omniskop/firmware
  • zenox/firmware
  • trilader/firmware
  • Danukeru/firmware
  • shoragan/firmware
  • zlatko/firmware
  • sistason/firmware
  • datenwolf/firmware
  • bene/firmware
  • amedee/firmware
  • martinling/firmware
  • griffon/firmware
  • chris007/firmware
  • adisbladis/firmware
  • dbrgn/firmware
  • jelly/firmware
  • rnestler/firmware
  • mh/firmware
  • ln/firmware
  • penguineer/firmware
  • monkeydom/firmware
  • jens/firmware
  • jnaulty/firmware
  • jeffmakes/firmware
  • marekventur/firmware
  • pete/firmware
  • h2obrain/firmware
  • DooMMasteR/firmware
  • jackie/firmware
  • prof_r/firmware
  • Draradech/firmware
  • Kartoffel/firmware
  • hinerk/firmware
  • abbradar/firmware
  • JustTB/firmware
  • LuKaRo/firmware
  • iggy/firmware
  • ente/firmware
  • flgr/firmware
  • Lorphos/firmware
  • matejo/firmware
  • ceddral7/firmware
  • danb/firmware
  • joshi/firmware
  • melle/firmware
  • fitch/firmware
  • deurknop/firmware
  • sargon/firmware
  • markus/firmware
  • kloenk/firmware
  • lucaswerkmeister/firmware
  • derf/firmware
  • meh/firmware
  • dx/card10-firmware
  • torben/firmware
  • yuvadm/firmware
  • AndyBS/firmware
  • klausdieter1/firmware
  • katzenparadoxon/firmware
  • xiretza/firmware
  • ole/firmware
  • techy/firmware
  • thor77/firmware
  • TilCreator/firmware
  • fuchsi/firmware
  • dos/firmware
  • yrlf/firmware
  • PetePriority/firmware
  • SuperVirus/firmware
  • sur5r/firmware
  • tazz/firmware
  • Alienmaster/firmware
  • flo_h/firmware
  • baldo/firmware
  • mmu_man/firmware
  • Foaly/firmware
  • sodoku/firmware
  • Guinness/firmware
  • ssp/firmware
  • led02/firmware
  • Stormwind/firmware
  • arist/firmware
  • coon/firmware
  • mdik/firmware
  • pippin/firmware
  • royrobotiks/firmware
  • zigot83/firmware
  • mo_k/firmware
106 results
Select Git revision
  • analog_clock
  • ch3/api-speed-eval2
  • ch3/dual-core
  • ch3/genapi-refactor
  • ch3/leds-api
  • ch3/splashscreen
  • dualcore
  • freertos-btle
  • genofire/ble-personal_state
  • ios-workarounds
  • koalo/bhi160-works-but-dirty
  • koalo/factory-reset
  • koalo/wip/i2c-for-python
  • longint_issue
  • master
  • mem_usage
  • more_fonts
  • more_fonts_ng
  • msgctl/faultscreen
  • msgctl/gfx_rle
  • msgctl/textbuffer_api
  • rahix/bhi
  • rahix/bma
  • rahix/simple_menu
  • renze/hatchery_apps
  • renze/safe_mode
  • schleicher-test
  • schneider/bonding
  • schneider/bootloader-update-9a0d158
  • schneider/bsec
  • schneider/fundamental-test
  • schneider/maxim-sdk-update
  • schneider/mp-for-old-bl
  • schneider/schleicher-test
  • utime_time_ms
  • bootloader-v1
  • release-1
  • v0.0
  • v1.0
  • v1.1
  • v1.2
  • v1.3
  • v1.4
43 results
Show changes
Showing
with 1777 additions and 35 deletions
.. py:module:: bhi160
``bhi160`` - Sensor Fusion
==========================
.. versionadded:: 1.4
Supports the BHI160 sensor on the card10 for accelerometer, gyroscope,
magnetometer and orientation.
The coordinate system of the BHI160 sensor data looks like this:
.. image:: ../static/bhi160-coordinates.png
* The **accelerometer** axes are just the ones shown in the picture.
* The **gyroscope**'s angular velocities rotate counter clockwise around
their respective axis.
* The **orientation** sensor uses the following mapping:
+---------------------+----------------------+-------------------+
| X | Y | Z |
+=====================+======================+===================+
| Azimuth (0° - 360°) | Pitch (-180° - 180°) | Roll (-90° - 90°) |
+---------------------+----------------------+-------------------+
**Example**:
.. code-block:: python
import bhi160
import time
bhi = bhi160.BHI160Orientation()
while True:
samples = bhi.read()
if len(samples) == 0:
time.sleep(0.25)
continue
# print the latest sample
print(samples[-1])
time.sleep(0.25)
Orientation
-----------
.. autoclass:: bhi160.BHI160Orientation
:members:
:inherited-members:
Accelerometer
-------------
.. autoclass:: bhi160.BHI160Accelerometer
:members:
:inherited-members:
Gyroscope
---------
.. autoclass:: bhi160.BHI160Gyroscope
:members:
:inherited-members:
Magnetometer
------------
.. autoclass:: bhi160.BHI160Magnetometer
:members:
:inherited-members:
``ble_hid`` - BLE HID
=====================
The ``ble_hid`` module provides access to the BLE Human Interface Device functionality.
.. note::
Make sure to enable the BLE HID functionality in :ref:`card10_cfg` and reboot your card10
if you want to use BLE HID.
Also make sure that the ``adafruit_hid`` folder from the card10 release archive is placed
on the file system of your card10.
.. warning::
At least Ubuntu Linux will keep auto connecting to BLE HID devices once they are
paired to the host computer. If you want to connect your card10 to a phone again,
you might have to temporarily turn off Bluetooth on your computer.
An example application can be found in the preload directory (named ``HID Demo``). It provides
examples how to use the card10 as keyboard, mouse or volume control.
Please refer to the Adafruit CircuitPython HID library for examples how to use the HID service.
The card10 implements the same HID descriptors as the Adafruit CircuitPython BLE library and
should be compatible with all uses of the Adafruit CircuitPython HID library.
**Example emulating a keyboard**:
Adapted from https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/master/CPB_Keybutton_BLE/cpb_keybutton_ble.py
A more complete version of this example can be found in the HID Demo app on your card10.
.. code-block:: python
import ble_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode
k = Keyboard(ble_hid.devices)
kl = KeyboardLayoutUS(k)
k.send(Keycode.BACKSPACE)
# use keyboard_layout for words
kl.write("Demo with a long text to show how fast a card10 can type!")
# add shift modifier
k.send(Keycode.SHIFT, Keycode.F19)
**Example emulating a mouse**:
.. code-block:: python
import ble_hid
import bhi160
import buttons
from adafruit_hid.mouse import Mouse
m = Mouse(ble_hid.devices)
def send_report(samples):
if len(samples) > 0:
x = -int(samples[0].z)
y = -int(samples[0].y)
m.move(x, y)
sensor = bhi160.BHI160Orientation(sample_rate=10, callback=send_report)
b_old = buttons.read()
while True:
b_new = buttons.read()
if not b_old == b_new:
print(b_new)
b_old = b_new
if b_new == buttons.TOP_RIGHT:
m.click(Mouse.MIDDLE_BUTTON)
elif b_new == buttons.BOTTOM_RIGHT:
m.click(Mouse.RIGHT_BUTTON)
elif b_new == buttons.BOTTOM_LEFT:
m.click(Mouse.LEFT_BUTTON)
.. note::
Make sure to catch ``OSError`` exceptions in real applications. The exception will be thrown if
there is connection to the host (or if it is lost) and you want to send an event.
.. automodule:: ble_hid
:members:
.. py:module:: bme680
``bme680`` - Environmental Sensor
=================================
Allows access to environmental data of card10's surroundings.
If ``bsec_enable`` is set in :ref:`card10_cfg`, the proprietary Bosch BSEC
library will be activated which offers the following extra functionality:
- Manual temperature offset compensation
The ``bsec_offset`` configuration allows to configure a static temperature
offset. Please use a reference thermometer to determine the offset of your
card10. If no offset is provided a default offset for a card10 which is
connected to USB, has BLE active and is without a case is used.
- A fixed measurement interval of 3 seconds
This helps to stabilize the temperature of the card10.
- An indoor air quality (IAQ) and equivalent CO2 estimation algorithm
Please refer to the :ref:`bsec_api` API documentation to get more information
about how to interpret these estimates.
.. note::
Please keep in mind that the BME680 can not directly measure CO2. It measures
Volatile Organic Compounds (VOCs). The BSEC library uses this measurement
to compute an Indoor Air Quality (IAQ) indication. It also assumes that all VOCs
in the air are from human breath and computes an equivalent CO2 (eCO2)
value from this. Please be aware of these facts when judging the accuracy
of the IAQ and eCO2 values. Some more information can be found in the
:ref:`bsec_api` API documentation.
.. warning::
For the BSEC library to properly work the card10 should be kept running
for at least 10 hours at least once. This is needed as the BSEC library
periodically writes calibration information about the sensor to the
card10's file system.
Please make sure to observe the IAQ accuracy field. It will tell you if the
IAQ and eCO2 measurements are deemed "accurate" by the BSEC library. Your
application should either inform the user about the current accuracy (e.g.
by color coding) or simply not show any values if the accuracy is below 2.
.. note::
See also the BLE :ref:`ESS`.
**Example**:
.. code-block:: python
import bme680, time
with bme680.Bme680() as environment:
while True:
d = environment.get_data()
print("Temperature: {:10.2f} °C".format(d.temperature))
print("Humidity: {:10.2f} % r.h.".format(d.humidity))
print("Pressure: {:10.2f} hPa".format(d.pressure))
print("Gas Resistance: {:10.2f} Ω".format(d.resistance))
time.sleep(1)
You can use the return type of :py:meth:`~bme680.Bme680.get_data` to decide
if you want to use/display the additonal fields returned if BSEC is enabled.
.. code-block:: python
if isinstance(d, bme680.BSECData):
print("Air quality: {:7d}".format(d.iaq))
Sensor Class
------------
.. autoclass:: bme680.Bme680
:members:
Deprecated Interface
--------------------
The following functions should no longer be used directly. The only exist for
compatibility as they were the old BME680 interface in previous firmware
versions.
.. py:function:: init()
Initialize the sensor.
Before being able to read data from the sensor, you have to call
:py:func:`bme680.init`.
.. versionadded:: 1.4
.. deprecated:: 1.10
Use the :py:class:`bme680.Bme680` class instead.
.. py:function:: get_data()
Perform a single measurement of environmental data.
:return: Tuple containing ``temperature`` (°C), ``humidity`` (% r.h.),
``pressure`` (hPa) and ``gas resistance`` (Ohm).
.. versionadded:: 1.4
.. deprecated:: 1.10
Use the :py:class:`bme680.Bme680` class instead.
.. py:function:: deinit()
Deinitialize the sensor.
.. versionadded:: 1.4
.. deprecated:: 1.10
Use the :py:class:`bme680.Bme680` class instead.
.. py:module:: buttons
``buttons`` - Push Buttons
==========================
The :py:mod:`buttons` module allows you to use card10's push buttons as input
in your scripts.
**Example**:
.. code-block:: python
import buttons
print("Press bottom left or right button:")
while True:
pressed = buttons.read(
buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT
)
if pressed != 0:
break
if pressed & buttons.BOTTOM_LEFT != 0:
print("Left button pressed!")
if pressed & buttons.BOTTOM_RIGHT != 0:
print("Right button pressed!")
.. py:function:: read(mask)
Read button status.
:param int mask: Mask of buttons to check. Create the mask by ORing
:py:data:`buttons.BOTTOM_LEFT`, :py:data:`buttons.BOTTOM_RIGHT`,
:py:data:`buttons.TOP_RIGHT`, and :py:data:`buttons.TOP_LEFT` (=
:py:data:`buttons.RESET`).
:returns: An integer with the bits for pressed buttons set. Use the same
costants as for the mask to check which buttons were pressed.
.. py:data:: BOTTOM_LEFT
Bottom left button.
.. py:data:: BOTTOM_RIGHT
Bottom right button.
.. py:data:: TOP_RIGHT
Top right button.
.. py:data:: TOP_LEFT
Top left button (Reset button).
.. py:data:: RESET
Top left button (Reset button).
...@@ -9,14 +9,633 @@ Color Class ...@@ -9,14 +9,633 @@ Color Class
Constants Constants
--------- ---------
The color module also contains a few constanst for commonly used colors: The color module also contains a few constanst for commonly used colors:
.. py:data:: color.BLACK Camp Colors
.. py:data:: color.WHITE ~~~~~~~~~~~
.. py:data:: color.RED .. py:data:: CHAOSBLUE
.. py:data:: color.GREEN
.. py:data:: color.YELLOW .. color-example:: #0076BA
.. py:data:: color.BLUE
.. py:data:: color.MAGENTA .. py:data:: CHAOSBLUE_DARK
.. py:data:: color.CYAN
.. color-example:: #005383
.. py:data:: COMMYELLOW
.. color-example:: #FFC600
.. py:data:: COMMYELLOW_DARK
.. color-example:: #D39A00
.. py:data:: CAMPGREEN
.. color-example:: #99BA00
.. py:data:: CAMPGREEN_DARK
.. color-example:: #6F8700
General
~~~~~~~
.. py:data:: BLACK
.. color-example:: #000
.. py:data:: WHITE
.. color-example:: #fff
.. py:data:: RED
.. color-example:: #f00
.. py:data:: GREEN
.. color-example:: #0f0
.. py:data:: YELLOW
.. color-example:: #ff0
.. py:data:: BLUE
.. color-example:: #00f
.. py:data:: MAGENTA
.. color-example:: #f0f
.. py:data:: CYAN
.. color-example:: #0ff
.. py:module:: htmlcolor
``htmlcolor`` - Color Constants
===============================
The ``htmlcolor`` module contains even more color constants. Note
that loading the ``htmlcolor`` module will require ~12K of RAM.
.. py:data:: ALICEBLUE
.. color-example:: aliceblue
.. py:data:: ANTIQUEWHITE
.. color-example:: antiquewhite
.. py:data:: AQUA
.. color-example:: aqua
.. py:data:: AQUAMARINE
.. color-example:: aquamarine
.. py:data:: AZURE
.. color-example:: azure
.. py:data:: BEIGE
.. color-example:: beige
.. py:data:: BISQUE
.. color-example:: bisque
.. py:data:: BLACK
.. color-example:: black
.. py:data:: BLANCHEDALMOND
.. color-example:: blanchedalmond
.. py:data:: BLUE
.. color-example:: blue
.. py:data:: BLUEVIOLET
.. color-example:: blueviolet
.. py:data:: BROWN
.. color-example:: brown
.. py:data:: BURLYWOOD
.. color-example:: burlywood
.. py:data:: CADETBLUE
.. color-example:: cadetblue
.. py:data:: CHARTREUSE
.. color-example:: chartreuse
.. py:data:: CHOCOLATE
.. color-example:: chocolate
.. py:data:: CORAL
.. color-example:: coral
.. py:data:: CORNFLOWERBLUE
.. color-example:: cornflowerblue
.. py:data:: CORNSILK
.. color-example:: cornsilk
.. py:data:: CRIMSON
.. color-example:: crimson
.. py:data:: CYAN
.. color-example:: cyan
.. py:data:: DARKBLUE
.. color-example:: darkblue
.. py:data:: DARKCYAN
.. color-example:: darkcyan
.. py:data:: DARKGOLDENROD
.. color-example:: darkgoldenrod
.. py:data:: DARKGRAY
.. color-example:: darkgray
.. py:data:: DARKGREEN
.. color-example:: darkgreen
.. py:data:: DARKKHAKI
.. color-example:: darkkhaki
.. py:data:: DARKMAGENTA
.. color-example:: darkmagenta
.. py:data:: DARKOLIVEGREEN
.. color-example:: darkolivegreen
.. py:data:: DARKORANGE
.. color-example:: darkorange
.. py:data:: DARKORCHID
.. color-example:: darkorchid
.. py:data:: DARKRED
.. color-example:: darkred
.. py:data:: DARKSALMON
.. color-example:: darksalmon
.. py:data:: DARKSEAGREEN
.. color-example:: darkseagreen
.. py:data:: DARKSLATEBLUE
.. color-example:: darkslateblue
.. py:data:: DARKSLATEGRAY
.. color-example:: darkslategray
.. py:data:: DARKTURQUOISE
.. color-example:: darkturquoise
.. py:data:: DARKVIOLET
.. color-example:: darkviolet
.. py:data:: DEEPPINK
.. color-example:: deeppink
.. py:data:: DEEPSKYBLUE
.. color-example:: deepskyblue
.. py:data:: DIMGRAY
.. color-example:: dimgray
.. py:data:: DODGERBLUE
.. color-example:: dodgerblue
.. py:data:: FIREBRICK
.. color-example:: firebrick
.. py:data:: FLORALWHITE
.. color-example:: floralwhite
.. py:data:: FORESTGREEN
.. color-example:: forestgreen
.. py:data:: FUCHSIA
.. color-example:: fuchsia
.. py:data:: GAINSBORO
.. color-example:: gainsboro
.. py:data:: GHOSTWHITE
.. color-example:: ghostwhite
.. py:data:: GOLD
.. color-example:: gold
.. py:data:: GOLDENROD
.. color-example:: goldenrod
.. py:data:: GRAY
.. color-example:: gray
.. py:data:: GREEN
.. color-example:: green
.. py:data:: GREENYELLOW
.. color-example:: greenyellow
.. py:data:: HONEYDEW
.. color-example:: honeydew
.. py:data:: HOTPINK
.. color-example:: hotpink
.. py:data:: INDIANRED
.. color-example:: indianred
.. py:data:: INDIGO
.. color-example:: indigo
.. py:data:: IVORY
.. color-example:: ivory
.. py:data:: KHAKI
.. color-example:: khaki
.. py:data:: LAVENDER
.. color-example:: lavender
.. py:data:: LAVENDERBLUSH
.. color-example:: lavenderblush
.. py:data:: LAWNGREEN
.. color-example:: lawngreen
.. py:data:: LEMONCHIFFON
.. color-example:: lemonchiffon
.. py:data:: LIGHTBLUE
.. color-example:: lightblue
.. py:data:: LIGHTCORAL
.. color-example:: lightcoral
.. py:data:: LIGHTCYAN
.. color-example:: lightcyan
.. py:data:: LIGHTGOLDENRODYELLOW
.. color-example:: lightgoldenrodyellow
.. py:data:: LIGHTGRAY
.. color-example:: lightgray
.. py:data:: LIGHTGREEN
.. color-example:: lightgreen
.. py:data:: LIGHTPINK
.. color-example:: lightpink
.. py:data:: LIGHTSALMON
.. color-example:: lightsalmon
.. py:data:: LIGHTSEAGREEN
.. color-example:: lightseagreen
.. py:data:: LIGHTSKYBLUE
.. color-example:: lightskyblue
.. py:data:: LIGHTSLATEGRAY
.. color-example:: lightslategray
.. py:data:: LIGHTSTEELBLUE
.. color-example:: lightsteelblue
.. py:data:: LIGHTYELLOW
.. color-example:: lightyellow
.. py:data:: LIME
.. color-example:: lime
.. py:data:: LIMEGREEN
.. color-example:: limegreen
.. py:data:: LINEN
.. color-example:: linen
.. py:data:: MAGENTA
.. color-example:: magenta
.. py:data:: MAROON
.. color-example:: maroon
.. py:data:: MEDIUMAQUAMARINE
.. color-example:: mediumaquamarine
.. py:data:: MEDIUMBLUE
.. color-example:: mediumblue
.. py:data:: MEDIUMORCHID
.. color-example:: mediumorchid
.. py:data:: MEDIUMPURPLE
.. color-example:: mediumpurple
.. py:data:: MEDIUMSEAGREEN
.. color-example:: mediumseagreen
.. py:data:: MEDIUMSLATEBLUE
.. color-example:: mediumslateblue
.. py:data:: MEDIUMSPRINGGREEN
.. color-example:: mediumspringgreen
.. py:data:: MEDIUMTURQUOISE
.. color-example:: mediumturquoise
.. py:data:: MEDIUMVIOLETRED
.. color-example:: mediumvioletred
.. py:data:: MIDNIGHTBLUE
.. color-example:: midnightblue
.. py:data:: MINTCREAM
.. color-example:: mintcream
.. py:data:: MISTYROSE
.. color-example:: mistyrose
.. py:data:: MOCCASIN
.. color-example:: moccasin
.. py:data:: NAVAJOWHITE
.. color-example:: navajowhite
.. py:data:: NAVY
.. color-example:: navy
.. py:data:: OLDLACE
.. color-example:: oldlace
.. py:data:: OLIVE
.. color-example:: olive
.. py:data:: OLIVEDRAB
.. color-example:: olivedrab
.. py:data:: ORANGE
.. color-example:: orange
.. py:data:: ORANGERED
.. color-example:: orangered
.. py:data:: ORCHID
.. color-example:: orchid
.. py:data:: PALEGOLDENROD
.. color-example:: palegoldenrod
.. py:data:: PALEGREEN
.. color-example:: palegreen
.. py:data:: PALETURQUOISE
.. color-example:: paleturquoise
.. py:data:: PALEVIOLETRED
.. color-example:: palevioletred
.. py:data:: PAPAYAWHIP
.. color-example:: papayawhip
.. py:data:: PEACHPUFF
.. color-example:: peachpuff
.. py:data:: PERU
.. color-example:: peru
.. py:data:: PINK
.. color-example:: pink
.. py:data:: PLUM
.. color-example:: plum
.. py:data:: POWDERBLUE
.. color-example:: powderblue
.. py:data:: PURPLE
.. color-example:: purple
.. py:data:: RED
.. color-example:: red
.. py:data:: ROSYBROWN
.. color-example:: rosybrown
.. py:data:: ROYALBLUE
.. color-example:: royalblue
.. py:data:: SADDLEBROWN
.. color-example:: saddlebrown
.. py:data:: SALMON
.. color-example:: salmon
.. py:data:: SANDYBROWN
.. color-example:: sandybrown
.. py:data:: SEAGREEN
.. color-example:: seagreen
.. py:data:: SEASHELL
.. color-example:: seashell
.. py:data:: SIENNA
.. color-example:: sienna
.. py:data:: SILVER
.. color-example:: silver
.. py:data:: SKYBLUE
.. color-example:: skyblue
.. py:data:: SLATEBLUE
.. color-example:: slateblue
.. py:data:: SLATEGRAY
.. color-example:: slategray
.. py:data:: SNOW
.. color-example:: snow
.. py:data:: SPRINGGREEN
.. color-example:: springgreen
.. py:data:: STEELBLUE
.. color-example:: steelblue
.. py:data:: TAN
.. color-example:: tan
.. py:data:: TEAL
.. color-example:: teal
.. py:data:: THISTLE
.. color-example:: thistle
.. py:data:: TOMATO
.. color-example:: tomato
.. py:data:: TURQUOISE
.. color-example:: turquoise
.. py:data:: VIOLET
.. color-example:: violet
.. py:data:: WHEAT
.. color-example:: wheat
.. py:data:: WHITE
.. color-example:: white
.. py:data:: WHITESMOKE
.. color-example:: whitesmoke
.. py:data:: YELLOW
.. color-example:: yellow
.. py:data:: YELLOWGREEN
.. color-example:: yellowgreen
``config`` - Configuration
==========================
The ``config`` module provides functions to interact with card10's
configuration file (:ref:`card10_cfg`).
.. automodule:: config
:members:
``display`` - Display
=====================
The display module let's you draw on the card10's display.
Pixels are addressed from top left to bottom right with a range of x: 0 to 159 and y: 0 to 79.
.. code-block:: text
0,0
+---------------------+
| |
| |
| |
| |
+---------------------+
159,79
Drawing operations are clipped, pixels outside of the screen will be ignored.
.. automodule:: display
:members:
.. py:module:: gpio
``gpio`` - GPIO Pins
==========================
The :py:mod:`gpio` module allows you to use card10's GPIO pins as input and
output in your scripts.
**Example**:
.. code-block:: python
import gpio
gpio.set_mode(gpio.WRISTBAND_1, gpio.mode.OUTPUT)
gpio.write(gpio.WRISTBAND_1, True)
gpio.set_mode(gpio.WRISTBAND_2, gpio.mode.INPUT | gpio.mode.PULL_UP)
state = gpio.read(gpio.WRISTBAND_2)
print("State of Wristband pin 2:", state)
.. py:function:: set_mode(pin, mode)
Configure GPIO pin state.
:param int pin: ID of the pin to be configured.
:param int mode: An integer with the bits for the wanted mode set. Create your
integer by ORing :py:data:`gpio.mode.OUTPUT`, :py:data:`gpio.mode.INPUT`,
:py:data:`gpio.mode.ADC`, :py:data:`gpio.mode.PULL_UP`,
:py:data:`gpio.mode.PULL_DOWN`.
.. note:: On WRISTBAND_3, there is no ADC functionality available
.. py:function:: get_mode(pin)
Get GPIO pin state.
:param int pin: ID of the pin of to get the mode of.
:returns: An integer with the configure mode bits set.
.. py:function:: write(pin, value)
Write a value to a GPIO pin.
:param int pin: ID of the pin of to get the mode of.
:param bool value: New pin value.
.. py:function:: read(pin)
Read GPIO pin value.
:param int pin: ID of the pin of to get the mode of.
:returns: Current value of the GPIO pin.
If the pin is configured as ADC, the value returned
will be between 0 and 1000, representing voltages from
0V to 3.3V (:py:data:`gpio.ADC` is only available in 1.9+).
.. py:data:: WRISTBAND_1
Pin ID for Wristband GPIO 1.
.. py:data:: WRISTBAND_2
Pin ID for Wristband GPIO 2.
.. py:data:: WRISTBAND_3
Pin ID for Wristband GPIO 3.
.. py:data:: WRISTBAND_4
Pin ID for Wristband GPIO 4.
.. py:module:: gpio.mode
.. py:data:: OUTPUT
Configures a pin as output.
.. py:data:: INPUT
Configures a pin as input.
.. py:data:: ADC
Configure pin as ADC input.
.. versionadded: 1.9
.. py:data:: PULL_UP
Enables the internal pull-up resistor of a pin.
.. py:data:: PULL_DOWN
Enables the internal pull-down resistor of a pin.
``leds`` - LEDs ``leds`` - LEDs
=============== ===============
The ``leds`` module provides functions to interact with card10's RGB LEDs.
This is the 11 LEDs above the display and 4 LEDs on the underside of the
top-board, in the four corners.
.. py:function:: leds.set(led, color) .. automodule:: leds
:members:
Set one of the card10's RGB LEDs to a certain color:: ``ledfx`` - LED Effects
=======================
import leds, color .. automodule:: ledfx
:members:
for i in range(11):
leds.set(i, color.RED)
:param led: Which led to set. 0-10 are the leds on the top and 11-14 are the 4 "ambient" leds.
:param color: What color to set the led to. Should be a :py:class:`color.Color` but any list/tuple
with 3 elements will work just as well.
.. py:data:: leds.BOTTOM_RIGHT
Index of the LED in the bottom right of card10.
.. py:data:: leds.BOTTOM_LEFT
Index of the LED in the bottom left of card10.
.. py:data:: leds.TOP_RIGHT
Index of the LED in the top right of card10.
.. py:data:: leds.TOP_LEFT
Index of the LED in the top left of card10.
.. py:module:: light_sensor
``light_sensor`` - Ambient Brightness
=====================================
On the harmonic board, there is an IR-LED which can be used in reverse as a
crude brightness sensor. Values returned are in no particular unit but seem to
be fairly stable.
.. py:function:: start()
Turn on the ADC and start reading brightness values. (In past this function must be
called before any measurements can be taken.)
.. py:function:: get_reading()
Get an ambient brightness reading. The returned value is in no particular
unit, though it seems to be fairly stable. The value could be between 0 and 400. Common values:
- ~8: Very dark are
- ~17: Typical hackerspace brightness
- >200: Direct sunlight
:returns: A brightness reading in no particular unit
.. py:function:: stop()
Stop the ADC.
.. py:function:: read()
Direct readout of the light-sensor.
Use this function for low latency readout. The time between polls can have
an effect on the values measures. If you do not need low latency, prefer
:py:func:`light_sensor.get_reading`.
.. versionadded:: 1.8
``max30001`` - MAX30001
=======================
.. automodule:: max30001
:members:
``max86150`` - MAX86150
=======================
.. automodule:: max86150
:members:
.. py:module:: os
``os`` - OS Functions
=====================
The ``os`` module allows access to a few core functionalities of Epicardium and
functions found in CPythons ``os`` module.
CPython-Like
------------
.. py:function:: listdir(dir)
List contents of a directory.
:param str dir: Path to the directory to list.
:returns: A list of entities (files or subdirectories) in the directory
``dir``.
.. py:function:: mkdir(path)
Create a directory named *path*.
:param str path: Path to the directory to create. Only the last component
of this path will be created.
.. py:function:: rename(src, dst)
Rename the file or directory *src* to *dst*. If *dst* exists, the operation
will fail.
:param str src: Path to source file to rename.
:param str dst: Destination path to rename to. Must not exist before
calling :py:func:`os.rename`.
.. py:function:: unlink(path)
Unlink (remove) a file.
:param str path: The file to remove.
.. py:function:: urandom(n)
Return ``n`` random bytes.
.. versionadded:: 1.3
:param int n: Number of random bytes to retrieve.
:returns: ``bytes()`` object with ``n`` random bytes.
Card10-Specific
---------------
.. py:function:: exit(ret = None)
Exit from the current app and return to the menu.
:param int ret: Optional return code, same semantics as Posix (``0`` means
success).
:return: This function will never return.
.. py:function:: exec(name)
Try executing a new app, stopping the currently running one.
``name`` is the path to either a l0dable (ending in ``.elf``) or a python
script (ending in ``.py``). If the path does not lead to an executable file,
``os.exec()`` will raise an exception.
:param str name: Path to new app/script/l0dable.
:return: This function never returns. It can, however raise an exception.
.. py:function:: read_battery()
Read the current battery voltage in V. Please keep in mind that battery
voltage behaves exponentially when interpreting this value.
.. warning::
Card10 will hard-shutdown once the voltage drops below 3.4 V
.. py:function:: reset()
Reboot card10.
.. warning::
Please only call this function if absolutely necessary. In most cases
you'll want to just :py:func:`os.exit` instead.
.. py:function:: usbconfig(config_type)
Change active USB configuration. By default, card10 boots with
:py:data:`os.USB_SERIAL` active.
This will deactivate the currently active USB configuration. This means
that, if you activate :py:data:`os.USB_FLASH` while :py:data:`os.USB_SERIAL`
was active, the USB serial will be disconnected.
:param config_type: Selects which config to activate. Possible
values are :py:data:`os.USB_SERIAL`, :py:data:`os.USB_FLASH`,
or :py:data:`os.USB_NONE`.
.. versionadded:: 1.11
.. py:data:: USB_NONE
No USB device active.
.. py:data:: USB_SERIAL
CDC-ACM serial device active.
.. py:data:: USB_FLASH
Mass-Storage device active.
.. py:function:: fs_is_attached()
Check whether the filesystem is currently attached to card10 (or whether a connected
USB host is currently holding control over it and possibly writing to it).
:returns:
- ``True`` if the filesystem is attached to card10 and an app can read and
write files.
- ``False`` if the filesystem is not available to card10 because a USB
host is currently controlling it.
.. versionadded: 1.18
.. _pycardium_overview:
Overview
========
Pycardium is what we call our MicroPython port for card10. For the most part,
it will behave like a normal MicroPython, enhanced by a few modules to
interface with card10's hardware. We have also included modules from Python's
standard library so you have lots of familiar functionality at hand to start
hacking!
.. note::
Right now, MicroPython is only available via the serial console. card10
makes its console available as a CDC ACM device via USB or, if you have a
debugger, on the debugging serial port.
This means, you can only interact with Python through the REPL console for
now. However, this will soon change, once `#10`_ and `#11`_ are implemented.
.. _#10: https://git.card10.badge.events.ccc.de/card10/firmware/issues/10
.. _#11: https://git.card10.badge.events.ccc.de/card10/firmware/issues/11
In other words: It is currently not possible to execute Python code
from .py files on the filesystem. You have to test new modules using the
serial console.
Serial Console
--------------
If you have a debugger, you can just use the debuggers serial console.
Otherwise, card10 will open a serial usb-device on its usb-port. On most Linux
systems this device will be called ``/dev/ttyACM0`` or ``/dev/ttyACM1``.
Choose a terminal-emulator of your liking and open the above mentioned device.
Baud-rate is 115200. Some options are:
* **screen**: ``sudo screen /dev/ttyACM0 115200``
* **picocom**: ``sudo picocom -b 115200 /dev/ttyACM0``
After connecting, reboot reset the card10 via the power button (left upper
corner) and you should see the output of **menu.py** script (it's located in
*preload/menu.py*). You can press CTRL-C to interrupt the script and jump into
the MicroPython prompt.
To switch on the blue fairy dust you must import the led python module::
import leds
and power it on::
leds.set_rocket(0, 31)
.. note::
If you're using iOS/Mac then you can connect to your serial console using:
.. code-block:: shell-session
screen /dev/tty.usbmodem* 115200
You can now see in your console what buttons you have pressed and your
console outputs/logs. With ``CTRL+C`` you exit the console.
REPL modes
^^^^^^^^^^
MicroPython supports a different REPL modes over the serial console. The modes
can be changed on every new line.
Normal mode
"""""""""""
This is the mode you will first see. You can switch to it by pressing CTRL-B.
If you are in a other mode you can return to this mode by pressing CTRL-B too.
Paste mode
""""""""""
You can enter the paste mode by pressing CTRL-E and you can simple copy 'n'
paste your source code into the console and it will be interpreted and executed
line by line. Every new line will be reply by the prompt with **===**.
RAW mode
""""""""
The RAW mode to be intendend for the usage with tools. By pressing CTRL-A you
will enter the RAW REPL mode. The type in code will not printed. By pressing
CTRL-D the whole entered code will be evaluated and executed. The board will
reply with **OK** and print after that the output (print commands) of the code
or give you tracebacks if an error occured.
You can use **pycard10** (tools/pycard10.py) to execute python files from your
PC directly on the card10.
This diff is collapsed.
``png`` - PNG Decoder
=====================
The ``png`` module provides functions to decode PNG files into raw pixel data
which can be displayed using the card10's display or its LEDs.
.. automodule:: png
:members:
This diff is collapsed.
``pride`` - Pride flags
=======================
The ``pride`` module provides an easy interface to print pride flags to the top LEDs and the display.
.. automodule:: pride
:members:
This diff is collapsed.
This diff is collapsed.