TheOtherHank
Posts: 3
Joined: Wed Feb 20, 2019 4:23 am

pygame and tft lcd

Wed Feb 20, 2019 4:53 am

Hello -

I recently got a 3.5 inch tft lcd. I have been playing around with pygame. I can get things to display on it. Here's a sample (test.py):

Code: Select all

#! /usr/bin/python

import os
import pygame
import time

os.putenv('SDL_FBDEV', '/dev/fb1')
pygame.init()
lcd = pygame.display.set_mode((480, 320))
lcd.fill((255, 0, 0))
pygame.display.update()
time.sleep(1)
lcd.fill((0, 255, 0))
pygame.display.update()
time.sleep(1)
lcd.fill((0, 0, 255))
pygame.display.update()
time.sleep(1)
This works when I run it via sudo (ie, sudo ./test.py). If I try running it without sudo (./test.py) I get this error:
$ ./test.py
Traceback (most recent call last):
File "./test.py", line 9, in <module>
lcd = pygame.display.set_mode((480, 320))
pygame.error: Unable to open a console terminal
$
Is there a way to run it without having to sudo?

Thanks,
Hank

Andyroo
Posts: 4467
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: pygame and tft lcd

Wed Feb 20, 2019 2:35 pm

It could be that your user is not authorised to access the second screed device.

With the screen connected and logged in as your normal user can you try:

Code: Select all

ls -l /dev/fb*
Need Pi spray - these things are breeding in my house...

Desoya
Posts: 4
Joined: Wed Feb 20, 2019 10:26 am

Re: pygame and tft lcd

Wed Feb 20, 2019 3:08 pm

Hello, what about getting all the users accessing your device with:

Code: Select all

sudo chmod a+rw /dev/fb1
Then if it solves your issue, feel free to find a more elegant and secure solution using ad-hoc linux groups for video devices.

TheOtherHank
Posts: 3
Joined: Wed Feb 20, 2019 4:23 am

Re: pygame and tft lcd

Thu Feb 21, 2019 3:22 am

Hi -

Thanks for the replies.

Code: Select all

$ ls -l /dev/fb*
crw-rw---- 1 root video 29, 0 Feb 20 19:10 /dev/fb0
crw-rw---- 1 root video 29, 1 Feb 20 19:11 /dev/fb1
$
So it looks like the video group has the same permissions as root. I tried adding my user to the video group (I negelected to check if it was already in that group before doing so).

Code: Select all

sudo gpasswd -a $USER video
Running ./test.py still gives the same error. I also tried

Code: Select all

chmod 666 /dev/fb1
Which also failed when I ran ./test.py

I'll keep plugging away.
Thanks,
- Hank

Return to “Python”