0

I have a Raspberry Pi 4 connected to an Official 7' Touchscreen Display that I want to display some data on, ideally from a Python application. What is the "most direct" way to go from an image in Python to displaying it on the screen? By "most direct" I mean the minimum number of programming hoops to jump through after an image is created. I'm not averse to using libraries or windowing systems, but I'd like to have as much of the extraneous detail hidden from me as practicable.

By way of example, I've used some Pimoroni boards with small displays. They (like many vendors of similar small screens aimed at the Raspberry Pi) provide a Python library that takes an image (often built up in Pillow) and does the work of getting it onto the display. I quite liked this way of interacting. Is there a similar library for the Official Touchscreen?

Some other avenues I've investigated and got stuck with:

  • Writing directly to the framebuffer. Either it complains that the Numpy array is too big when it's created, or it can't do the matrix operations to map the image into it, for reasons I don't understand. I also don't fully understand what the array represents. The R/G/B(and sometimes /A) values of each pixel? But they don't seem to behave that way in the examples I have got to work. Also, I seem to be fighting the console's cursor, despite the command given to turn it off.
  • I don't want a desktop environment or a window manager; the display will be a one-trick pony.
  • I might need a windowing system, but I'm not sure what the minimum install on Raspberry Pi OS Lite to get one is. My searches keep falling over people having bother launching an X application automatically on boot.
  • I've seen suggestions to use something like Tkinter, but I don't want UI elements per se; the display will be completely passive and located somewhere it won't be convenient to physically interact with.

1 Answer 1

0

I have a Raspberry Pi 3 with Bullseye 32 bit with Desktop loaded connected to a Raspberry Pi 7" screen. I can run a Python Pygame script that display an image in full screen mode. It will overlay the whole Desktop window. I run the program from another system using ssh. To exit the program, just press the Enter/Return key.

#!/usr/bin/env python3
# https://pygame.readthedocs.io/en/latest/3_image/image.html
# Download bird.png in same director as program.
# Press the enter key to exit.

import pygame
from pygame.locals import *
import os

w, h = 800, 480  # check with fbset
GRAY = (150, 150, 150)

pygame.init()
pygame.mouse.set_visible(0)
#screen = pygame.display.set_mode((w, h))
screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)

try: 
    img = pygame.image.load('bird.png')
except: 
    img = pygame.image.load(os.path.join(
                 "/usr/share/lxpanel/images/xkb-flags",
                 "us.png"))

img.convert()
rect = img.get_rect()
rect.center = w//2, h//2

screen.fill(GRAY)
screen.blit(img, rect)
pygame.display.update()

input()
2
  • I had previously seen Pygame discussed but had dismissed it out of hand as likely too complicated, but your example suggests it is not. As-is, it's crashing for me, but that's most likely due to me having no windowing system. I will investigate further.
    – Scott
    Mar 18 at 18:50
  • See github.com/mataebi/i2fb. "This repository provides i2fb, a simple and straightforward tool to display images on the screen of a Raspberry Pi using its framebuffer only and therefore without the need to run any window system / desktop software like X."
    – bstipe
    Mar 19 at 11:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.