Skip to content

Instantly share code, notes, and snippets.

@mcauser
Last active October 15, 2021 02:24
Show Gist options
  • Select an option

  • Save mcauser/c84ac7a64ae43d6b8a54d65b3b090380 to your computer and use it in GitHub Desktop.

Select an option

Save mcauser/c84ac7a64ae43d6b8a54d65b3b090380 to your computer and use it in GitHub Desktop.

Revisions

  1. mcauser revised this gist Oct 15, 2021. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions tinys2_ips_cpy_demo.py
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,8 @@

    # https://unexpectedmaker.com/tinys2
    # https://www.tinypico.com/add-ons
    # https://circuitpython.org/board/unexpectedmaker_tinys2/
    # https://github.com/adafruit/Adafruit_CircuitPython_ST7735

    # The IPS display has pins labelled for TinyPICO.
    # These are the matching TinyS2 pins.
  2. mcauser created this gist Oct 15, 2021.
    135 changes: 135 additions & 0 deletions tinys2_ips_cpy_demo.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,135 @@
    # UM TinyS2 + RGB IPS Display Shield CircuitPython example

    # https://unexpectedmaker.com/tinys2
    # https://www.tinypico.com/add-ons

    # The IPS display has pins labelled for TinyPICO.
    # These are the matching TinyS2 pins.

    # Pin TinyPICO TinyS2
    # SCK IO5 IO37
    # MISO IO19 IO36
    # MOSI IO23 IO35
    # CS IO5 IO14
    # D/C IO15 IO6
    # BL IO14 IO5

    # ------------------------------
    # Example 1: Basic displayio

    # You should see
    # +--------------------------+
    # |Snake |
    # | |
    # | >>> print('Hello') |
    # | Hello |
    # | >>> |
    # +--------------------------+

    import board
    import busio
    import displayio
    from digitalio import DigitalInOut, Direction
    from adafruit_st7735r import ST7735R

    spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)

    backlight = DigitalInOut(board.IO5)
    backlight.direction = Direction.OUTPUT
    backlight.value = True

    displayio.release_displays()
    display_bus = displayio.FourWire(spi, command=board.IO6, chip_select=board.IO14, reset=None)

    # if you set the intial rotation to 0 or 180, set width=80 and height=160
    # if you set the intial rotation to 90 or 270, set width=160 and height=80
    display = ST7735R(display_bus, width=80, height=160, colstart=26, rowstart=1, rotation=0, bgr=False, invert=True)
    # display = ST7735R(display_bus, width=160, height=80, colstart=26, rowstart=1, rotation=90, bgr=False, invert=True)
    # display = ST7735R(display_bus, width=80, height=160, colstart=26, rowstart=1, rotation=180, bgr=False, invert=True)
    # display = ST7735R(display_bus, width=160, height=80, colstart=26, rowstart=1, rotation=270, bgr=False, invert=True)

    # after constructing ST7735R, you're free to change it without resetting width/height
    # display.rotation = 0
    display.rotation = 90
    # display.rotation = 180
    # display.rotation = 270

    print('Hello')

    # ------------------------------
    # Example 2: Coloured text

    # You should see
    # +--------------------------+
    # | Red Cyan |
    # | Green Magenta |
    # | Blue Yellow |
    # | White Black |
    # +--------------------------+

    # Note: if your Red+Blue are swapped, change `bgr=False` to `bgr=True` in the ST7735R constructor

    import board
    import busio
    import displayio
    import terminalio
    from digitalio import DigitalInOut, Direction
    from adafruit_st7735r import ST7735R
    from adafruit_display_text import label

    spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)

    backlight = DigitalInOut(board.IO5)
    backlight.direction = Direction.OUTPUT
    backlight.value = True

    displayio.release_displays()
    display_bus = displayio.FourWire(spi, command=board.IO6, chip_select=board.IO14, reset=None)

    display = ST7735R(display_bus, width=160, height=80, colstart=26, rowstart=1, rotation=90, bgr=False, invert=True)

    # some colours
    red = 0xFF0000
    green = 0x00FF00
    blue = 0x0000FF
    white = 0xFFFFFF
    cyan = 0x00FFFF
    magenta = 0xFF00FF
    yellow = 0xFFFF00
    black = 0x000000
    light_grey = 0x111111

    splash = displayio.Group(max_size=10)
    display.show(splash)

    # fill the screen with light grey
    color_bitmap = displayio.Bitmap(160, 80, 1)
    color_palette = displayio.Palette(1)
    color_palette[0] = light_grey

    bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
    splash.append(bg_sprite)

    # add some text to the left side
    text_group_left = displayio.Group(max_size=10, scale=1, x=0, y=6)
    text_area_red = label.Label(terminalio.FONT, text="RED", color=red)
    text_area_green = label.Label(terminalio.FONT, text="\nGREEN", color=green)
    text_area_blue = label.Label(terminalio.FONT, text="\n\nBLUE", color=blue)
    text_area_white = label.Label(terminalio.FONT, text="\n\n\nWHITE", color=white)
    text_group_left.append(text_area_red)
    text_group_left.append(text_area_green)
    text_group_left.append(text_area_blue)
    text_group_left.append(text_area_white)
    splash.append(text_group_left)

    # add some text to the right side
    text_group_right = displayio.Group(max_size=10, scale=1, x=80, y=6)
    text_area_cyan = label.Label(terminalio.FONT, text="CYAN", color=cyan)
    text_group_right.append(text_area_cyan)
    text_area_magenta = label.Label(terminalio.FONT, text="\nMAGENTA", color=magenta)
    text_group_right.append(text_area_magenta)
    text_area_yellow = label.Label(terminalio.FONT, text="\n\nYELLOW", color=yellow)
    text_group_right.append(text_area_yellow)
    text_area_black = label.Label(terminalio.FONT, text="\n\n\nBLACK", color=black)
    text_group_right.append(text_area_black)
    splash.append(text_group_right)