Simulate Raspberry Pi add-on hardware
Soft Pi
![© Lead Image © Author, 123RF.com © Lead Image © Author, 123RF.com](/var/linux_magazin/storage/images/issues/2020/230/simulated-pi-hardware/besjunior_123rf-steampunk_robot_tools.png/760351-1-eng-US/besjunior_123rf-Steampunk_robot_tools.png_medium.png)
© Lead Image © Author, 123RF.com
Python and tk_tools let you create software versions of Raspberry Pi mini-displays, LED keypads, and NeoPixel hardware.
Raspberry Pis have some great hardware options for displaying information or accepting input. You can use either specialty plates that mount directly on top of the Rasp Pi or a variety of wired components.
Although nothing beats using real hardware for projects, if you're missing the hardware or you'd like to duplicate a value remotely, then a soft version of the hardware can be very useful. In this article, I look at three examples of hardware simulated with the help of Python and the tk_tools Python library [1]: a seven-segment wired display, an LCD keypad, and a NeoPixel string.
Seven-Segment Display
A seven-segment display uses seven horizontal and vertical bars, familiar in clocks, meters, and other electronic devices, to represent numbers and letters. The displays are often based on the HT16K33 [2] or TM1637 [3] chipset (Figure 1).
The tk_tools Python library [1] contains a soft component for a seven-segment display that can save you writing code from scratch. To install the module, enter:
pip install tk_tools
The tk_tools
seven-segment component can function like a TM1637 or HT16K33 display component, with support for various heights, digit colors, and background color. Listing 1 is an example that displays the Rasp Pi's CPU temperature (Figure 2). After creating the seven-segment display object (line 8), simply call set_value
(line 18) to display the updated Pi temperature value.
Listing 1
Show Pi CPU Temperature
LCD Keypad
LCD keypad plates [4] have five or six configurable buttons and a 2x16-character LCD display. These keypads are ideal in small projects for which you want some local control. My daughters and I have used the LCD keypad plates on a number of Pi projects, such as FM radios (Figure 3) and streaming music players.
The tk_tools library doesn't have an LCD keypad component, but I found that it is easy to simulate with the standard Python Tkinter library. For my example, I tried to replicate the look and feel of the Pi plate that I had, but you could enhance or change it to meet your requirements.
Listing 2 is a Python LCD keypad example that displays key presses (Figure 4). Lines 13-17 create a single label with white on blue text. The grid's rowspan
and columnspan
properties (line 18) create a label two lines high that spans the entire window. The label automatically handles the line wrap to the second line, or a new line character (\n
) forces text to the second line.
Listing 2
Simulated Pi LCD Keypad
A common function, myfunc
(line 4), is called when a button is pushed. In this example, the buttons pass their button text to myfunc
, which then shows the custom text message in the two-line display.
NeoPixels
NeoPixels [5] are addressable full-color RGB LEDs that come in a variety of arrangements, such as LED strings (Figure 5), matrix arrays, Pi plates, and a variety of sewable components that can be used on wearable products. NeoPixels were first available only for Arduino projects, but now, Python libraries for Raspberry Pis are available, as well.
Listing 3 is a Python Tkinter example that simulates 10 NeoPixels in a string arrangement (Figure 6). The array object ledstrip
(line 10) becomes a number of colored Tkinter labels (line 13), which are placed sequentially in a grid to form a string (line 14). However, you could also arrange the labels into a matrix or a circle. An LED color is set with the configure(background= 'red')
command (line 17).
Listing 3
Simulated NeoPixels
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.
![Learn More](https://www.linux-magazine.com/var/linux_magazin/storage/images/media/linux-magazine-eng-us/images/misc/learn-more/834592-1-eng-US/Learn-More_medium.png)
News
-
Kernel 6.10 Available for General Usage
Linus Torvalds has released the 6.10 kernel and it includes significant performance increases for Intel Core hybrid systems and more.
-
TUXEDO Computers Releases InfinityBook Pro 14 Gen9 Laptop
Sporting either AMD or Intel CPUs, the TUXEDO InfinityBook Pro 14 is an extremely compact, lightweight, sturdy powerhouse.
-
Google Extends Support for Linux Kernels Used for Android
Because the LTS Linux kernel releases are so important to Android, Google has decided to extend the support period beyond that offered by the kernel development team.
-
Linux Mint 22 Stable Delayed
If you're anxious about getting your hands on the stable release of Linux Mint 22, it looks as if you're going to have to wait a bit longer.
-
Nitrux 3.5.1 Available for Install
The latest version of the immutable, systemd-free distribution includes an updated kernel and NVIDIA driver.
-
Debian 12.6 Released with Plenty of Bug Fixes and Updates
The sixth update to Debian "Bookworm" is all about security mitigations and making adjustments for some "serious problems."
-
Canonical Offers 12-Year LTS for Open Source Docker Images
Canonical is expanding its LTS offering to reach beyond the DEB packages with a new distro-less Docker image.
-
Plasma Desktop 6.1 Released with Several Enhancements
If you're a fan of Plasma Desktop, you should be excited about this new point release.
-
SUSE Offers CentOS 7 Support with Liberty Linux Lite
SUSE's Liberty Linux support offering now includes CentOS 7, which means businesses won't be forced to migrate those servers for some time.
-
Ubuntu's App Center Finally Supports Local Installs Again
If you regularly download .deb files and would prefer a GUI method of installing, Ubuntu has your back.