adafruit_simple_text_display

A helper library for displaying lines of text on a display using displayio.

  • Author(s): Kattni Rembor

Implementation Notes

Hardware:

Any microcontroller with a built-in display, or an external display.

Software and Dependencies:

class adafruit_simple_text_display.SimpleTextDisplay(title=None, title_color=(255, 255, 255), title_scale: int = 1, title_length: int = 0, text_scale: int = 1, font=None, colors=None, display=None)

Easily display lines of text on a display using displayio.

Display lines of text on a display using displayio. Lines of text are created in order as shown in the example below. If you skip a number, the line will be shown blank on the display, e.g. if you include [0] and [2], the second line on the display will be empty, and the text specified for lines 0 and 2 will be displayed on the first and third line. Remember, Python begins counting at 0, so the first line on the display is 0 in the code. Setup occurs before the loop. For data to be dynamically updated on the display, you must include the data call in the loop by using .text =. For example, if setup is saved as temperature_data = simple_text_display() then temperature_data[0].text = microcontroller.cpu.temperature must be inside the while True: loop for the temperature data displayed to update as the values change. You must call show() at the end of the list for anything to display. See example below for usage.

Parameters
  • title (None,str) – The title displayed above the data. Set title="Title text" to provide a title. Defaults to None.

  • title_color (None,Tuple(int,int,int)) – The color of the title. Not necessary if no title is provided. Defaults to white (255, 255, 255).

  • title_scale (int) – Scale the size of the title. Not necessary if no title is provided. Defaults to 1.

  • title_length (int) – DEPRECATED/IGNORED - This will be removed in a future version.

  • text_scale (int) – Scale the size of the data lines. Scales the title as well. Defaults to 1.

  • font (BuiltinFont,BDF,PCF) – The font to use to display the title and data. Defaults to terminalio.FONT.

  • colors (None,Tuple(Tuple(int,int,int),...)) – A list of colors for the lines of data on the display. If you provide a single color, all lines will be that color. Otherwise it will cycle through the list you provide if the list is less than the number of lines displayed. Default colors are used if colors is not set. For example, if creating two lines of data, colors=((255, 255, 255), (255, 0, 0)) would set the first line white and the second line red, and if you created four lines of data with the same setup, it would alternate white and red. You can also use the colors built into the library. For example, if you import the library as from adafruit_simple_text_display import SimpleTextDisplay, you can indicate the colors as follows: colors=(SimpleTextDisplay.WHITE, SimpleTextDisplay.RED).

  • display (None,Display) – The display object. Defaults to assuming a built-in display. To use with an external display, instantiate the display object and provide it here. Defaults to board.DISPLAY.

This example displays two lines with temperature data in C and F on the display. Remember to call show() after the list to update the display.

import microcontroller
from adafruit_simple_text_display import SimpleTextDisplay

temperature_data = SimpleTextDisplay(title="Temperature Data!", title_scale=2)

while True:
    sensor_data[0].text = "Temperature: {:.2f} degrees C".format(
        microcontroller.cpu.temperature
    )
    sensor_data[1].text = "Temperature: {:.2f} degrees F".format(
        (microcontroller.cpu.temperature * (9 / 5) + 32)
    )
    sensor_data.show()
add_text_line(color=(255, 255, 255))

Adds a line on the display of the specified color and returns the label object.

show()

Call show() to display the data list.

show_terminal()

Revert to terminalio screen.