Ejemplo n.º 1
0
    def __init__(self,
                 *,
                 width=64,
                 height=32,
                 bit_depth=2,
                 alt_addr_pins=None,
                 color_order="RGB"):

        if not isinstance(color_order, str):
            raise ValueError("color_index should be a string")
        color_order = color_order.lower()
        red_index = color_order.find("r")
        green_index = color_order.find("g")
        blue_index = color_order.find("b")
        if -1 in (red_index, green_index, blue_index):
            raise ValueError("color_order should contain R, G, and B")

        if "Matrix Portal M4" in os.uname().machine:
            # MatrixPortal M4 Board
            addr_pins = [board.MTX_ADDRA, board.MTX_ADDRB, board.MTX_ADDRC]
            if height > 16:
                addr_pins.append(board.MTX_ADDRD)
            if height > 32:
                addr_pins.append(board.MTX_ADDRE)
            rgb_pins = [
                board.MTX_R1,
                board.MTX_G1,
                board.MTX_B1,
                board.MTX_R2,
                board.MTX_G2,
                board.MTX_B2,
            ]
            clock_pin = board.MTX_CLK
            latch_pin = board.MTX_LAT
            oe_pin = board.MTX_OE
        elif "Feather" in os.uname().machine:
            # Feather Style Board
            if "nrf52" in os.uname().sysname:
                # nrf52840 Style Feather
                addr_pins = [board.D11, board.D5, board.D13]
                if height > 16:
                    addr_pins.append(board.D9)
                rgb_pins = [
                    board.D6, board.A5, board.A1, board.A0, board.A4, board.D11
                ]
                clock_pin = board.D12
            else:
                addr_pins = [board.A5, board.A4, board.A3]
                if height > 16:
                    addr_pins.append(board.A2)
                rgb_pins = [
                    board.D6,
                    board.D5,
                    board.D9,
                    board.D11,
                    board.D10,
                    board.D12,
                ]
                clock_pin = board.D13
            latch_pin = board.D0
            oe_pin = board.D1
        else:
            # Metro/Grand Central Style Board
            if alt_addr_pins is None and height <= 16:
                raise RuntimeError(
                    "Pin A2 unavailable in this mode. Please specify alt_addr_pins."
                )
            addr_pins = [board.A0, board.A1, board.A2, board.A3]
            rgb_pins = [
                board.D2, board.D3, board.D4, board.D5, board.D6, board.D7
            ]
            clock_pin = board.A4
            latch_pin = board.D10
            oe_pin = board.D9

        # Alternate Address Pins
        if alt_addr_pins is not None:
            addr_pins = alt_addr_pins

        try:
            displayio.release_displays()
            matrix = rgbmatrix.RGBMatrix(
                width=width,
                height=height,
                bit_depth=bit_depth,
                rgb_pins=(
                    rgb_pins[red_index],
                    rgb_pins[green_index],
                    rgb_pins[blue_index],
                    rgb_pins[red_index + 3],
                    rgb_pins[green_index + 3],
                    rgb_pins[blue_index + 3],
                ),
                addr_pins=addr_pins,
                clock_pin=clock_pin,
                latch_pin=latch_pin,
                output_enable_pin=oe_pin,
            )
            self.display = framebufferio.FramebufferDisplay(matrix)
        except ValueError:
            raise RuntimeError(
                "Failed to initialize RGB Matrix") from ValueError
Ejemplo n.º 2
0
import board
import displayio
from display_layouts.absolute_layout import AbsoluteLayout
from adafruit_bitmapsaver import save_pixels
import time
import adafruit_ili9341

DIR = "./screenshots/"

# Release any resources currently in use for the displays
displayio.release_displays()

spi = board.SPI()
tft_cs = board.CE0
tft_dc = board.D25

display_bus = displayio.FourWire(spi,
                                 command=tft_dc,
                                 chip_select=tft_cs,
                                 reset=board.D24)
display = adafruit_ili9341.ILI9341(display_bus, width=320, height=240)

board.DISPLAY = display

f = open("layouts/badge_test.json", "r")
layout_str = f.read()
f.close()
main_layout = AbsoluteLayout(board.DISPLAY, layout_str)
board.DISPLAY.show(main_layout.view)
main_layout.sub_view_by_id("name_lbl").label.text = "Blinka"
main_layout.sub_view_by_id("name_lbl").update_position()
Ejemplo n.º 3
0
# Minimal example displaying an image tiled across multiple RGB LED matrices.
# This is written for MatrixPortal and four 64x32 pixel matrices, but could
# be adapted to different boards and matrix combinations.
# No additional libraries required, just uses displayio.
# Image wales.bmp should be in CIRCUITPY root directory.

import board
import displayio
import framebufferio
import rgbmatrix

displayio.release_displays()  # Release current display, we'll create our own

# Create RGB matrix object for a chain of four 64x32 matrices tiled into
# a single 128x64 pixel display -- two matrices across, two down, with the
# second row being flipped. width and height args are the combined size of
# all the tiled sub-matrices. tile arg is the number of rows of matrices in
# the chain (horizontal tiling is implicit from the width argument, doesn't
# need to be specified, but vertical tiling must be explicitly stated).
# The serpentine argument indicates whether alternate rows are flipped --
# cabling is easier this way, downside is colors may be slightly different
# when viewed off-angle. bit_depth and pins are same as other examples.
MATRIX = rgbmatrix.RGBMatrix(width=128,
                             height=64,
                             bit_depth=6,
                             tile=2,
                             serpentine=True,
                             rgb_pins=[
                                 board.MTX_R1, board.MTX_G1, board.MTX_B1,
                                 board.MTX_R2, board.MTX_G2, board.MTX_B2
                             ],