Added CS pin definitions, switched to FRONT

This commit is contained in:
Phil Howard
2019-04-03 21:49:38 +01:00
parent 093de23d2b
commit c1afe9cfd1
6 changed files with 53 additions and 4 deletions

View File

@@ -30,7 +30,7 @@ SPI_SPEED_MHZ = 10 # Higher speed = higher framerate
# Create ST7735 LCD display class.
disp = ST7735.ST7735(
port=0,
cs=0,
cs=ST7735.BG_SPI_CS_FRONT,
dc=9,
backlight=18,
rotation=90,

View File

@@ -32,7 +32,7 @@ else:
# Create TFT LCD display class.
disp = ST7735.ST7735(
port=0,
cs=0,
cs=ST7735.BG_SPI_CS_FRONT,
dc=9,
backlight=18,
spi_speed_hz=4000000

View File

@@ -32,7 +32,7 @@ image_file = sys.argv[1]
# Create ST7735 LCD display class.
disp = ST7735.ST7735(
port=0,
cs=0,
cs=ST7735.BG_SPI_CS_FRONT,
dc=9,
backlight=18,
rotation=90,

View File

@@ -0,0 +1,46 @@
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
import time
import ST7735
MESSAGE = "Hello World! How are you today?"
# Create ST7735 LCD display class.
disp = ST7735.ST7735(
port=0,
cs=ST7735.BG_SPI_CS_FRONT,
dc=9,
backlight=18,
rotation=90,
spi_speed_hz=10000000
)
# Initialize display.
disp.begin()
WIDTH = disp.width
HEIGHT = disp.height
img = Image.new('RGB', (WIDTH, HEIGHT), color=(0, 0, 0))
draw = ImageDraw.Draw(img)
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", 30)
size_x, size_y = draw.textsize(MESSAGE, font)
text_x = 160
text_y = (80 - size_y) // 2
t_start = time.time()
while True:
x = (time.time() - t_start) * 100
x %= (size_x + 160)
draw.rectangle((0, 0, 160, 80), (0, 0, 0))
draw.text((int(text_x - x), text_y), MESSAGE, font=font, fill=(255, 255, 255))
disp.display(img)

View File

@@ -28,7 +28,7 @@ import ST7735
# Create ST7735 LCD display class.
disp = ST7735.ST7735(
port=0,
cs=0,
cs=ST7735.BG_SPI_CS_FRONT,
dc=9,
backlight=18,
rotation=90,

View File

@@ -26,6 +26,9 @@ import spidev
import RPi.GPIO as GPIO
BG_SPI_CS_BACK = 0
BG_SPI_CS_FRONT = 1
SPI_CLOCK_HZ = 16000000
# Constants for interacting with display registers.