2015-10-04 95 views
2

我試圖從python腳本輸出一些數據到Sainsmart 1.8 TFT顯示器。其次從https://github.com/notro/fbtft/wiki的指示,我能夠顯示樹莓的屏幕TFT顯示屏上Raspberry Pi:如何在TFT顯示器上顯示python的輸出

FRAMEBUFFER=/dev/fb1 startx 

當我嘗試輸出數據從我的Python腳本,一個pygame的窗口(「彈出up'樣)打開,但不是在tft屏幕上,而是在連接到帶有HDMI的樹莓的主屏幕上。

我的代碼是從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屏幕上輸出?

回答

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之下,仍然能夠登錄在此之後,使用的用戶界面。

+0

非常感謝 - 它的工作原理!你能否給我提供一個鏈接或者你在這之後如何設法登錄?由於我的主屏幕變黑,我無法輸入任何內容。 – user3255061

+0

哦不,發佈時間早:(我現在無法再使用UI登錄,現在登錄後輸入'startx'後,會啓動clock.py(在主屏幕上)。 – user3255061