This is the source-code for my custom LED display using a Raspberry Pi.
Hardware:
- Raspberry Pi 4 (but could have been any other board that provides two GPIO pins).
- 16-digit 7-segment LED display based on TM1640 chip.
- Mine has this text printed on the back of the PCB: JY-MCU JY-LM1640 V:1.1
- It's the same one from these projects:
- And I can't find this module for sale anymore.
Software:
- Any (modern) Linux distribution. I'm running Gentoo arm64 (
aarch64
), but it doesn't matter. - Python 3.
- The code from this repository.
Hardware setup:
- Connect the LED display module to the pins on the Raspberry Pi.
- The module has four wires:
- VDD 5V (for powering the LEDs and the board)
- GND (ground, AKA 0V)
- DIN (data input, data transmitted from the Raspberry Pi to the display)
- SCLK (serial clock, driven by the Raspberry Pi via software)
- Connect VDD and GND.
- Pick any two GPIO pins and connect DIN and SCLK to those pins. Remember to take note of the number (e.g. GPIO23 and GPIO24).
- Confused about the pins in your Raspberry Pi? There are a few ideas:
- Look at https://pinout.xyz/.
- Run the command-line tool
pinout
(also available in./venv/bin/pinout
), provided bygpiozero
package.
- The module has four wires:
- Make sure your power supply is good enough.
- According to the datasheet, this module can have 400mW of power consumption, which roughly translates to 80mA at 5V. I haven't measured the actual consumption, though.
Software setup:
- Run:
./one_time_setup.sh
Just run: ./ip_addresses.py
If desired, set it up to run on boot on your Raspberry Pi (see ip_addresses.init.d
for an OpenRC script that works on Gentoo, and adapt as needed).
Finally, just edit ip_addresses.py
according to your needs. Someday in the far future it may be restructured to read data from a configuration file… But for now everything is simply hard-coded in the script itself.
My objective is to have a nice extra display in addition to whatever else that Raspberry Pi is already doing. This extra display can show relevant information, such as:
- Raspberry Pi health monitors
- CPU temperature
- CPU clock frequency
- Load average
- Memory usage
- Clock and date
- Local time
- In another timezone (world clock)
- Swatch Internet Time (but nobody uses it anyway)
- Age of (or countdown to) a certain moment
- Easter date and other moving dates (e.g. Carnival), dateutil.easter can be helpful
- DST changes (find out the date for the next DST change based on tzinfo)
- Data from Home Assistant
- But which pieces of data are relevant?
- And how to fetch data from Home Assistant? Or should Home Assistant push the data to this display?
- Weather
- But from which service? There are many!
- Might be a better idea to just get data from whatever service is already set up on my Home Assistant.
- Anything else I can come up with
As for the implementation, I envision a daemon that would communicate with the display and handle some extra time-related logic (e.g. scrolling the text, updating the clock, etc.). Additionally, this daemon would expose an HTTP API to control the display. Then, I could have a static HTML page that talks to that API. This whole architecture seems to give me the most power and flexibility… but we are far from getting there.
I've configured it to run automatically on boot on my Raspberry Pi, and it has been running flawlessly for years.
But everything is hard-coded and cannot be modified without editing the code and restarting the script. So… it's a hacky project, but it works and it provides useful information to anyone around the display.
Make sure you are part of the gpio
group. (Or whatever group is relevant for your distro.)
See gpiozero FAQ.
Please see this forum post and this ticket. In summary, upstream rpi.gpio
fails to compile on GCC version 10 due to -fno-common
now being the default.
The initial version of this code only displayed the IP address of the machine, and nothing else. It was a great diagnostic tool, as I could connect the Raspberry Pi to a wired network (using an Ethernet cable) and view the assigned IP address without having to connect a large monitor over HDMI.
Over time, the script evolved to display a clock, some countdowns, and some stats; but it was never renamed.