Add ST7735 support.

master
rdagger 1 month ago
parent dd749fb0c2
commit cf24adaf11

@ -19,6 +19,7 @@ def test():
# Baud rate of 40000000 seems about the max
spi = SPI(1, baudrate=40000000, sck=Pin(14), mosi=Pin(13))
display = Display(spi, dc=Pin(4), cs=Pin(16), rst=Pin(17))
display.clear()
# Load sprite

@ -1,8 +1,8 @@
"""ILI9341 demo (bouncing boxes)."""
from machine import Pin, SPI
from machine import Pin, SPI # type: ignore
from random import random, seed
from ili9341 import Display, color565
from utime import sleep_us, ticks_cpu, ticks_us, ticks_diff
from utime import sleep_us, ticks_cpu, ticks_us, ticks_diff # type: ignore
class Box(object):
@ -81,6 +81,7 @@ def test():
# Baud rate of 40000000 seems about the max
spi = SPI(1, baudrate=40000000, sck=Pin(14), mosi=Pin(13))
display = Display(spi, dc=Pin(4), cs=Pin(16), rst=Pin(17))
display.clear()
colors = [color565(255, 0, 0),
@ -90,7 +91,7 @@ def test():
color565(0, 255, 255),
color565(255, 0, 255)]
sizes = [12, 11, 10, 9, 8, 7]
boxes = [Box(239, 319, sizes[i], display,
boxes = [Box(display.width, display.height, sizes[i], display,
colors[i]) for i in range(6)]
while True:

@ -1,7 +1,7 @@
"""ILI9341 demo (CircuitPython Text, Shape & Sprite)."""
import board
from busio import SPI
from digitalio import DigitalInOut
import board # type: ignore
from busio import SPI # type: ignore
from digitalio import DigitalInOut # type: ignore
from ili9341 import Display, color565
from xglcd_font import XglcdFont
from time import monotonic, sleep
@ -98,7 +98,7 @@ def test():
print('This demo is for CircuitPython only!')
exit()
try:
# Configuratoin for CS and DC pins:
# Configuration for CS and DC pins:
cs_pin = DigitalInOut(board.P0_15)
dc_pin = DigitalInOut(board.P0_17)
rst_pin = DigitalInOut(board.P0_20)

@ -1,11 +1,9 @@
"""ILI9341 demo (clear)."""
from time import sleep, ticks_ms
from ili9341 import Display, color565
from machine import Pin, SPI
from machine import Pin, SPI # type: ignore
import gc
valid_hlines = [1, 2, 4, 5, 8, 10, 16, 20, 32, 40, 64, 80, 160]
colors = {
"RED": (255, 0, 0),
"GREEN": (0, 255, 0),
@ -13,7 +11,7 @@ colors = {
"YELLOW": (255, 255, 0),
"AQUA": (0, 255, 255),
"MAROON": (128, 0, 0),
"DARKGREEN": (0, 128, 0),
"DARK_GREEN": (0, 128, 0),
"NAVY": (0, 0, 128),
"TEAL": (0, 128, 128),
"PURPLE": (128, 0, 128),
@ -22,12 +20,27 @@ colors = {
"CYAN": (128, 255, 255),
}
def test():
"""Test code."""
# Baud rate of 40000000 seems about the max
spi = SPI(1, baudrate=40000000, sck=Pin(14), mosi=Pin(13))
display = Display(spi, dc=Pin(4), cs=Pin(16), rst=Pin(17))
# Calculate valid hlines parameters for display clear method
valid_hlines = []
for i in range(1, display.height):
if display.height % i == 0:
valid_hlines.append(i)
# Ensure only 13 entries, truncate or repeat the last one
valid_hlines = valid_hlines[:13]
if len(valid_hlines) < 13:
valid_hlines += [valid_hlines[-1]] * (13 - len(valid_hlines))
# Ensure only 13 entries, truncate or repeat the last one
valid_hlines = valid_hlines[:13]
if len(valid_hlines) < 13:
valid_hlines += [valid_hlines[-1]] * (13 - len(valid_hlines))
print('Clearing to black...')
start = ticks_ms()
display.clear()

@ -1,7 +1,7 @@
"""ILI9341 demo (color palette)."""
from time import sleep
from ili9341 import Display, color565
from machine import Pin, SPI
from machine import Pin, SPI # type: ignore
def hsv_to_rgb(h, s, v):
@ -47,12 +47,19 @@ def test():
spi = SPI(1, baudrate=40000000, sck=Pin(14), mosi=Pin(13))
display = Display(spi, dc=Pin(4), cs=Pin(16), rst=Pin(17))
radius = 9
step_size = (radius + 1) * 2
num_circles_x = (display.width // step_size)
num_circles_y = (display.height // step_size)
total_circles = num_circles_x * num_circles_y
c = 0
for x in range(0, 240, 20):
for y in range(0, 320, 20):
color = color565(*hsv_to_rgb(c / 192, 1, 1))
display.fill_circle(x + 9, y + 9, 9, color)
for x in range(0, num_circles_x):
for y in range(0, num_circles_y):
color = color565(*hsv_to_rgb(c / total_circles, 1, 1))
display.fill_circle(x * step_size + radius, y * step_size + radius,
radius, color)
c += 1
sleep(9)
display.cleanup()

@ -1,13 +1,9 @@
"""ILI9341 demo (color wheel)."""
from time import sleep
from ili9341 import Display, color565
from machine import Pin, SPI
from machine import Pin, SPI # type: ignore
from math import cos, pi, sin
HALF_WIDTH = const(120)
HALF_HEIGHT = const(160)
CENTER_X = const(119)
CENTER_Y = const(159)
ANGLE_STEP_SIZE = 0.05 # Decrease step size for higher resolution
PI2 = pi * 2
@ -55,22 +51,27 @@ def test():
spi = SPI(1, baudrate=40000000, sck=Pin(14), mosi=Pin(13))
display = Display(spi, dc=Pin(4), cs=Pin(16), rst=Pin(17))
half_width = display.width // 2
half_height = display.height // 2
center_x = half_width - 1
center_y = half_height - 1
x, y = 0, 0
angle = 0.0
# Loop all angles from 0 to 2 * PI radians
while angle < PI2:
# Calculate x, y from a vector with known length and angle
x = int(CENTER_X * sin(angle) + HALF_WIDTH)
y = int(CENTER_Y * cos(angle) + HALF_HEIGHT)
x = int(center_x * sin(angle) + half_width)
y = int(center_y * cos(angle) + half_height)
color = color565(*hsv_to_rgb(angle / PI2, 1, 1))
display.draw_line(x, y, CENTER_X, CENTER_Y, color)
display.draw_line(x, y, center_x, center_y, color)
angle += ANGLE_STEP_SIZE
sleep(5)
for r in range(CENTER_X, 0, -1):
color = color565(*hsv_to_rgb(r / HALF_WIDTH, 1, 1))
display.fill_circle(CENTER_X, CENTER_Y, r, color)
for r in range(center_x, 0, -1):
color = color565(*hsv_to_rgb(r / half_width, 1, 1))
display.fill_circle(center_x, center_y, r, color)
sleep(9)
display.cleanup()

@ -1,34 +1,36 @@
"""ILI9341 demo (colored squares)."""
from time import sleep
from ili9341 import Display
from machine import Pin, SPI
from sys import modules
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)
from ili9341 import Display, color565
from machine import Pin, SPI # type: ignore
colors = {
0: color565(255, 0, 0), # Red
1: color565(0, 255, 0), # Green
2: color565(0, 0, 255), # Blue
3: color565(255, 255, 0), # Yellow
4: color565(255, 0, 255), # Fuchsia
5: color565(0, 255, 255), # Aqua
6: color565(128, 0, 0), # Maroon
7: color565(0, 128, 0), # Dark green
8: color565(0, 0, 128), # Navy
9: color565(0, 128, 128), # Teal
10: color565(128, 0, 128), # Purple
11: color565(128, 128, 0), # Olive
12: color565(255, 128, 0), # Orange
13: color565(255, 0, 128), # Deep pink
14: color565(128, 255, 0), # Chartreuse
15: color565(0, 255, 128), # Spring green
16: color565(128, 0, 255), # Indigo
17: color565(0, 128, 255), # Dodger blue
18: color565(128, 255, 255), # Cyan
19: color565(255, 128, 255), # Pink
20: color565(255, 255, 128), # Light yellow
21: color565(255, 128, 128), # Light coral
22: color565(128, 255, 128), # Light green
23: color565(128, 128, 255), # Light slate blue
24: color565(255, 255, 255), # White
}
def test():
@ -37,16 +39,20 @@ def test():
spi = SPI(1, baudrate=40000000, sck=Pin(14), mosi=Pin(13))
display = Display(spi, dc=Pin(4), cs=Pin(16), rst=Pin(17))
# Build color list from all upper case constants (lazy approach)
colors = [getattr(modules[__name__], name) for name in dir(
modules[__name__]) if name.isupper() and name is not 'SPI']
cols = 5 # Number of columns
rows = 5 # Number of rows
rect_width = display.width // cols # Width of each rectangle
rect_height = display.height // rows # Height of each rectangle
c = 0 # Color index
for row in range(rows): # Loop through rows
for col in range(cols): # Loop through columns
x = col * rect_width # Calculate X coordinate
y = row * rect_height # Calculate Y coordinate
display.fill_rectangle(x, y, rect_width - 1, rect_height - 1,
colors[c]) # Draw a filled rectangle
c += 1 # Increment color index
c = 0
for y in range(0, 320, 64):
for x in range(0, 240, 48):
display.fill_rectangle(x, y, 47, 63, colors[c])
c += 1
sleep(9)
sleep(10)
display.cleanup()

@ -1,7 +1,7 @@
"""ILI9341 demo (fonts)."""
from time import sleep
from ili9341 import Display, color565
from machine import Pin, SPI
from machine import Pin, SPI # type: ignore
from xglcd_font import XglcdFont
@ -32,68 +32,107 @@ def test():
wendy = XglcdFont('fonts/Wendy7x8.c', 7, 8)
print('Fonts loaded.')
display.draw_text(0, 0, 'Arcade Pix 9x11', arcadepix, color565(255, 0, 0))
display.draw_text(0, 22, 'Bally 7x9', bally, color565(0, 255, 0))
display.draw_text(0, 43, 'Broadway 17x15', broadway, color565(0, 0, 255))
display.draw_text(0, 66, 'Espresso Dolce 18x24', espresso_dolce,
text_heights = [11, 9, 15, 24, 8, 7, 21, 24, 8] # Heights of each line
num_lines = len(text_heights) # Number of lines
total_text_height = sum(text_heights) # Total height of all text lines
# Calculate available space to distribute
available_height = display.height - total_text_height
# Calculate the vertical gap between each line
gap_between_lines = available_height // (num_lines + 1)
# Start drawing the text at the first position
y_position = gap_between_lines # Start of first line of text
# Draw each text line with adjusted Y positions
display.draw_text(0, y_position, 'Arcade Pix 9x11', arcadepix,
color565(255, 0, 0))
y_position += text_heights[0] + gap_between_lines
display.draw_text(0, y_position, 'Bally 7x9', bally, color565(0, 255, 0))
y_position += text_heights[1] + gap_between_lines
display.draw_text(0, y_position, 'Broadway', broadway,
color565(0, 0, 255))
y_position += text_heights[2] + gap_between_lines
display.draw_text(0, y_position, 'Espresso', espresso_dolce,
color565(0, 255, 255))
display.draw_text(0, 104, 'Fixed Font 5x8', fixed_font,
y_position += text_heights[3] + gap_between_lines
display.draw_text(0, y_position, 'Fixed Font 5x8', fixed_font,
color565(255, 0, 255))
display.draw_text(0, 125, 'Neato 5x7', neato, color565(255, 255, 0))
display.draw_text(0, 155, 'ROBOTRON 13X21', robotron,
y_position += text_heights[4] + gap_between_lines
display.draw_text(0, y_position, 'Neato 5x7', neato, color565(255, 255, 0))
y_position += text_heights[5] + gap_between_lines
display.draw_text(0, y_position, 'ROBOTRON', robotron,
color565(255, 255, 255))
display.draw_text(0, 190, 'Unispace 12x24', unispace,
y_position += text_heights[6] + gap_between_lines
display.draw_text(0, y_position, 'Unispace', unispace,
color565(255, 128, 0))
display.draw_text(0, 220, 'Wendy 7x8', wendy, color565(255, 0, 128))
y_position += text_heights[7] + gap_between_lines
display.draw_text(0, y_position, 'Wendy 7x8', wendy, color565(255, 0, 128))
sleep(9)
display.clear()
display.draw_text(0, 255, 'Arcade Pix 9x11', arcadepix,
color565(255, 0, 0),
landscape=True)
display.draw_text(22, 255, 'Bally 7x9', bally, color565(0, 255, 0),
landscape=True)
display.draw_text(43, 255, 'Broadway 17x15', broadway, color565(0, 0, 255),
landscape=True)
display.draw_text(66, 255, 'Espresso Dolce 18x24', espresso_dolce,
color565(0, 255, 255), landscape=True)
display.draw_text(104, 255, 'Fixed Font 5x8', fixed_font,
color565(255, 0, 255), landscape=True)
display.draw_text(125, 255, 'Neato 5x7', neato, color565(255, 255, 0),
landscape=True)
display.draw_text(155, 255, 'ROBOTRON 13X21', robotron,
color565(255, 255, 255),
landscape=True)
display.draw_text(190, 255, 'Unispace 12x24', unispace,
color565(255, 128, 0),
landscape=True)
display.draw_text(220, 255, 'Wendy 7x8', wendy, color565(255, 0, 128),
landscape=True)
sleep(9)
display.clear()
display.draw_text(0, 0, 'Arcade Pix 9x11', arcadepix, color565(255, 0, 0),
background=color565(0, 255, 255))
display.draw_text(0, 22, 'Bally 7x9', bally, color565(0, 255, 0),
background=color565(0, 0, 128))
display.draw_text(0, 43, 'Broadway', broadway, color565(0, 0, 255),
background=color565(255, 255, 0))
display.draw_text(0, 66, 'Espresso', espresso_dolce,
y_position = gap_between_lines # Start of first line of text
display.draw_text(0, y_position, 'Arcade Pix 9x11', arcadepix,
color565(255, 0, 0), background=color565(0, 255, 255))
y_position += text_heights[0] + gap_between_lines
display.draw_text(0, y_position, 'Bally 7x9', bally,
color565(0, 255, 0), background=color565(0, 0, 128))
y_position += text_heights[1] + gap_between_lines
display.draw_text(0, y_position, 'Broadway', broadway,
color565(0, 0, 255), background=color565(255, 255, 0))
y_position += text_heights[2] + gap_between_lines
display.draw_text(0, y_position, 'Espresso', espresso_dolce,
color565(0, 255, 255), background=color565(255, 0, 0))
display.draw_text(0, 104, 'Fixed Font 5x8', fixed_font,
y_position += text_heights[3] + gap_between_lines
display.draw_text(0, y_position, 'Fixed Font 5x8', fixed_font,
color565(255, 0, 255), background=color565(0, 128, 0))
display.draw_text(0, 125, 'Neato 5x7', neato, color565(255, 255, 0),
background=color565(0, 0, 255))
display.draw_text(0, 155, 'ROBOTRON 13X21', robotron,
y_position += text_heights[4] + gap_between_lines
display.draw_text(0, y_position, 'Neato 5x7', neato,
color565(255, 255, 0), background=color565(0, 0, 255))
y_position += text_heights[5] + gap_between_lines
display.draw_text(0, y_position, 'ROBOTRON', robotron,
color565(255, 255, 255),
background=color565(128, 128, 128))
display.draw_text(0, 190, 'Unispace', unispace, color565(255, 128, 0),
background=color565(0, 128, 255))
display.draw_text(0, 220, 'Wendy 7x8', wendy, color565(255, 0, 128),
y_position += text_heights[6] + gap_between_lines
display.draw_text(0, y_position, 'Unispace', unispace,
color565(255, 128, 0), background=color565(0, 128, 255))
y_position += text_heights[7] + gap_between_lines
display.draw_text(0, y_position, 'Wendy 7x8', wendy,
color565(255, 0, 128),
background=color565(255, 255, 255))
sleep(9)
display.clear()
# Calculate available horizontal space
available_width = display.width - total_text_height
# Calculate the horizontal gap between each line
gap_between_lines = available_width // (num_lines + 1)
# Starting X position for each line
x_position = gap_between_lines
# Draw each text line with adjusted X positions
display.draw_text(x_position, display.height - 1, 'Arcade Pix 9x11',
arcadepix, color565(255, 0, 0), landscape=True)
x_position += text_heights[0] + gap_between_lines
display.draw_text(x_position, display.height - 1, 'Bally 7x9', bally,
color565(0, 255, 0), landscape=True)
x_position += text_heights[1] + gap_between_lines
display.draw_text(x_position, display.height - 1, 'Broadway 17x15',
broadway, color565(0, 0, 255), landscape=True)
x_position += text_heights[2] + gap_between_lines
display.draw_text(x_position, display.height - 1, 'Espresso',
espresso_dolce, color565(0, 255, 255), landscape=True)
x_position += text_heights[3] + gap_between_lines
display.draw_text(x_position, display.height - 1, 'Fixed Font 5x8',
fixed_font, color565(255, 0, 255), landscape=True)
x_position += text_heights[4] + gap_between_lines
display.draw_text(x_position, display.height - 1, 'Neato 5x7', neato,
color565(255, 255, 0), landscape=True)
x_position += text_heights[5] + gap_between_lines
display.draw_text(x_position, display.height - 1, 'ROBOTRON',
robotron, color565(255, 255, 255), landscape=True)
x_position += text_heights[6] + gap_between_lines
display.draw_text(x_position, display.height - 1, 'Unispace',
unispace, color565(255, 128, 0), landscape=True)
x_position += text_heights[7] + gap_between_lines
display.draw_text(x_position, display.height - 1, 'Wendy 7x8', wendy,
color565(255, 0, 128), landscape=True)
sleep(9)
display.cleanup()

@ -15,16 +15,12 @@ def test():
display.draw_text8x8(0, 0, 'Built-in', color565(255, 0, 255))
display.draw_text8x8(16, 16, 'MicroPython', color565(255, 255, 0))
display.draw_text8x8(32, 32, '8x8 Font', color565(0, 0, 255))
display.draw_text8x8(x_center - 40, 120, "Rotate = 0",
color565(0, 255, 0))
display.draw_text8x8(0, y_center - 44, "Rotate = 90",
color565(255, 0, 0), rotate=90)
display.draw_text8x8(x_center - 48, display.height - 9, "Rotate = 180",
color565(0, 255, 255), rotate=180)
display.draw_text8x8(display.width - 9, y_center - 48, "Rotate = 270",
color565(255, 255, 255), rotate=270)
display.draw_text8x8(x_center - 40, 140, "Rotate = 0",
color565(0, 255, 0), background=color565(255, 0, 0))
display.draw_text8x8(20, y_center - 44, "Rotate = 90", color565(255, 0, 0),
@ -35,7 +31,6 @@ def test():
display.draw_text8x8(display.width - 29, y_center - 48, "Rotate = 270",
color565(255, 255, 255), rotate=270,
background=color565(255, 0, 255))
sleep(15)
display.cleanup()

@ -10,47 +10,28 @@ def test():
display = Display(spi, dc=Pin(4), cs=Pin(16), rst=Pin(17))
display.draw_text8x8(0, 0, 'Built-in', color565(255, 0, 0))
display.fill_rectangle(0, 10, 127, 20, color565(255, 0, 0))
display.draw_text8x8(0, 15, 'Built-in', color565(0, 0, 0),
display.fill_rectangle(0, 10, 104, 12, color565(255, 0, 0))
display.draw_text8x8(0, 12, 'Built-in', color565(0, 0, 0),
color565(255, 0, 0))
display.draw_text8x8(0, 40, 'MicroPython', color565(0, 255, 0))
display.fill_rectangle(0, 50, 127, 20, color565(0, 255, 0))
display.draw_text8x8(0, 55, 'MicroPython-in', color565(0, 0, 0),
display.draw_text8x8(0, 30, 'MicroPython', color565(0, 255, 0))
display.fill_rectangle(0, 40, 104, 12, color565(0, 255, 0))
display.draw_text8x8(0, 42, 'MicroPython', color565(0, 0, 0),
color565(0, 255, 0))
display.draw_text8x8(0, 80, '8x8 Font', color565(0, 0, 255))
display.fill_rectangle(0, 90, 127, 20, color565(0, 0, 255))
display.draw_text8x8(0, 95, '8x8 Font', color565(0, 0, 0),
display.draw_text8x8(0, 60, '8x8 Font', color565(0, 0, 255))
display.fill_rectangle(0, 70, 104, 12, color565(0, 0, 255))
display.draw_text8x8(0, 72, '8x8 Font', color565(0, 0, 0),
color565(0, 0, 255))
display.draw_text8x8(0, 120, 'Built-in', color565(255, 255, 0))
display.fill_rectangle(0, 130, 127, 20, color565(255, 255, 0))
display.draw_text8x8(0, 135, 'Built-in', color565(0, 0, 0),
color565(255, 255, 0))
display.draw_text8x8(0, 160, 'MicroPython', color565(0, 255, 255))
display.fill_rectangle(0, 170, 127, 20, color565(0, 255, 255))
display.draw_text8x8(0, 175, 'MicroPython-in', color565(0, 0, 0),
color565(0, 255, 255))
display.draw_text8x8(0, 200, '8x8 Font', color565(255, 0, 255))
display.fill_rectangle(0, 210, 127, 20, color565(255, 0, 255))
display.draw_text8x8(0, 215, '8x8 Font', color565(0, 0, 0),
color565(255, 0, 255))
display.draw_text8x8(0, 240, 'No Background', color565(255, 255, 255))
display.fill_rectangle(0, 250, 127, 20, color565(255, 255, 255))
display.draw_text8x8(0, 255, 'No Background', color565(255, 255, 255))
display.draw_text8x8(0, 90, 'No Background', color565(255, 255, 255))
display.fill_rectangle(0, 100, 104, 12, color565(255, 255, 255))
display.draw_text8x8(0, 102, 'No Background', color565(255, 255, 255))
y_center = display.height // 2
display.draw_text8x8(display.width - 29, y_center - 48, "Rotate = 270",
color565(255, 255, 255), rotate=270)
display.fill_rectangle(display.width - 19, 60, 18, 200,
color565(255, 128, 0))
display.draw_text8x8(display.width - 14, y_center - 48, "Rotate = 270",
color565(255, 255, 255), rotate=270,
background=color565(255, 128, 0))
display.draw_text8x8(display.width - 10, y_center - 48, "Rotate = 270",
color565(0, 255, 255), color565(255, 0, 255),
rotate=270)
sleep(15)
display.cleanup()

@ -1,7 +1,7 @@
"""ILI9341 demo (fonts rotated)."""
from time import sleep
from ili9341 import Display, color565
from machine import Pin, SPI
from machine import Pin, SPI # type: ignore
from xglcd_font import XglcdFont
@ -29,56 +29,56 @@ def test():
'Portrait', arcadepix,
color565(255, 255, 0),
landscape=False, rotate_180=False)
text_width = arcadepix.measure_text('Landscape')
text_width = arcadepix.measure_text('Landscape')
display.draw_text(0, display.height - 1,
'Landscape', arcadepix,
color565(255, 0, 0),
landscape=True, rotate_180=False)
text_width = arcadepix.measure_text('Portrait, Rotate 180')
text_width = arcadepix.measure_text('Port. Rot. 180')
display.draw_text(display.width - text_width - 1,
display.height - font_height,
'Portrait, Rotate 180', arcadepix,
'Port. Rot. 180', arcadepix,
color565(255, 0, 255),
landscape=False, rotate_180=True)
text_width = arcadepix.measure_text('Landscape, Rotate 180')
display.draw_text(display.width - font_height - 1 , text_width,
'Landscape, Rotate 180', arcadepix,
text_width = arcadepix.measure_text('Land. Rot. 180')
display.draw_text(display.width - font_height - 1, text_width,
'Land. Rot. 180', arcadepix,
color565(0, 0, 255),
landscape=True, rotate_180=True)
sleep(5)
sleep(5)
# Espresso Dolce
display.clear()
font_height = espressodolce.height
display.draw_text(0, 0,
'PORTRAIT', espressodolce,
'PORT.', espressodolce,
color565(255, 255, 0),
landscape=False, rotate_180=False)
text_width = espressodolce.measure_text('LANDSCAPE')
text_width = espressodolce.measure_text('LAND.')
display.draw_text(0, display.height - 1,
'LANDSCAPE', espressodolce,
'LAND.', espressodolce,
color565(255, 0, 0),
landscape=True, rotate_180=False)
text_width = espressodolce.measure_text('PORTRAIT,')
text_width = espressodolce.measure_text('PORT.')
display.draw_text(display.width - text_width - 1,
display.height - font_height,
'PORTRAIT,', espressodolce,
'PORT.', espressodolce,
color565(255, 0, 255),
landscape=False, rotate_180=True)
text_width = espressodolce.measure_text('ROTATE 180')
text_width = espressodolce.measure_text('ROT. 180')
display.draw_text(display.width - text_width - 1,
display.height - font_height * 2,
'ROTATE 180', espressodolce,
'ROT. 180', espressodolce,
color565(255, 0, 255),
landscape=False, rotate_180=True)
text_width = espressodolce.measure_text('LANDSCAPE,')
display.draw_text(display.width - font_height - 1 , text_width,
'LANDSCAPE,', espressodolce,
text_width = espressodolce.measure_text('LAND.')
display.draw_text(display.width - font_height - 1, text_width,
'LAND.', espressodolce,
color565(0, 0, 255),
landscape=True, rotate_180=True)
text_width = espressodolce.measure_text('ROTATE 180')
display.draw_text(display.width - font_height * 2 - 1 , text_width,
'ROTATE 180', espressodolce,
text_width = espressodolce.measure_text('ROT. 180')
display.draw_text(display.width - font_height * 2 - 1, text_width,
'ROT. 180', espressodolce,
color565(0, 0, 255),
landscape=True, rotate_180=True)
sleep(5)
@ -90,56 +90,56 @@ def test():
'Portrait', neato,
color565(255, 255, 0),
landscape=False, rotate_180=False)
text_width = neato.measure_text('Landscape')
text_width = neato.measure_text('Landscape')
display.draw_text(0, display.height - 1,
'Landscape', neato,
color565(255, 0, 0),
landscape=True, rotate_180=False)
text_width = neato.measure_text('Portrait, Rotate 180')
text_width = neato.measure_text('Portrait Rotate 180')
display.draw_text(display.width - text_width - 1,
display.height - font_height,
'Portrait, Rotate 180', neato,
'Portrait Rotate 180', neato,
color565(255, 0, 255),
landscape=False, rotate_180=True)
text_width = neato.measure_text('Landscape, Rotate 180')
display.draw_text(display.width - font_height - 1 , text_width,
'Landscape, Rotate 180', neato,
text_width = neato.measure_text('Landscape Rotate 180')
display.draw_text(display.width - font_height - 1, text_width,
'Landscape Rotate 180', neato,
color565(0, 0, 255),
landscape=True, rotate_180=True)
sleep(5)
# Robotron
display.clear()
font_height = robotron.height
display.draw_text(0, 0,
'PORTRAIT', robotron,
'PORT.', robotron,
color565(255, 255, 0),
landscape=False, rotate_180=False)
text_width = robotron.measure_text('LANDSCAPE')
text_width = robotron.measure_text('LAND.')
display.draw_text(0, display.height - 1,
'LANDSCAPE', robotron,
'LAND.', robotron,
color565(255, 0, 0),
landscape=True, rotate_180=False)
text_width = robotron.measure_text('PORTRAIT,')
text_width = robotron.measure_text('PORT.')
display.draw_text(display.width - text_width - 1,
display.height - font_height,
'PORTRAIT,', robotron,
'PORT.', robotron,
color565(255, 0, 255),
landscape=False, rotate_180=True)
text_width = robotron.measure_text('ROTATE 180')
text_width = robotron.measure_text('ROT. 180')
display.draw_text(display.width - text_width - 1,
display.height - font_height * 2,
'ROTATE 180', robotron,
'ROT. 180', robotron,
color565(255, 0, 255),
landscape=False, rotate_180=True)
text_width = robotron.measure_text('LANDSCAPE,')
display.draw_text(display.width - font_height - 1 , text_width,
'LANDSCAPE,', robotron,
text_width = robotron.measure_text('LAND.')
display.draw_text(display.width - font_height - 1, text_width,
'LAND.', robotron,
color565(0, 0, 255),
landscape=True, rotate_180=True)
text_width = robotron.measure_text('ROTATE 180')
display.draw_text(display.width - font_height * 2 - 1 , text_width,
'ROTATE 180', robotron,
text_width = robotron.measure_text('ROT. 180')
display.draw_text(display.width - font_height * 2 - 1, text_width,
'ROT. 180', robotron,
color565(0, 0, 255),
landscape=True, rotate_180=True)
sleep(5)
@ -148,43 +148,43 @@ def test():
display.clear()
font_height = unispace.height
display.draw_text(0, 0,
'PORTRAIT', unispace,
'PORT. ', unispace,
color565(255, 255, 0),
background=color565(255, 0, 0),
landscape=False, rotate_180=False)
text_width = unispace.measure_text('LANDSCAPE')
text_width = unispace.measure_text('LAND. ')
display.draw_text(0, display.height - 1,
'LANDSCAPE', unispace,
'LAND. ', unispace,
color565(255, 0, 0),
background=color565(255, 255, 0),
landscape=True, rotate_180=False)
text_width = unispace.measure_text('PORTRAIT,')
text_width = unispace.measure_text('PORT. ')
display.draw_text(display.width - text_width - 1,
display.height - font_height,
'PORTRAIT,', unispace,
'PORT. ', unispace,
color565(255, 0, 255),
background=color565(0, 255, 0),
landscape=False, rotate_180=True)
text_width = unispace.measure_text('ROTATE 180')
text_width = unispace.measure_text('ROT. 180')
display.draw_text(display.width - text_width - 1,
display.height - font_height * 2,
'ROTATE 180', unispace,
'ROT. 180', unispace,
color565(255, 0, 255),
background=color565(0, 255, 0),
landscape=False, rotate_180=True)
text_width = unispace.measure_text('LANDSCAPE,')
display.draw_text(display.width - font_height - 1 , text_width,
'LANDSCAPE,', unispace,
text_width = unispace.measure_text('LAND. ')
display.draw_text(display.width - font_height - 1, text_width,
'LAND. ', unispace,
color565(0, 0, 255),
background=color565(255, 255, 0),
landscape=True, rotate_180=True)
text_width = unispace.measure_text('ROTATE 180')
display.draw_text(display.width - font_height * 2 - 1 , text_width,
'ROTATE 180', unispace,
text_width = unispace.measure_text('ROT. 180')
display.draw_text(display.width - font_height * 2 - 1, text_width,
'ROT. 180', unispace,
color565(0, 0, 255),
background=color565(255, 255, 0),
landscape=True, rotate_180=True)
sleep(10)
display.cleanup()

@ -1,7 +1,7 @@
"""ILI9341 demo (images)."""
from time import sleep
from ili9341 import Display
from machine import Pin, SPI
from machine import Pin, SPI # type: ignore
def test():
@ -10,16 +10,22 @@ def test():
spi = SPI(1, baudrate=40000000, sck=Pin(14), mosi=Pin(13))
display = Display(spi, dc=Pin(4), cs=Pin(16), rst=Pin(17))
display.draw_image('images/RaspberryPiWB128x128.raw', 0, 0, 128, 128)
sleep(2)
display.draw_image('images/MicroPython128x128.raw', 0, 129, 128, 128)
sleep(2)
display.draw_image('images/Tabby128x128.raw', 112, 0, 128, 128)
sleep(2)
display.draw_image('images/Tortie128x128.raw', 112, 129, 128, 128)
if display.width >= 240 and display.height >= 240:
display.draw_image('images/RaspberryPiWB128x128.raw', 0, 0, 128, 128)
sleep(2)
display.draw_image('images/MicroPython128x128.raw', 0, 129, 128, 128)
sleep(2)
display.draw_image('images/Tabby128x128.raw', 112, 0, 128, 128)
sleep(2)
display.draw_image('images/Tortie128x128.raw', 112, 129, 128, 128)
else:
display.draw_image('images/RaspberryPiWB128x128.raw', 0, 0, 128, 128)
sleep(4)
display.draw_image('images/MicroPython128x128.raw', 0, 0, 128, 128)
sleep(4)
display.draw_image('images/Tabby128x128.raw', 0, 0, 128, 128)
sleep(4)
display.draw_image('images/Tortie128x128.raw', 0, 0, 128, 128)
sleep(9)

@ -11,9 +11,14 @@ def test():
display = Display(spi, dc=Pin(4), cs=Pin(16), rst=Pin(17))
display.clear()
display.fill_rectangle(0, 0, 100, 100, color565(255, 0, 0))
display.fill_polygon(3, 140, 140, 70, color565(0, 255, 0), rotate=15)
display.fill_circle(170, 240, 50, color565(0, 0, 255))
display.fill_rectangle(4, 4, display.width // 3, display.height // 4,
color565(255, 0, 0))
display.fill_polygon(3, display.width // 2, display.height // 2,
display.height // 8, color565(0, 255, 0), rotate=15)
display.fill_circle(display.width - (display.width // 4),
display.height - (display.height // 5),
display.height // 6, color565(0, 0, 255))
display.draw_image('images/Python41x49.raw', display.width - 49, 0, 41, 49)
sleep(2)
display.invert()

@ -1,7 +1,7 @@
"""ILI9341 demo (orientation)."""
from time import sleep
from ili9341 import Display, color565
from machine import Pin, SPI
from machine import Pin, SPI # type: ignore
from xglcd_font import XglcdFont
@ -12,33 +12,33 @@ def test():
print('Font loaded.')
# Baud rate of 40000000 seems about the max
spi = SPI(1, baudrate=40000000, sck=Pin(14), mosi=Pin(13))
display = Display(spi, dc=Pin(4), cs=Pin(16), rst=Pin(17),
width=240, height=320, rotation=0)
width=240, height=320, rotation=0)
display.draw_text(0, 0, 'Espresso Dolce 18x24', espresso_dolce,
color565(0, 255, 255))
display.draw_text(0, 319, 'Espresso Dolce 18x24', espresso_dolce,
color565(255, 255, 0), landscape=True)
sleep(5)
display = Display(spi, dc=Pin(4), cs=Pin(16), rst=Pin(17),
width=320, height=240, rotation=90)
width=320, height=240, rotation=90)
display.draw_text(0, 215, 'Espresso Dolce 18x24', espresso_dolce,
color565(255, 0, 255))
display.draw_text(295, 239, 'Espresso Dolce 18x24', espresso_dolce,
color565(255, 255, 255), landscape=True)
sleep(5)
display = Display(spi, dc=Pin(4), cs=Pin(16), rst=Pin(17),
width=240, height=320, rotation=180)
width=240, height=320, rotation=180)
display.draw_text(0, 0, 'Espresso Dolce 18x24', espresso_dolce,
color565(0, 0, 255))
display.draw_text(0, 319, 'Espresso Dolce 18x24', espresso_dolce,
color565(255, 0, 0), landscape=True)
sleep(5)
display = Display(spi, dc=Pin(4), cs=Pin(16), rst=Pin(17),
width=320, height=240, rotation=270)
width=320, height=240, rotation=270)
display.draw_text(0, 215, 'Espresso Dolce 18x24', espresso_dolce,
color565(225, 0, 128))
display.draw_text(295, 239, 'Espresso Dolce 18x24', espresso_dolce,
@ -46,7 +46,5 @@ def test():
sleep(5)
display.cleanup()
test()
test()

@ -9,15 +9,15 @@ def test():
try:
# Implementation dependant pin and SPI configuration
if implementation.name == 'circuitpython':
import board
from busio import SPI
from digitalio import DigitalInOut
import board # type: ignore
from busio import SPI # type: ignore
from digitalio import DigitalInOut # type: ignore
cs_pin = DigitalInOut(board.P0_15)
dc_pin = DigitalInOut(board.P0_17)
rst_pin = DigitalInOut(board.P0_20)
spi = SPI(clock=board.P0_24, MOSI=board.P0_22)
else:
from machine import Pin, SPI
from machine import Pin, SPI # type: ignore
cs_pin = Pin(16)
dc_pin = Pin(4)
rst_pin = Pin(17)

@ -20,7 +20,7 @@ SD card should be formatted to Fat32.
from ili9341 import Display, color565
from xpt2046 import Touch
from machine import idle, Pin, SPI # type: ignore
from sdcard import SDCard
from sdcard import SDCard # type: ignore
import os

@ -1,7 +1,7 @@
"""ILI9341 demo (shapes)."""
from time import sleep
from ili9341 import Display, color565
from machine import Pin, SPI
from machine import Pin, SPI # type: ignore
def test():

@ -1,7 +1,7 @@
"""ILI9341 demo (bouncing sprite)."""
from ili9341 import Display
from machine import Pin, SPI
from utime import sleep_us, ticks_us, ticks_diff
from machine import Pin, SPI # type: ignore
from utime import sleep_us, ticks_us, ticks_diff # type: ignore
class BouncingSprite(object):

@ -0,0 +1,43 @@
"""ILI9341 demo (ST7735s)."""
from time import sleep
from ili9341 import Display
from xglcd_font import XglcdFont
from machine import Pin, SPI # type: ignore
from micropython import const # type: ignore
WHITE = const(0XFFFF) # (255, 255, 255)
RED = const(0XF800) # (255, 0, 0)
GREEN = const(0X07E0) # (0, 255, 0)
BLUE = const(0X001F) # (0, 0, 255)
INDIGO = const(0X801F) # (128, 0, 255)
def test():
"""Test code."""
# Baud rate of 40000000 seems about the max
# spi = SPI(1, baudrate=40000000, sck=Pin(14), mosi=Pin(13))
spi = SPI(1, baudrate=40000000, sck=Pin(12), mosi=Pin(11))
display = Display(spi, dc=Pin(4), cs=Pin(16), rst=Pin(17),
width=128, height=160,
mirror=True, bgr=False, gamma=True,
x_offset=2, y_offset=1)
robotron = XglcdFont('fonts/Robotron13x21.c', 13, 21)
display.clear()
display.draw_rectangle(0, 0, 128, 160, WHITE)
display.draw_text8x8(0, 0, 'Top-Left', INDIGO)
display.draw_text(20, 30, 'RED', robotron, RED)
display.draw_text(20, 70, 'GREEN', robotron, GREEN)
display.draw_text(20, 110, 'BLUE', robotron, BLUE)
display.draw_image('images/Python41x49.raw', 86, 110, 41, 49)
sleep(15)
display.cleanup()
test()

@ -94,7 +94,7 @@ class Display(object):
}
def __init__(self, spi, cs, dc, rst, width=240, height=320, rotation=0,
mirror=False, bgr=True, gamma=True):
mirror=False, bgr=True, gamma=True, x_offset=0, y_offset=0):
"""Initialize OLED.
Args:
@ -108,6 +108,8 @@ class Display(object):
mirror (Optional bool): Mirror display (default False)
bgr (Optional bool): Swaps red and blue colors (default True)
gamma (Optional bool): Custom gamma correction (default True)
x_offset (Optional int): X-axis origin offset (default 0)
y_offset (Optional int): Y-axis origin offset (default 0)
"""
self.spi = spi
self.cs = cs
@ -121,6 +123,10 @@ class Display(object):
self.rotation = self.MIRROR_ROTATE[mirror, rotation]
if bgr: # Set BGR bit
self.rotation |= 0b00001000
# Check for offset
self.offset = bool(x_offset or y_offset)
self.x_offset = x_offset
self.y_offset = y_offset
# Initialize GPIO pins and set implementation specific methods
if implementation.name == 'circuitpython':
@ -181,6 +187,12 @@ class Display(object):
y1 (int): Ending Y position.
data (bytes): Data buffer to write.
"""
if self.offset: # Add offset if specified
x0 += self.x_offset
x1 += self.x_offset
y0 += self.y_offset
y1 += self.y_offset
self.write_cmd(self.SET_COLUMN,
x0 >> 8, x0 & 0xff, x1 >> 8, x1 & 0xff)
self.write_cmd(self.SET_PAGE,

@ -1,9 +1,9 @@
"""Search online for pwned passwords."""
from machine import Pin, SPI
from machine import Pin, SPI # type: ignore
from hashlib import sha1
from ubinascii import hexlify
from ubinascii import hexlify # type: ignore
from urequests2 import get
from network import STA_IF, WLAN
from network import STA_IF, WLAN # type: ignore
import gc
from xpt2046 import Touch
from ili9341 import Display, color565

@ -1,4 +1,5 @@
"""Touch keyboard."""
from micropython import const # type: ignore
class TouchKeyboard(object):
@ -35,7 +36,7 @@ class TouchKeyboard(object):
)
def __init__(self, display, font):
"""Initialize Keybaord.
"""Initialize Keyboard.
Args:
display (Display class): LCD Display

@ -10,10 +10,11 @@ Notes:
memory allocation errors when parsing REST API data.
"""
import usocket
import usocket # type: ignore
ITER_CHUNK_SIZE = 128
class Response:
def __init__(self, f):

@ -20,7 +20,7 @@ class XglcdFont(object):
you must use XP compatibility mode or you can just use the clipboard.
"""
# Dict to tranlate bitwise values to byte position
# Dict to translate bitwise values to byte position
BIT_POS = {1: 0, 2: 2, 4: 4, 8: 6, 16: 8, 32: 10, 64: 12, 128: 14, 256: 16}
def __init__(self, path, width, height, start_letter=32, letter_count=96):
@ -30,7 +30,7 @@ class XglcdFont(object):
path (string): Full path of font file
width (int): Maximum width in pixels of each letter
height (int): Height in pixels of each letter
start_letter (int): First ACII letter. Default is 32.
start_letter (int): First ASCII letter. Default is 32.
letter_count (int): Total number of letters. Default is 96.
"""
self.width = width
@ -127,7 +127,7 @@ class XglcdFont(object):
pos += 16
lh -= 8
else:
# Descrease position to start of previous column
# Decrease position to start of previous column
pos -= (letter_height * 4) - (lh * 2)
lh = letter_height
else:

@ -1,5 +1,6 @@
"""XPT2046 Touch module."""
from time import sleep
from micropython import const # type: ignore
class Touch(object):

Loading…
Cancel
Save