code.py
 1  # SPDX-FileCopyrightText: 2019 Carter Nelson for Adafruit Industries
 2  #
 3  # SPDX-License-Identifier: MIT
 4  
 5  import board
 6  import displayio
 7  
 8  # Release any previously configured displays
 9  displayio.release_displays()
10  
11  # Setup SPI bus
12  spi_bus = board.SPI()
13  
14  # Digital pins to use
15  tft_cs = board.D10
16  tft_dc = board.D9
17  
18  # Setup the display bus
19  display_bus = displayio.FourWire(spi_bus, command=tft_dc, chip_select=tft_cs)
20  
21  # Setup the initialization sequence
22  # stolen from adafruit_ili9341.py
23  INIT_SEQUENCE = (
24      b"\x01\x80\x80"            # Software reset then delay 0x80 (128ms)
25      b"\xEF\x03\x03\x80\x02"
26      b"\xCF\x03\x00\xC1\x30"
27      b"\xED\x04\x64\x03\x12\x81"
28      b"\xE8\x03\x85\x00\x78"
29      b"\xCB\x05\x39\x2C\x00\x34\x02"
30      b"\xF7\x01\x20"
31      b"\xEA\x02\x00\x00"
32      b"\xc0\x01\x23"            # Power control VRH[5:0]
33      b"\xc1\x01\x10"            # Power control SAP[2:0];BT[3:0]
34      b"\xc5\x02\x3e\x28"        # VCM control
35      b"\xc7\x01\x86"            # VCM control2
36      b"\x36\x01\x38"            # Memory Access Control
37      b"\x37\x01\x00"            # Vertical scroll zero
38      b"\x3a\x01\x55"            # COLMOD: Pixel Format Set
39      b"\xb1\x02\x00\x18"        # Frame Rate Control (In Normal Mode/Full Colors)
40      b"\xb6\x03\x08\x82\x27"    # Display Function Control
41      b"\xF2\x01\x00"            # 3Gamma Function Disable
42      b"\x26\x01\x01"            # Gamma curve selected
43      b"\xe0\x0f\x0F\x31\x2B\x0C\x0E\x08\x4E\xF1\x37\x07\x10\x03\x0E\x09\x00" # Set Gamma
44      b"\xe1\x0f\x00\x0E\x14\x03\x11\x07\x31\xC1\x48\x08\x0F\x0C\x31\x36\x0F" # Set Gamma
45      b"\x11\x80\x78"            # Exit Sleep then delay 0x78 (120ms)
46      b"\x29\x80\x78"            # Display on then delay 0x78 (120ms)
47  )
48  
49  # Setup the Display
50  display = displayio.Display(display_bus, INIT_SEQUENCE, width=320, height=240)
51  
52  #
53  # DONE - now you can use the display however you want
54  #
55  
56  bitmap = displayio.Bitmap(320, 240, 2)
57  
58  palette = displayio.Palette(2)
59  palette[0] = 0
60  palette[1] = 0xFFFFFF
61  
62  for x in range(10, 20):
63      for y in range(10, 20):
64          bitmap[x, y] = 1
65  
66  tile_grid = displayio.TileGrid(bitmap, pixel_shader=palette)
67  
68  group = displayio.Group()
69  group.append(tile_grid)
70  display.show(group)
71  
72  # Loop forever so you can enjoy your image
73  while True:
74      pass