Use an Android smartphone as a Raspberry Pi screen
Recycled
A simple Python program turns a disused smartphone into a wirelessly connected Raspberry Pi display.
New low-end $100 smartphones offer enough performance for everyday life, but the market for used devices is dismal. Instead of letting your smartphones and tablets gather dust, you can put their touchscreens to work and provide a better display than those of the same size marketed for the Raspberry Pi.
One disadvantage is the lack of a connection cable for the output from the Raspberry Pi to the smartphone. Fortunately, you have alternatives, such as a wireless connection, which I will show you how to set up in this article.
Another problem is the display size. Although the 800x480-pixel resolution of a smartphone, for example, is close to that of the official Pi display, the screen area is extremely small; a normal desktop simply cannot be displayed on devices smaller than a 10-inch tablet.
For many projects, you don't need a full desktop, though (e.g., if you only need to output a small amount of data or status information), and you can limit the controls to a couple of buttons. With very little effort, you can write programs with graphical interfaces that fit perfectly on the smartphone screen. In this article is an example program you can use as a model for your own projects.
Alternatives
One approach for displaying a graphical user interface on the smartphone is to split the application and display into two programs. For example, the Rasp Pi could run a program that serves up its output as a website, with the smartphone browser displaying the results.
The disadvantage of this solution is that, whereas a small web server can be integrated into any program – independent of the programming language and without too much overhead, thanks to a wide variety of program libraries – an attractive presentation also requires know-how in web design and JavaScript programming.
A variant of this approach uses an app on the smartphone instead of the web browser. Although this involves significantly more work, it also offers more freedom (e.g., communication over Bluetooth instead of a wireless network).
The smart Blue Dot [1] app, which sets up an Android device as a Bluetooth remote for Raspberry Pi, can be used as a project template, and you can integrate it directly into your own programs thanks to the matching Python library (Figure 1). The well-known Pi Control [2], which is a web-based application that provides status information about your Rasp Pi, is another example and requires you to be familiar with the Android or iOS environment, instead of web design.
If you only want to write a program, use the approach described in the following sections. The program runs on the Rasp Pi and outputs the graphical user interface to another computer on the network (i.e., a smartphone or tablet) rather than over its HDMI interface. Although not particularly efficient – both the user data and the user interface need to cross the wire – the programming overhead is manageable.
Old and Good?
Programs running on the Rasp Pi output the graphical user interface via the X server, an independent program that receives the graphics commands and takes care of the rest of the work.
X server is older than Linux itself and dates back to a time when computers were exclusively located in data centers. Special terminals in the office ran only an X server, which displayed programs with graphical interfaces. The server received the graphics commands over the network from the programs in the data center.
The combination of a Rasp Pi and smartphone uses the same approach. The Rasp Pi plays the part of the remote computer and the smartphone the part of the X terminal. Because you only want to see the output of a single program and are not interested in seeing the complete desktop interface, you do not even need to install the Raspbian Pixel desktop.
On the Pi side, you only need the X client. If you have installed Raspbian with a graphical user interface, everything you need is already on board. For the Lite version, you need a separate client, which also handles the installation of the sample program as a desirable side effect.
The ancient X architecture has suffered from various issues over the years, especially relating to security and performance. Modern computers (like the Rasp Pi) contain a powerful GPU that does the rendering itself, which does not make sense if you want to transfer the output across the wire and restricts you somewhat in your choice of program libraries: The output from directly rendered programs only displays locally.
X Server
For an Android smartphone, you need to install XSDL [3], a free and open source [4] X server, from the Playstore. In the lab, I even managed to install it on an ancient device with Android 2.3, but the program always crashed when launched. Through lack of experience and no apparent suitable app, I cannot give iOS users any recommendations.
When starting the X server, configure it using the button that occupies the entire top margin. Set the mouse emulation to Tablet and the left mouse button to Touch or hold. In the Video menu, configure the alignment to suit your needs for the project at hand (e.g., landscape, portrait, automatic).
The next configuration step looks a bit arcane: A screen appears that offers various resolutions. If you do not want to use the native resolution, then tap on the desired alternative. You can also select font scaling afterward. You can change both at each startup; in case of doubt, the server simply starts with the old configuration. Changing the resolution is only possible on displays with a very high resolution anyway.
The X server itself does not provide any interaction; after startup you will only see a blank screen with some instructions. More specifically, the server displays the IP address of the mobile device. Every application you launch then reverts to this background. For example, Figure 2 shows the Xeyes program from the x11-apps package that's just for fun: The eyes follow the mouse cursor.
For the Rasp Pi to find the smartphone automatically later on, you need to assign a fixed IP address on the local network to the cellphone. You can either do this via your router by permanently assigning the IP address to the MAC address of the device or in the advanced network settings of the smartphone, which you can normally access with a long press on the network connection.
To avoid managing the lengthy IP address on the Raspberry Pi, you can enter it in the Pi's /etc/hosts
file and assign a meaningful name to the smartphone.
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
-
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.
-
ZorinOS 17.1 Released, Includes Improved Windows App Support
If you need or desire to run Windows applications on Linux, there's one distribution intent on making that easier for you and its new release further improves that feature.
-
Linux Market Share Surpasses 4% for the First Time
Look out Windows and macOS, Linux is on the rise and has even topped ChromeOS to become the fourth most widely used OS around the globe.
-
KDE’s Plasma 6 Officially Available
KDE’s Plasma 6.0 "Megarelease" has happened, and it's brimming with new features, polish, and performance.
-
Latest Version of Tails Unleashed
Tails 6.0 is based on Debian 12 and includes GNOME 43.
-
KDE Announces New Slimbook V with Plenty of Power and KDE’s Plasma 6
If you're a fan of KDE Plasma, you'll be thrilled to hear they've announced a new Slimbook with an AMD CPU and the latest version of KDE Plasma desktop.
-
Monthly Sponsorship Includes Early Access to elementary OS 8
If you want to get a glimpse of what's in the pipeline for elementary OS 8, just set up a monthly sponsorship to help fund its continued existence.
-
DebConf24 to be Held in South Korea
Busan will be the location of the latest DebConf running July 28 through August 4