Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display GUI on Raspberry Pi without startx

Tags:

raspberry-pi

I'm currently playing with my brand-new raspberry with adafruit's touch-tft and raspberry Cam.

I noticed, if I run raspivid -p, it displays the preview in a frame on top of the bash.

How can I create an application (java, python, c++(preferred)) to display a GUI without having to startx?

I'd love to use adafruit's touch-tft for a project, but startx needs a lot of resources. Of course it would be cool to have the touch-functionality too.

Edit:

Maybe I expressed myself a little bit confusing: I would like to create an application that doesn't need startx but has some kind of GUI.

The answers below aren't 100% ready to go but they pointed me to the right direction. Since I saw many similar questions I will try to give a step-by-step solution:

  1. Setup your raspberry with adafruit's TFT: https://learn.adafruit.com/adafruit-pitft-28-inch-resistive-touchscreen-display-raspberry-pi/overview (you don't have to replace the TFT with HDMI as standart display)

  2. be sure FRAMEBUFFER=/dev/fb1 startx is running correctly on the TFT screen, I have my TV plugged in the HDMI port, this way I can use the bash on the TV screen and run x on the TFT

  3. Follow this tutorial to create your first pygame: http://www.pygame-doku.laymaxx.de/tut/intro/intro.html (you can just copy&paste, wget ball.gif)

  4. Insert this 2 lines at the beggining: (github.com/notro/fbtft/wiki/Pygame)

    import os
    os.environ["SDL_FBDEV"] = "/dev/fb1"
    
  5. If you want to test the touch-screen to, you can change Line 15: From:

    if event.type == pygame.QUIT: sys.exit()
    

    To:

    if event.type == pygame.MOUSEBUTTONDOWN: sys.exit()
    

    This will exit the application if you touch the screen

  6. Save file e.g. pygame1.py and execute with $python pygame1.py

You should now see a bouncing ball on your TFT while the HDMI output still displays the BASH on your TV (but it isn't active of course) touching the screen will exit the game if you completed step 6

Why I'm doing this? This way you can display a simple GUI with e.g. buttons to do some action, like turn your lights on/off if you use your RPI for home-control.

like image 335
G-M Avatar asked Jun 10 '14 17:06

G-M


People also ask

How do I access my Raspberry Pi GUI remotely?

Open up VNC Viewer on your computer and type in the IP address of your Raspberry Pi. Initially (if you haven't changed the default raspberry pi user and password) this will be “pi”and “raspberry”. The first time you log in you will see a very compact and bijou desktop of a whopping 720 x 480.

Does Raspberry Pi have a GUI?

You may have installed Raspberry Pi OS Lite on your Raspberry Pi, which does not ship with a GUI. If you change your mind and want a GUI after all, you can just install one.


1 Answers

You can use for example pygame library! check this tutorial http://archive.furtherfield.org/rp-resources/RP-workshop-handout.pdf pg. 17

like image 59
Dimitry K Avatar answered Sep 23 '22 10:09

Dimitry K