init_sequence_hd458 = bytes(( b'\xff\x05w\x01\x00\x00\x13' b'\xef\x01\x08' b'\xff\x05w\x01\x00\x00\x10' b'\xc0\x02w\x00' b'\xc1\x02\t\x08' b'\xc2\x02\x01\x02' b'\xc3\x01\x02' b'\xcc\x01\x10' b'\xb0\x10@\x14Y\x10\x12\x08\x03\t\x05\x1e\x05\x14\x10h3\x15' b'\xb1\x10@\x08S\t\x11\t\x02\x07\t\x1a\x04\x12\x12d))' b'\xff\x05w\x01\x00\x00\x11' b'\xb0\x01m' b'\xb1\x01\x1d' b'\xb2\x01\x87' b'\xb3\x01\x80' b'\xb5\x01I' b'\xb7\x01\x85' b'\xb8\x01 ' b'\xc1\x01x' b'\xc2\x01x' b'\xd0\x01\x88' b'\xe0\x03\x00\x00\x02' b'\xe1\x0b\x02\x8c\x00\x00\x03\x8c\x00\x00\x0033' b'\xe2\r3333\xc9<\x00\x00\xca<\x00\x00\x00' b'\xe3\x04\x00\x0033' b'\xe4\x02DD' b'\xe5\x10\x05\xcd\x82\x82\x01\xc9\x82\x82\x07\xcf\x82\x82\x03\xcb\x82\x82' b'\xe6\x04\x00\x0033' b'\xe7\x02DD' b'\xe8\x10\x06\xce\x82\x82\x02\xca\x82\x82\x08\xd0\x82\x82\x04\xcc\x82\x82' b'\xeb\x07\x08\x01\xe4\xe4\x88\x00@' b'\xec\x03\x00\x00\x00' b'\xed\x10\xff\xf0\x07eO\xfc\xc2/\xf2,\xcf\xf4Vp\x0f\xff' b'\xef\x06\x10\r\x04\x08?\x1f' b'\xff\x05w\x01\x00\x00\x00' b'\x11\x80x' b'5\x01\x00' b':\x81fd' b')\x00' ))
tft_timings = { "frequency": 16000000, "width": 320, "height": 960, "overscan_left": 80, "hsync_pulse_width": 10, "hsync_front_porch": 30, "hsync_back_porch": 50, "hsync_idle_low": False, "vsync_pulse_width": 2, "vsync_front_porch": 15, "vsync_back_porch": 17, "vsync_idle_low": False, "pclk_active_high": False, "pclk_idle_high": False, "de_idle_high": False, }
from displayio import release_displays release_displays() import time import random import displayio import busio import board import dotclockframebuffer from framebufferio import FramebufferDisplay tft_pins = dict(board.TFT_PINS) tft_timings = { "frequency": 16000000, "width": 320, "height": 960, "overscan_left": 80, "hsync_pulse_width": 10, "hsync_front_porch": 30, "hsync_back_porch": 50, "hsync_idle_low": False, "vsync_pulse_width": 2, "vsync_front_porch": 15, "vsync_back_porch": 17, "vsync_idle_low": False, "pclk_active_high": False, "pclk_idle_high": False, "de_idle_high": False, } init_sequence_hd458 = bytes(( b'\xff\x05w\x01\x00\x00\x13' b'\xef\x01\x08' b'\xff\x05w\x01\x00\x00\x10' b'\xc0\x02w\x00' b'\xc1\x02\t\x08' b'\xc2\x02\x01\x02' b'\xc3\x01\x02' b'\xcc\x01\x10' b'\xb0\x10@\x14Y\x10\x12\x08\x03\t\x05\x1e\x05\x14\x10h3\x15' b'\xb1\x10@\x08S\t\x11\t\x02\x07\t\x1a\x04\x12\x12d))' b'\xff\x05w\x01\x00\x00\x11' b'\xb0\x01m' b'\xb1\x01\x1d' b'\xb2\x01\x87' b'\xb3\x01\x80' b'\xb5\x01I' b'\xb7\x01\x85' b'\xb8\x01 ' b'\xc1\x01x' b'\xc2\x01x' b'\xd0\x01\x88' b'\xe0\x03\x00\x00\x02' b'\xe1\x0b\x02\x8c\x00\x00\x03\x8c\x00\x00\x0033' b'\xe2\r3333\xc9<\x00\x00\xca<\x00\x00\x00' b'\xe3\x04\x00\x0033' b'\xe4\x02DD' b'\xe5\x10\x05\xcd\x82\x82\x01\xc9\x82\x82\x07\xcf\x82\x82\x03\xcb\x82\x82' b'\xe6\x04\x00\x0033' b'\xe7\x02DD' b'\xe8\x10\x06\xce\x82\x82\x02\xca\x82\x82\x08\xd0\x82\x82\x04\xcc\x82\x82' b'\xeb\x07\x08\x01\xe4\xe4\x88\x00@' b'\xec\x03\x00\x00\x00' b'\xed\x10\xff\xf0\x07eO\xfc\xc2/\xf2,\xcf\xf4Vp\x0f\xff' b'\xef\x06\x10\r\x04\x08?\x1f' b'\xff\x05w\x01\x00\x00\x00' b'\x11\x80x' b'5\x01\x00' b':\x81fd' b')\x00' )) board.I2C().deinit() i2c = busio.I2C(board.SCL, board.SDA) tft_io_expander = dict(board.TFT_IO_EXPANDER) #tft_io_expander['i2c_address'] = 0x38 # uncomment for rev B dotclockframebuffer.ioexpander_send_init_sequence(i2c, init_sequence_hd458, **tft_io_expander) i2c.deinit() BAR_WIDTH = 256 BAR_HEIGHT = 64 bitmap = displayio.Bitmap(BAR_WIDTH, 7*BAR_HEIGHT, 65535) fb = dotclockframebuffer.DotClockFramebuffer(**tft_pins, **tft_timings) display = FramebufferDisplay(fb, auto_refresh=False) # Create a TileGrid to hold the bitmap tile_grid = displayio.TileGrid(bitmap, pixel_shader=displayio.ColorConverter(input_colorspace=displayio.Colorspace.RGB565)) # Create a Group to hold the TileGrid group = displayio.Group() # Add the TileGrid to the Group group.append(tile_grid) # Add the Group to the Display display.root_group = group display.auto_refresh = True for i in range(BAR_WIDTH): b = i >> 3 g = (i >> 2) << 5 r = b << 11 for j in range(BAR_HEIGHT): bitmap[i, j] = b bitmap[i, j+BAR_HEIGHT*1] = b|g bitmap[i, j+BAR_HEIGHT*2] = g bitmap[i, j+BAR_HEIGHT*3] = g|r bitmap[i, j+BAR_HEIGHT*4] = r bitmap[i, j+BAR_HEIGHT*5] = r|b bitmap[i, j+BAR_HEIGHT*6] = r|g|b # Loop forever so you can enjoy your image while True: time.sleep(1) display.auto_refresh = False group.x = random.randint(0, display.width - BAR_WIDTH) group.y = random.randint(0, display.height - BAR_HEIGHT*7) display.auto_refresh = True
Go ahead and save the example you your CircuitPython code.py and run the code. Your display should now look like this:
Text editor powered by tinymce.