Use an Android smartphone as a Raspberry Pi screen
Event Processing
The button methods retrieve system information and write the results to the text field. However, this cannot happen directly because the application "freezes" while the method is running. MainLoop()
cannot respond to interface events (move window, press button, etc.) during this time.
The button method on_uptime()
starting in line 74 thus only starts a thread, and the actual work is then handled asynchronously in get_uptime()
(starting in line 90).
As usual with all graphical libraries, only the main thread (MainLoop()
) can update the interface. Therefore, the thread creates and sends a self-defined event at the end (line 100). This private event, which I dub SysCmdFinishEvent()
, contains only the text to be displayed; the definition is at the beginning of the listing.
The program also binds a method to this event (line 31) in the constructor of AppFrame
. A text field is updated here (starting in line 81), and thus the circle closes.
If you want to fill a field automatically with status information, you can use the same approach. A thread running for a long time simply sends an update event with the new field content at fixed intervals.
Integration
The program still has two problems: If it starts when the X server is not (yet) running, it crashes, and it stops as soon as the X server app stops running or is out of range.
You can solve the first problem by testing for the X server at program launch and then only continuing the program if there is a response (the code is missing from Listing 1 because of a lack of space). As soon as the app starts, the interface pops up. This only works if you don't use multiple Raspberry Pis on one smartphone.
The system daemon solves the second problem for you. You can start the program as a service with the wxvlcd.service
file (Listing 2), which is also where you set the DISPLAY
variable. The only special thing about the unit definition is line 10 with the Restart=always
statement. It ensures that systemd automatically restarts the program after it has ended. Details and alternatives to always
(e.g., on-failure
) can be found with the man systemd.service
command.
Listing 2
wxvlcd.service
Conclusions
Thanks to the X server and wxPython, you can implement simple control and info displays for your Rasp Pi projects with minimal effort – and all communication is wireless.
If you do not have an Android device or would rather use one of the small 3.2-inch displays with the Raspberry Pi, you can still use wxPython. The program evaluates the DISPLAY
variable, so the program can be output locally or over the network, depending on the configuration.
The mature development stage of wxPython offers another benefit. The toolkit is extremely stable, and you will find a sample solution for almost every need online. Even if you have never programmed a graphical user interface before, you will quickly turn out an attractive GUI just by following the example in this article.
Infos
- Project Blue Dot: https://www.stuffaboutcode.com/2017/04/bluedot-bluetooth-remote-for-raspberry.html
- Pi Control: https://pi-control.de
- Android X server (app): https://play.google.com/store/apps/details?id=x.org.server&hl=en
- Android X server (project): https://github.com/pelya/xserver-xsdl
- Kivy: https://www.kivy.org
- Project page for the article: https://github.com/bablokb/pi-vlcd
« Previous 1 2 3
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.
-
Linux Usage Increases in Two Key Areas
If market share is your thing, you'll be happy to know that Linux is on the rise in two areas that, if they keep climbing, could have serious meaning for Linux's future.
-
Vulnerability Discovered in xz Libraries
An urgent alert for Fedora 40 has been posted and users should pay attention.
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.