This Raspberry Pi 400 project displays ...
- CPU usage %,
- RAM usage %,
- Disk space used %,
- CPU temperature,
- machine ip address,
- and timestamp
... on a Waveshare ePaper (250 x 122 pixels, 2.13 inch EPD HAT for Raspberry Pi, Black/White, RPI SPI interface) connected to a Adafruit Cyberdeck Bonnett (which then connects to the Raspberry Pi 400's GPIO pins). The scripts clear.py (clears the display) and update.py (gets and writes data onto the display) are written in python.
The python script does what any robust software should and takes various test cases into consideration:
- Is the display plugged into the GPIO?
- Can the display driver be located?
- Can configurations be read from the .ini file?
These are useful functions transferable to future projects.
MotivationsI'm a professional Java full stack web developer at a bank and I wanted to learn more about Linux command line. I had self-studied python in my free time but didn't have many opportunities to put it to use.
This project is the perfect vehicle for learning to use the Linux terminal (especially apt, cp, less, systemctl, systemd, crontab, cd), and practice some python while I'm at it.
ComponentsSince this is taking the first step into the world of Raspberry Pi projects, I needed a project that was inexpensive to do and required few components (considering the shortages and scalping at the time of writing). This project only requires a ePaper display, a HAT that helps breakout the awkward GPIO layout of the Raspberry Pi 400, and some good old software. Not including the Raspberry Pi 400, this only costs ~20 USD.
TutorialSee step-by-step instructions with photos and ready-to-copy-paste command line at my GitHub repository RPiDev. The README.md is very extensive so it would be better to link it here than copy-paste 300-400 lines of .md syntax.
https://github.com/omgitskuei/RPiDev/blob/main/RPi400/Cyberdeck_Stats_Monitor/
- Step 1 - Acquire the necessary components and connect them
- Step 2 - Make sure Python 3 is installed
- Step 3 - Make sure the ePaper driver is in ./library and the bmp file is in ./pic
- Step 4 - Use systemd to run update.py every 4 mins
- Step 4 - Use Cron to run update.py every 4 mins
- Step 5 - Use systemd to run clear.py script before shutdown
- Step 6 - Try running the scripts through terminal
Temporarily disable the display:
- To stop the display from refreshing, run clear.py.
- Open the .ini file with Notepad++ and change
enable=true
toenable=false
.
AND/OR
- Don't plug in the display - ❗ Note, if display is not plugged in BUT enable=true, this still uses up the GPIO pins every 4 mins meaning it will probably interfere with other projects also using the pins. This is fine if nothing is using the GPIO pins though using the .ini file too is best.
Uninstalling by removing cron jobs/systemd services and timers:
crontab -e
and remove the cron jobs
OR
systemctl disable [the timer and service files]
sudo rm [the timer and service files]
❗ Be careful with the rm command, double check for typos!sudo systemctl daemon-reload
Version 1 - first attempt at writing data onto the display. The two black lines divide the width and length into halves.
Version 2 - noticed that the placement of the CPU usage (a percentage) and the CPU temperature (in Celsius) are placed incorrected on the display in Version 1.
Version 3 - added timestamp and ip address.
Version 4 - noticed that running the script at reboot will return an empty string for ip address - the display would show (eg.) | 2022-01-13 10:55
. Swapped their placements so that if there's no IP, it can return an empty string without changing the timestamp's placement and also not print an unnecessary "|". A thing to note is that the timestamp might also be 'wrong' when first run on reboot, returning time in UTC not localtime. This is caused by the cronjob @reboot running too early before the OS has fetched localtime. There may not be any way to fix this unless systemd is used instead of cron for the reboot's script run because systemd can specify the order in which the script is run whereas cron can't specify order.
Version 5 - added configparser to read ini file - the ini file can modify the display to show Farenheit instead of Celsius (default) and can also disable the display being refreshed. Noticed this version breaks the cron job due to Permission Denied when trying to read the ini file.
Version 6 - replaced cron jobs with systemd instead, debugged Permission denied when trying to read ini file, debugged systemd unit file shutdown service causing shutdown to hang when display is not plugged in by removing unit "Requires=".
Version 7 - added software to check if display is plugged in, if not, exit right away.
Licenseomgitskuei/RPiDev is licensed under the GNU General Public License v3.0.
Permissions of this strong copyleft license are conditioned on making available complete source code of licensed works and modifications, which include larger works using a licensed work, under the same license.
Copyright and license notices must be preserved. Contributors provide an express grant of patent rights.
Comments