I use MicroPython.
You may find this helpful as it uses the standard frame buffer. This was written for a Waveshare display but will probably work.
# WS 320x240 display example
from machine import Pin,SPI,PWM
import framebuf
import utime
import os
import gc
import micropython
def report():
gc.collect()
micropython.mem_info()
print('-----------------------------')
print('Initial free: {} allocated: {}'.format(gc.mem_free(), gc.mem_alloc()))
def func():
a = bytearray(100) # 10000
gc.collect()
print('Func definition: {} allocated: {}'.format(gc.mem_free(), gc.mem_alloc()))
func()
print('Func run free: {} allocated: {}'.format(gc.mem_free(), gc.mem_alloc()))
gc.collect()
print('Garbage collect free: {} allocated: {}'.format(gc.mem_free(), gc.mem_alloc()))
print('-----------------------------')
print("\nFirst - After loading libraries")
report()
print()
BL = 13
DC = 8
RST = 12
MOSI = 11
SCK = 10
CS = 9
class LCD_1inch3(framebuf.FrameBuffer): # For 320x240 display
def __init__(self):
self.width = 320
self.height = 240
self.cs = Pin(CS,Pin.OUT)
self.rst = Pin(RST,Pin.OUT)
self.cs(1)
self.spi = SPI(1)
self.spi = SPI(1,1000_000)
self.spi = SPI(1,100000_000,polarity=0, phase=0,sck=Pin(SCK),mosi=Pin(MOSI),miso=None)
self.dc = Pin(DC,Pin.OUT)
self.dc(1)
self.buffer = bytearray(self.height * self.width * 2)
super().__init__(self.buffer, self.width, self.height, framebuf.RGB565)
self.init_display()
self.RED = 0x07E0
self.GREEN = 0x001f
self.BLUE = 0xf800
self.WHITE = 0xffff
self.BALCK = 0x0000
def write_cmd(self, cmd):
self.cs(1)
self.dc(0)
self.cs(0)
self.spi.write(bytearray([cmd]))
self.cs(1)
def write_data(self, buf):
self.cs(1)
self.dc(1)
self.cs(0)
self.spi.write(bytearray([buf]))
self.cs(1)
def init_display(self):
"""Initialize display"""
self.rst(1)
self.rst(0)
self.rst(1)
self.write_cmd(0x36)
self.write_data(0x70)
self.write_cmd(0x3A)
self.write_data(0x05)
self.write_cmd(0xB2)
self.write_data(0x0C)
self.write_data(0x0C)
self.write_data(0x00)
self.write_data(0x33)
self.write_data(0x33)
self.write_cmd(0xB7)
self.write_data(0x35)
self.write_cmd(0xBB)
self.write_data(0x19)
self.write_cmd(0xC0)
self.write_data(0x2C)
self.write_cmd(0xC2)
self.write_data(0x01)
self.write_cmd(0xC3)
self.write_data(0x12)
self.write_cmd(0xC4)
self.write_data(0x20)
self.write_cmd(0xC6)
self.write_data(0x0F)
self.write_cmd(0xD0)
self.write_data(0xA4)
self.write_data(0xA1)
self.write_cmd(0xE0)
self.write_data(0xD0)
self.write_data(0x04)
self.write_data(0x0D)
self.write_data(0x11)
self.write_data(0x13)
self.write_data(0x2B)
self.write_data(0x3F)
self.write_data(0x54)
self.write_data(0x4C)
self.write_data(0x18)
self.write_data(0x0D)
self.write_data(0x0B)
self.write_data(0x1F)
self.write_data(0x23)
self.write_cmd(0xE1)
self.write_data(0xD0)
self.write_data(0x04)
self.write_data(0x0C)
self.write_data(0x11)
self.write_data(0x13)
self.write_data(0x2C)
self.write_data(0x3F)
self.write_data(0x44)
self.write_data(0x51)
self.write_data(0x2F)
self.write_data(0x1F)
self.write_data(0x1F)
self.write_data(0x20)
self.write_data(0x23)
self.write_cmd(0x21)
self.write_cmd(0x11)
self.write_cmd(0x29)
def show(self):
self.write_cmd(0x2A)
self.write_data(0x00)
self.write_data(0x00)
self.write_data(0x01)
self.write_data(0x3f)
self.write_cmd(0x2B)
self.write_data(0x00)
self.write_data(0x00)
self.write_data(0x00)
self.write_data(0xEF)
self.write_cmd(0x2C)
self.cs(1)
self.dc(1)
self.cs(0)
self.spi.write(self.buffer)
self.cs(1)
# Colour Mixing Routine
def colour(R,G,B): # Compact method!
mix1 = ((R&0xF8)*256) + ((G&0xFC)*8) + ((B&0xF8)>>3)
return (mix1 & 0xFF) *256 + int((mix1 & 0xFF00) /256) # low nibble first
# ==== Main ====
pwm = PWM(Pin(BL))
pwm.freq(1000)
pwm.duty_u16(32768)#max 65535
print("\nSecond - before initialising the display")
report()
LCD = LCD_1inch3()
#color BRG
LCD.fill(LCD.WHITE)
LCD.show()
print("\nThird - After initialising and clearing the display")
report()
utime.sleep(0.1)
LCD.fill_rect(0,0,320,24,LCD.RED)
LCD.rect(0,0,320,24,LCD.RED)
LCD.text("Raspberry Pi Pico",2,8,LCD.WHITE)
utime.sleep(0.1)
LCD.show()
LCD.fill_rect(0,24,320,24,LCD.BLUE)
LCD.rect(0,24,320,24,LCD.BLUE)
LCD.text("PicoGo",2,32,LCD.WHITE)
utime.sleep(0.1)
LCD.show()
LCD.fill_rect(0,48,320,24,LCD.GREEN)
LCD.rect(0,48,320,24,LCD.GREEN)
LCD.text("Pico-LCD-2",2,54,LCD.WHITE)
utime.sleep(0.1)
LCD.show()
LCD.fill_rect(0,72,320,24,0X07FF)
LCD.rect(0,72,320,24,0X07FF)
utime.sleep(0.1)
LCD.show()
LCD.fill_rect(0,96,320,24,0xF81F)
LCD.rect(0,96,320,24,0xF81F)
utime.sleep(0.1)
LCD.show()
LCD.fill_rect(0,120,320,24,0x7FFF)
LCD.rect(0,120,320,24,0x7FFF)
utime.sleep(0.1)
LCD.show()
LCD.fill_rect(0,144,320,24,0xFFE0)
LCD.rect(0,144,320,24,0xFFE0)
utime.sleep(0.1)
LCD.show()
LCD.fill_rect(0,168,320,24,0XBC40)
LCD.rect(0,168,320,24,0XBC40)
utime.sleep(0.1)
LCD.show()
LCD.fill_rect(0,192,320,24,0XFC07)
LCD.rect(0,192,320,24,0XFC07)
utime.sleep(0.1)
LCD.show()
LCD.fill_rect(0,216,320,24,0X8430)
LCD.rect(0,216,320,24,0X8430)
utime.sleep(0.1)
LCD.show()
LCD.fill(0xFFFF)
utime.sleep(0.1)
LCD.show()
utime.sleep(0.1)
LCD.fill(0)
LCD.rect(0,0,319,239,colour(0,0,255)) # Blue Frame
LCD.text("WaveShare", 44,10,colour(255,0,0))
LCD.text('Pico Display 1.8"', 10,24,colour(255,255,0))
LCD.text("320x240 SPI", 38,37,colour(0,255,0))
LCD.text("Tony Goodhew", 30,48,colour(100,100,100))
LCD.show()
LCD.pixel(0,0,0xFFFF) # Left Top - OK
LCD.pixel(0,239,0xFFFF) # Left Bottom - OK
LCD.pixel(319,0,0xFFFF) # Right Top - OK
LCD.pixel(319,239,0xFFFF) # Right Bottom - OK
LCD.show()
utime.sleep(20)
Best of luck
Tony