1

I'm just trying to get into new world of RaspPi, Python etc. but facing situation where I am fully lost now and trying to find some guidance.

For my scenario, I connected an (RGB) LCD display in order to show some output from my software scripts. Even though I can get Texts and graphical objects on it, there is still an issue to show-up images like logo or other simple pictures.

I tried for several days now w/ different functions and examples but there is not break-through yet. As a quick 'n dirty code-line to get on the same track (this is just testing purposes - no productive usage!), please follow the example code lines herewith:

from PIL import Image, ImageFont
from luma.core.virtual import viewport
from demo_opts import get_device
from luma.core.render import canvas
from luma.core.interface.serial import spi
from luma.lcd.device import st7735

s = spi(port=0, device=0, cs_high=True, gpio_DC=23, gpio_RST=24)
device=st7735(s,rotate=0,width=160,height=128,h_offset=0,v_offset=0,bgr=False)

print ("Starting...")

img = Image.open("img/starwars.png")
img = img.resize((120,40),Image.BILINEAR) 
screen = viewport(device, width=device.width, height=device.height)

while True: 
    for _ in range(2):
        with canvas(screen) as draw:
            draw.bitmap((20, 0), img)   #works
            draw.arc((20,20,50,50), 0, 90)   #works

It works fine unless I am using the simple starwars.png. When using another file format (colored picture, different file format etc.), I'm faced w/ different kind of errors I could not yet resolve - e.g. bad transparency mask, no show-up. I'm aware that bitmap-function is tricky here, as it just forces a masking by pre-given image format. But I could not derive any other function yet to get any other image been shown on the LCD.

Question: Any idea how to move on? Where's the pitfall? Any tips for an beginner in that area? :)

Side note: I also tried to use this library and examples: https://github.com/pimoroni/st7735-python/blob/1a70d3ae7eee6f376de430c944ff4e95d294543e/examples/image.py However, using this code line, the LCD is not even triggered at all.

Thanks for any feedback for such a blind passenger and rookie :-)

OlliD
  • 11
  • 1
  • You have commented the `draw.bitmap()` call as "#works", so it's not clear what's going wrong with the code. The only potential problem I see is that you might need to explicitly give the `fill=` parameter to that call, to keep the image from being drawn as black-on-black. – jasonharper Apr 12 '22 at 23:48
  • I am unfamiliar with the library you are using, and jason's answer may well be correct - try it. I would say that the Star Wars image is `L` mode and the library may well expect `RGB` or `RGBA` images. Try `img = Image.open("img/starwars.png").convert('RGB')` and also RGBA. See https://stackoverflow.com/a/52307690/2836621 – Mark Setchell Apr 13 '22 at 07:42
  • Thanks guys, seems I'm getting closer :) However, I may not have expressed it sufficiently so let me rephrase the core: Using the starwars image is working fine w/ the code mentioned. Other images are throwing 'bad transparency mask' error in console. Defining `fill=` doesn't change behavior. But the starwars logo is drawn in the given color. Hence, I suppose the `draw.bitmap()` just puts a 'mask' onto grayscale images (which starwars in fact is). My target: getting any other .jpg or .gif colored icon image on LCD. BTW - using `.convert=('L')` also works but gives grayscale tones. – OlliD Apr 13 '22 at 18:50
  • Why are you not using in-kernel driver for this panel? After enabling it you can draw on it as on regular frame buffer. – 0andriy Apr 16 '22 at 22:11
  • Not sure what you mean by this or how I can obtain information on usage of in-kernel driver you are referring to @0andriy. Do you have more docu or specific content I can look at? Sorry, still quite new to the topic – OlliD Apr 18 '22 at 07:00
  • What kind (part number / model) of LCD do you have? Usually they are serial interfaced (SPI, rarely I²C) and supported by either DRM drivers (https://elixir.bootlin.com/linux/latest/source/drivers/gpu/drm/tiny/Kconfig) or FBTFT (https://elixir.bootlin.com/linux/latest/source/drivers/staging/fbtft/Kconfig). You may enable all of them, will be probably easier to find out on the running machine what's what. You have to provide DTS (and then compile it to DTB) with the description of the display. I believe there are plenty examples over Internet, but first thing first — understand your HW parts. – 0andriy Apr 18 '22 at 08:26

0 Answers0