Skip to content

Instantly share code, notes, and snippets.

@MartinRGB
Last active November 2, 2023 22:40
Show Gist options
  • Save MartinRGB/20f65ec60dd6e5466996e7f66760da9c to your computer and use it in GitHub Desktop.
Save MartinRGB/20f65ec60dd6e5466996e7f66760da9c to your computer and use it in GitHub Desktop.

image

ILI9341_T4

LCD

#define PIN_SCK     13      // mandatory
#define PIN_MISO    12      // mandatory (if the display has no MISO line, set this to 255 but then VSync will be disabled)
#define PIN_MOSI    11      // mandatory
#define PIN_DC      9      // mandatory, can be any pin but using pin 10 (or 36 or 37 on T4.1) provides greater performance

#define PIN_CS      10       // optional (but recommended), can be any pin.  
#define PIN_RESET   6       // optional (but recommended), can be any pin. 

Touch

// XPT2046 TOUSCHSCREEN CONNECTED ON THE SAME SPI PORT AS ILI9341:
// 
// -> connect T_DIN to the same Teensy pin as PIN_MOSI
// -> connect T_DO to the same Teensy pin as PIN_MISO
// 
#define PIN_TOUCH_CS  4     // mandatory for this example, can be any pin
#define PIN_TOUCH_IRQ 3     // (optional) can be any digital pin with interrupt capabilities
@MartinRGB
Copy link
Author

Simple ILI9341 shader test

mySetup.py

from ili9341 import Display
from machine import Pin, SPI,SoftSPI

TFT_CLK_PIN = const(13)
TFT_MOSI_PIN = const(11)
TFT_MISO_PIN = const(12)

TFT_CS_PIN = const(10)
TFT_RST_PIN = const(6)
TFT_DC_PIN = const(9)

def createMyDisplay():
    #sw
    #tftSpi = SoftSPI(baudrate=40000000, polarity=1, phase=0,sck=Pin(TFT_CLK_PIN), mosi=Pin(TFT_MOSI_PIN), miso=Pin(TFT_MISO_PIN))
    # hw
    tftSpi = SPI(0, 40 * 1000000)
    display = Display(spi = tftSpi,
                      dc=Pin(TFT_DC_PIN), cs=Pin(TFT_CS_PIN), rst=Pin(TFT_RST_PIN))
    return display
       

main.py

"""
Raspperry Pi Pico exercise display on ili9341 SPI Display
using rdagger/micropython-ili9341,
MicroPython ILI9341 Display and XPT2046 Touch Screen Drivers
https://github.com/rdagger/micropython-ili9341
"""
from machine import Pin, SPI
from sys import implementation
from os import uname
import utime
import math
import ili9341
from xglcd_font import XglcdFont
import mySetup

print(implementation.name)
print(uname()[3])
print(uname()[4])

print(SPI(0))
print(SPI(1))

display = mySetup.createMyDisplay()

class Vector2:
    """A two-dimensional vector with Cartesian coordinates."""

    def __init__(self, x, y):
        self.x, self.y = x, y

    def __str__(self):
        """Human-readable string representation of the vector."""
        return '{:g}i + {:g}j'.format(self.x, self.y)

    def __repr__(self):
        """Unambiguous string representation of the vector."""
        return repr((self.x, self.y))

    def dot(self, other):
        """The scalar (dot) product of self and other. Both must be vectors."""

        if not isinstance(other, Vector2D):
            raise TypeError('Can only take dot product of two Vector2D objects')
        return self.x * other.x + self.y * other.y
    # Alias the __matmul__ method to dot so we can use a @ b as well as a.dot(b).
    __matmul__ = dot

    def __sub__(self, other):
        """Vector subtraction."""
        return Vector2(self.x - other.x, self.y - other.y)

    def __add__(self, other):
        """Vector addition."""
        return Vector2(self.x + other.x, self.y + other.y)

    def __mul__(self, scalar):
        """Multiplication of a vector by a scalar."""

        if isinstance(scalar, int) or isinstance(scalar, float):
            return Vector2(self.x*scalar, self.y*scalar)
        raise NotImplementedError('Can only multiply Vector2D by a scalar')

    def __rmul__(self, scalar):
        """Reflected multiplication so vector * scalar also works."""
        return self.__mul__(scalar)

    def __neg__(self):
        """Negation of the vector (invert through origin.)"""
        return Vector2(-self.x, -self.y)

    def __truediv__(self, scalar):
        """True division of the vector by a scalar."""
        return Vector2(self.x / scalar, self.y / scalar)

    def __mod__(self, scalar):
        """One way to implement modulus operation: for each component."""
        return Vector2(self.x % scalar, self.y % scalar)

    def __abs__(self):
        """Absolute value (magnitude) of the vector."""
        return math.sqrt(self.x**2 + self.y**2)

    def distance_to(self, other):
        """The distance between vectors self and other."""
        return abs(self - other)

    def to_polar(self):
        """Return the vector's components in polar coordinates."""
        return self.__abs__(), math.atan2(self.y, self.x)
    
downScale = 0.125*1
oW = 240;
oH = 320;
cX = 0;



while True:
    cX = cX + 0.05;
    for x in range(int(oW*downScale)):
        for y in range(int(oH*downScale)):
            uv=Vector2(x,1.-y)
            speed = .1;
            scale = 0.01*int(1/downScale);
            p = Vector2(x*scale,y*scale)
                    
            for i in range(1,2):
                p.x+=0.3/i*math.sin(i*3.*p.y ) + cX;
                p.y+=0.3/i*math.cos(i*3.*p.x);
            r=math.cos(p.x+p.y+1.)*.5+.5;
            g=math.sin(p.x+p.y+1.)*.5+.5;
            b=(math.sin(p.x+p.y)+math.cos(p.x+p.y))*.3+.5;
                    
            c = ili9341.color565(int(r*255),int(g*255),int(255 - b*255))
            display.fill_rectangle(x*int(1/downScale), y*int(1/downScale),int(1/downScale),int(1/downScale), c)

print("- bye -")


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment