Skip to content

Instantly share code, notes, and snippets.

@Jachimo
Created June 29, 2023 21:49
Show Gist options
  • Save Jachimo/b0912589cef695eb4997c099fca7ee84 to your computer and use it in GitHub Desktop.
Save Jachimo/b0912589cef695eb4997c099fca7ee84 to your computer and use it in GitHub Desktop.
PiFlavor: Report model and version of a Raspberry Pi programmatically
#!/usr/bin/env python3
# Script to check the hardware version of a Raspberry Pi
# REQUIRES PYTHON 3.5+
import sys
# Following information based on https://elinux.org/RPi_HardwareHistory
pi_revisions = {
'9020' : '3 Model A+ (Sony, UK)',
'900021' : 'A+ (Sony, UK)',
'900032' : 'B+ (Sony, UK)',
'900092' : 'Zero (Sony, UK)',
'900093' : 'Zero (Sony, UK)',
'902120' : 'Zero 2 W (Sony, UK)',
'920093' : 'Zero (Embest, PRC)',
'0002' : 'B',
'0003' : 'B with ECN0001',
'0004' : 'B (Sony, UK)',
'0005' : 'B (Qisda, PRC)',
'0006' : 'B (Egoman, PRC)',
'0007' : 'A (Egoman, PRC)',
'0008' : 'A (Sony, UK)',
'0009' : 'A (Qisda, PRC)',
'000d' : 'B (Egoman, PRC)',
'000e' : 'B (Sony, UK)',
'000f' : 'B (Qisda, PRC)',
'0010' : 'B+ (Sony, UK)',
'0011' : 'Compute Module 1 (Sony, UK)',
'0012' : 'A+ (Sony, UK)',
'0013' : 'B+ (Embest, PRC)',
'0014' : 'Compute Module 1 (Embest, PRC)',
'0015' : 'A+ (Embest, PRC)',
'9000c1' : 'Zero W (Sony, UK)',
'a01040' : '2 Model B (Sony, UK)',
'a01041' : '2 Model B (Sony, UK)',
'a02082' : '3 Model B (Sony, UK)',
'a020a0' : 'Compute Module 3 / CM3 Lite (Sony, UK)',
'a020d3' : '3 Model B+ (Sony, UK)',
'a02100' : 'Compute Module 3+ (Sony, UK)',
'a03111' : '4 Model B (Sony, UK)',
'a21041' : '2 Model B (Embest, PRC)',
'a22042' : '2 Model B with BCM2837 (Embest, PRC)',
'a22082' : '3 Model B (Embest, PRC)',
'a32082' : '3 Model B (Sony, JP)',
'b03111' : '4 Model B (Sony, UK)',
'b03112' : '4 Model B (Sony, UK)',
'b03114' : '4 Model B (Sony, UK)',
'b03115' : '4 Model B (Sony, UK)',
'Beta' : 'B Beta',
'c03111' : '4 Model B (Sony, UK)',
'c03112' : '4 Model B (Sony, UK)',
'c03114' : '4 Model B (Sony, UK)',
'c03115' : '4 Model B (Sony, UK)',
'd03114' : '4 Model B (Sony, UK)',
'd03115' : '4 Model B (Sony, UK)',
}
with open('/proc/cpuinfo', 'r') as f:
cpuinfo = f.readlines()
revline = ''
for line in cpuinfo:
if line.startswith('Revision'):
revline = line # we only care about last 'Revision' line
if not revline:
print("Revision not found in /proc/cpuinfo!")
sys.exit(1)
revision = revline.split()[-1]
print(f"Hardware revision: {revision}")
if revision[:4] == '1000':
print("Unit is over-volted")
revision = revision[4:]
print(f"Model is: Raspberry Pi {pi_revisions[revision]}")
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment