Use an Android smartphone as a Raspberry Pi screen
Recycled

© Lead Image © Valery Kachaev, 123RF.com
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
Direct Download
Read full article as PDF:
Price $2.95
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Find SysAdmin Jobs
News
-
MNT Seeks Financial Backing for New Seven-Inch Linux Laptop
MNT Pocket Reform is a tiny laptop that is modular, upgradable, recyclable, reusable, and ships with Debian Linux.
-
Ubuntu Flatpak Remix Adds Flatpak Support Preinstalled
If you're looking for a version of Ubuntu that includes Flatpak support out of the box, there's one clear option.
-
Gnome 44 Release Candidate Now Available
The Gnome 44 release candidate has officially arrived and adds a few changes into the mix.
-
Flathub Vying to Become the Standard Linux App Store
If the Flathub team has any say in the matter, their product will become the default tool for installing Linux apps in 2023.
-
Debian 12 to Ship with KDE Plasma 5.27
The Debian development team has shifted to the latest version of KDE for their testing branch.
-
Planet Computers Launches ARM-based Linux Desktop PCs
The firm that originally released a line of mobile keyboards has taken a different direction and has developed a new line of out-of-the-box mini Linux desktop computers.
-
Ubuntu No Longer Shipping with Flatpak
In a move that probably won’t come as a shock to many, Ubuntu and all of its official spins will no longer ship with Flatpak installed.
-
openSUSE Leap 15.5 Beta Now Available
The final version of the Leap 15 series of openSUSE is available for beta testing and offers only new software versions.
-
Linux Kernel 6.2 Released with New Hardware Support
Find out what's new in the most recent release from Linus Torvalds and the Linux kernel team.
-
Kubuntu Focus Team Releases New Mini Desktop
The team behind Kubuntu Focus has released a new NX GEN 2 mini desktop PC powered by Linux.