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=16777215, auto_refresh=True, rotation=270, debug=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, *, qr_size=1, x=0, y=0, qr_color=0)

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, position=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=None, headers=None, json_path=None, regexp_path=None, default_bg=16777215, status_neopixel=None, json_transform=None, rotation=270, debug=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)

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)

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.

Parameters

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

fetch(refresh_url=None, timeout=10, auto_refresh=True)

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()

Refresh the display

set_text(val, index=0, auto_refresh=True)

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=None, extract_values=True, debug=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

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

Return whether any button is pressed

property battery

Return the voltage of the battery

property button_a_pressed

Return whether Button A is pressed

property button_b_pressed

Return whether Button B is pressed

property button_c_pressed

Return whether Button C is pressed

property button_d_pressed

Return whether Button D is pressed

deinit()

Call deinit on all resources to free them

property light

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

Enable or disable the neopixels for power savings

play_tone(frequency, duration)

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

Enable or disable the speaker for power savings