Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
st7789_mpy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
st7789_mpy
Commits
fb30e2ee
Commit
fb30e2ee
authored
Jun 28, 2020
by
Russ
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes and tweaks to demo's
parent
a9355821
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
248 additions
and
30 deletions
+248
-30
examples/pyb_hello.py
examples/pyb_hello.py
+2
-3
examples/pyb_scroll.py
examples/pyb_scroll.py
+124
-0
examples/time_trial.py
examples/time_trial.py
+1
-1
examples/ttgo_fonts.py
examples/ttgo_fonts.py
+0
-13
examples/ttgo_hello.py
examples/ttgo_hello.py
+13
-13
examples/ttgo_scroll.py
examples/ttgo_scroll.py
+108
-0
No files found.
examples/pyb_hello.py
View file @
fb30e2ee
"""
"""
ttgo
_hello.py
pyb
_hello.py
Writes "Hello!" in random colors at random locations on a
Writes "Hello!" in random colors at random locations on a
on a ST7789 TFT display connected to a pyboard1.1.
on a ST7789 TFT display connected to a pyboard1.1.
video: https://youtu.be/OtcERmad5ps
https://youtu.be/OtcERmad5ps
"""
"""
import
random
,
time
import
random
,
time
from
pyb
import
SPI
,
Pin
from
pyb
import
SPI
,
Pin
...
...
examples/pyb_scroll.py
0 → 100644
View file @
fb30e2ee
"""
pyb_scroll.py
Smoothly scroll all characters of a font up the screen. Fonts heights
must be even multiples of the screen height (i.e. 8 or 16 pixels high).
https://youtu.be/ro13rvaLKAc
"""
import
utime
import
random
from
pyb
import
SPI
,
Pin
import
st7789
# choose a font
# import vga1_8x8 as font
# import vga2_8x8 as font
# import vga1_8x16 as font
# import vga2_8x16 as font
# import vga1_16x16 as font
# import vga1_bold_16x16 as font
# import vga2_16x16 as font
import
vga2_bold_16x16
as
font
def
cycle
(
p
):
try
:
len
(
p
)
except
TypeError
:
cache
=
[]
for
i
in
p
:
yield
i
cache
.
append
(
i
)
p
=
cache
while
p
:
yield
from
p
def
main
():
tft
=
st7789
.
ST7789
(
SPI
(
1
,
SPI
.
MASTER
,
baudrate
=
30000000
,
polarity
=
1
,
phase
=
0
),
240
,
320
,
reset
=
Pin
(
'X3'
,
Pin
.
OUT
),
cs
=
Pin
(
'X5'
,
Pin
.
OUT
),
dc
=
Pin
(
'X4'
,
Pin
.
OUT
),
backlight
=
Pin
(
'X2'
,
Pin
.
OUT
),
rotation
=
0
)
colors
=
cycle
([
0xe000
,
0xece0
,
0xe7e0
,
0x5e0
,
0x00d3
,
0x7030
])
foreground
=
next
(
colors
)
background
=
st7789
.
BLACK
tft
.
init
()
tft
.
fill
(
background
)
utime
.
sleep
(
1
)
height
=
tft
.
height
()
width
=
tft
.
width
()
last_line
=
height
-
font
.
HEIGHT
tfa
=
0
tfb
=
0
tft
.
vscrdef
(
tfa
,
height
,
tfb
)
scroll
=
0
character
=
0
while
True
:
# clear top line before scrolling off display
tft
.
fill_rect
(
0
,
scroll
,
width
,
1
,
background
)
# Write new line when we have scrolled the height of a character
if
scroll
%
font
.
HEIGHT
==
0
:
line
=
(
scroll
+
last_line
)
%
height
# write character hex value as a string
tft
.
text
(
font
,
'x{:02x}'
.
format
(
character
),
0
,
line
,
foreground
,
background
)
# write character using a integer (could be > 0x7f)
tft
.
text
(
font
,
character
,
64
,
line
,
foreground
,
background
)
# write character+128 hex value as a string
tft
.
text
(
font
,
'x{:02x}'
.
format
(
character
+
128
),
120
,
line
,
foreground
,
background
)
# write character+128 using a integer (could be > 0x7f)
tft
.
text
(
font
,
character
+
128
,
184
,
line
,
foreground
,
background
)
# change color for next line
foreground
=
next
(
colors
)
# next character with rollover at 256
character
+=
1
character
%=
128
tft
.
vscsad
(
scroll
+
tfa
)
scroll
+=
1
scroll
%=
height
utime
.
sleep
(
0.01
)
main
()
examples/time_trial.py
View file @
fb30e2ee
...
@@ -14,7 +14,7 @@ import st7789 as st7789
...
@@ -14,7 +14,7 @@ import st7789 as st7789
import
time
import
time
import
utime
import
utime
from
fonts
import
vga2_8x16
as
font
import
vga2_8x16
as
font
def
main
():
def
main
():
...
...
examples/ttgo_fonts.py
View file @
fb30e2ee
...
@@ -11,23 +11,10 @@ import random
...
@@ -11,23 +11,10 @@ import random
from
machine
import
Pin
,
SPI
from
machine
import
Pin
,
SPI
import
st7789
import
st7789
# Choose fonts
import
vga1_8x8
as
font1
import
vga1_8x8
as
font1
#import vga2_8x8 as font1
import
vga1_8x16
as
font2
import
vga1_8x16
as
font2
#import vga2_8x16 as font2
# import vga1_16x16 as font3
import
vga1_bold_16x16
as
font3
import
vga1_bold_16x16
as
font3
# import vga2_16x16 as font3
#import vga2_bold_16x16 as font3
# import vga1_16x32 as font4
import
vga1_bold_16x32
as
font4
import
vga1_bold_16x32
as
font4
# import vga2_16x32 as font4
#import vga2_bold_16x32 as font4
def
main
():
def
main
():
tft
=
st7789
.
ST7789
(
tft
=
st7789
.
ST7789
(
...
...
examples/ttgo_hello.py
View file @
fb30e2ee
...
@@ -4,7 +4,7 @@ ttgo_hello.py
...
@@ -4,7 +4,7 @@ ttgo_hello.py
Writes "Hello!" in random colors at random locations on a
Writes "Hello!" in random colors at random locations on a
LILYGO® TTGO T-Display.
LILYGO® TTGO T-Display.
https://
www.youtube.com/watch?v=atBa0BYPAAc
https://
youtu.be/z41Du4GDMSY
"""
"""
import
random
import
random
...
@@ -13,21 +13,21 @@ import st7789
...
@@ -13,21 +13,21 @@ import st7789
# Choose a font
# Choose a font
#
from fonts
import vga1_8x8 as font
# import vga1_8x8 as font
#
from fonts
import vga2_8x8 as font
# import vga2_8x8 as font
#
from fonts
import vga1_8x16 as font
# import vga1_8x16 as font
#
from fonts
import vga2_8x16 as font
# import vga2_8x16 as font
#
from fonts
import vga1_16x16 as font
# import vga1_16x16 as font
#
from fonts
import vga1_bold_16x16 as font
# import vga1_bold_16x16 as font
#
from fonts
import vga2_16x16 as font
# import vga2_16x16 as font
#
from fonts
import vga2_bold_16x16 as font
# import vga2_bold_16x16 as font
#
from fonts
import vga1_16x32 as font
# import vga1_16x32 as font
#
from fonts
import vga1_bold_16x32 as font
# import vga1_bold_16x32 as font
#
from fonts
import vga2_16x32 as font
# import vga2_16x32 as font
from
fonts
import
vga2_bold_16x32
as
font
import
vga2_bold_16x32
as
font
def
main
():
def
main
():
tft
=
st7789
.
ST7789
(
tft
=
st7789
.
ST7789
(
...
...
examples/
scroll_font
.py
→
examples/
ttgo_scroll
.py
View file @
fb30e2ee
"""
"""
ttgo_
fonts
.py
ttgo_
scroll
.py
Smoothly scroll
s all font characters up the screen on the LILYGO® TTGO
Smoothly scroll
all characters of a font up the LILYGO® TTGO T-Display
T-Display. Only works with fonts with heights that are even multiples of
screen. Fonts heights must be even multiples of the screen height
the screen height, (i.e. 8 or 16 pixels high)
(i.e. 8 or 16 pixels high).
https://youtu.be/GQa-RzHLBak
"""
"""
import
utime
import
utime
import
random
import
random
...
@@ -12,7 +13,6 @@ from machine import Pin, SPI
...
@@ -12,7 +13,6 @@ from machine import Pin, SPI
import
st7789
import
st7789
# choose a font
# choose a font
# import vga1_8x8 as font
# import vga1_8x8 as font
# import vga2_8x8 as font
# import vga2_8x8 as font
# import vga1_8x16 as font
# import vga1_8x16 as font
...
@@ -20,10 +20,22 @@ import st7789
...
@@ -20,10 +20,22 @@ import st7789
# import vga1_16x16 as font
# import vga1_16x16 as font
# import vga1_bold_16x16 as font
# import vga1_bold_16x16 as font
# import vga2_16x16 as font
# import vga2_16x16 as font
import
vga2_bold_16x16
as
font
import
vga2_bold_16x16
as
font
def
main
():
def
cycle
(
p
):
try
:
len
(
p
)
except
TypeError
:
cache
=
[]
for
i
in
p
:
yield
i
cache
.
append
(
i
)
p
=
cache
while
p
:
yield
from
p
def
main
():
tft
=
st7789
.
ST7789
(
tft
=
st7789
.
ST7789
(
SPI
(
2
,
baudrate
=
30000000
,
polarity
=
1
,
phase
=
1
,
sck
=
Pin
(
18
),
mosi
=
Pin
(
19
)),
SPI
(
2
,
baudrate
=
30000000
,
polarity
=
1
,
phase
=
1
,
sck
=
Pin
(
18
),
mosi
=
Pin
(
19
)),
135
,
135
,
...
@@ -34,36 +46,62 @@ def main():
...
@@ -34,36 +46,62 @@ def main():
backlight
=
Pin
(
4
,
Pin
.
OUT
),
backlight
=
Pin
(
4
,
Pin
.
OUT
),
rotation
=
0
)
rotation
=
0
)
colors
=
cycle
([
0xe000
,
0xece0
,
0xe7e0
,
0x5e0
,
0x00d3
,
0x7030
])
foreground
=
next
(
colors
)
background
=
st7789
.
BLACK
tft
.
init
()
tft
.
init
()
tft
.
fill
(
background
)
utime
.
sleep
(
1
)
height
=
tft
.
height
()
width
=
tft
.
width
()
last_line
=
height
-
font
.
HEIGHT
print
(
tft
.
width
(),
tft
.
height
())
tfa
=
40
# top free area
last_line
=
tft
.
height
()
-
font
.
HEIGHT
tfb
=
40
# bottom free area
tfa
=
40
tft
.
vscrdef
(
tfa
,
height
,
tfb
)
tfb
=
40
tft
.
vscrdef
(
tfa
,
240
,
tfb
)
tft
.
fill
(
st7789
.
BLUE
)
scroll
=
0
scroll
=
0
character
=
0
character
=
0
while
True
:
while
True
:
tft
.
fill_rect
(
0
,
scroll
,
tft
.
width
(),
1
,
st7789
.
BLUE
)
# clear top line before scrolling off display
tft
.
fill_rect
(
0
,
scroll
,
width
,
1
,
background
)
# Write new line when we have scrolled the height of a character
if
scroll
%
font
.
HEIGHT
==
0
:
if
scroll
%
font
.
HEIGHT
==
0
:
line
=
(
scroll
+
last_line
)
%
height
# write character hex value as a string
tft
.
text
(
tft
.
text
(
font
,
font
,
'
\\
x{:02x}= {:s} '
.
format
(
character
,
chr
(
character
)
),
'
x{:02x}'
.
format
(
character
),
0
,
16
,
(
scroll
+
last_line
)
%
tft
.
height
()
,
line
,
st7789
.
WHITE
,
foreground
,
st7789
.
BLUE
)
background
)
character
=
character
+
1
if
character
<
256
else
0
# write character using a integer (could be > 0x7f)
tft
.
text
(
font
,
character
,
90
,
line
,
foreground
,
background
)
tft
.
vscsad
(
scroll
+
tfa
)
# change color for next line
scroll
+=
1
foreground
=
next
(
colors
)
if
scroll
==
tft
.
height
:
# next character with rollover at 256
scroll
=
0
character
+=
1
character
%=
256
# scroll the screen up 1 row
tft
.
vscsad
(
scroll
+
tfa
)
scroll
+=
1
scroll
%=
height
utime
.
sleep
(
0.01
)
utime
.
sleep
(
0.01
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment