Skip to content

Commit 38f8800

Browse files
committed
add an offscreen buffer example code
1 parent be0685d commit 38f8800

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22

33
This is a modified version of [GuyCarver's ST7735.py](https://github.com/GuyCarver/MicroPython/blob/master/lib/ST7735.py) ST7735 TFT LCD driver for MicroPython.
44

5-
This version is for micropython-esp32.
6-
75
A font file is necessary for displaying text (some font files are in [GuyCarver's repo](https://github.com/GuyCarver/MicroPython/tree/master/lib)).
86

97
Text nowrap option added(default: nowrap=False).
108

11-
graphicstest.py is a sample code. I wrote this to make it similar to [Adafruit's graphicstest sketch for Arduino](https://github.com/adafruit/Adafruit-ST7735-Library/tree/master/examples/graphicstest).
9+
`graphicstest.py` is a sample code. I wrote this to make it similar to [Adafruit's graphicstest sketch for Arduino](https://github.com/adafruit/Adafruit-ST7735-Library/tree/master/examples/graphicstest).
1210

13-
If graphicstest.py doesn't work correctly, try replaceing initr() at line 8 to initg() or initb() or initb2(). You can also change rgb(True) to rgb(False) to switch red and blue pixels if your LCD module shows incorrect colors.
11+
If `graphicstest.py` doesn't work correctly, try replaceing `initr()` at line 8 to `initg()` or `initb()` or `initb2()`. You can also change `rgb(True)` to `rgb(False)` to switch red and blue pixels if your LCD module shows incorrect colors.
1412

15-
Pin connections:
13+
Pin connections for ESP32:
1614

1715
LCD |ESP32-DevKitC
1816
----|----
@@ -27,6 +25,8 @@ GND |GND
2725

2826
[![YouTube image here](https://img.youtube.com/vi/xIy8DPBZsIk/0.jpg)](https://www.youtube.com/watch?v=xIy8DPBZsIk)
2927

30-
tftbmp.py is another sample similar to [Adafruit's tftbmp sketch for Arduino](https://github.com/adafruit/Adafruit-ST7735-Library/blob/master/examples/spitftbitmap/spitftbitmap.ino).
28+
`tftbmp.py` is another sample similar to [Adafruit's tftbmp sketch for Arduino](https://github.com/adafruit/Adafruit-ST7735-Library/blob/master/examples/spitftbitmap/spitftbitmap.ino).
29+
30+
Place bmp file named `test128x160.bmp` in the file system of MicroPython using file uploading tool such as [ampy](https://github.com/adafruit/ampy), etc.
3131

32-
Place bmp file named 'test128x160.bmp' in the file system of MicroPython using file uploading tool such as [ampy](https://github.com/adafruit/ampy), etc.
32+
`offscreen-buffer.py` shows how you can use an offscreen frame buffer which is an instance of FrameBuffer class. I tested this on Raspberry Pi Pico. See https://github.com/boochow/MicroPython-ST7735/issues/9 for the pin connections.

offscreen-buffer.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from machine import SPI,Pin
2+
from ST7735 import TFT
3+
spi = SPI(0, baudrate=20000000, polarity=0, phase=0, sck=Pin(2), mosi=Pin(3), miso=Pin(0))
4+
tft=TFT(spi,4,5,1)
5+
tft.initr()
6+
tft.rgb(True)
7+
tft.fill(TFT.BLACK)
8+
9+
from framebuf import FrameBuffer, RGB565
10+
buf = bytearray(128*160*2)
11+
fb = FrameBuffer(buf, 128, 160, RGB565)
12+
13+
tft._setwindowloc((0,0),(127,159))
14+
15+
size=20
16+
(xmax, ymax) = (128-size, 160-size)
17+
(x, y) = (size, size)
18+
(vx, vy) = (1, 1)
19+
20+
while True:
21+
fb.fill(0)
22+
fb.ellipse(x, y, size, size, 0xffff, True)
23+
x += vx
24+
if x == xmax or x == size:
25+
vx = -vx
26+
y += vy
27+
if y == ymax or y == size:
28+
vy = -vy
29+
tft._writedata(buf)

0 commit comments

Comments
 (0)