3

I'm trying to output some data from a python script to a Sainsmart 1.8 TFT display. Followed the instructions from https://github.com/notro/fbtft/wiki, I am able to show the raspberry's screen on the tft display with

FRAMEBUFFER=/dev/fb1 startx

When I try to output data from my python script, a pygame window ('pop up'-like) opens, but not on the tft screen, but on the main screen connected to the Raspberry with HDMI.

My code is from this tutorial:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

#
# Creation:    26.05.2013
# Last Update: 07.04.2015
#
# Copyright (c) 2013-2015 by Georg Kainzbauer <http://www.gtkdb.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#

import os
import sys
import time
import pygame

time_stamp_prev=0

os.environ["SDL_FBDEV"] = "/dev/fb1"
os.environ['SDL_VIDEODRIVER']="fbcon"

def displaytext(text,size,line,color,clearscreen):
  if clearscreen:
    screen.fill((255,255,255))

  font = pygame.font.Font(None,size)
  text = font.render(text,0,color)
  rotated = pygame.transform.rotate(text,-90)
  textpos = rotated.get_rect()
  textpos.centery = 80
  if line == 1:
    textpos.centerx = 99
    screen.blit(rotated,textpos)
  elif line == 2:
    textpos.centerx = 61
    screen.blit(rotated,textpos)
  elif line == 3:
    textpos.centerx = 25
    screen.blit(rotated,textpos)

def main():
  global screen

  pygame.init()
  pygame.mouse.set_visible(0)
  size = width,height = 128,160
  screen = pygame.display.set_mode(size)

  while True:
    displaytext(time.strftime("%d.%m.%Y"),40,1,(0,0,0),True)
    displaytext(time.strftime("%H:%M:%S"),40,2,(0,0,0),False)
    displaytext("www.gtkdb.de",20,3,(0,0,0),False)
    pygame.display.flip()
    time.sleep(1)

if __name__ == '__main__':
  main()

Can anyone tell me how to show the script's output on the tft screen?

0

1 Answer 1

1

I read on the startx command and a solution seems to me to create a .xinitrc file.

Try this:

chmod +x ./clock.py # make the clock file executable
mv ./clock.py ~/.xinitrc # move it to where startx starts it
FRAMEBUFFER=/dev/fb1 startx # startx will start it

Note: I tested this under Lubuntu and was still able to log in after this and use the user interface.

3
  • Thanks a lot - it works! Could you please provide me with a link or something how you managed to login after this? Because my main screen turns black and I'm not able to type anything. Commented Oct 10, 2015 at 10:17
  • Oh no, posted to early :(. I'm not able to login with the UI any more now. It starts clock.py (on my main screen) after I type 'startx' after logging in now. Commented Oct 10, 2015 at 10:22
  • You can open a new terminal window with Control+Alt+F3, log in and edit from there with nano ~/.xinitrc.
    – User
    Commented Jun 16, 2018 at 15:37

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.