raspberry pi utilities – rpinfo

rpinfo (or rpinfo.sh) is a Bash script that I’ve written over time to print out key statistics of my various Raspberry Pi systems. And when I say various, I mean various. Since 2013 I’ve slowly accumulated various versions of the Raspberry Pi, including several Raspberry Pi Zeroes, to the point where I now have over a dozen of the little critters sitting around and doing things.

The script will look for and if found, query certain applications I care about. Except for calling the external tools to get their versions, I’ve tried to keep everything within Bash itself, especially using Bash’s built-in string and array features. Of course it doesn’t always turn out that way. The use of cat (concatenate and print files), tr (translate characters), sed (stream editor) and grep (globally search a regular expression and print) is so deeply engrained in the way I write scripts due to decades of use.

Looking at the screen capture above, there are a few interesting items to call out. At the very top is the name of the board including revision. This is followed by a block of statistics that includes the CPU type and the OS Description. At the very bottom is the filesystem size. Yes, I have a 128GB Sandisk micro SDXC card installed. It’s an Extreme and I’ve been slowly picking them up from my local Costco because Costco has been selling them in a two pack for US $30. They’re high performance with lots of elbow room. With a 128GB card in the Raspberry Pi 4 I have a computer that exceeds my desk side Dell tower I was using in the early to mid 2000s.

The way I use this script is to have a copy on every Raspberry Pi I have in the house. It’s just a quick way to catalogue the critical features I need. It’s my hope you find this useful, either in whole or some of its parts.

#!/usr/bin/env bash## Copyright (c) 2019 William H. Beebe, Jr.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.## ------------------------------------------------------------------------------## Simple Bash script to display information about any Raspberry Pi board in# inventory.## Note that for the version string we have to use tr to substitute the ending# null byte for a newline, or else a warning about null is emitted by the# latest versions of Bash.#model=$(cat /proc/device-tree/model | tr '\0' '\n')echoecho " ${model}"echomemTotal=$(cat /proc/meminfo | grep MemTotal | sed 's/:/ :/' | sed 's/ */ /g')echo " ${memTotal}"# Look for the explicit processor/core type (i.e. 'Cortex-A53')#data=$(lscpu | grep 'Model name:')wordarray=(${data//:/ })echo " CPU Type : ${wordarray[2]}"# Look for the core count. Use wc (word count) to count lines (-l).#coreCount=$(cat /proc/cpuinfo | grep processor | wc -l)echo " Core Count : ${coreCount}"hardware=$(cat /proc/cpuinfo | grep Hardware | tr '\t' ' ')echo " ${hardware}"revision=$(cat /proc/cpuinfo | grep Revision | tr '\t' ' ')echo " ${revision}"echokernelRevision=$(uname -r)echo " Kernel Release: ${kernelRevision}"description=$(lsb_release --all 2>/dev/null | grep Description | tr '\t' ' ')echo " OS ${description}"echoecho " Tools"version=$(git --version)echo " Git: ${version}"echoecho " Languages Installed"golang='/usr/local/go/bin/go'if [ -e ${golang} ]thenversion=$(${golang} version)echo " Go: ${version}"elseecho " No Go found."firustlang="$HOME/.cargo/bin/rustc"if [ -e ${rustlang} ]thenversion=$(${rustlang} --version)echo " Rust: ${version}"elseecho " No Rust found."fi# Redirect stderr to stdout for Python 2 version, because# that's they way they did it, printing version string to# stderr...version=$(python -V 2>&1)echo " ${version}"version=$(python3 -V)echo " ${version}"version=$(pip3 -V)wordarray=(${version})echo " Pip ${wordarray[1]}"version=$(gcc --version)wordArray=(${version})echo " Gcc ${wordArray[3]}"echodf -kh .echo

raspberry pi 4 cpu temperature observations

The short video above shows the Adafruit Feather displays attached to the Raspberry Pi 4, along with the micro:bit and scroll:bit I wrote about last post. The Adafruit Feather work was done over a year ago. You can find and read about it in the section Golang.

Basically I’m using the USB as well as the GPIO/I2C connections to drive a number of devices. In one terminal I have tempmonitor.py running, and in another I have a Bash script, clock.sh, running. The Bash script uses some of the Go developed apps to manipulate the Adafruit Feather displays using I2C. The Bash script simply displays the system time, sleeps a bit, and then displays the system date. Then it repeats. The script for this is at the bottom of the post.

Observations

  • I’ve taken the top off the official Raspberry Pi 4 case. It’s open now, and as a consequence the CPU is now running a good 15C cooler than it was with the top on. Which begs the question who designed that case that way without any vents at all for circulation of the heat out of the enclosure.
  • Running the same code on the Raspberry Pi 3B+ shows the CPU temp to be a good 20C cooler, and this board is in a case. The case has a lot of ventilation holes in it, and thus probably helps it run cool. Furthermore, that CPU has a heat sink attached to it as well.
  • When the Raspberry Pi 4 is running cooler, the entire board is running cooler, especially the USB chip itself. When it’s hot, USB communication is intermittent and can be seen when the micro:bit/scroll:bit fails to scroll the temperature sent to it. I’ve debugged the original Python script, and know when it’s sending a message to the micro:bit when I see a corresponding message on the terminal. About one out of every eight attempts to send a message fails when the CPU is registering 75C. At this much cooler temperature (around 55C) all messages are sent across and scrolled. You can draw your own conclusions.
  • I’ve ordered a Flirc aluminum case which has a heatsink that’s part of the case and is designed to pull heat away from the CPU. I don’t know when it’ll arrive since this was a pre-order, but it was only about US $12, so I figured why not.
#!/bin/bash## Copyright (c) 2019 William H. Beebe, Jr.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.## ------------------------------------------------------------------------------## A simple clock that uses the Bash shell to send the Unix date and time to a# pair of Adafruit displays.## CTRL C is trapped to turn off the displays before exiting from the script.#trap ctrl_c INTfunction ctrl_c() {display clear > /dev/nullexit}## Get the date from the Unix date command, using +%r to get the time formatted# in the locale's time format. This will give it in 12 hour format, with an# AM or PM. Then use the Bash shell's built-in regex to replace the last ':'# and second digits with a space, so that the time string is in the format# '12:00 PM' and will print across the eight Adafruit hexadecimal digits.#while true; doDATE=$(date +%r)display print "${DATE//:[0-9][0-9] / }" > /dev/nullsleep 3DATE=$(date +%D)display print "$DATE" > /dev/nullsleep 3display clear > /dev/nulldone