diff --git a/docs/tft_display.md b/docs/tft_display.md new file mode 100644 index 0000000..032c934 --- /dev/null +++ b/docs/tft_display.md @@ -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 +``` diff --git a/installer.sh b/installer.sh index 0c5ba2c..7182815 100644 --- a/installer.sh +++ b/installer.sh @@ -138,6 +138,34 @@ else echo "jq already installed, skipping..." fi +# ---------------------------- Pillow Requirements --------------------------- # +REQUIRED_PKG="libjpeg-dev" +PKG_OK=$(dpkg-query -W --showformat='${Status}\n' $REQUIRED_PKG|grep "install ok installed") +if [ "" = "$PKG_OK" ]; then + echo "No $REQUIRED_PKG. Setting up $REQUIRED_PKG..." + sudo apt-get install libjpeg-dev -y +else + echo "libjpeg-dev already installed, skipping..." +fi + +REQUIRED_PKG="zlib1g-dev" +PKG_OK=$(dpkg-query -W --showformat='${Status}\n' $REQUIRED_PKG|grep "install ok installed") +if [ "" = "$PKG_OK" ]; then + echo "No $REQUIRED_PKG. Setting up $REQUIRED_PKG..." + sudo apt-get install zlib1g-dev -y +else + echo "zlib1g-dev already installed, skipping..." +fi + +REQUIRED_PKG="libfreetype6-dev" +PKG_OK=$(dpkg-query -W --showformat='${Status}\n' $REQUIRED_PKG|grep "install ok installed") +if [ "" = "$PKG_OK" ]; then + echo "No $REQUIRED_PKG. Setting up $REQUIRED_PKG..." + sudo apt-get install libfreetype6-dev -y +else + echo "libfreetype6-dev already installed, skipping..." +fi + # -------------------------------- Python 3.11 ------------------------------- # pytohn_version=$(python -c 'import sys; print(".".join(map(str, sys.version_info[0:2])))') if [ "$pytohn_version" != "3.11" ]; then diff --git a/openpod/modules/op_display.py b/openpod/modules/op_display.py new file mode 100644 index 0000000..6bb83b5 --- /dev/null +++ b/openpod/modules/op_display.py @@ -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) diff --git a/requirements.txt b/requirements.txt index 6b0a80d..815950c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,7 @@ +adafruit-circuitpython-rgb-display==3.10.19 config==0.5.1 paho-mqtt==1.6.1 +Pillow==9.4.0 pubsub==0.1.2 PyJWT==2.6.0 Pypubsub==4.0.3