-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
83d0763
commit 64457f6
Showing
4 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# TFT Display | ||
|
||
A small TFT display provides excellent feedback for the user. It can be used to display the current status of the device, or to display the current settings. | ||
|
||
## Pod Display | ||
|
||
The latest version of the Pod uses the [Adafruit 1.3" TFT display](https://www.adafruit.com/product/4313). This display is a 240x240 pixel display with a 16-bit color depth. It is a wide-angle display, which means that it can be viewed from a wide range of angles without the image becoming distorted. | ||
|
||
Detailed connection instructions are available on the [Adafruit Website](https://learn.adafruit.com/adafruit-1-14-240x135-color-tft-breakout/python-wiring-and-setup), basic pin connections are shown below. | ||
|
||
| TFT Display | Pod | | ||
|-------------|---------| | ||
| Vin | 3.3V | | ||
| GND | GND | | ||
| SCK | SLCK | | ||
| MOSI(SI) | MOSI | | ||
| CS | CE0 | | ||
| RST | GPIO 24 | | ||
| D/C | GPIO 25 | | ||
|
||
## Programming the Display | ||
|
||
**Note: All requirements are fulfilled when running the OpenPod installer.** | ||
|
||
Drivers for the display are found in the [Adafruit CircuitPython RGB Display Repository](https://github.com/adafruit/Adafruit_CircuitPython_RGB_Display) and can be installed using the following command: | ||
|
||
```bash | ||
sudo pip3 install adafruit-circuitpython-rgb-display | ||
``` | ||
|
||
To use the display with Python, you will need to install the following packages and libraries: | ||
|
||
```bash | ||
sudo apt-get install libjpeg-dev | ||
sudo apt-get install zlib1g-dev | ||
sudo apt-get install libfreetype6-dev | ||
sudo pip3 install Pillow | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
''' | ||
OpenPod | op_display.py | ||
Manages a TFT display, currently setup for the Adafruit 1.3" 240x240 TFT display. | ||
https://learn.adafruit.com/adafruit-1-3-and-1-54-240-x-240-wide-angle-tft-lcd-displays | ||
''' | ||
|
||
import time | ||
import busio | ||
import digitalio | ||
from board import SCK, MOSI, MISO, CE0, D24, D25 | ||
|
||
from adafruit_rgb_display import color565 | ||
from adafruit_rgb_display.st7789 import ST7789 | ||
from PIL import Image, ImageDraw, ImageFont | ||
|
||
# Configuration for CS and DC pins: | ||
CS_PIN = CE0 | ||
DC_PIN = D25 | ||
RESET_PIN = D24 | ||
BAUDRATE = 24000000 | ||
|
||
# Setup SPI bus using hardware SPI: | ||
spi = busio.SPI(clock=SCK, MOSI=MOSI, MISO=MISO) | ||
|
||
# Create the ST7789 display: | ||
display = ST7789( | ||
spi, | ||
# rotation=90, | ||
# width=240, | ||
# height=240, | ||
# x_offset=53, | ||
# y_offset=40, | ||
baudrate=BAUDRATE, | ||
cs=digitalio.DigitalInOut(CS_PIN), | ||
dc=digitalio.DigitalInOut(DC_PIN), | ||
rst=digitalio.DigitalInOut(RESET_PIN)) | ||
|
||
# Main loop: same as above | ||
while True: | ||
display.fill(0) # Clear the display | ||
display.pixel(120, 160, color565(255, 0, 0)) # Draw a red pixel in the center. | ||
time.sleep(2) # Pause 2 seconds. | ||
display.fill(color565(0, 0, 255)) # Clear the screen blue. | ||
time.sleep(2) # Pause 2 seconds. | ||
|
||
width = display.width | ||
height = display.height | ||
image = Image.new("RGB", (width, height)) | ||
draw = ImageDraw.Draw(image) | ||
draw.rectangle((0, 0, width, height), outline=0, fill=(0, 0, 0)) | ||
|
||
draw.rectangle((0, 0, width, height), fill=(0, 255, 0)) | ||
|
||
display.image(image) | ||
|
||
BORDER = 20 | ||
draw.rectangle((BORDER, BORDER, width - BORDER - 1, height - BORDER - 1), fill=(170, 0, 136)) | ||
|
||
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 24) | ||
|
||
TEXT = "Hello World!" | ||
(font_width, font_height) = font.getsize(TEXT) | ||
draw.text( | ||
(width // 2 - font_width // 2, height // 2 - font_height // 2), | ||
TEXT, | ||
font=font, | ||
fill=(255, 255, 0), | ||
) | ||
|
||
display.image(image) | ||
time.sleep(10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters