【问题标题】:Raspberry Pi: How to show output from python on TFT displayRaspberry Pi:如何在 TFT 显示器上显示 python 的输出
【发布时间】:2015-10-04 14:27:57
【问题描述】:

我正在尝试将一些数据从 python 脚本输出到 Sainsmart 1.8 TFT 显示器。按照https://github.com/notro/fbtft/wiki 的指示,我可以在 tft 显示器上显示覆盆子屏幕

FRAMEBUFFER=/dev/fb1 startx

当我尝试从我的 python 脚本输出数据时,会打开一个 pygame 窗口(类似“弹出”),但不是在 tft 屏幕上,而是在通过 HDMI 连接到 Raspberry 的主屏幕上。

我的代码来自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()

谁能告诉我如何在 tft 屏幕上显示脚本的输出?

【问题讨论】:

    标签: python pygame raspberry-pi


    【解决方案1】:

    我阅读了on the startx command,在我看来一个解决方案是创建一个.xinitrc 文件。

    试试这个:

    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
    

    注意:我在 Lubuntu 下对此进行了测试,之后仍然能够登录并使用用户界面。

    【讨论】:

    • 非常感谢 - 它有效!您能否提供一个链接或您在此之后如何登录的信息?因为我的主屏幕变黑了,我无法输入任何内容。
    • 哦,不,早点发布:(。我现在不能再用 UI 登录了。在我登录后输入“startx”后,它会启动clock.py(在我的主屏幕上)现在。
    • 您可以使用 Control+Alt+F3 打开一个新的终端窗口,然后使用 nano ~/.xinitrc 从那里登录和编辑。
    猜你喜欢
    • 1970-01-01
    • 2016-12-21
    • 1970-01-01
    • 2018-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-26
    相关资源
    最近更新 更多