Connecting a ILI9341 2.8" Touch Display 320*240 to Raspberry Pico

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
cebersp
Posts: 30
Joined: Mon Feb 08, 2021 12:07 pm

Connecting a ILI9341 2.8" Touch Display 320*240 to Raspberry Pico

Post by cebersp » Mon Feb 22, 2021 5:10 pm

Edit: See 4th post for a library including touch input.

Perhaps someone is looking for information how to connect a display to Pico.
This Library
https://github.com/jeffmer/micropython-ili9341
works with Pico, if you use the following settings and pins:

Code: Select all

spi = SPI(0, baudrate=32000000, sck=Pin(18), mosi=Pin(19)) 
display = ILI9341(spi, cs=Pin(17), dc=Pin(20), rst=Pin(21), w=320, h=240, r=3)

Code: Select all

# Tested with Pico
from ili934xnew import ILI9341, color565
from machine import Pin, SPI
import tt14

# Einige Farben from https://www.hobbyelektroniker.ch/resources/PytEsp20.zip
RED = const(0XF800)  # (255, 0, 0)
GREEN = const(0X07E0)  # (0, 255, 0)
BLUE = const(0X001F)  # (0, 0, 255)
YELLOW = const(0XFFE0)  # (255, 255, 0)
FUCHSIA = const(0XF81F)  # (255, 0, 255)
AQUA = const(0X07FF)  # (0, 255, 255)
MAROON = const(0X8000)  # (128, 0, 0)
DARKGREEN = const(0X0400)  # (0, 128, 0)
NAVY = const(0X0010)  # (0, 0, 128)
TEAL = const(0X0410)  # (0, 128, 128)
PURPLE = const(0X8010)  # (128, 0, 128)
OLIVE = const(0X8400)  # (128, 128, 0)
ORANGE = const(0XFC00)  # (255, 128, 0)
DEEP_PINK = const(0XF810)  # (255, 0, 128)
CHARTREUSE = const(0X87E0)  # (128, 255, 0)
SPRING_GREEN = const(0X07F0)  # (0, 255, 128)
INDIGO = const(0X801F)  # (128, 0, 255)
DODGER_BLUE = const(0X041F)  # (0, 128, 255)
CYAN = const(0X87FF)  # (128, 255, 255)
PINK = const(0XFC1F)  # (255, 128, 255)
LIGHT_YELLOW = const(0XFFF0)  # (255, 255, 128)
LIGHT_CORAL = const(0XFC10)  # (255, 128, 128)
LIGHT_GREEN = const(0X87F0)  # (128, 255, 128)
LIGHT_SLATE_BLUE = const(0X841F)  # (128, 128, 255)
WHITE = const(0XFFFF)  # (255, 255, 255)
BLACK = const(0)

text = 'Fine'
spi = SPI(0, baudrate=32000000, sck=Pin(18), mosi=Pin(19)) #SPI(2, baudrate=20000000, miso=Pin(19),mosi=Pin(23), sck=Pin(18))
display = ILI9341(spi, cs=Pin(17), dc=Pin(20), rst=Pin(21), w=320, h=240, r=3)
#spi = SPI(2, baudrate=20000000, miso=Pin(19),mosi=Pin(23), sck=Pin(18))
#display = ILI9341(spi, cs=Pin(2), dc=Pin(27), rst=Pin(33), w=320, h=240, r=0)
display.erase()
display.set_color(WHITE,0)
display.set_font(tt14)
display.set_pos(0,0)
display.print(text)
display.set_pos(0,20)
display.print(text)
display.set_pos(40,20)
display.print(text)
for x in range(0,100):
    display.pixel(2*x,x,BLUE)


Last edited by cebersp on Tue Feb 23, 2021 9:45 am, edited 1 time in total.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Connecting a ILI9341 2.8' Display 320*240 to Pico

Post by pythoncoder » Mon Feb 22, 2021 5:50 pm

There is also nano-gui which has a driver for ILI9341.

Unfortunately some of the widgets don't work with the Pico because currently the Pico lacks the cmath library. Hopefully that, and other similar issues, will be fixed soon. Only the circular widgets and the graph plotting module are affected.
Peter Hinch
Index to my micropython libraries.

cebersp
Posts: 30
Joined: Mon Feb 08, 2021 12:07 pm

Re: Connecting a ILI9341 2.8' Display 320*240 to Pico

Post by cebersp » Tue Feb 23, 2021 9:40 am

Thanks, Peter, I will have a look at this too!

cebersp
Posts: 30
Joined: Mon Feb 08, 2021 12:07 pm

Re: Connecting a ILI9341 2.8' Display 320*240 to Pico

Post by cebersp » Tue Feb 23, 2021 9:43 am

If someone is interested to use touch and display with the same spi-bus, this library works:
https://github.com/rdagger/micropython-ili9341

See pins in the following demo.
Enjoy!
Christof

Code: Select all

# demo_touch works with Pico
# https://github.com/rdagger/micropython-ili9341

# touch and display use the same SPI bus!

from machine import Pin, SPI
from ili9341 import Display, color565
from xglcd_font import XglcdFont
from utime import sleep #sleep_us, ticks_cpu, ticks_us, ticks_diff

from xpt2046 import *

# Einige Farben  from https://www.hobbyelektroniker.ch/resources/PytEsp20.zip
RED = const(0XF800)  # (255, 0, 0)
GREEN = const(0X07E0)  # (0, 255, 0)
BLUE = const(0X001F)  # (0, 0, 255)
YELLOW = const(0XFFE0)  # (255, 255, 0)
FUCHSIA = const(0XF81F)  # (255, 0, 255)
AQUA = const(0X07FF)  # (0, 255, 255)
MAROON = const(0X8000)  # (128, 0, 0)
DARKGREEN = const(0X0400)  # (0, 128, 0)
NAVY = const(0X0010)  # (0, 0, 128)
TEAL = const(0X0410)  # (0, 128, 128)
PURPLE = const(0X8010)  # (128, 0, 128)
OLIVE = const(0X8400)  # (128, 128, 0)
ORANGE = const(0XFC00)  # (255, 128, 0)
DEEP_PINK = const(0XF810)  # (255, 0, 128)
CHARTREUSE = const(0X87E0)  # (128, 255, 0)
SPRING_GREEN = const(0X07F0)  # (0, 255, 128)
INDIGO = const(0X801F)  # (128, 0, 255)
DODGER_BLUE = const(0X041F)  # (0, 128, 255)
CYAN = const(0X87FF)  # (128, 255, 255)
PINK = const(0XFC1F)  # (255, 128, 255)
LIGHT_YELLOW = const(0XFFF0)  # (255, 255, 128)
LIGHT_CORAL = const(0XFC10)  # (255, 128, 128)
LIGHT_GREEN = const(0X87F0)  # (128, 255, 128)
LIGHT_SLATE_BLUE = const(0X841F)  # (128, 128, 255)
WHITE = const(0XFFFF)  # (255, 255, 255)
BLACK = const(0)

dispCS=Pin(17,Pin.OUT) # display shares spi
dispCS.value(1)

#spi = SPI(0, baudrate=32000000, sck=Pin(18), mosi=Pin(19), miso=Pin(16)) too fast!
spi = SPI(0, baudrate=10000000, sck=Pin(18), mosi=Pin(19), miso=Pin(16))

t= Touch(spi,Pin(22), width=240, height=320,
                 x_min=288, x_max=1616, y_min=328, y_max=1872) # spi, CS
d = Display(spi, cs=Pin(17), dc=Pin(20), rst=Pin(21))
d.clear(color565(64, 0, 255))
font = XglcdFont('fonts/FixedFont5x8.c', 5, 8)
sleep(1)
d.clear()
#d.draw_text(0, 319, 'Hello', font, color565(255, 0, 255), landscape=True)
d.draw_text(0, 319, 'Hello', font, YELLOW, landscape=True)
sleep(1)

newX=0
newY=0

while True:
    newPos=t.get_touch()
    if newPos!=None:
        oldX=newX
        oldY=newY
        newX,newY=newPos

        d.clear()
        #print(newX,newY, end=".  ")
        print(t.raw_touch(), end=".")
        d.draw_circle(239-newX,newY,10, GREEN)
        sleep(0.3)
    


Post Reply