adafruit_magtag.graphics

Helper Library for the Adafruit MagTag.

  • Author(s): Melissa LeBlanc-Williams

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_magtag.graphics.Graphics(*, default_bg: str | int = 16777215, auto_refresh: bool = True, rotation: int = 270, debug: bool = False)

Graphics Helper Class for the MagTag Library

Parameters:
  • default_bg – The path to your default background image file or a hex color. Defaults to 0xFFFFFF.

  • auto_refresh (bool) – Automatically refresh the eInk after writing to displayio. Defaults to True.

  • rotation – Default rotation is landscape (270) but can be 0, 90, 180 for portrait/rotated

  • debug – Turn on debug print outs. Defaults to False.

qrcode(qr_data: bytes | str, *, qr_size: int = 1, x: int = 0, y: int = 0, qr_color: int = 0) None

Display a QR code on the eInk

Parameters:
  • qr_data – The data for the QR code.

  • qr_size (int) – The scale of the QR code.

  • x – The x position of upper left corner of the QR code on the display.

  • y – The y position of upper left corner of the QR code on the display.

set_background(file_or_color: str | int, position: Tuple[int, int] | None = None) None

The background image to a bitmap file.

Parameters:
  • file_or_color – The filename of the chosen background image, or a hex color.

  • position (tuple) – Optional x and y coordinates to place the background at.

adafruit_magtag.magtag

Helper library for the Adafruit MagTag.

  • Author(s): Melissa LeBlanc-Williams

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_magtag.magtag.MagTag(*, url: str | None = None, headers: Dict[str, str] | None = None, json_path: Sequence[Any] | None = None, regexp_path: Sequence[str] | None = None, default_bg: str | int = 16777215, status_neopixel: Pin | NeoPixel | None = None, json_transform: Sequence[Callable] | Callable = None, rotation: int = 270, debug: bool = False)

Class representing the Adafruit MagTag.

Parameters:
  • url – The URL of your data source. Defaults to None.

  • headers – The headers for authentication, typically used by Azure API’s.

  • json_path – The list of json traversal to get data out of. Can be list of lists for multiple data points. Defaults to None to not use json.

  • regexp_path – The list of regexp strings to get data out (use a single regexp group). Can be list of regexps for multiple data points. Defaults to None to not use regexp.

  • default_bg – The path to your default background image file or a hex color. Defaults to 0x000000.

  • status_neopixel – The pin for the status NeoPixel. Use board.NEOPIXEL for the on-board NeoPixel. Defaults to None, to not use the status LED

  • json_transform – A function or a list of functions to call with the parsed JSON. Changes and additions are permitted for the dict object.

  • rotation – Default rotation is landscape (270) but can be 0, 90, or 180 for portrait/rotated

  • debug – Turn on debug print outs. Defaults to False.

enter_light_sleep(sleep_time: float) None

Enter light sleep and resume the program after a certain period of time.

See https://circuitpython.readthedocs.io/en/latest/shared-bindings/alarm/index.html for more details.

Parameters:

sleep_time (float) – The amount of time to sleep in seconds

exit_and_deep_sleep(sleep_time: float) None

Stops the current program and enters deep sleep. The program is restarted from the beginning after a certain period of time.

See https://circuitpython.readthedocs.io/en/latest/shared-bindings/alarm/index.html for more details.

Note: This function is for time based deep sleep only. If you want to use a PinAlarm to wake up from deep sleep you need to deinit() the pins and use the alarm module directly.

Parameters:

sleep_time (float) – The amount of time to sleep in seconds

fetch(refresh_url: str | None = None, timeout: int = 10, auto_refresh: bool = True) Any

Fetch data from the url we initialized with, perfom any parsing, and display text or graphics. This function does pretty much everything Optionally update the URL

Parameters:
  • refresh_url (str) – The overriding URL to fetch from. Defaults to None.

  • timeout (int) – The timeout period in seconds.

refresh() None

Refresh the display

remove_all_text(auto_refresh=True, clear_font_cache=False)

Remove all added text and labels.

Parameters:
  • auto_refresh – Automatically refresh the display after setting the text. Defaults to True.

  • clear_font_cache (bool) – Clear the font cache. Defaults to False.

set_text(val: str, index: int = 0, auto_refresh: bool = True) None

Display text, with indexing into our list of text boxes.

Parameters:
  • val (str) – The text to be displayed

  • index – Defaults to 0.

  • auto_refresh – Automatically refresh the display after setting the text. Defaults to True

adafruit_magtag.network

Helper library for the Adafruit MagTag.

  • Author(s): Melissa LeBlanc-Williams

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_magtag.network.Network(*, status_neopixel: Pin | NeoPixel | None = None, extract_values: bool = True, debug: bool = False)

Class representing the Adafruit MagTag.

Parameters:
  • status_neopixel – The pin for the status NeoPixel. Use board.NEOPIXEL for the on-board NeoPixel. Defaults to None, not the status LED

  • extract_values (bool) – If true, single-length fetched values are automatically extracted from lists and tuples. Defaults to True.

  • debug – Turn on debug print outs. Defaults to False.

property enabled: bool

Get or Set whether the WiFi is enabled

adafruit_magtag.peripherals

Helper Library for the Adafruit MagTag.

  • Author(s): Melissa LeBlanc-Williams

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_magtag.peripherals.Peripherals

Peripherals Helper Class for the MagTag Library

property any_button_pressed: bool

Return whether any button is pressed

property battery: float

Return the voltage of the battery

property button_a_pressed: bool

Return whether Button A is pressed

property button_b_pressed: bool

Return whether Button B is pressed

property button_c_pressed: bool

Return whether Button C is pressed

property button_d_pressed: bool

Return whether Button D is pressed

deinit() None

Call deinit to free all resources used by peripherals. You must call this function before you can use the peripheral pins for other purposes like PinAlarm with deep sleep.

property light: int

Return the value of the light sensor. The neopixel_disable property must be false to get a value.

import time
from adafruit_magtag.magtag import MagTag

magtag = MagTag()

while True:
    print(magtag.peripherals.light)
    time.sleep(0.01)
property neopixel_disable: bool

Enable or disable the neopixels for power savings

play_tone(frequency: float, duration: float) None

Automatically Enable/Disable the speaker and play a tone at the specified frequency for the specified duration It will attempt to play the sound up to 3 times in the case of an error.

property speaker_disable: bool

Enable or disable the speaker for power savings