SirLefti / Python_ILI9486

Python module to control an ILI9486 TFT. Allows simple drawing PIL images on the display.
MIT License
4 stars 4 forks source link

ILI9486 blank screen, no errors #1

Open craigerl opened 2 weeks ago

craigerl commented 2 weeks ago

Raspberry Pi 3.5inch RPi LCD (B) Waveshare

(.venv) pi@digipi:~/.venv/Python_ILI9486 $ sudo ../bin/python image.py Initialized display with landscape mode = True and dimensions (480, 320) Loading image... Drawing image Drawing partial image Turning on inverted mode Turning off inverted mode

..

screen is blank the entire time with backlight on. dtoverlay is not loaded.

SirLefti commented 2 weeks ago

Hi Craig, sorry to hear that.

It is not mentioned in the README.md, but is SPI enabled on your device? It is not enabled by default, but I would expect a FileNotFoundError anyways if it was not enabled.

Can you provide additional information?

I just cloned it onto my RPi 2B using the latest Raspberry OS based on Debian 12 Bookworm and it worked just fine.

craigerl commented 2 weeks ago

Hi SirLefti, it looks like it's isolated to Pi5. it works on a PiZero2w. Probably spidev/gpio related, i'll closer at this.

Using bookworm, original kernel (no errata). direct connection on gpio header

Even on the PiZero2W, the "image.py" example displays an image only for two seconds, then screen blanks. I'm trying to write an app that will display a png, that's it. Not quite there. thanks!

https://www.amazon.com/dp/B07V9WW96D

#!/usr/bin/python

from PIL import Image
import RPi.GPIO as GPIO
from spidev import SpiDev
import time
import ILI9486 as LCD
import config

spi: SpiDev = None

if __name__ == '__main__':
    try:
        GPIO.setmode(GPIO.BCM)
        spi = SpiDev(config.SPI_BUS, config.SPI_DEVICE)
        spi.mode = 0b10  # [CPOL|CPHA] -> polarity 1, phase 0
        # default value
        # spi.lsbfirst = False  # set to MSB_FIRST / most significant bit first
        spi.max_speed_hz = 64000000
        lcd = LCD.ILI9486(dc=config.DC_PIN, rst=config.RST_PIN, spi=spi).begin()
        print(f'Initialized display with landscape mode = {lcd.is_landscape()} and dimensions {lcd.dimensions()}')
        print('Loading image...')
        image = Image.open('sample.png')
        width, height = image.size
        partial = image.resize((width // 2, height // 2))

        print('Drawing image')
        lcd.display(image)
        time.sleep(10)

-craig

SirLefti commented 2 weeks ago

Something comes to my mind regarding this. Pi 5 and Zero 2 are using ARMv8 64-bit SOCs, while my old 2B is ARMv7 32-bit. I assume that you have the 64-bit version of Raspberry OS installed, which might have some differences to the 32-bit version.

But I remember something else that might be relevant. I switched here in my piboy project from RPi.GPIO to rpi-lgpio, which was the initial reason writing this driver, when I rewrote the setup guide for the latest Raspberry OS based on Debian Bookworm, because the old lib had issues with edge detection. The new lib apparaently uses a different approach controling the GPIO pins. I do not understand the details, but maybe the issues have something in common.

What you can try:

The new lib is a drop-in replacement, because its module has the same name as the old one. Thus it is required to remove the old lib to avoid conflicts.

However I have to admit that my example script also worked with the old lib for me. But as already mentioned, old SOC, 32-bit OS.

craigerl commented 2 weeks ago

yah, spi is enabled. it's a pi5 thing, in conjunction with bookworm spi and gpio were generally destroyed in favor of gpiod, possibly gpiozero. the former requires a chip id, the latter uses an entire cpu core just to monitor a button. In any event, it's easy to reproduce on a pi5 and only a pi5 with bookworm.

SirLefti commented 2 weeks ago

Okay, so you would have to rewrite it with gpiod or gpiozero to make it work, Have you tested the mentioned rpi-lgpio as well?