Test 1.44" 128x128 ST7735 SPI TFTs, on XIAO nRF52840 Sense/CicuitPython

These are two models of ST7735 SPI TFT LCD:
- marked "haoda-SPI-144" green pcb
- marked "KMR1441_SPI V2" red pcb

both are 1.44 inch 128x128, but in difference setting.

It's a exercise run on XIAO nRF52840 Sense with CircuitPython 8.1.0-beta.1, to display on them using adafruit_st7735 and adafruit_st7735r libraries with parameters setting.

remark: I bought "KMR1441_SPI V2" a few years ago. This exercise just for functional testing for programming, not for quality comparison.


Libraries needed
- adafruit_display_shapes folder
- adafruit_st7735.mpy
- adafruit_st7735r.mpy

Connection

#connection
#TFT_GND GND
#TFT_VCC 3V3
TFT_SCL = board.SCK  #D8
TFT_SDA = board.MOSI #D10
TFT_RES = board.D3
TFT_DC  = board.D4
TFT_CS  = board.D5
#TFT_BL  3V3
Both LCDs connected in parallel.

Exercise code

cpynRF_st7735.py
"""
Test on two 1.44" 128x128 ST7735 SPI IFI
- "haoda-SPI-144" green pcb
- "KMR1441_SPI V2" red pcb

with XIAO nRF52840 Sense/CircuitPython 8.1.0-beta.1
"""
import os, sys
import time
import board, busio
import displayio
import adafruit_st7735
import adafruit_st7735r
from adafruit_display_shapes.rect import Rect

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

#--- init ST7735 ---
TFT_WIDTH =128
TFT_HEIGHT=128

#connection
#TFT_GND GND
#TFT_VCC 3V3
TFT_SCL = board.SCK  #D8
TFT_SDA = board.MOSI #D10
TFT_RES = board.D3
TFT_DC  = board.D4
TFT_CS  = board.D5
#TFT_BL  3V3

tft_spi = busio.SPI(clock=TFT_SCL, MOSI=TFT_SDA)
display_bus = displayio.FourWire(
    tft_spi, command=TFT_DC, chip_select=TFT_CS, reset=TFT_RES
)

# for 1.44" 128x128 ST7735S marked "haoda-SPI-144" green pcb
display = adafruit_st7735r.ST7735R(display_bus,
                                   width=TFT_WIDTH, height=TFT_HEIGHT,
                                   colstart=0, rowstart=33,
                                   rotation=0,
                                   bgr=False)
msgDrv = adafruit_st7735r.__name__ + " " + adafruit_st7735r.__version__

"""
# for 1.44" 128x128 ST7735S marked "KMR1441_SPI V2" red pcb
# using adafruit_st7735
display = adafruit_st7735.ST7735(display_bus,
                                 width=TFT_WIDTH, height=TFT_HEIGHT,
                                 rotation=0)
msgDrv = adafruit_st7735.__name__ + " " + adafruit_st7735.__version__
"""
"""
# for 1.44" 128x128 ST7735S marked "KMR1441_SPI V2" red pcb
# using adafruit_st7735r
display = adafruit_st7735r.ST7735R(display_bus,
                                   width=TFT_WIDTH, height=TFT_HEIGHT,
                                   rotation=0,
                                   bgr = True)
msgDrv = adafruit_st7735r.__name__ + " " + adafruit_st7735r.__version__
"""
#------------------------
print("========================================")
print(sys.implementation[0], os.uname()[3],
      "\nrun on", os.uname()[4])
print("========================================")
print(msgDrv)
print("width:   ", display.width)
print("height:  ", display.height)

#------------------------
"""
show() is deprecated and will be removed in CircuitPython 9.0.0. Use .root_group = group instead.
https://docs.circuitpython.org/en/latest/shared-bindings/displayio/index.html#displayio.Display.show
"""
group = displayio.Group()
#display.show(group)
display.root_group = group

no_of_color = 256
bg_bitmap = displayio.Bitmap(display.width, display.height, no_of_color)
bg_palette = displayio.Palette(no_of_color)
bg = displayio.TileGrid(bg_bitmap, pixel_shader=bg_palette)

print("All WHITE")
for i in range(256):
    bg_palette[i] = 0xFFFFFF #All WHITE
    
for x in range(128):
    for y in range(128):
        bg_bitmap[x, y] = x+y
group.append(bg)

sq = Rect(0, 0, display.width, display.height, outline=0xFFFFFF)
group.append(sq)

time.sleep(2)
print("RED")
for i in range(256):
    bg_palette[i] = i*0x10000 #RED

time.sleep(2)
print("GREEN")
for i in range(256):
    bg_palette[i] = i*0x100   #GREEN
    
time.sleep(2)
print("BLUE")
for i in range(256):
    bg_palette[i] = i         #BLUE
    
time.sleep(2)
print("WHITE/GRAY")
for i in range(256):
    bg_palette[i] = i*0x10000 + i*0x100 + i  #WHITE/GRAY
    
while True:
    pass








Comments

Popular posts from this blog

MicroPython/ESP32-C3 + 1.8" 128x160 TFT ST7735 SPI, using boochow/MicroPython-ST7735 library.

CameraWebServe: ESP32-S3 (arduino-esp32) + OV5640 camera module