API Reference
adafruit_fruitjam
Helper library for the FruitJam board
Author(s): Tim Cocks
Implementation Notes
Hardware:
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://circuitpython.org/downloads
# * Adafruit’s Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
- class adafruit_fruitjam.FruitJam(*, url=None, headers=None, json_path=None, regexp_path=None, convert_image=True, default_bg=0x000000, status_neopixel=None, text_font=terminalio.FONT, text_position=None, text_color=0x808080, text_wrap=False, text_maxlen=0, text_transform=None, text_scale=1, json_transform=None, image_json_path=None, image_resize=None, image_position=None, image_dim_json_path=None, caption_text=None, caption_font=None, caption_position=None, caption_color=0x808080, image_url_path=None, success_callback=None, esp=None, external_spi=None, debug=False, secrets_data=None)
Class representing the Adafruit Fruit Jam.
- 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
Noneto 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
Noneto not use regexp.convert_image – Determine whether or not to use the AdafruitIO image converter service. Set as False if your image is already resized. Defaults to True.
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.NEOPIXELfor the on-board NeoPixel. Defaults toNone, not the status LEDtext_font (str) – The path to your font file for your data text display.
text_position – The position of your extracted text on the display in an (x, y) tuple. Can be a list of tuples for when there’s a list of json_paths, for example
text_color – The color of the text, in 0xRRGGBB format. Can be a list of colors for when there’s multiple texts. Defaults to
None.text_wrap – Whether or not to wrap text (for long text data chunks). Defaults to
False, no wrapping.text_maxlen – The max length of the text for text wrapping. Defaults to 0.
text_transform – A function that will be called on the text before display
text_scale (int) – The factor to scale the default size of the text by
json_transform – A function or a list of functions to call with the parsed JSON. Changes and additions are permitted for the
dictobject.image_json_path – The JSON traversal path for a background image to display. Defaults to
None.image_resize – What size to resize the image we got from the json_path, make this a tuple of the width and height you want. Defaults to
None.image_position – The position of the image on the display as an (x, y) tuple. Defaults to
None.image_dim_json_path – The JSON traversal path for the original dimensions of image tuple. Used with fetch(). Defaults to
None.success_callback – A function we’ll call if you like, when we fetch data successfully. Defaults to
None.caption_text (str) – The text of your caption, a fixed text not changed by the data we get. Defaults to
None.caption_font (str) – The path to the font file for your caption. Defaults to
None.caption_position – The position of your caption on the display as an (x, y) tuple. Defaults to
None.caption_color – The color of your caption. Must be a hex value, e.g.
0x808000.image_url_path – The HTTP traversal path for a background image to display. Defaults to
None.esp – A passed ESP32 object, Can be used in cases where the ESP32 chip needs to be used before calling the pyportal class. Defaults to
None.external_spi (busio.SPI) – A previously declared spi object. Defaults to
None.debug – Turn on debug print outs. Defaults to False.
- fetch(refresh_url=None, timeout=10, force_content_type=None)
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
- set_caption(caption_text, caption_position, caption_color)
A caption. Requires setting
caption_fontin init!- Parameters:
caption_text – The text of the caption.
caption_position – The position of the caption text.
caption_color – The color of your caption text. Must be a hex value, e.g.
0x808000.
- sync_time(**kwargs)
Set the system RTC via NTP using this FruitJam’s Network.
This is a convenience wrapper for
self.network.sync_time(...).- Parameters:
server (str) – Override NTP host (defaults to
NTP_SERVERor"pool.ntp.org"if unset). (Pass viaserver=...in kwargs.)tz_offset (float) – Override hours from UTC (defaults to
NTP_TZ;NTP_DSTis still added). (Pass viatz_offset=....)tuning (dict) – Advanced options dict (optional). Supported keys:
timeout(float, socket timeout seconds; defaults toNTP_TIMEOUTor 5.0),cache_seconds(int; defaults toNTP_CACHE_SECONDSor 0),require_year(int; defaults toNTP_REQUIRE_YEARor 2022). (Pass viatuning={...}.)
- Returns:
Synced time
- Return type:
adafruit_fruitjam.peripherals
Hardware peripherals for Adafruit Fruit Jam
Author(s): Tim Cocks
Implementation Notes
Hardware:
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://circuitpython.org/downloads
# * Adafruit’s Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
- class adafruit_fruitjam.peripherals.Peripherals(audio_output: str = 'headphone', safe_volume_limit: float = 0.75, sample_rate: int = 11025, bit_depth: int = 16, i2c: I2C = None)
Peripherals Helper Class for the FruitJam Library
- Parameters:
audio_output – The audio output interface to use ‘speaker’ or ‘headphone’
safe_volume_limit – The maximum volume allowed for the audio output. Default is 0.75. Using higher values can damage some speakers, change at your own risk.
sample_rate – The sample rate to play back audio data in hertz. Default is 11025.
bit_depth – The bits per sample of the audio data. Supports 8 and 16 bits. Default is 16.
i2c – The I2C bus the audio DAC is connected to. Set as False to disable audio.
- neopixels
The NeoPixels on the Fruit Jam board. See https://circuitpython.readthedocs.io/projects/neopixel/en/latest/api.html
- Type:
NeoPxiels
- property audio: audiobusio.I2SOut
Instance of
audiobusio.I2SOutready to play audio through the TLV320 DAC.
- property dac: TLV320DAC3100
The instance of the
adafruit_tlv320.TLV320DAC3100driver class. Can be used for lower level DAC control.
- play_file(file_name, wait_to_finish=True)
Play a wav file.
- play_mp3_file(filename: str)
Play a mp3 audio file.
- Parameters:
filename (str) – The name of the mp3 file to play.
- stop_play()
Stops playing a wav file.
- adafruit_fruitjam.peripherals.get_display_config()
Get the current display size configuration.
- Returns:
display_config: Tuple containing the width, height, and color_depth of the display in pixels and bits respectively.
- adafruit_fruitjam.peripherals.request_display_config(width=None, height=None, color_depth=None)
Request a display size configuration. If the display is un-initialized, or is currently using a different configuration it will be initialized to the requested width and height.
This function will set the initialized display to
supervisor.runtime.display- Parameters:
width – The width of the display in pixels. Leave unspecified to default to the
CIRCUITPY_DISPLAY_WIDTHenvironmental variable if provided. Otherwise, aValueErrorexception will be thrown.height – The height of the display in pixels. Leave unspecified to default to the appropriate height for the provided width.
color_depth – The color depth of the display in bits. Valid values are 1, 2, 4, 8, 16, 32. Larger resolutions must use smaller color_depths due to RAM limitations. Default color_depth for 720 and 640 width is 8, and default color_depth for 320 and 360 width is 16.
- Returns:
None