Giter VIP home page Giter VIP logo

adafruit_circuitpython_rgb_display's Introduction

Introduction

Documentation Status Discord Build Status Code Style: Black

Port of display drivers from https://github.com/adafruit/micropython-adafruit-rgb-display to Adafruit CircuitPython for use on Adafruit's SAMD21-based and other CircuitPython boards.

Note

This driver currently won't work on micropython.org firmware, instead you want the micropython-adafruit-rgb-display driver linked above!

This CircuitPython driver currently supports displays that use the following display-driver chips: HX8353, HX8357, ILI9341, S6D02A1, ST7789, SSD1331, SSD1351, and ST7735 (including variants ST7735R and ST7735S).

Dependencies

This driver depends on:

Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle.

For the Pillow Examples, you will need to be running CPython. This means using a Single Board Computer such as a Raspberry Pi or using a chip such as an FT232H on Linux, Window, or Mac. CircuitPython does not support PIL/pillow (python imaging library)!

For improved performance consider installing NumPy.

Installing from PyPI

On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:

pip3 install adafruit-circuitpython-rgb-display

To install system-wide (this may be required in some cases):

sudo pip3 install adafruit-circuitpython-rgb-display

To install in a virtual environment in your current project:

mkdir project-name && cd project-name
python3 -m venv .venv
source .venv/bin/activate
pip3 install adafruit-circuitpython-rgb-display

Usage Example

2.2", 2.4", 2.8", 3.2" TFT

import time
import busio
import digitalio
from board import SCK, MOSI, MISO, D2, D3

from adafruit_rgb_display import color565
import adafruit_rgb_display.ili9341 as ili9341


# Configuration for CS and DC pins:
CS_PIN = D2
DC_PIN = D3

# Setup SPI bus using hardware SPI:
spi = busio.SPI(clock=SCK, MOSI=MOSI, MISO=MISO)

# Create the ILI9341 display:
display = ili9341.ILI9341(spi, cs=digitalio.DigitalInOut(CS_PIN),
                          dc=digitalio.DigitalInOut(DC_PIN))

# Main loop:
while True:
    # Clear the display
    display.fill(0)
    # Draw a red pixel in the center.
    display.pixel(120, 160, color565(255, 0, 0))
    # Pause 2 seconds.
    time.sleep(2)
    # Clear the screen blue.
    display.fill(color565(0, 0, 255))
    # Pause 2 seconds.
    time.sleep(2)

1.14" TFT with Raspbery Pi 4

With 1.14" wiring, here is the working code:

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


# 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=135,
    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:
    # Clear the display
    display.fill(0)
    # Draw a red pixel in the center.
    display.pixel(120, 160, color565(255, 0, 0))
    # Pause 2 seconds.
    time.sleep(2)
    # Clear the screen blue.
    display.fill(color565(0, 0, 255))
    # Pause 2 seconds.
    time.sleep(2)

Documentation

API documentation for this library can be found on Read the Docs.

For information on building library documentation, please check out this guide.

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

adafruit_circuitpython_rgb_display's People

Contributors

brennen avatar caternuson avatar chfw avatar deshipu avatar dhalbert avatar evaherrada avatar foamyguy avatar johennes avatar kattni avatar ladyada avatar makermelissa avatar matt-land avatar michabyte avatar mrmcwethy avatar nerdcorenet avatar philippkeller avatar reza-n avatar sommersoft avatar tannewt avatar tdicola avatar tekktrik avatar thekitty avatar unknownerror55 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adafruit_circuitpython_rgb_display's Issues

Can only draw full screen image

The image method currently only allows to redraw the whole screen.

    def image(self, img, rotation=None):
        ...
        imwidth, imheight = img.size
        if imwidth != self.width or imheight != self.height:
            raise ValueError(...
        ...
        self._block(0, 0, self.width-1, self.height - 1, pixels)

Especially on lower end boards it seems advantageous to be able to draw smaller images in part of the screen only without having to refresh the whole screen.

I would like to suggest to add two new arguments to the method for specifying the origin

    def draw(self, image, x0=0, y0=0):

to drop the if imwidth != self.width or imheight != self.height: check and to adapt the call to _block so that the image's size is passed in instead of the screen size.

    self.display._block(x0, y0, x0 + imwidth - 1, y0 + imheight - 1, pixels)

Instead of removing the size check, one could also replace it with a check to ensure that the image is not bigger than the screen size.

Happy to submit a pull request if this makes sense.

Red and Blue switched on ST7735R

Running a ST7735R on a Feather M0 Basic, and when it should display red - IE, color565(255,0,0) - it displays blue instead, and the reverse is also true.

The super simple code I am using:

import busio
import digitalio
import board
import time
from adafruit_rgb_display import color565
import adafruit_rgb_display.st7735 as st7735

spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)

display = st7735.ST7735R(spi, cs=digitalio.DigitalInOut(board.D9), dc=digitalio.DigitalInOut(board.D10), rst=digitalio.DigitalInOut(board.D11))

while True:
    time.sleep(2.5)
    print("RED")
    display.fill(color565(255,0,0))
    time.sleep(2.5)
    print("BLUE")
    display.fill(color565(0,0,255))

for completeness sake, I've removed the other driver files (hx8353, ili9341, etc) from the folder to save on space, as the M0 basic has almost none.

Animated Gif Player Performance improvements

I mostly want to list ideas here for performance improvement ideas. The first idea I had is taking the image loading time into account for the delay. At the moment it loads the images, then does a delay. This change should have a significant impact.

/dev/spidev0.0 does not exist

Traceback (most recent call last):
  File "rgb_display_minipitfttest.py", line 14, in <module>
    board.SPI(),
  File "/usr/local/lib/python3.7/dist-packages/board.py", line 186, in SPI
    return busio.SPI(SCLK, MOSI, MISO)
  File "/usr/local/lib/python3.7/dist-packages/busio.py", line 186, in __init__
    self._spi = _SPI(portId)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_blinka/microcontroller/generic_linux/spi.py", line 22, in __init__
    self._spi = spi.SPI(device=(portid, 0))
  File "/usr/local/lib/python3.7/dist-packages/Adafruit_PureIO/spi.py", line 165, in __init__
    raise IOError("{} does not exist".format(device))
OSError: /dev/spidev0.0 does not exist

running rgb_display_minipitfttest.py after installing adafruit-circuitpython-rgb-display, spidev, ttf-dejavu, python3-numpy

please help

Text is inverted

Hello,

I've been messing with this library for a while now and when I import Image.Draw text it displays on my ST7789 screen but it comes out inverted. I tried messing with ST7789.py and noticed an option called "_INVON" and I thought maybe this had something to do with it?

'No module named displayio' error on raspberry pi zero

Hi, Is Raspberry pi zero w with 1.14 inch st7789 LCD supported?
I pip installed adafruit-blinka and adafruit-circuitpython-rgb-display, but when I tried the rgb_display_simpletest.py example, I got 'No module named displayio' Error, and I can't pip install
adafruit-circuitpython-displayio

Inverted colors when using PITFT 2.8" TFT 320X240 + CAPACITIVE

When using a PITFT 2.8" TFT 320X240 + CAPACITIVE ( https://www.adafruit.com/product/1983 ), colors are inverted.

disp.fill(color565(255, 0, 0))  # red => Fills the screen with blue (cyan)
disp.fill(color565(0, 0, 255))  # blue => Fills with Yellow
disp.fill(color565(0, 255, 0))  # green => Magenta

It's probably just and initialization issue, but I don't know enough to fix it myself (besides manually inverting colors).

The display is initialized with

disp = ili9341.ILI9341(
    spi,
    rotation=270,  # 2.2", 2.4", 2.8", 3.2" ILI9341
    cs=cs_pin,
    dc=dc_pin,
    rst=reset_pin,
    baudrate=BAUDRATE,
)

otherwise it's just the sample from https://github.com/adafruit/Adafruit_CircuitPython_RGB_Display#22-24-28-32-tft

When using the sample AnimatedGif the images look inverted as well.

Thanks.

DummyPin doesn't reflect the pin API

Trying to use DummyPin for CS that I have pulled down permanently on this breakout (because Trinket M0 doesn't have enough pins to handle CS), I get:

>>> cs = DummyPin()
>>> display = st7735.ST7735(spi, cs=cs, dc=dc, rst=rst)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "adafruit_rgb_display/st7735.py", line 98, in __init__
  File "adafruit_rgb_display/rgb.py", line 104, in __init__
  File "adafruit_bus_device/spi_device.py", line 59, in __init__
AttributeError: 'DummyPin' object has no attribute 'switch_to_output'

chip select issue with multiple screens

Hi, I'm trying to control two 2.2 TFT screens, both on SPI 0 using the two chip selects (CE0 and CE1).

Whenever I display to the first screen on CE0, it's fine (i.e. only displays on the first screen), but displaying to the second screen (CE1) pushes the same image to both screens. I can't seem to figure out why. Trying to manually throw CE0 high hasn't appeared to work.

Here's the implementation (adjusted from the sample code):

import digitalio
import board
from PIL import Image, ImageDraw, ImageFont
import adafruit_rgb_display.ili9341 as ili9341
import time

# First define some constants to allow easy resizing of shapes.
BORDER = 0
FONTSIZE = 24

# Configuration for CS and DC pins (these are PiTFT defaults):
cs_pin = digitalio.DigitalInOut(board.CE0)
cs2_pin = digitalio.DigitalInOut(board.CE1)
dc_pin = digitalio.DigitalInOut(board.D25)
dc2_pin = digitalio.DigitalInOut(board.D25)
reset_pin = digitalio.DigitalInOut(board.D24)
reset_pin2 = digitalio.DigitalInOut(board.D24)

# Config for display baudrate (default max is 24mhz):
BAUDRATE = 24000000

# Setup SPI bus using hardware SPI:
spi = board.SPI()
print('spi set up')

# pylint: disable=line-too-long
# Create the display:
disp = ili9341.ILI9341(
    spi,
    rotation=90,  # 2.2", 2.4", 2.8", 3.2" ILI9341
    cs=cs_pin,
    dc=dc_pin,
    rst=reset_pin,
    baudrate=BAUDRATE,
)

disp2 = ili9341.ILI9341(
    spi,
    rotation=90,  # 2.2", 2.4", 2.8", 3.2" ILI9341
    cs=cs2_pin,
    dc=dc2_pin,
    rst=reset_pin2,
    baudrate=BAUDRATE,
)
# pylint: enable=line-too-long

# Create blank image for drawing.
# Make sure to create image with mode 'RGB' for full color.
if disp.rotation % 180 == 90:
    height = disp.width  # we swap height/width to rotate it to landscape!
    width = disp.height
else:
    width = disp.width  # we swap height/width to rotate it to landscape!
    height = disp.height

image = Image.new("RGB", (width, height))

if disp2.rotation % 180 == 90:
    height2 = disp2.width  # we swap height/width to rotate it to landscape!
    width2 = disp2.height
else:
    width2 = disp2.width # we swap height/width to rotate it to landscape!
    height2 = disp2.height 

image2 = Image.new("RGB", (width2, height2))
print('width2:', width2, 'height2:', height2)

# Get drawing object to draw on image.
draw = ImageDraw.Draw(image)
draw2 = ImageDraw.Draw(image2)

# Draw a white filled box as the background
draw.rectangle((00, 0, disp.width+100, disp.height+100), fill=(225, 225, 225))
disp.image(image)

input('draw blue box on second screen only')

#Draw a blue box only on the second screen
draw2.rectangle((0, 0, disp2.width+100, disp2.height+100), fill=(0, 225, 225))
disp2.image(image2)

Essentially the blue box appears on both screens instead of just the second one!

I'm not sure if I'm doing something wrong with the chip selects/setup, or if this library just can't support multiple SPI devices.

row start and column start offsets are not being applied

Discovered corruption on two sides while testing the 1.44" TFT display with ST7735R. When I tested using Arduino, no issues were seen.

Looking at the Arduino Library code (Adafruit-ST7735), _rowstart and _colstart are being set in the function Adafruit_ST7735::initR for the different displays. These offsets are then used to adjust the start and end points when writing data in the function Adafruit_ST77xx::setAddrWindow. This is not being done in the CircuitPython code and is causing corruption along two edges of the screen.

I assume the offsets are the same, so it should be a simple matter of adding them to the rgb and st7735 modules.

Could not open SPI device

Hello, I am new to hardware. I am trying to configure the Mini PiTFT 135x240 on a Pi Zero W (https://learn.adafruit.com/adafruit-mini-pitft-135x240-color-tft-add-on-for-raspberry-pi/python-setup), and when I run the rgb_display_minipitfttest.py script, I get the following error:

Could not open SPI device - check if SPI is enabled in kernel!
Traceback (most recent call last):
File "rgb_display_minipitfttest.py", line 14, in
width=135, height=240, x_offset=53, y_offset=40)
File "/usr/local/lib/python3.7/dist-packages/adafruit_rgb_display/st7789.py", line 120, in init
x_offset=x_offset, y_offset=y_offset, rotation=rotation)
File "/usr/local/lib/python3.7/dist-packages/adafruit_rgb_display/rgb.py", line 250, in init
super().init(width, height, rotation)
File "/usr/local/lib/python3.7/dist-packages/adafruit_rgb_display/rgb.py", line 126, in init
self.init()
File "/usr/local/lib/python3.7/dist-packages/adafruit_rgb_display/st7789.py", line 123, in init
super().init()
File "/usr/local/lib/python3.7/dist-packages/adafruit_rgb_display/rgb.py", line 131, in init
self.write(command, data)
File "/usr/local/lib/python3.7/dist-packages/adafruit_rgb_display/rgb.py", line 266, in write
spi.write(bytearray([command]))
File "/usr/local/lib/python3.7/dist-packages/busio.py", line 170, in write
return self._spi.write(buf, start, end)
File "/usr/local/lib/python3.7/dist-packages/adafruit_blinka/microcontroller/generic_linux/spi.py", line 49, in write
self._spi.open(self._port, 0)
FileNotFoundError: [Errno 2] No such file or directory

I have gone back through the CircuitPython on Linux and Raspberry Pi guide, and done every step, and the "blinka test" passed on all fronts. The only red flag was that the output from /dev/spi* did not include spidev0.0, only 0.1

Can you offer any guidance?

FR: Backlight control

Would it be feasible to provide backlight control through those interfaces?
I know it's just some PWM on a specific pin, but it would make things easier.

Thanks.

minor write() optimization

Consider that you will often write data bytes without a command byte, but will almost never write a command byte without data bytes. For example, after setting up the display and issuing commands to set the write window and ram write mode, an application might then simply start continuously writing frames. Or even internally, look at the fill_rectangle() command.

As an optimization, consider leaving self.dc_pin.value = 1 as the default state, and only changing it to 0 and then back to 1 when ever a command byte is being written.

I believe the changes for this would trivial and isolated to the write() and read() methods. And to be extra safe, possibly setting it to 1 at the end of init().

Some examples are using displayio

Since this library is an alternative to displayio, it doesn't make sense to be loading displayio because those examples will not run on Blinka.

Image drawing is incredibly slow

The original Adafruit_ILI9341 library was using Numpy to speed up the conversion from pixels to an SPI-conformant byte array (see here).

The new library in this repository uses the following loop

        # Iterate through the pixels
        for x in range(self.width):       # yes this double loop is slow,
            for y in range(self.height):  #  but these displays are small!
                pix = color565(img.getpixel((x, y)))
                pixels[2*(y * self.width + x)] = pix >> 8
                pixels[2*(y * self.width + x) + 1] = pix & 0xFF

The comment about slowness is no understatement indeed. On a Raspberry Pi Zero, drawing a black image with a single line of text takes 8 seconds in my testing.

When I used the old code

pixelbytes = list(image_to_data(image))
self.display._block(0, 0, self.display.width-1, self.display.height - 1, pixelbytes)

with

def image_to_data(image):
    """Generator function to convert a PIL image to 16-bit 565 RGB bytes."""
    #NumPy is much faster at doing this. NumPy code provided by:
    #Keith (https://www.blogger.com/profile/02555547344016007163)
    pb = np.array(image.convert('RGB')).astype('uint16')
    color = ((pb[:,:,0] & 0xF8) << 8) | ((pb[:,:,1] & 0xFC) << 3) | (pb[:,:,2] >> 3)
    return np.dstack(((color >> 8) & 0xFF, color & 0xFF)).flatten().tolist()

the time consumed drops down to below half a second. Unless there was a technical reason not to depend on Numpy, I think it'd be worth to bring back the old code. 8 seconds for a screen update puts an end to a lot of use cases.

rgb_display_ili9341test.py fails

administrator@raspberrypi:~ $ python3 rgb_display_ili9341test.py
Traceback (most recent call last):
File "/home/administrator/rgb_display_ili9341test.py", line 25, in
spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)
File "/usr/local/lib/python3.9/dist-packages/busio.py", line 365, in init
self._spi = _SPI(portId)
File "/usr/local/lib/python3.9/dist-packages/adafruit_blinka/microcontroller/generic_linux/spi.py", line 25, in init
self._spi = spi.SPI(device=(portid, 0))
File "/usr/local/lib/python3.9/dist-packages/Adafruit_PureIO/spi.py", line 149, in init
raise IOError(f"{device} does not exist")
OSError: /dev/spidev0.0 does not exist

Whats wrong here?

Example names do not match repo name

The examples all start with rgbdisplay_ and should begin with rgb_display_. Examples need to be renamed to match CircuitPython library standards.

The lines including this file name in the docs/examples.rst file must also be updated to reflect the name change, e.g.:

.. literalinclude:: ../examples/current_file_name.py
    :caption: examples/current_file_name.py
    :linenos:

would be updated to:

.. literalinclude:: ../examples/current_file_name_changed.py
    :caption: examples/current_file_name_changed.py
    :linenos:

can't get my screen to display info / can't run script

I setup pi-hole on a pi zero w and that all works fine and is running properly. i just can't get the screen working yet.

I am NOT using the OLED kit, I'm using the Mini PiTFT.

I'm following the guide for the kit i bought here: https://learn.adafruit.com/pi-hole-ad-blocker-with-pi-zero-w?view=all

when i type the command "sudo python3 ~pi/stats.py" it just returns

Traceback (most recent call last):
File "/home/pi/stats.py", line 16, in
import adafruit_rgb_display.st7789 as st7789
ModuleNotFoundError: No module named 'adafruit_rgb_display'

I assume I must be missing a step but i don't know what.
I would really appreciate the help I am new to the raspberry pi world

Touch Support

What would it take to add touch support to this library?

chip select issue with multiple screens (ST7789)

Hello!

I have two ST7789 lcds sharing the same SPI bus and I can draw on one or another screen but not on both at the same time (specifically, after I create another ST7789 object, previous one stops working).

Here is my code

display1 = ST7789(spi, rotation=0, width=240, height=240, x_offset=0, y_offset=80, baudrate=BAUDRATE,
                 cs=cs1_pin,
                 dc=dc_pin,
                 rst=rs_pin)
display1.fill(color565(255, 0, 0))
time.sleep(2)
display2 = ST7789(spi, rotation=0, width=240, height=240, x_offset=0, y_offset=80, baudrate=BAUDRATE,
                 cs=cs2_pin,
                 dc=dc_pin,
                 rst=rs_pin)
display2.fill(color565(0, 255, 0))

When I run this code, the first screen displays red (actually, yellow. I think its because both CS are enabled by default until I initialized driver?), then after 2 sec the first screen goes black and then the second screen shows green.
I am willing to have something drawn on both screens at the same time, and not just on one or another?

Originally posted by @BioRyajenka in #95 (comment)

ModuleNotFoundError: No module named 'RPi._GPIO'

Hi
I am getting this GPIO error when trying to setup a pitft 240x240.
I am trying to install on a pi zero docker with python 3.6, 3.7, 3.8 so far.

Can you tell me what versions of linux and python work with this PiTFT?
I've tried all this stuff:
https://stackoverflow.com/questions/70697888/rpi-gpio-modulenotfounderror-no-module-named-rpi-gpio

Am I missing something? Thanks for any help!!!
Here's all the stuff getting installed:

RUN apt-get update && apt-get install build-essential \
  apt-utils \
  fonts-dejavu \ 
  python3-dev \
  python3-rpi.gpio

RUN pip3 install adafruit-circuitpython-rgb-display RPi.GPIO
RUN pip3 install --upgrade --force-reinstall spidev
Logs]    [4/9/2022, 4:43:15 AM] [main]   File "rgb_display_minipitfttest.py", line 4, in <module>
[Logs]    [4/9/2022, 4:43:15 AM] [main]     import digitalio
[Logs]    [4/9/2022, 4:43:15 AM] [main]   File "/usr/local/lib/python3.8/site-packages/digitalio.py", line 18, in <module>
[Logs]    [4/9/2022, 4:43:15 AM] [main]     from adafruit_blinka.microcontroller.bcm283x.pin import Pin
[Logs]    [4/9/2022, 4:43:15 AM] [main]   File "/usr/local/lib/python3.8/site-packages/adafruit_blinka/microcontroller/bcm283x/pin.py", line 5, in <module>
[Logs]    [4/9/2022, 4:43:15 AM] [main]     from RPi import GPIO
[Logs]    [4/9/2022, 4:43:15 AM] [main]   File "/usr/lib/python3/dist-packages/RPi/GPIO/__init__.py", line 23, in <module>
[Logs]    [4/9/2022, 4:43:15 AM] [main]     from RPi._GPIO import *
[Logs]    [4/9/2022, 4:43:15 AM] [main] ModuleNotFoundError: No module named 'RPi._GPIO'

Thanks!!

SSD1357

Can I use adafruit_rgb_display.ssd1351 to control SSD1357 driver?

Missing Type Annotations

There are missing type annotations for some functions in this library.

The typing module does not exist on CircuitPython devices so the import needs to be wrapped in try/except to catch the error for missing import. There is an example of how that is done here:

try:
    from typing import List, Tuple
except ImportError:
    pass

Once imported the typing annotations for the argument type(s), and return type(s) can be added to the function signature. Here is an example of a function that has had this done already:

def wrap_text_to_pixels(
    string: str, max_width: int, font=None, indent0: str = "", indent1: str = ""
) -> List[str]:

If you are new to Git or Github we have a guide about contributing to our projects here: https://learn.adafruit.com/contribute-to-circuitpython-with-git-and-github

There is also a guide that covers our CI utilities and how to run them locally to ensure they will pass in Github Actions here: https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/check-your-code In particular the pages: Sharing docs on ReadTheDocs and Check your code with pre-commit contain the tools to install and commands to run locally to run the checks.

If you are attempting to resolve this issue and need help, you can post a comment on this issue and tag both @FoamyGuy and @kattni or reach out to us on Discord: https://adafru.it/discord in the #circuitpython-dev channel.

The following locations are reported by mypy to be missing type annotations:

  • adafruit_rgb_display/rgb.py:42
  • adafruit_rgb_display/rgb.py:53
  • adafruit_rgb_display/rgb.py:72
  • adafruit_rgb_display/rgb.py:75
  • adafruit_rgb_display/rgb.py:83
  • adafruit_rgb_display/rgb.py:91
  • adafruit_rgb_display/rgb.py:99
  • adafruit_rgb_display/rgb.py:120
  • adafruit_rgb_display/rgb.py:134
  • adafruit_rgb_display/rgb.py:150
  • adafruit_rgb_display/rgb.py:154
  • adafruit_rgb_display/rgb.py:158
  • adafruit_rgb_display/rgb.py:162
  • adafruit_rgb_display/rgb.py:171
  • adafruit_rgb_display/rgb.py:203
  • adafruit_rgb_display/rgb.py:221
  • adafruit_rgb_display/rgb.py:225
  • adafruit_rgb_display/rgb.py:229
  • adafruit_rgb_display/rgb.py:239
  • adafruit_rgb_display/rgb.py:249
  • adafruit_rgb_display/rgb.py:288
  • adafruit_rgb_display/rgb.py:299
  • adafruit_rgb_display/st7789.py:99
  • adafruit_rgb_display/st7735.py:124
  • adafruit_rgb_display/st7735.py:186
  • adafruit_rgb_display/st7735.py:271
  • adafruit_rgb_display/ssd1351.py:100
  • adafruit_rgb_display/ssd1331.py:108
  • adafruit_rgb_display/ssd1331.py:136
  • adafruit_rgb_display/s6d02a1.py:62
  • adafruit_rgb_display/ili9341.py:79
  • adafruit_rgb_display/ili9341.py:108
  • adafruit_rgb_display/hx8357.py:95
  • adafruit_rgb_display/hx8353.py:62

Screen occasionally goes black on image swap

I have a simple application that updates a screen (Adafruit 1.14" 240x135 Color TFT Display + MicroSD Card Breakout - ST7789 Product ID: 4383) from a Pi Zero W 2, every 1/2 to 1 second, rendering moving 'eyes'. It consists of a main program (face_test.py) and a threaded class (face.py). The updating is done from a thread. The eyes are transparent PNG files that are enumerated from a text file and loaded at startup. In the thread, the code creates a green background, pastes the 'eyes' onto it, and then displays the image to the screen. This part appears to work fine. The main program can call a method on the class that tells it which PNG it should be using. At random times, this part appears to be resetting the screen, as it goes black and doesn't display anything else for the remainder of the run. I've attached all files, with the Python files as txt files.

The main program:

import os
import time

import face

def main():
	face_animate = face.FaceAnimate()
	face_animate.start()
	for x in range(100):
		time.sleep(2)
		face_animate.set_face("squint")
		time.sleep(2)	
		face_animate.set_face("regular")
	face_animate.stop()
	face_animate.join()

if __name__ == "__main__":
    main()

The threaded class:

import os
import threading
import random
import time
import digitalio
import board
from PIL import Image, ImageDraw
from adafruit_rgb_display import st7789

# Configuration for CS and DC pins (these are PiTFT defaults):
cs_pin = digitalio.DigitalInOut(board.CE0)
dc_pin = digitalio.DigitalInOut(board.D25)
reset_pin = digitalio.DigitalInOut(board.D24)

# Config for display baudrate (default max is 24mhz):
BAUDRATE = 24000000

# Setup SPI bus using hardware SPI:
spi = board.SPI()

disp = st7789.ST7789(spi, 
        rotation=270, 
        width=135, 
        height=240, 
        x_offset=53, 
	y_offset=40, # 1.14" ST7789
	cs=cs_pin,
	dc=dc_pin,
	rst=reset_pin,
	baudrate=BAUDRATE,
	)

if disp.rotation % 180 == 90:
    height = disp.width  # we swap height/width to rotate it to landscape!
    width = disp.height
else:
    width = disp.width  # we swap height/width to rotate it to landscape!
    height = disp.height

class FaceAnimate(threading.Thread):
	def __init__(self):
		threading.Thread.__init__(self)
		self.face_offset_x = 0
		self.face_offset_y = 0
		self.images = {}
		self.load_images(os.getcwd() + "/images.txt")
		self.face_key = list(self.images.keys())[0]
		self.face = self.images[self.face_key]		
		self.running = True
		random.seed()

	def load_images(self, file_list_path):
		try:
			with open(file_list_path, 'r') as file:
				for line in file:
					image_filename = line.strip()
					key = image_filename.split('.')[0]
					image = Image.open(os.getcwd() + "/" + image_filename)
					self.images[key] = image
		except Exception as e:
			print(f"{e}")

	def run(self):
		while self.running:
			time.sleep(random.uniform(.5, 1))
			self.face_offset_x = random.randint(-5, 5)
			self.face_offset_y = random.randint(-5, 5)
			self.show_face()

	def set_face(self, face_name):
		self.face = self.images[face_name]
		self.show_face()

	def get_background(self, R, G, B):
		image = Image.new("RGB", (width, height))
		draw = ImageDraw.Draw(image)
		draw.rectangle((0, 0, width, height), outline=0, fill=(R, G, B))
		return image

	def show_face(self):
		background = self.get_background(int("6B", 16), int("8E", 16), int("23",16))
		background.paste(self.face, (self.face_offset_x, self.face_offset_y), self.face)
		disp.image(background)

	def stop(self):
		self.running = False

face.txt
images.txt
regular
squint
face_test.txt

Cookiecutter this!

We need to make sure all files from cookiecutter are here and that the README matches the template.

For instructions on cookiecutter see here.

Usage with displayio?

I'm trying to use adafruit-circuitpython-display-text in combination with this repo.

I found the following code in this video

import board
import displayio
from st7735r import ST7735R

spi = board.SPI()
cs = board.D11
dc = board.D10

displayio.release_displays()
display_bus = displayio.FourWire(spi, command=dc, chip_select=cs, reset=board.D9)

display = ST7735R(display_bus, width=128, height=160)

Is something like this possible? Or should I use this repo instead?

I tried using the code, but I can't import displayio and I have no idea what pip package provides displayio.

LCD shows garbage data on initialization

When my LCD powers on and initializes, it shows garbage data on the screen for a moment. Here is the example codes I was following:

import digitalio
import adafruit_rgb_display.st7789 as st7789  # pylint: disable=unused-import

# Configuration for CS and DC pins (these are PiTFT defaults):
cs_pin = digitalio.DigitalInOut(board.CE0)
reset_pin = digitalio.DigitalInOut(board.D24)
dc_pin = digitalio.DigitalInOut(board.D25)

# Config for display baudrate (default max is 24mhz):
BAUDRATE = 24000000

# Setup SPI bus using hardware SPI:
spi = board.SPI()

# Create the display:
disp = st7789.ST7789(spi, rotation=90, width=135, height=240, x_offset=53, y_offset=40, # 1.14" ST7789
    cs=cs_pin,
    dc=dc_pin,
    rst=reset_pin,
    baudrate=BAUDRATE,
)

This is what appears on the LCD screen:

IMG_20200715_124034

st7789v wrong color

from adafruit_rgb_display.st7789 import ST7789
display.fill(color565(255, 0, 0))

IMG_20240203_162627

No support for the "red tab" ST7735 displays

The ST7735 display comes in two versions, referred to at Adafruit as "green tab" and "red tab" for some reason (even though the "green tab" ones often come with black tabs, and "red tab" ones often have green tabs). Those two kinds require different initialization code.

The MicroPython driver has a separate class for this, called ST7735R. Not sure how it would be best handled here.

LVGL support

What does it take to add LVGL support to this library?

rgb.py ValueError

Following instructions at,
https://learn.adafruit.com/adafruit-1-3-and-1-54-240-x-240-wide-angle-tft-lcd-displays/python-wiring-and-setup

Resulted in,

Traceback (most recent call last):
File "/home/pi/./direwatch.py", line 305, in
disp.image(image)
File "/usr/local/lib/python3.11/dist-packages/adafruit_rgb_display/rgb.py", line 230, in image
pix = color565(img.getpixel((i, j)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/adafruit_rgb_display/rgb.py", line 58, in color565
red, g, b = r
^^^^^^^^^
ValueError: too many values to unpack (expected 3)

Raspberry Pi OS Bookworm/12

curiously,
-craig

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.