Have you ever been working on a Pi that is maybe remote, and wondered what board it is running on ?
Well you can actually work it out; but just in case its of any use to anyone, I bashed out this bash script (did you see what I did there…) to do exactly that;
#! /bin/bash
#
# Return the version of the Raspberry Pi we are running on
# Written by Andy Taylor
#
# Pull the Board revision from /proc/cpuinfo
boardRev=`grep 'Revision' /proc/cpuinfo | sed 's/.*: //'`
# Make the board revision human readable
case $boardRev in
[0002]*)
raspberryVer="Model B Revision 1.0 (256MB)"
;;
[0003]*)
raspberryVer="Model B Revision 1.0 + ECN0001 (no fuses, D14 removed) (256MB)"
;;
[0004]*)
raspberryVer="Model B Revision 2.0 Mounting holes (256MB)"
;;
[0005]*)
raspberryVer="Model B Revision 2.0 Mounting holes (256MB)"
;;
[0006]*)
raspberryVer="Model B Revision 2.0 Mounting holes (256MB)"
;;
[0007]*)
raspberryVer="Model A Mounting holes (256MB)"
;;
[0008]*)
raspberryVer="Model A Mounting holes (256MB)"
;;
[0009]*)
raspberryVer="Model A Mounting holes (256MB)"
;;
[000d]*)
raspberryVer="Model B Revision 2.0 Mounting holes (512MB)"
;;
[000e]*)
raspberryVer="Model B Revision 2.0 Mounting holes (512MB)"
;;
[000f]*)
raspberryVer="Model B Revision 2.0 Mounting holes (512MB)"
;;
[0010]*)
raspberryVer="Model B+ (512MB)"
;;
[0011]*)
raspberryVer="Compute Module (512MB)"
;;
[0012]*)
raspberryVer="Model A+ (256MB)"
;;
[a01041]*)
raspberryVer="Pi 2 Model B (1GB) - Sony, UK"
;;
[a21041]*)
raspberryVer="Pi 2 Model B (1GB) - Embest, China"
;;
[900092]*)
raspberryVer="Pi Zero (512MB)"
;;
[a02082]*)
raspberryVer="Pi 3 Model B (1GB) - Sony, UK"
;;
[a22082]*)
raspberryVer="Pi 3 Model B (1GB) - Embest, China"
;;
*)
raspberryVer="Unknown"
;;
esac
#Output
echo $raspberryVer
As suggested by @Jon I think this would be a useful addition to the emonPi part of Emoncms Admin server stats page. Also this is a better method to detect a pi rather than what we currently use ifconfig | grep b8:27:eb:' :
The ifconfig grep falls down when a Pi Model A is used!
Understood on the detection, similarly I can’t rely on this detection method either - because anything that is not a Pi will just be “unknown” at this point.
I will Improve the script and then come back to the Pi detection again.
Is this not the behaviour we want? If “unknown” is returned then we assume the system is not a Pi therefore don’t display the Pi specific items such as type, CPU temp etc.
Your script IDs my Pi as a “Model B Revision 1.0 + ECN0001 (no fuses, D14 removed) (256MB)”
As you can see by the Revision : 3a21041 in my /proc/cpuinfo data, it’s a Pi 2.
Looks like grep is seeing the 3 in the string 3a21041, but not the entire string.
(the 0003 branch in your case construct matches the reported ID)
Adding an echo $boardRev immediately after boardRev=`grep ‘Revision’ /proc/cpuinfo | sed ‘s/.*: //’
shows the variable is indeed getting set to 3a21041.
Here’s a way to strip the leading characters (up to and including the space character immediately preceeding the ID sting) from boardRev without the need for a sub-shell call, i.e. sed:
(Ref: BashFAQ/100 - Greg's Wiki) and BashFAQ/082 - Greg's Wiki
So after some clean up, and some thoughts about how to handle the many un-knowns;
I now have this revised version, this time I check for ARM CPU (vs anything else) and detect (more reliably) the Pi version.
I don’t have access to Banana / Orange / Beaglebone etc to add detection for those, so right now I assume anything that is ARM and not in my list is just unknown. I don’t even know if they show the revision line (something that is also not accounted for at this point).
As Glyn has already realised - yes this little exercise is all in aid of better Pi detection for the emonCMS system
#! /bin/bash
#
# Return the version of the Raspberry Pi we are running on
# Written by Andy Taylor (MW0MWZ)
#
# Pull the CPU Model from /proc/cpuinfo
modelName=`grep 'model name' /proc/cpuinfo | sed 's/.*: //'`
if [[ $modelName == "ARM"* ]]
then
# Pull the Board revision from /proc/cpuinfo
boardRev=`grep 'Revision' /proc/cpuinfo | sed 's/.*: //'`
# Make the board revision human readable
case $boardRev in
*0002) raspberryVer="Model B Revision 1.0 (256MB)";;
*0003) raspberryVer="Model B Revision 1.0 + ECN0001 (no fuses, D14 removed) (256MB)";;
*0004) raspberryVer="Model B Revision 2.0 Mounting holes (256MB)";;
*0005) raspberryVer="Model B Revision 2.0 Mounting holes (256MB)";;
*0006) raspberryVer="Model B Revision 2.0 Mounting holes (256MB)";;
*0007) raspberryVer="Model A Mounting holes (256MB)";;
*0008) raspberryVer="Model A Mounting holes (256MB)";;
*0009) raspberryVer="Model A Mounting holes (256MB)";;
*000d) raspberryVer="Model B Revision 2.0 Mounting holes (512MB)";;
*000e) raspberryVer="Model B Revision 2.0 Mounting holes (512MB)";;
*000f) raspberryVer="Model B Revision 2.0 Mounting holes (512MB)";;
*0010) raspberryVer="Model B+ (512MB)";;
*0011) raspberryVer="Compute Module (512MB)";;
*0012) raspberryVer="Model A+ (256MB)";;
*a01041) raspberryVer="Pi 2 Model B (1GB) - Sony, UK";;
*a21041) raspberryVer="Pi 2 Model B (1GB) - Embest, China";;
*900092) raspberryVer="Pi Zero (512MB)";;
*a02082) raspberryVer="Pi 3 Model B (1GB) - Sony, UK";;
*a22082) raspberryVer="Pi 3 Model B (1GB) - Embest, China";;
*) raspberryVer="Unknown ARM based System";;
esac
echo $raspberryVer
else
echo "Generic "`uname -p`" class computer"
fi
My Pi 3 idles at 600MHz and hits 1.2GHz under load, my Pi 2 does similar things (although its not running the OpenEnergyMonitor image).
So you might not be “Overclocked” but depending on the kernel / system you are running on, you might not need to set those features.
The reason I ask about over volt - once you have over-volted the Pi just once, it registers that in the SOC, and I believe the version number is where that is set - as usual, quite prepared to be wrong about that
Understandable, since the Pi 3 max clock freq is 1200 MHz.
Here’s one I didn’t know about until today:
When running lscpu or cat /proc/cpuinfo the reported processor ist (sic) ARMv7. To tell the RPi3B to start in ARMv8-mode you have to add a new line to config.txt: arm_control=0x200
Ref: RPiconfig - eLinux.org
Locking my Pi 2 at 900 MHz seems to make it a bit more responsive, while staying within spec’d maximums. All of my Pis are in enclosures, so to keep the operating temps reasonable, I’ve never overvolted or overclocked them.
I knew about setting the overvolt bit (and how that used to void your warranty), but I havent got a clue about where the version number is stored.